What is the best way to load tracking in php / java script?

if I like to track and receive all possible information about users downloading my application without forcing them to register
what is the best php script for? or is the best method for managing downloads?

+4
source share
4 answers

This is the perfect use case for tracking Google Analytics events . This is fairly easy to implement, although you will need a Google Analytics account (obviously). Here is sample code in jQuery.

$(function() { $('#myDownloadLink').click(function() { var tracker = _gat._getTracker('UA-xxxxxx-x'), // get the analytics tracker - your UA code href = this.href, // get the href - the file downloaded page = location.pathname.toLowerCase(); tracker._trackEvent(page, 'download', href); // tracks the event }); }); 

Using GA allows you to access your analytics everywhere and gives you a decent set of filtering tools. In fact, if you need more detailed information, you can track it as a pageview, and not (or how) an event:

 tracker._trackPageview('/download/' + href); // tracks as a page view 

You can even add the current page to this to find out where the download came from. You will receive information about the browser, operating system, screen resolution, country of origin, etc.

+2
source

If you do not want to register them, all you can get is:

  • IP address
  • Browser Information
  • Information about the system (computer)
  • Loading time.

To get the IP address of a user in PHP, use this:

  $IP = $_SERVER['REMOTE_ADDR']; 

Then you can use GeoIP tools to get your country or city if you want.

And to get information about the browser in PHP, use get_browser() .

+1
source

Here is an open source project written in php and javascript that does just that: http://www.warefeed.com

0
source

+1 for Ryan Kinal's answer . I like the idea of ​​using an already proven and working solution for this. Much less hassle than writing something yourself.

If you don’t want to use googles tools, but you have full control over yourself, you can watch Piwik , a web statistics tracker that provides similar functionality for Google Analytics, written in php, open source and hosted on your own server. Thus, you have access to the collected data. Like google, it provides many graphs, features, and ways to track user movements through your site.

http://piwik.org/

0
source

All Articles