1

I have a page with a series of links to Greasemonkey userscripts. The userscripts have @updateURL parameters set, so that when I upload a new version to the page people who have the script installed either have their version of it updated automatically or are asked if they want to upgrade.

This all works fine. I have Google analytics installed on the hosting page, so I can see how many hits the page gets, but what I would like to know is how many people are getting the updates.
The normal analytics won't work because they all rely on somebody clicking on a link, but Greasemonkey downloads the updated file without clicking on anything (or, as far as I can tell, triggering a page hit in analytics).

I'm assuming I need a server-side solution, but I have no idea what it would look like. Maybe all the above about GM is irrelevant, and the simple question is:
How can I track how many times a file is downloaded from my server (without relying on counting clicks on download links)?

[EDIT FOR FURTHER INFO]

@Brock Adams Thank you for the answer - it was very detailed and exactly what I was looking for. I wasn't aware of the separate meta.js option, but reading a little into it I see that it's a good idea anyway as it means that only the meta.js file has to be downloaded (as opposed to the entire user.js file) when checking for updates. When I set this up, auto-updates were kind of new and there wasn't much documentation around about them. I still can't find much, so I wonder if you could clarify. The metadata in the main user.js file stays the same, just with a pointer to meta.js in the @updateURL and without the version number, ie:

// ==UserScript==
// @namespace   http://namespace.com/userscripts
// @description some description. 
// @downloadURL https://namespace.com/userscripts/example.user.js
// @updateURL   https://namespace.com/userscripts/example.meta.js
// @include     https://example.com/*
// @grant       none
// ==/UserScript==

and then all example.meta.js has to have is

// ==UserScript==
// @version 2.1
// ==/UserScript==

is that correct? thanks again.

lucas
  • 1,485
  • 13
  • 22

1 Answers1

2

The only way to do this is to process your HTTP server logs (kept by Apache, Nginx, etc.). Google analytics cannot do this because it relies on running its own javascript -- something that is bypassed on script updates and direct downloads.

You can access your raw HTTP logs from your host control panel or via FTP. See your host company for more information.

In a raw log, a direct download typically looks like this:

107.178.216.165 - - [12/Jun/2014:17:22:35 -0500] "GET /test/Alert.user.js HTTP/1.1" 200 37 "-" "Mozilla/5.0 {redacted} Firefox"

Note the lack of referrer (The "_" column just before the browser info), and these are often the only request from a given IP address for that session, whereas typical page requests GET several files per session.

Unfortunately, the standard log-analysis programs, provided by most hosts are Webalizer and Awstats. Neither one of these will help you track downloads as-is. But, you can set up a custom AWStats config file and configure it to view *.user.js files as downloads (See this answer for a possible recipe).


Important: When Greasemonkey checks for updates, it downloads the file specified by @updateURL (or by @downloadURL if @updateURL is not specified) -- just to compare the version numbers.

So, to track real downloads, always use a separate *.meta.js file for the @updateURL directive. This will avoid having routine checks counted as downloads.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • @lucas, when you edit your comment, or your question, I don't see alerts for the changes. Use a new comment. As for your additional question, I think so, but I'd have to test to make sure. – Brock Adams Jun 13 '14 at 05:27
  • OK, thanks again. I will test it out and post back if I find anything noteworthy. – lucas Jun 13 '14 at 16:30