Track Downloads Using Google Analytic Events

For the PocketNotes application, I added the new google analytics code to the php index page. I also added a GA Event for when an application download button is clicked. The first script will let me know when a user visits the page. The second script will let me know when a user has downloaded an application from the website.

I followed the instructions to embed google analytics code dynamically using the information at google analytics.

First I created a php include file, nimAnalytics.php, that has the javascript snippet containing the latest Asynchronous version of GA tracking code:

<?php
	//analytics
	echo '<script type="text/javascript">

		var _gaq = _gaq || [];
		_gaq.push([\'_setAccount\', \'UA-XXXXXX-X\']);
		_gaq.push([\'_trackPageview\']);

  (function() {
    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
  })();
  </script>
  '
  
?>

This allows me to change the code in one place and then deploy it on many different php pages by including the following in a php file within the <head> tags:

<?php 
	//new asynchronous GA code to be used for tracking 
	require_once "nimAnalytics.php"; 
?>

I used the event tracker guide to setup tracking for when a user downloads an application based on the information at this google site. An example snippet from this web page is listed below:


<p><a class="awesomeButton" href="./../download.php?file=/pocketnotes/PocketNotesSetup.exe" 

onclick="_gaq.push(['_trackEvent', 'Downloads', 'EXE', 'PocketNotesSetup.exe']);"

target="_self">PocketNotes 1.0 (EXE Installer)</a><br />

This package contains everything you need to use NIM PocketNotes. Simply
download the EXE file above, run it and follow the steps of the installation program.

You need local installation rights.

</p>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: