views:

27

answers:

1

I'm writing a widget that will be embedded in other people's websites. I'm using Google Analytics to track all the people that visit all instances of my script on the embedding websites. I understand that the new asynchronous tracking code resolves this problem so that there's no interference with those websites' own Google Analytics accounts.

However, what if my analytics tracking code uses the new asynchronous tracker, and the embedding website is using the legacy (traditional) tracking code? Would there be any interference between these two blocks of code?

My tracker code:

<script>
...
_gaq.push(
  ['myTracker._setAccount', 'UA-XXXXX-2'], // naming the tracker 'myTracker' to be different from any default tracker already defined
  ['myTracker._trackPageview']
);
...
</script>

Embedding website's code:

<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-1");
pageTracker._trackPageview();
} catch(err) {}</script>

Can pageTracker and myTracker co-exist and register analytics information to their own separate accounts?

A: 

As far as official advice goes this is not a supported scenario:

And there are pitfalls:

When you say embedded in peoples websites if you mean that your widget lives inside an iframe then you dont need to worry.

If the code is going to be loose in the page then you should try to use a different variable name to the default one so it doesn't clash. This means change the var _gaq = ... to something else and then renaming it throughout your code.

I'm not entirely clear on your setup but if it is being inserted into many domains you are going to need to set up multiple GA accounts and use different account numbers per user.

If this is for clients that you have access to then you might consider simply adding an extra user to the report so that you can view all the accounts from one central account:

rtpHarry