Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have written an advertising system for a client that serves adverts on one website (say, www.adhost.com) as a small HTML page and a second website (say, www.addisplay.com) pulls this page in as an iframe to be displayed as an advertising banner. Google Analytics is present in the adverts in order to track clickthroughs, but the clicks are being tracked under www.adhost.com's profile because the clicks are occurring within the iframe and Analytics knows no better.

Would it be possible to make these clicks track under www.addisplay.com's profile, even though they are occurring within a page hosted on www.adhost.com? If so, how?

Thanks, Alex

share|improve this question

migrated from stackoverflow.com Sep 4 '11 at 22:04

This question came from our site for professional and enthusiast programmers.

    
Why reinvent the wheel and write an advertising system? Try to use doubleclick (dfp small business is free for up to 90M ad impressions/month) or OpenX. –  eduardocereto Sep 3 '11 at 0:46
    
unfortunately that was not my call, I inherited this project and had to make do with what I got. I know I said I wrote the system but I guess I should've said "I have been extending a client's advertising system". –  mrnoob1 Sep 5 '11 at 7:31

1 Answer 1

up vote 2 down vote accepted

You would need to pass their account variable as a parameter to the iFrame. You could then grab it (via server side or JS) and throw it into the GA call.

<iframe src="adhost.com/displayad.php?ga=UA-XXXXXXXX-X">

.. in displayad.php:

var GAaccount = 'UA-XXXXXXXX-X'; // grabbed via server side or custom JS function
<script type="text/javascript"> 
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', GAaccount]);
  // ...
</script> 

This will get you at least pageviews for the ads. You'll probably want to do a couple of other things:

  1. Since the cookies will be on different domains (one on addisplay.com and one on adhost.com) you'll also want to do things like _gaq.push(['_setAllowLinker', true]); and an onclick with _gaq.push(['_link', 'ad.destination.url']). This will keep the visitor's session across the domains.
  2. Add on extra campaign details using utm_source,utm_medium,etc. You can easily build these links here of you so desire - I'd strongly suggest doing this.

Like eduardocereto mentioned, this isn't the best way to go about this... but hopefully this helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.