English 中文(简体)
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 visible 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:





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签