开发者

Google Analytics to track FireFox extension use

I'm developing a Firefox extension and would like to track its use with google analytics, but I can't get it working.

I've tried manually calling a function from ga.js, but that didn't work for some reason. No error was produced, but neither was any data collected.

My last attempt was to have a website that just holds the tracking javascript and then load it within the extension in an iframe with the URL configured so it contains meaningful data. This way the analytics are getting connected when I visit said webpage with a browser, but not in an extension. I've tried putting some v开发者_如何学Cisible javascript on the site and have confirmed the site's javascript is executing. This method also works with other trackers, but I don't like their output and would prefer Google Analytics.

Any ideas what else I could try to accomplish this?


The solution is to use Remy Sharp's mini library for tracking bookmarklets and extensions with Google Analytics. Works like a charm.

Usage is as simple as:

gaTrack('UA-123456', 'yoursite.com', '/js/script.js');

Note that, since it doesn't use cookies, there's no differentiation between pageviews and visits, or for that matter, between visits and visitors. But, the rest of the functionality is fairly reliable.


Depending on what you want to track you may not need Google Analytics. Mozilla's addon.mozilla.org portal already provides comprehensive tracking and usage statistics for addons.

To check if Mozilla provides what you need go to the Statistics Dashboard and choose the statistics for one of the publicly available addons.


Here is a small library to proxy the requests through an iframe hosted on another server: https://github.com/yelloroadie/google_analytics_proxy

This gets around the bug in the add-on sdk that causes ga.js to die (https://bugzilla.mozilla.org/show_bug.cgi?id=785914).

This method allows full use of google analytics, unlike the limited use found in the library by Remy Sharp.


I don't think this is possible. Firefox extensions don't allow you to load pages from other servers. So the only way I can think of is to have an invisible iframe load up the code. The pings to Google's servers need to be from a domain belonging to you. So I guess your own servers have to serve up pages every time a user loads the extension, which just kills your server and defeats the purpose of Google doing all the work!! Please post if you have found a way around it. Chrome extensions can be tracked easily!


For using analytics in the main/background script you might want to use this solution: https://stackoverflow.com/a/17430194/193017

Citing part of the answer:

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:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜