Possible to use GA to track events in a 3rd party widget? Can it work side-by-side site analytics?

Showing 1-5 of 5 messages
Possible to use GA to track events in a 3rd party widget? Can it work side-by-side site analytics? chrisbsides 7/13/11 9:39 AM
Hi,

I'm developing a 3rd party JavaScript widget that I always host.  Is Google Analytics an option for me?  I am a big fan of the reporting and async event support, but I don't think this is likely to work since I'll probably be interfering with a client's website's own GA integration.

<code>
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);
</code>

It looks like a singleton to me and _maybe_ i could set the account to mine, post my analytics, and return it to the client account, but this seems risky and kludgy.

I just wanted to see if anyone else has attempted this or has other ideas?

Thanks in advance!
Re: Possible to use GA to track events in a 3rd party widget? Can it work side-by-side site analytics? chrisbsides 7/13/11 10:14 AM
It looks like this may be possible:

Pushing commands to multiple trackers also works.

_gaq.push(
  ['_setAccount', 'UA-XXXXX-1'],
  ['_trackPageview'],
  ['b._setAccount', 'UA-XXXXX-2'],
  ['b._trackPageview']
);

Hopefully anything under "b" is isolated.  I'll give this a shot.
Re: Possible to use GA to track events in a 3rd party widget? Can it work side-by-side site analytics? chrisbsides 7/13/11 10:14 AM
(Adding reference)
Re: Possible to use GA to track events in a 3rd party widget? Can it work side-by-side site analytics? msmtech 10/7/11 10:42 AM
We have a javascript widget that we provide to third party sites.  Basically it is called through a basic script src tag <script type="text/javascript" src="http://ourwidgeturl.com/widget.js"></script>

Our widget returns a html output through document.write tags.  We want to include google anayltics in the javascript code so that we can track impressions, sources, etc.  I have implemented it as follows, and that does call GA, but the GA reports do not include the full domains of the site that is calling the widget, just the relative paths of the files that are calling the page.

I am also concerned that this code may interfere with GA code that our partners may have imeplented on their pages for their own tracking purposes.

Is this the correct way to be doing it?  How can I make it so that GA reports have the full names, instead of reletive paths, and could this cause any issues with their own GA code?

document.write('widget output in html code');
  var _gaq = _gaq || [];
  _gaq.push(["_setAccount", "UA-XXXXXX-X"]);
  _gaq.push(["_trackPageview"]);
  (function() {
    var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
    ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
    var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
  })();
Re: Possible to use GA to track events in a 3rd party widget? Can it work side-by-side site analytics? chrisbsides 10/8/11 9:30 AM
Hi,

You may want to try to namespace you GA calls as mentioned above (see b._setAccount, etc). This should stop any conflicts with the host page. As to your other question it sounds worth starting a new help thread, as I haven't seen that in my setup.

The biggest difference in our approaches is your document.write which frankly sounds a little scary for a widget to be doing but I assume you've done plenty of testing around it