Going Beyond the Code Snippet
Many people I know use Google Analytics, especially for their own web sites. It’s free, easy to implement and starting to get competitive with the bigger, enterprise tools on the market. However I have found that many think that “tagging” their site with the code snippet given to them by Google Analytics is all it takes and that the data provided by it is the end-all, be-all of the traffic data they can get.
When you use a free tool like Google Analytics, you don’t get such consulting services and are left on your own to figure out that you can do custom tagging and tracking. Admittedly for very small sites a lot of the custom tracking is probably unnecessary, but there may come an occasion where you may require it. To that end I want to try and walk you through some of the custom tagging options you can do with Google Analytics.
If you run any sort of business and sell your products or services through your website, you are going to want to track that activity. Google Analytics includes the ability to track your ecommerce transactions on your site, although it is not enabled by default. There is a three step process to get this tracking to work correctly:
Step 1 – Enable Ecommerce Tracking
The first step before you add Google Analytics to your shopping cart pages is to enable ecommerce tracking in Google Analytics by following these steps:
- Click the Admin tab at the top right of any screen in Analytics. If you are not already on the Account Administration screen, click the All Accounts link at top left, just below the menu bar
- Click the name of the account and then the name of the property that has the profile you want to enable Ecommerce Tracking for. If you have a lot of accounts or properties, use the drop down search box in the top left of the menu bar and type to search.
- Use the Profile drop down menu to select the profile you want.
- Click the Profile Settings tab.
- Under the E-Commerce Settings section, select Yes, an E-Commerce Site/App.
- Click Apply.
Note: If you are using a 3rd party shopping cart, or if your shopping cart lives on a separate domain than the rest of your site, you will need to do cross-domain tracking.
The next step is to add the ga.js code snippet to your ecommerce pages, pretty much the same way you already did to the rest of your site. If you haven’t actually added the code snippet to the rest of your site yet, there is a quickstart guide that can help you do that.
Step 3: Adding the Ecommerce Tracking Code
- _addTrans() – this will initialize a transaction object, which is used to store all the related information about that transaction.
- _addItem()– this will track all the individual items within the visitors shopping cart and will associate those items to the transaction.
- Related to this is the orderId field which helps associate the items to the transaction.
- _trackTrans() – this will confirm that a purchase has happened and all the data tracked so far related to this purchase is consolidated as part of a transaction.
Things to keep in mind when you’re implementing your ecommerce tracking are:
- Make sure you provide a unique SKU (stock-keeping unit) for every item/service for purchase on your site. This will ensure more accurate tracking.
- Don’t use the coma in currency formatting when specifying price or total variables. For example if you entered 2,478.57 as a total, it will be recorded as 2.47857, and not as $2,478.57. It’s best to just write it as 2478.57, and let your ecommerce software handle the currency conversion.
Here is a short snippet of what the _addTrans() piece of of the tracking code would look like. You can visit Google Analytics Developers Guide to view the complete example.
‘1234’, // order ID – required
‘Acme Clothing’, // affiliation or store name
‘11.99’, // total – required
‘1.29’, // tax
‘5’, // shipping
‘San Jose’, // city
‘California’, // state or province
‘USA’ // country
If you ever do any kind of online advertising campaigns, either SEM (Search Engine Marketing), banner ad, or email campaigns, doing custom campaign tracking can be extremely valuable. It will give you additional insight into how well your campaign is performing, and will help you make more informed decisions for future campaigns.
For Google Analytics to be able to track traffic to your site from your campaign ads, you need to include what’s known as a query string variable at the end of the URL that drives traffic from the ad back to your site or custom landing page. There are two ways you can do this:
- Enable auto-tagging, which automatically imports AdWords data into Analytics.
- Manually add the appropriate query string parameter, which will be required if you’re not using AdWords for your campaign (for example if you’re doing an email campaign, or buying banner ad-space on a specific web site, not affiliated with Google).
Auto-tagging for Google AdWords
Here are the steps Google recommends to enable auto-tagging:
To enable/disable auto-tagging:
- Sign in to your AdWords account.
- Click the My account tab, and select Account preferences.
- In the Tracking section, click Edit.
- Select (enable) or clear (disable) the Destination URL Auto-tagging checkbox.
- Click Save changes.
Manual (custom) campaign tracking
Manual or custom campaign tracking is best used for email campaigns, newsletters, search marketing on other search engines (Yahoo, Bing), or when directly buying ad banner space on specific web sites (like ESPN, EETimes, etc.). Google recommends disabling auto-tagging mentioned above when using manual campaign tracking, however if you’re not doing manual tracking on an AdWords campaign, there shouldn’t be a conflict with your data (please correct me if I’m wrong on this assumption).
Google has created a handy little custom URL builder to help you create manual tracking URLs, however I will still walk through the process of writing them as I think it’s helpful to understand what the code actually means.
Google analytics has 5 different query string parameters (they call them custom campaign parameters) that it recognizes.
- utm_source: Identify the advertiser, site, publication, etc. that is sending traffic to your property, e.g. google, citysearch, newsletter4, billboard.
- utm_medium: The advertising or marketing medium, e.g.: cpc, banner, email newsletter.
- utm_campaign: The individual campaign name, slogan, promo code, etc. for a product.
- utm_term: Identify paid search keywords. If you’re manually tagging paid keyword campaigns, you should also use utm_term to specify the keyword.
- utm_content: Used to differentiate similar content, or links within the same ad. For example, if you have two call-to-action links within the same email message, you can use utm_content and set different values for each so you can tell which version is more effective.
The way you use these query strings is by appending them to the end of your URL, the first one using a ? and the additional ones added on with & (this is important – if you use the ? or & incorrectly, the tracking will not work). Here is an example of what a URL would look like using two of the five listed parameters:
As you can see each parameter starts with either a ? or an &, followed by =, and finally followed by a variable. The parameter variable is entirely up to you, and is what will appear in your Google Analytics campaign reports. The variables can be anything you want, with the following exceptions:
- No spaces
- Avoid most special characters (especially ?, & and =). The only special characters recommended would be an underscore (_) or hyphen (-).
- These are case sensitive. If you use the same parameter variables in multiple locations, but are inconsistent with the capitalization, each version will be reported independently.
For more advanced campaign tracking that you can set up on your site, there is additional coding you can add using GATC Campaign Tracking Methods.
Part 2 Coming Soon …