Tuesday, November 15, 2011

Google Analytics to track calls to a ajax json response

Google Analytics provides an easy way to track clicks on links that lead to file downloads. Because these links do not lead to a page on your site containing the tracking code, you'll need to tag the link itself with the _trackPageview() JavaScript if you would like to track these downloads. This function assigns a virtual pageview to any click on a link - the pageview is applied to the filename you provide in the function call.

For details on how to use this in your links, see Virtual Pageviews in the Asynchronous Migration Examples guide, which shows how to do this in all versions of the tracking code. The following example shows how you might fabricate a link using the asynchronous tracking code:

<a href="http://www.example.com/files/map.pdf" onClick="javascript: _gaq.push(['_trackPageview', '/downloads/map']);">

To verify that _trackPageview is being called correctly, you can check your Top Content report 24-48 hours after the updated tracking code has been executed. You should be able to see the assigned pagename in your report.

Reference:
http://www.google.com/support/analytics/bin/answer.py?answer=55529
http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html#VirtualPageviews

No comments: