You are on page 1of 14

Implementing Google Analytics

A Conversion Sciences Guide Brian Massey, The Conversion Scientist

2011 Brian Massey. All rights reserved.

Table of Contents
Why is Analytics is So Important? ............................ 3 The Conversion Sciences Helper Code ..................... 4 Visitors who click on links that take them to another URL ......................................................... 5 Visitors who are taken to another web site when they complete a form .......................................... 5 Visitors who download a file ................................ 5 Vistiors who login or complete a form ................ 5 Setting up Google Analytics Correctly...................... 6 Signs your Google Analytics Isnt Setup Right...... 6 The Google Analytics Code Appears at the Bottom of the Pages ............................................ 7

The Asynchronous version of Google Analytics is Being Used ........................................................ 7 Implementing the Conversion Sciences Helper Code .................................................................................. 8 The Conversion Sciences Helper Code ..................... 9 The Conversion Sciences Helper Code ............... 10 Tracking Links that Lead Off-site ............................ 11 Implementing Helper Code in Drupal .................... 12 Custom Code Snippets ....................................... 12 Implementing Helper Code in Wordpress ............. 13

Why is Analytics is So Important?


Were not using them right now. Your analytics data is a database of behavioral market research on your audience. Once you have collected an entire years worth of data, you can ask some very helpful questions, questions you may not have yet. What pages make visitors run in fear? Which topics are of most interest to my readers? Which pages tend to increase purchases? What makes visitors buy more than others? You may not have these questions today, but if you instrument your site properly with analytics, you

can go back and ask any of these questions and more. Its like asking your past visitors their opinion without the delay and trouble of sending out a survey. Guessing doesnt work. Think if the leads or sales youll miss by guessing wrong. Go ahead and add this free tool, Google Analytics to your site, so youll be ready when you start asking the hard questions.

The Conversion Sciences Helper Code


There are a few things that every site should measure, so that when you start asking questions, the data will be there to give you answers. There are two ways to track visitor actions in Google Analytics, and the helper code offers functions to support them both. 1. Virtual URLs (or Fake URLs) 2. Events We will use a combination of virtual URLs and Events to track visitor behaviors. We prefer virtual URLs when we want an action to be included in a conversion funnel.
Figure 1: Funnel reports tell us when visitors leave the path toward conversion.

The Conversion Sciences Helper uses both virtual URLs and Events to track visitor actions. These include:

Visitors who login or complete a form


Visitors that login to our online system identify themselves as existing customers or repeat visitors. This is very helpful information to track.

Visitors who click on links that take them to another URL


Well want to know which page they left from, and where they went, specifically.

Visitors who are taken to another web site when they complete a form
This happens frequently when your shopping cart is on another domain.

Visitors who download a file


We want to know when someone downloads a file, such as a PDF. This is tracked as an Event.

Setting up Google Analytics Correctly


The first step is to create a Google Analytics account and to set it up on your site correctly. You can setup your account by visiting: http://conversci.com/GoogleAnalytics You must add some instructions, or code to each web page on your site. To access the right code for your site, start here: http://conversci.com/GetStartedWithGA

Figure 2: Get Started with Google Analytics Help

Signs your Google Analytics Isnt Setup Right


Google Analytics has changed over the years, and if you have GA installed already, it may be out of date. In particular, look for these things: 6

The Google Analytics Code Appears at the Bottom of the Pages


Google Analytics used to be placed at the bottom of the page so that the loading of the code didnt impact the load time of the page. Slow load times will decrease your conversion rate. Your GA code should be at the top of the page, before the </head> tag. See Figure 3. 1. Open any page that has GA installed in a browser. 2. Right-click on the page and select View Source from the context menu that appears. 3. Press Ctrl+F to open a page search dialog box. Enter _trackPageview

4. If found, then you can see if it is near the top of the page (before </head>) or near the bottom of the page (before </html>).

The Asynchronous version of Google Analytics is Being Used


To check to see if you have the most recent version of Google Analytics, follow the steps outlined previously. In step 3, enter ga.async into the search field. If found, you have the asynchronous version of Google Analytics.

Implementing the Conversion Sciences Helper Code


The helper code is designed to make it easier to tell Google Analytics when a visitor takes an action that cant be measured. For example, when they click on a link that takes them to another site, they disappear and cant be tracked. Using the helper code, you can simply add a little Javascript to the link and record a virtual URL or a Google Analytics Event. The Helper Code must go after the Google Analytics code provided by Google, but before the </head> tag on each page. See Figure 3.

Figure 3: The proper location of Google Analytics scripts on each Web page.

The Conversion Sciences Helper Code


The Conversion Sciences Helper Code can be cut from this document and pasted into your pages or page templates. IMPORTANT: You must change the Google Analytics ID, or UA-Code in the Helper Code to match that of your site. Look for UA-#######-# in the helper code and replace it with your UA-code.

The Conversion Sciences Helper Code


<!-- This script enables the _TrackPageview functionality and must occur before any functions that use it. --> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <!-- This script allows us to record links that go to external URLs. --> <script type="text/javascript"> function recordOutboundLink(urlNext, urlCurrent, txtLink) { var pageTracker = _gat._getTracker("UA-########-#"); var txtVirtualURL="/outgoing/"+urlNext+"//"+urlCurrent+"/<"+txtLink+">"; console.log("\nVirtual URL="+txtVirtualURL); pageTracker._trackPageview(txtVirtualURL); setTimeout('document.location = "' + urlNext +'"', 1000); } </script> <!This script records actions on the site that dont generate a new page --> <script type="text/javascript"> function recordAction(urlCurrent, txtDesc) { var pageTracker = _gat._getTracker("UA-########-#"); var txtVirtualURL="/action/"+urlCurrent+"/<"+txtDesc+">"; console.log("\nVirtual URL="+txtVirtualURL); pageTracker._trackPageview(txtVirtualURL); } </script> <!-- This script allows us to measure form submissions that take the visitor to external URLs --> <script type="text/javascript"> function recordFormSubmit(urlNext, urlCurrent, txtLink) { var pageTracker = _gat._getTracker("UA-########-#"); var txtVirtualURL="/outgoing/"+urlNext+"//"+urlCurrent+"/<"+txtLink+">"; console.log("\nVirtual URL="+txtVirtualURL); pageTracker._trackPageview(txtVirtualURL); } </script> <!-- All scripts must be placed before the </head> tag on every page -->

Download the script at http://conversci.com/GAHelperCode

10

Tracking Links that Lead Off-site


Here are examples of how to implement each of the functions found in the Conversion Sciences Google Analytics Helper Code. Links that take visitors way from measureable pages are registered with the following code:
<a href=http://domain.com/page onClick=recordOutboundLink('/domain.com/pa ge', location.hostname+location.pathname,'Visit Domain.com')>Visit Domain.com</a>

Sometimes form submissions take us to a third party site. For example, Add to Cart may send the visitor to a third-party shopping cart. If we create a virtual URL for this event, we can track it as a conversion. Here is an example of the code to record this action.
<form action="/test-outbound.php" method="post" onSubmit="recordFormSubmit('/[destination.c om]', location.hostname+location.pathname,'Submit .frm');">

The script that intercepts a click on the page should use the following function call to record a virtual URL.
recordAction(domain.com/page, ('location.hostname+location.pathname,'See List')

11

Implementing Helper Code in Drupal


Drupal versions 5, 6 and 7 have a module called Google Analytics that performs all of the services found in the Conversion Sciences Helper Code. The module can be downloaded at: http://drupal.org/project/google_analytics To properly instrument the site, please ensure that the following options are enabled: Outgoing links are tracked. Downloads are tracked Mailto: links are tracked.

Custom Code Snippets


In some situations, the Google Analytics plugin may not record the information required. It may be necessary to use one of the calls found in the Conversion Sciences Helper Code. The contents of the Helper Code should be pasted as a custom code snippet and be made available for specific uses.

12

Implementing Helper Code in Wordpress


The Google Analyticator plugin for Wordpress offers an impressive implementation for tracking downloads and off-site, or outgoing links. The plugin site is at http://ronaldheft.com/code/analyticator/ To configure the plugin for greatest impact, choose the following settings: Outbound Link Tracking Event Tracking Prefix external links: Prefix download links: Additional Tracking Code (After tracker initialization) Enabled Enabled outgoing download Insert Helper Code

13

About Conversion Sciences


Conversion Sciences shows businesses how to convert more if their visitors into leads and sales. The firm works with analytics, best practices, testing and excellent communication theory to deliver Web sites that grow businesses and delight visitors. Since 2006, Conversion Sciences has audited the Web sites of hundreds of businesses of all sizes. Industries include: Health Insurance Utilities Retail Outlets E-commerce Real estate Electronics

Weight Loss Pet Relocation Health supplements Self-Storage Digital Printing Educational Sales Consultants Executive Coaching Hosting Law firms University Facilities Management

Contact Conversion Sciences Brian Massey brian@ConversionScientist.com www.ConversionScientist.com 512.961.6604

14

You might also like