Archive for the 'Google Analytics' Category

Aug, 24th, 2015

How to retrieve traffic sources data without Google Analytics cookies

Customised analytics
At FIRST, we have a deep level of understanding of analytics and its application to our clients’ requirements.  As an example, a client has a custom CRM and wanted to retrieve the first and last click data into their CRM system. They wanted to truly measure new customer acquisition by understanding their very first originating channel. However, with the upgrade to Universal Analytics, there is no Google Analytics cookie present anymore where values can be extracted.

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:

  • source
  • medium
  • campaign
  • content
  • keyword

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

The Code:

See the code to retrieve traffic sources data without GA cookie.

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 “” 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 “Traffic Sources Data” Custom HTML tag

The 1st Party Cookies variables for the FirstSession and ReturningSession cookies (click image to enlarge):

The 1st Party Cookies variables for the FirstSession and ReturningSession cookies:

Below are some illustrations of FirstSession and ReturningSession variable values as shown in the GTM Preview (click images to enlarge):

FirstSession Variable illustration

ReturningSession Variable illustration

ReturningSession Variable 2 illustration

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!

No responses yet

Sep, 19th, 2014

Tracking fragment URLs in Universal Analytics with Google Tag Manager

Ah, fragment URLs – you know these URLs with a hashtag (such as, that can’t be tracked with Google Analytics

Indeed, Google Analytics strips out everything after the hashtag. Yet seeing what’s after the hashtag can be useful to know what are the most popular filtering options, for example, or to check if your visitors go beyond the first page of your product listing.

With Google Tag Manager, tracking these URLs as virtual pageviews becomes relatively easy. No need to be a developer or adding any code on your web pages.

Here is how to do it :

1. Create a Universal Analytics tag for Virtual Pageviews with a hashtag

This tag is different from your existing Universal Analytics Page View tag.

In the field for Document Path, click on the brick to insert the new {{hashtag URL}} macro that you create in step 2.


UA virtual pageview tag for hashtag URLs

UA virtual pageview tag for hashtag URLs
(Click image to enlarge)

2. Create the {{hashtag URL}} Custom JavaSscript macro with the function below:

function() {
var newURL = window.location.pathname + + window.location.hash;
return newURL;

3. Create the firing rules for the UA Virtual Pageview tag

You want to fire the virtual pageview tag when:

  • The URL changes in the browser without the page loading again (history change event rule)
  • Or when the user lands directly on a hashtag URL (fragment URL is present on the page load).

The first “History change event” firing rule is as follows:


Firing rule for the UA Virtual Pageviews tag

Firing rule for the UA Virtual Pageviews tag
(Click image to enlarge)


The rule calls the History Listener tag: {{event}} equals gtm.historyChange (see

The second “Fragment URL loaded” firing rule is like below:


Fragment URL loaded firing rule

“Fragment URL loaded” firing rule
(Click image to enlarge)


For this rule, you’ll need to create the {{fragment url}} macro as below:


Fragment URL macro

Fragment URL macro
(Click image to enlarge)


4. Save your UA Virtual Pageview tag

5. Create the History Listener tag


History listener tag to fire on all pages

History listener tag to fire on all pages
(Click image to enlarge)

6. Add the “Fragment URL loaded” rule as a blocking rule in your “standard” UA pageview tag

Because you don’t want to double track the hashtag URL on the page load.

7. Preview and debug your container version

Check that your Virtual Pageview tag for hashtag URLs fires when a fragment URL is loaded (tag fired on GTM Page Load event) AND also when you navigate to another hashtag URL (tag fired on gtm.hisotryChange event)

8. Visit your site and check your Real-Time Content report in Google Analytics


Google Analytics Real-Time Content report

Google Analytics Real-Time Content report
(Click image to enlarge)

Hooray, it works!

9. Create your new Google Tag Manager container version, name it, publish it, and get yourself a well-deserved cup of coffee, tea or whatever beverage you most prefer :-)


 Story based on:

2 responses so far

Sep, 11th, 2014

New Google Analytics benchmarking reports gives insights and competitive intelligence

Google has announced new Benchmarking reports available in Analytics.

These reports allow you to compare your website performance against the averages of similar sites. For example:

You can filter by the following dimensions:

  • Channel Grouping (Direct, Organic, Paid, Referral, Email, Social, Display and Other)
  • Location (Country)
  • Device (Desktop, Mobile and Tablet)

You can compare the following metrics:

  • Sessions
  • % New Sessions
  • New Sessions
  • Pages / Session
  • Average Session Duration
  • Bounce Rate

On the Google Analytics Blog they show an example of Twiddy‘s results compared to peers in their industry (see image below).

Analytics report for Twiddy

The reports even use colour to show at a glance whether your business is above or below the industry average.

You will find these reports under Audiences -> Benchmarking in your left-hand menu.

If you cannot see these reports, you will need to follow these instructions.  Only if you choose to share your data anonymously with others will you be able to see the reports.

It does provide interesting data benchmarks, for example: in New Zealand, for Shopping sites averaging 1,000 to 5,000 sessions per day, Google is currently collecting data from 125 properties – the below is from these sites in August:

  • Average sessions per month: 62,000
  • % new sessions: 45%
  • Average pages per session: 6.14
  • Average session duration: 4:08
  • Bounce rate: 35%

And here is how the various traffic sources contribute to total sessions:

An observation from this limited set of data – organic search, email and direct referral sources are the biggest drivers of website visitors for NZ shopping sites.  Display and social activity on average do not drive a significant number of website visitor sessions.

Note: we have found a few discrepancies in the data that we will observe further:

1) Not all data correlates exactly with these benchmarking reports.  For example, we have a client for which they were showing 10% the average number of sessions being driven by paid search, where we know in fact they are higher than the average.

2) The sum of the channels does not equate to the sessions noted in the top line.  Just something to be aware of.

3) For smaller regions (such as NZ) data will not show for many subcategories unless there are enough contributing properties to protect the privacy of those websites.

Perhaps not perfect, but this new Google Analytics benchmarking feature provides reasonable benchmarking data that may be difficult (or expensive) to get in other ways. Take some time and benchmark your business – if you are way ahead of the average, evaluate success and ROI and if you’re getting good results, keep doing more of it.  If you are lagging behind average it gives a good indication of where you need to be investing.

No responses yet

Aug, 12th, 2014

Is your security affecting your search rankings?

Google with SSL encryption

Google recently announced it is going to start using HTTPS as a ranking algorithm. It’s only a slight factor, “affecting fewer than 1% of global queries” and carries less weight than, for example, high-quality content.

On Twitter, @RyanJones, an SEO expert in UK, summarised things nicely: “for the record, there’s about 100 things you could do right now that would have a bigger SEO impact than switching to SSL”.

Regardless, much of SEO is a game of hundreds of small wins, so it would be foolish to ignore a small win.

So, our advice is: don’t panic, but do move to HTTPS.

Google states: “over time, we may decide to strengthen it, because we’d like to encourage all website owners to switch from HTTP to HTTPS to keep everyone safe on the web.”

We’ve had a number of clients move to HTTPS this year (with our encouragement) and seen no disruption to their traffic.

What is HTTPS?

First off, let’s explain Hypertext Transfer Protocol (HTTP). HTTP is the primary technology protocol that transfers data between the client and server in plain text, which allows users to link and browse on the web.

Hypertext Transfer Protocol Secure (HTTPS) is another protocol, but uses Secure Sockets Layer (SSL). Unlike HTTP, HTTPS encrypts the data flow between the client and server to create a secure and safe web for users. Basically, this makes it much harder for people to spy on your traffic. With the growing concerns around web security, this has been rapidly becoming a hot subject online.

HTTPS migration guidelines

Here are some of our tips on how to migrate to HTTPS with minimal downtime to your website.

Content Loading

Since the HTTPS version of the site will typically use more resources to serve the site as it is encrypting the connection, it is important to note that Google takes into account page speed in its algorithm, so it is important the infrastructure can deal with SSL. Also, care needs to be taken to ensure all content is moved to HTTPS to avoid mixed content warnings. All internal links should start to use HTTPS, not just to pages but also for images.

301 Redirects

Since the secure (HTTPS) version of the site may be considered a new domain in the eyes of Google, it will be important to ensure that every URL on the current site is 301 redirected to the corresponding URL on the new site to let search engines know the site has permanently moved. This is also necessary to avoid the possibility of having duplicate content, which can create issues.

Another advantage of having 301s, is there are many sites already linking to the HTTP version – therefore these 301 redirects will ensure that the value of these links will be passed on to the new HTTPS pages.

Robots.txt file

Add a robots.txt file on the new HTTPS domain and exclude any folders that should not be crawled and/or indexed by search engines. FIRST can provide recommendations on the URLs that should be excluded. Assuming no changes to site structure, this file will be the same as the robots.txt on the HTTP site.

Webmaster Tools

There are a few things to consider with regards to the migration to a secure server when it comes to Google Webmaster Tools.

Since HTTP and HTTPS are considered different sites, the HTTPS version will have to be listed separately in Webmaster Tools.

You can contact FIRST if you require any assistance with switching your website from HTTP to HTTPS.

No responses yet

Jun, 2nd, 2014

10 themes from the Google Analytics Summit 2014

Google Analytics Summit 2014
As a Google Analytics Partner, we have had the privilege of spending the last two days at the 2014 Google Analytics Summit in San Francisco. What a wonderful conference it was! Although I could write much, I wanted to summarise and highlight just 10 consistent themes of the conference.

  1. Agility – Agility and speed is a weapon and some of the most important skills in business today. We must be smarter, faster and more agile.
  2. The Analytics Cycle – a) capture data, b) analyse data, c) take action. Then rinse and repeat.
  3. Universal Analytics – Migrating to Universal Analytics is an absolute necessity
  4. GTM – Implementing Google Tag Manager (GTM) is critical to success (and efficiency)
  5. Attribution – Attribution was a very strong theme throughout the whole conference and is only going to get more important. My key takeaway – if you are using ‘last click’ as your primary success metric, you are doing it wrong!
  6. Enhanced eCommerce – Google launched Enhanced eCommerce publicly at this event. It is a complete rework of the eCommerce reports and now includes fantastic visualisation and more ways to take action from your data efficiently and effectively. I have played with this, and it is cool. More info and next steps here
  7. Lets get more technical – Google Analytics API use is strongly encouraged and perhaps necessary for more advanced insights
  8. Upload offline/external data – There is an understanding that ‘web’ is only a portion of the story, to really understand your customers and their journey, you will need to upload external and offline data as well and combine.
  9. Remarketing – Remarketing should be an ‘always-on’ tactic. Is it for you?
  10. Segmentation – With all of the above, averages are pretty useless. Segmenting data is very powerful and is the best way to find gold and act according to the behaviour and needs of each segment.

There is certainly something for all of us to work on, and I am very excited by the possibilities Google Analytics will bring as they continually roll out new features. You can view the official Google Analytics blog here.

FIRST is always happy to talk through any of the above in more detail.

No responses yet

« Prev - Next »

© 2015 FIRST, part of the BeyondD Digital Marketing Group a wholly owned subsidiary of Beyond International.