Aug, 24th, 2015
To overcome this, FIRST designed and built a solution where two custom cookies were created per user and where their originating traffic source was not overwritten. What this means is that the client can understand how they attracted the user to visit their site in the first place – thus, allowing for smarter business decision in terms of where to spend valuable marketing budget.
In this post, I’m going to show you a way to retrieve traffic sources without Google Analytics cookies. As this is a working project, feel free to contribute. Your ideas are welcome.
Now, let’s get down to specifics.
The problem with Universal Analytics in tracking traffic sources
With the Google Analytics traditional tracking method (ga.js), it was easy to get this data since they were stored in the __utmz cookie. However, in Universal Analytics (analytics.js), the data is stored on Google’s server, making it impossible to retrieve. You can only see the value of traffic sources in your Google Analytics reports.
You are probably wondering why would you need to use these traffic sources data outside Google Analytics anyway.
Well, retrieving the data can be useful for mainly two reasons:
- To push traffic sources data to your CRM system, which doesn’t have a built-in solution to integrate Google Analytics. As explained earlier, we designed this solution for a client who needed to access the first and last click data to push it in their CRM system;
- To fire tags based on the traffic source data, e.g. enable a heatmap tracking tool only for users coming from your Google Adwords campaigns.
The solution – stimulating the Google Analytics processing flow
In order to retrieve the data, you would need to stimulate the Google Analytics processing flow to determine the values of traffic sources parameters:
However, this solution sometimes gives different dimensions values than Google Analytics for the following reasons:
- There is no source precedence meaning traffic sources are overridden by any source – unlike Google Analytics where traffic sources are not overridden when a Direct session follows a paid campaign
- There is no session timeout defined – unlike Google analytics where a session ends after 30 minutes of inactivity by default, and at midnight
- There is no ignored referrers – unlike Google Analytics, where you can specify referral domains to be ignored (See Referral exclusion feature). You can still customise the code provided below to ignore a specific referral
- Only the main search engines are defined for organic source: Google, Bing, Yahoo, Baidu, Ask and Yandex – but again you can customise the code to add your own search engines if needed
What it does
The first section of the code retrieves the utm_ parameters by following a similar processing logic as Google Analytics. You’ll need to change the “example.com” to your domain.
The self-invoking function creates 2 cookies:
- the FirstSession cookie retrieving the traffic sources data of the first time session;
- the ReturningSession cookie retrieving the traffic sources data when the FirstSession cookie already exists.
These cookies expire after 182 days, i.e. approximately six months (same as Google Analytics campaign timeout period).
How to implement this with Google Tag Manager
Implementing this code in GTM is relatively straightforward. All you need is to create:
- One Custom HTML tag including the code to fire on the landing page only
- Two 1st Party Cookie variables for the FirstSession and ReturningSession cookies
The “Traffic Sources Data” custom HTML tag (click image to enlarge):
The 1st Party Cookies variables for the FirstSession and ReturningSession cookies (click image to enlarge):
Below are some illustrations of FirstSession and ReturningSession variable values as shown in the GTM Preview (click images to enlarge):
Then, you can use these 1st Party Cookie variables to trigger other tags depending on their values. For instance, fire a heatmap tool for returning visitors from your email campaigns only or trigger a pop up for first time users only.
Building a customised solution helped our client identify and understand where customers first interacted with their website. This in turn helped them come up with improved new customer acquisition strategies that increased the number of conversions and satisfied customers on their website.
Now it’s your turn. Have you tried any customised tracking methods? How did you use them? Let us know!