开发者

Track direct file downloads with google analytics

I have a django project in which a user will type in a url and they will get served an image. This image is not embeded in anything and is served directly as an image. Does anyone know any neat trickery that I can use to track my traffic with google analytics?

I know that you can use the onclick events to track file downloads. This is not a solution to my problem because the request does not originate from a mouse click or even from my own web page.

Just to clarify. My service may NEVER render an html page or any page that I can embed and run javascript. Basically, I'm just serving files from various URLs that a user types into their browser or directly 开发者_如何学运维links from their web site.


Well, I eventually dug up my own answer and figured I should post it here.

The search term I needed and eventually came across is "Server Side Google Analytics"

Google has an example written in php. Found Here.

And I found this nice python implementation. Found Here on Github.

And finally, Google has a python module called gdata that is designed to assist with handling calls to many of their APIs, including Analytics.


Well, once you catch and identify the relevant event (which seems to be just a user entering a url for a particular image resource, into a text box), then you can pass any identifier you like to the relevant GA method so that the action you wish to track is identifiable in your GA data.

So, a user entering a valid url into the text field should cause pageTracker._trackEvent to fire, and send to the GA servers, a request to increment that event by one. I suppose you want an event handler that is dispatched when the user types in the text box (.change() ?) though perhaps passing a validation check (valid url and with directory and file name matching one of those in a list you gave the validator).

?How will you know which image the user downloaded? (i assume there is more than one.) There are several ways you can do this, perhaps you can use the last two parameters in the _trackEvent method signature (in total, there are four of them, category, action, opt_label, opt_value)--e.g., bind either opt_label or opt_value to the particular value (url string) entered in the text box. And as you know, you can easily map a multiple urls each to a corresponding resource id which is recorded in GA and is also incremented.


My service may NEVER render an html page or any page that I can embed and run javascript. Basically, I'm just serving files from various URLs that a user types into their browser or directly links from their web site.

Then you won't be able to track data of users which download those files with Google Analytics.

The only data you'll have is the log file of your web server.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜