I would like to use Google Analytics Event tracking for my Firefox addon. I have included ga script like this in my popup.html.
<script src="http://www.google-analytics.com/ga.js"></script>
And also added:
<script >
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
</script>
I push events with the following code:
_gaq.push(['_trackEvent', 'example', 'clickedit']);
I dont see any error in the firefox error console and also the event is not there in the analytics page.
Any idea? Does firefox doesn't allow this?
Thanks
This is the bug that causes GA to break in the panel module: https://bugzilla.mozilla.org/show_bug.cgi?id=785914
Even if this was fixed, Mozilla won't allow the inclusion of ga.js due to the obfuscated source and security concerns. So you can't distribute your add-on via their addons.mozilla.org if you include ga.js.
To workaround all of this:
I created an iframe hosted on my server to proxy the analytics requests through. The code is on github here: https://github.com/yelloroadie/google_analytics_proxy
I hope this may be of some use to you.
I would suggest you take a look at the new Measurement Protocol in Universal Analytics:
https://developers.google.com/analytics/devguides/collection/protocol/v1/
This allows you to use XHR POST to simply send GA events directly.
This will coexist much better with Firefox extensions.
The code would look something like this:
Note that you'll have to create a new property in Google Analytics so you can specify it as Universal Analytics.