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

  • 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. Sep 3, 2011 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, 2011 at 7:31

1 Answer 1


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]);
  // ...

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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