views:

35

answers:

4

I am running a Image gallery website which can be used to download images... say if you call somedomain.com/flowers it will return a zip file containing top 10 flower images....

Now my requirement is to track these downloads.. how can I implement this.. any possibility to use Google Analytics.

Update: I forgot to add another important thing because of which I can't use custom events...

It is not necessary to always click and download a zip file.... I have created a little app (AIR application) to directly download the file.In that case I can't able to use any GA script... I want to know whether it is possible to use GA in this case if yes then how to implement?

A: 

Fire a custom event when the user clicks on the download link.

rjack
A: 

The two basic ways are event tracking (registering the click) and the other is by a virtual 'pageview'. The problem with the first is that clicks are less reliably measured; the problem with the second when the user clicks the link, trackPageview might not have time to execute. One common solution is to use the virtual pageview technique and add a small timer to cause a 100 millisecond delay:

In practice, you need two pieces of js code--one to modify the a href tag by binding the onclick handler to a function, and the other to create that function: (shown first, below)

<script type="text/javascript">
  function obl(this) {
    try {
      var pageTracker=_gat._getTracker("UA-XXXXXXX-X");
      pageTracker._trackPageview("a_download_link");
      setTimeout('document.location = "' + this.href + '"', 100)
    }catch(err){}
}
</script>



<a href="a_download_link" onclick='obl(this);return false;'>Click Here to Download</a>


If you are using the newest (asynchronous GA Code) replace the function above with this one:

<script type="text/javascript">
  function obl(this) {
    _gaq.push(['_trackPageview', 'a_download_link'+this.href]);
    setTimeout('document.location = "' + this.href + '"', 100)
  }
</script>

One complication this technique introduces is that it causes your downloads to be co-mingled with your page view totals. As long as you are aware of it, it's trivial to deal with--just create a filter to remove these 'false' page views. Similarly, to actually show the downloads in the GA Browser, you might want to create a separate profile (e.g., 'Downloads') and then create an 'Advanced Segment' by filtering all page views except the download page views.

doug