Our widget works as a client, including a javascript file on its website. Our javascript code adds the widget to the right places on the page.
Adding Google Analytics was pretty simple: I added the GA code to the javascript file uploaded by the client site:
// setup google analytics var _gaq = _gaq || []; _gaq.push(['REPLACE_WITH_SOME_UNIQUE_NAMESPACE._setAccount', 'REPLACE_WITH_YOUE_GA_ID']); _gaq.push(['REPLACE_WITH_SOME_UNIQUE_NAMESPACE._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); })();
I also track other specific events directly from our Javascript:
_gaq.push(['REPLACE_WITH_SOME_UNIQUE_NAMESPACE._trackEvent', 'REPLACE_WITH_YOUR_EVENT_CATEGORY', 'REPLACE_WITH_YOUR_EVENT_ACTION']);
Attention!
You must use the namespace to avoid a collision with the GA site (if any)
You need to set up a Google Analytics profile to display the host. Google has a good explanation for this in here (under "Change your cross-domain network profile with a filter to show the full domain in your content reports")
For now, this approach works fine if you make sure that the cookie configuration (domain, etc.) is similar to the hosting site. If, for example, the host domain is different, it can cause duplicate images.
davidrac
source share