Recently, I had a conversation with some web analysts about the different traffic attribution models in Web Analytics. This is a topic that web analysts and marketers will never reach an agreement on! A few days after the dry theoretical discussion, I got a request from one of our clients to change the traffic attribution model in Google Analytics to treat “direct” traffic like any other traffic sources, which will enable them to measure the impact of their branding efforts.
What is considered “direct traffic” in Google Analytics?
Direct Traffic represents visitors who typed the URL directly into the web browser, clicked on a bookmark to arrive at your site, or clicked on an untagged URL in a desktop based application that link to your site.
What is the issue:
By default, Google Analytics attributes a visit and its conversions and sales to the last traffic source; that is what we call Last Click Attribution model. An exception to this rule is a “direct” visit. If a visitor returns to a site directly, the last traffic source before the direct visit will still get credit for that visit’s activities. This behavior is disliked by (few) analysts who prefer to look at the “direct” traffic like any other traffic sources.
Here is a simple example to illustrate the issue:
You are a web analyst at forever21… you ran a huge online campaign for the back to school sale (banner, email, social media, affiliate,..) now you want to measure your brand awareness in the market. You want to see how many people because of your branding efforts visit your website directly by typing your URL?
A few months after the end of the campaign you still see visits are tracked as “paid search”, “email” and “banner”. You see a very small number of “direct” visits. In the budgeting meeting you shared the numbers with the board and you decided to spend more $$$ on marketing because you haven’t reached your brand awareness goals yet.
Hold on! Do you know that most of these “paid search”, “email” and “banner” visits that you see today in your report are “direct” visits?These campaigns did their job months ago and now the whole universe knows about your brand and comes to your site directly. Unfortunately, you have no insight about these “direct” visits because of the rule that “direct” visits do not override previous traffic sources for 6 months!
Can we change this rule? If this will answer your business needs and save you money, of course we can 🙂
Solution:
Simple! Just credit visits to the last campaign/traffic source regardless of whether the visit was a direct or non-direct visit. See the table below for a comparison between the default GA reporting settings and the “True Direct” solution settings:
Visitor | Visit 1 | Visit 2 | Visit 3 | Visit 4 |
Source / Medium | cnn.com / Referral | ask / organic | Direct Access | Bookmark |
Last Click Attribution | cnn.com / referral | ask / organic | ask / organic | ask / organic |
True Direct Attribution | cnn.com / referral | ask / organic | direct / none | direct / none |
How:
We will need to run some JavaScript code before firing the Google Analytics tracking code. This JavaScript code will check:
- the value of the URL of the page that loaded the current page (Output: URL or Null)
- the current page’s URL (Tagged with Google Analytics campaign UTMs or not tagged)
- if the value of the referring page is NULL and the current URL doesn’t contain any UTMs, then update the URL with the following utm parameters utm_source=(direct)&utm_medium=(none)&utm_campaign=(not set)
Why do we check whether the current page is tagged or not?
Sometimes pages are loaded without referring information, yet they might have been manually tagged with campaign parameters to force GA to credit the visit to a certain channel. We do not want these pages to be overridden by our “direct” parameters.
Example:
The traffic source for this visit will be:
- Source = cnn.com
- Medium = banner
- Campaign = thanksgiving
Click here to view the entire code segment
Let us explore the code, section by section:
function get_referrer() {
var source = document.referrer;
if (source == null || source == “”)
return “direct”;
}
This portion of the code will determine the URL value of the page that loaded the current page (referring page). If the value is NULL, the function will return “direct” indicating that the current page was not referred by another site.
function get_parameter() {
var urlstr = window.location.href;
var results = urlstr.match(/[\\?&#]utm_source=([^&#]*)/);
if (results != null)
return “tagged”;
}
This portion of the code will determine if the current page is manually tagged with Google Analytics campaign parameters.
if (srcPage == “direct” && parameter != “tagged”) {
window.location.hash = “utm_source=(direct)&utm_medium=(none)&utm_campaign=(not set)”;
}
This portion of the code will check the values returned by the two functions above. If the visit has no referring information (direct) and the URL is not tagged with any Google Analytics campaign UTMs, then the page URL will be updated with Google Analytics UTM parameters setting the source and medium for the visit to “direct”
Page URL
New URL
set)
* Notice that we did not use window.location.href function because this function will reload the page with the new URL, which is not what we want to happen. We just want to update the URL, without affecting the visitor experience, in order for the Google Analytics tracking code to attribute the visit in a certain way.
Bonus: Defining a Search Term as Direct Traffic
Sometimes out of convenience or laziness visitors reach your website by entering your domain name or business name as a search term in a web search engine (ex. google, yahoo, bing). Those visits will be attributed in GA as organic search visits, even though, the only difference between the two visits is that in one visit the URL was typed into the web browser’s address bar and the other was typed into the browser’s search box.
In my opinion, these branded searches should be dealt with as direct visits. In GA we have the option to do that so if you are convinced, then let’s configure Google Analytics to treat certain search terms (our brand) as direct traffic.
The configuration has to take place at the code level. It will be simply adding the _addIgnoredOrganic() method inside the Google Analytics tracking code for each keyword we want to track as direct traffic.
The custom Google Analytics tracking code will look like this:
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-xxxxxx-x’]);
_gaq.push([‘_setAllowAnchor’, true]);
_gaq.push([‘_addIgnoredOrganic’, ‘e-nor’]);
_gaq.push([‘_addIgnoredOrganic’, ‘e-nor.com’]);
_gaq.push([‘_addIgnoredOrganic’, ‘www.e-nor.com’]);
_gaq.push([‘_trackPageview’]);
(function () {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘https://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Congratulation, now you don’t only have access to the direct visits data of those who visit your site for the first time as direct, but you will have insight into all direct visits regardless of whether they took place during the first, second or even the tenth visit.