All posts by Zorin Radovančević

Senior Web Analytics implementation and planning specialist - all things related to Google Analytics, Google Tag Manager and Yandex Metrica.

Site Speed reports in Google Analytics

A small refresher course in how you deal with site speed reports and page timings in particular. As Google announced site speed to be one of the ranking factors the issue got more ‘real’ – a wast number of articles show the importance of site speed and its effect on the business outcome (a recent one by Stéphane Hamel shows some numbers – link) yet the most important thing is the end user which may or may not like slow loading pages.

This article will present 2 simple things:

  1. Technical manipulation of the site speed measurement
  2. Averages suck – drill down

How to set the site speed feature for Google Analytics (Page timings)

Some basic facts:

  1. Site speed info is sent without any additional GA code needed
  2. Site speed info is sent with pageview hits
  3. Site speed sample can be increased reduced with additional code
  4. Default site speed sample size is described here

The implementation part if you want to manipulate the sample size is quite easy as you only need to slightly adapt the basic GA tracking code (info on the siteSpeedSampleRate field):

ga('create', 'UA-XXXX-Y', 'auto', {'siteSpeedSampleRate': 50});

Note that the values expected are 0-100. The default value, without any code adaptation, is 1%.

With GTM it is even easier to do this. It also allows you to be flexible if you want to determine for which part(s) of the site you actually want to see a larger sample – more important parts of the site.

For instance if you by any chance use dynamic remarketing there already is a variable present which you can freely use such as ecomm_pagetype which provides info on the page type viewed (conversionintent, searchresults, category, product etc.).

A simple example of how to set siteSpeedSampleRate in GTM

This example is based on the assumption you already have dynamic remarketing variable present on the site (if not you can always create a customJS variable and set the siteSpeedSampleRate based on Page URL or similar).

Variable 1 – fetch the ecom_pagetype value (example based on dataLayer)

Screen Shot 2016-02-12 at 09.29.34

Variable 2 – set the siteSpeedSampleRate based on value from ecomm_pagetype variable

Screen Shot 2016-02-12 at 09.31.07

Just to explain a bit we set the input values as expected strings from the ecomm_pagetype variable and set the output as values used for the siteSpeedSampleRate field – a lookup table variable is used in this case. And one additional thing if the variable does match any of the explicitly defined strings we set the default value to 1 (you can freely change this to any number you prefer (0-100)). By doing this you effectively increase the chance the timing hit will indeed be sent.

The Google Analytics Pageview Tag – one and only in this case 

Screen Shot 2016-02-12 at 09.32.30

The only thing you need to set inside your main Pageview tag is the Fields to set part – Field Name: siteSpeedSampleRate and Value: {{util – siteSpeedSampleRate}} (or any other variable name you set). Publish.

The results

Nicely described here –

The averages suck part

With page timings be very very careful when analysing data as for some pages the sample can be so small it can easily lead you to wrong conclusions.

A small example on data collected from this blog. When looking at Behavior > Site Speed > Page Timings report there will probably be pages which are above or below average for a metric such as avg. page load time.

Screen Shot 2016-02-12 at 09.49.28

Issue detected? Of course you would need to check if that page has an obvious reason as it can be resource heavy so try not to compare to average but with similar pages (page types – use Content Grouping!). A very simple approach to continue detecting the reason if nothing obvious is found – secondary dimension. Just click on the page in question inside the table report and add a secondary dimension which will reveal the context – as an initial idea try Country, Device Category, Browser or similar. For example:

Screen Shot 2016-02-12 at 10.00.03

Yes, our site on mobile sucks. But do not be hasty in making such decisions – always use an additional segmentation to prove this hypothesis. So lets see the issue with an another Secondary dimension:

Screen Shot 2016-02-12 at 10.05.49

Now you can definitely see  there are some outliers (in a sucky small sample of data) which affect the average heavily which can defeat any initial hypothesis we created.

Standard reports will only get you so far. For more in depth look at the issue create a Custom report which will allow for a more granular look at the data and some more metrics (more appropriate). Create something like this – custom report link where it is much easier to find the ‘real’ culprit and act on it.




Sending a Custom Metric with a Pageview Tag with GTM

One would think it is easy to send a Custom Metric with a pageview yet apparently there are some mishaps which may occur due to something obscure as a timing hit. Reading through the recent article written by Yeshoua Coren describing custom and calculated metrics there was a mention of this being the issue and the idea on how to solve it though not in detail (hitCallback) – fortunately enough I have only sent Custom metrics with events which by default do not add an additional timing hit so this article is just curiosity based:).

The issue

The real issue is when you send a pageview hit which has the set custom metric if there is a subsequent timing hit the custom metric will be inflated or better say sent twice. The volume of this additional hits is very well described on Google official developer site.  So if by any chance you opt to set Fields to set field siteSpeedSampleRate like this – your reports may be polluted:


So when you send a pageview this will happen (from debug):


GTM uses set on a named tracker – tracker name is in this case gtm1453223458541 so for each subsequent hit (while it persists) for this tracker name the Custom metric will be sent again. Fortunately a subsequent event will not be affected as the name of the tracker will changed as it uses timestamp in naming convention. And now the timing hit which follows immediately after the pageview hit:


The solution (so far)

In your Pageview tag add Fields to set Field > hitCallback:


The value will be a Custom  JavaScript variable (name it as you see fit) (note that with named trackers – when you explicitly define the tracker name the situation is ‘a bit different’):

function() { 
   return function() { 
      ga(function() { 
         tracker = ga.getAll()[0].get('name');
         ga(tracker+'.set','metric2', 0);

Once you set this up the debug will show:

Running command: ga(“gtm1453224328813.set”, “metric2”, 0) which will set the value to 0 for the subsequent timing hit.


Please note that this applies to simple implementations only and should be revised especially in cases where:

  • more trackers are present
  • you use named trackers

Would be extremely happy to hear if there are any other workarounds for the issue!:)

Traffic management based on product performance with Google Analytics

The goal of the article is to provide the tools needed to determine which traffic acquisition channel is responsible for selling a specific product or set of products. We will do this in 2 parts. The first one deals with the direct tie between the product and the acquisition channel – please note we will be working in the realm of last non direct attribution model so it is all about the last known source. The second part deals with the situation where the product is hard to sell directly so we need to resort to more devious sales methods in specific using related products – in simple terms sell more product X by selling more product Y.

Part 1 – tie between the traffic acquisition channel and the product

Note that the following tool does not, by default, say which channel is the most effective – cost effective yet gives the information on sales volume related to source.

A prerequisite is of course a working GA property and ecommerce tracking implemented.

Believe it or not this report is available in standard reports though a bit hidden. Go to Conversions > Ecommerce > Product performance report.


Choose Pivot table for report display type.



Proceed to dimension and metric selection process:


  • Primary dimension can report on Product name, category and sku
  • Pivot by offers a selection of dimensions which you need to make sense of – depends of the questions you have:
    • choose a time based dimension if you need an answer when to sell
    • choose campaign if you want to see which campaign sold which product
    • choose basic default channel grouping (works only with standard ecommerce and not with enhanced ecommerce) or source / medium if you need a high level understanding what drives sales for a particular product (as in the current example)
  • Metrics are limited to product related scope

The table can be further filtered as appropriate – e.g. only products which generated > 10.000 product revenue.

Once the report is set you can use the Shortcut feature which will save most of the report settings and probably save you time on further reporting efforts.


Are there other ways to do this? Of course yet this is the easiest one for ad hoc analysis. Based on the report you can redefine your traffic management based on sales requirements – it gives a simple answer which channels you invested before which generated product X sales volume – this gives you the opportunity to test how a specific channel scales and can it give more.

Part 2 – Related products – Sell more X by selling more Y

So our product X is really hard to sell by itself. All our direct traffic acquisition efforts have failed (long tail campaigns) yet the product seems to sell but from completely unrelated campaigns. A solution may be that the product is more sell friendly by pushing campaigns for related products where users buy it as an additional product. So how to obtain this valuable piece of information?

Option 1 – Custom segment

Build a custom segment (the segment is user scoped) which will in return report the following – report on all products which have been bought in transactions, in defined time range, where Call of Duty: Black Ops III (our product X which causes problems) was in at least one of the transactions.


Option 2 – Related products – ecommerce feature

This is an ideal way to automate the data pull and gain some insights into correlation between products inside a transaction. It is usually used when you do not have access to a more advanced CRM / ERP which does these things – is built for these things.

Prerequisites include a working GA property, ecommerce tracking implemented and the feature enabled inside the GA view ecommerce settings.


Once turned on it allows us to fetch additional dimensions and metrics using Google Analytics Core API – more info on the subject:

For testing purposes you can use this nice addition to Google tool set – Query Explorer where you can fetch the data on the fly – basically test your query prior to any automation attempt.


After the basic setup is done you may do more tinkering in terms of filters applied – only specific product Ids or only results where the correlation score metrics is >0.8.

The end result is a table which displays the queried product Id, related product Id and the correlation score (values can be 0-1 – where values closer to 1 is what we are after – high level of correlation between the products).


This kind of report can then easily be replicated in Google Sheets using the Google Analytics extension which also allows filtering flexibility and scheduling / automation.



When you find products with high correlation score to your product X revert to part 1 of the article and see which channel is responsible for sales and test the scalability to improve both product X and product Y sales. 


How to track internal campaigns using Google Analytics

Let’s start with the basics …

What is an internal campaign

An internal campaign, from a business perspective, is any element on a site(s) which links to your content and its purpose is to speed up the purchase decision, highlight a product or category, give incentive in any part of the purchase funnel and more. A simple example would be a click on banner which is placed on our home page – – which links to a product page (also on our site(s)) –

Some examples / methods of internal campaigns:

  1. urgent – offer ends in 2 hours
  2. limited – only 5 left
  3. popular – top 5 products
  4. deal – buy 1 get one for free

The truth of the matter is internal campaigns are often used to push products with these common attributes – hard to sell, large stock, high margin and let’s not forget fill the gaps in design:)

A simple example ( – part of the homepage):


Why track internal campaigns

The obvious reason is – why not. Internal promotions often take a lot of screen real estate and this fact should not be taken lightly. Aside from that you need to invest time and money for campaign production – copy, images, … so in short you owe it to yourself to prove / test its (in)efficiency. From a marketeers perspective there are some quite useful goodies gained from tracking internal campaigns – what works and what does not:

  1. copy
  2. incentive type
  3. position
  4. colour
  5. season
  6. category
  7. price
  8. and so much more


Before we get to how to track these campaigns …

How NOT to track internal campaigns

Do not use UTM tagging to track internal campaigns. Never. Never ever.

There may be some cases where you feel tempted to use UTM taging such as a multisite environment where you own multiple properties – still, don’t.

A common error in web analytics is using features like UTM tagging for the wrong reasons resulting in bad data. If we opt to tag internal campaigns with UTM we actively affect Google Analytics traffic source attribution. Let’s see what happens if we do:

  1. A user clicks on our Google AdWords ad – Google Analytics will report on this session as coming from google / cpc
  2. Inside that session the same user clicks on our banner which has UTM tags (utm_source, utm_medium, …)
  3. This results in traffic being attributed to our banner and not Google Adwords (and will create a new session)
  4. If a user activates a type of conversion on our site standard report will attribute it to Internal campaign while the MCF part of reports will attribute Google AdWords as an assisting channel in the conversion path – a mess not easy to decipher

How TO track internal campaigns

You will probably encounter a few main methods of how to properly track this sales tool. The most popular ones are:

  1. Site search – this was nicely explained by none other than Justin Cutroni
  2. Enhanced ecommerce – this is probably the first Google Analytics feature which has a specific area designated for internal campaign (promotion) tracking this is also by far the most difficult method of tracking (as tracking internal promotions makes real sense only if you track all other EE activities on the site)
  3. Event tracking – a very flexible method of tracking almost anything on your site (I will describe some of the basic ways to do event tracking with Google Tag Manager)
  4. Custom dimensions – in addition to event tracking we can add a new layer of data to existing hits (events / pageviews) in order to better describe the actual internal promotion

As the methods 1 and 2 are described thoroughly let’s focus on event tracking and custom dimensions and we will do a hybrid of these 2.

Tracking Internal campaigns with Google Analytics Event tracking

First of all we need to decide the naming policy for our event / campaign tracking efforts. In short what will be the category, action and label values used throughout the site – note that if the naming is not consistent, time and site wise, it will be really hard to do meaningful reports. So lets revert to the basic questions – what would we like to know:

  1. Does the internal campaign help sell stuff? – we have that covered – create a segment using category / action / label and track conversion behaviour
  2. Which internal promotions are most likely to sell (and why – tricky but at least try)? – we need info here on:
    1. promotion placement (page, position)
    2. size, color, copy (think in terms of utm_content)
    3. incentive type (price, urgency, loyalty, package, any additional added value)
    4. some other attribute

As you can imagine it is not a small feat to push all these values into 3 event hit default dimensions so there is always the option to add a custom dimensions in the mix to help out (if you can spare the Custom dimensions slots!!! – note there is a limit of 20 CDs per property). An initial suggestion would be:

  • Event category = ‘internal_campaign’ (if we have a rollup property we can add the site the click happened on so it would be ‘internal_campaign_sitename’ (think utm_source))
  • Event action = ‘shoes_men_spring_2015’ (think utm_campaign)
  • Event label = ‘250*250|red|buy_now|a|2’ Ad / Banner / Campaign content (think utm_content) – size of the banner, color, CTA, variation, position (if a slider present)
  • CD1 = incentive type or some other attribute = hit scope dimension

Now that we solved what we wanted to report on let’s see how can we retrieve these values. this part will emphasize on the fact that GTM is not a one click install system and it often requires additional development work on site as the site itself is rarely built to provide info which marketeers need in an easy to consume / report form.

Trigger the Google Analytics Tag Event tag

So lets first solve the triggering part where we want to send a GA event only when someone clicks on an Internal campaign ad / link. For this case we need a way to identify the click on the internal campaign.

Here are a few basic options to solve the trigger part:

  1. use the DOM event – onmousedown, onclick – <a href=”#” onclick=”dataLayer.push({‘event’ : ‘trackEvent’}];”> – use the onclick event to push a custom event via dataLayer
  2. use GTM click / linkClick triggers which track clicks on DOM elements / links – these are GTM built in events – <a href=”#” id=”intcmp” data-gtm-data=”someImportantInfo”> – use of GTMs click / linkClick trigger in combination with auto event variables (element attributes (Click ID or element attribute auto event variable – data-gtm-data))

Trigger case 1 (DOM event)


Trigger case 2 (GTM click / linkClick)


Enable when part is optional and takes care of performance issues so you do not listen the clicks on lets say all pages but only ones that contain internal promotions. When using Auto event variables make sure the ones you will use are activated in the Variables section of GTM interface:



How to set and read the data payload for GA event tag

And now we come to the tricky part. It is not hard to send basic info to Google Analytics yet it is quite hard to come by ‘ready to consume info’ from the site. Let’s look at an example – this is not a good example of how to do it properly but an example of what you can usually expect:

<div class="slide" style="width: 980px; float: left;">
<a href="/running.html">
<img src="" alt="">

As you can see here there is almost no notion of the stuff we would really like to track – position, size, CTA, copy, color and similar. In addition to that there are no clear identifiers of the element being the internal campaign link aside from the class=”slide”.  We have two main options here:

  1. Scrape whatever we can from DOM – Click URL, image name (this gives us a really limited data set in most cases)
  2. Add some code which would better describe what the user has actually clicked (better yet we usually need developer support – preferred version)

Option 1
A very simplified way of sending the info to GTM and subsequently to Google Analytics would be to use a dataLayer custom event:

<a href="#" class="someclass" id="internalcamp" onmousedown="dataLayer.push({'event' : 'trackEvent','eventCategory': 'internal_campaign','eventAction': 'shoes_men_spring_2015','eventLabel': '250*250|red|buy_now|a|2','customDimension1':'price'});">

Option 2
An option where you have lots and lots of Custom dimensions slots available:

<a href="#" class="someclass" id="internalcamp" onmousedown="dataLayer.push({'event' : 'trackEvent','eventCategory': 'internal_campaign','eventAction':'shoes_men_spring_2015','customDimension1':'250*250','customDimension2':'red','customDimension3':'buy_now','customDimension4':'a','customDimension5':'2','customDimension6':'price'});">

Option 3
Yet another option for streamlining event information to GTM is to use HTML data attributes – I personally find this approach very useful but it is usually applicable with long term relationship clients where analytics needs are both a part of the development and marketing process (additional benefit – whatever changes in terms of class or id of the element the data-gtm- logic usually stays intact). So for example:

<a href="#" class="someclass" id="internalcamp" data-gtm-event="internal_campaign" data-gtm-action="shoes_men_spring_2015" data-gtm-label="250*250|red|buy_now|a|2">

The only thing you need to do now is to ‘catch’ the data on link click in GTM and here is how you do it:

Values needed to identify the right event and to push the final payload to event.

3 variables are needed all type of Auto Event variables where you choose Element Attribute and create all 3 data-gtm- variations.


How we trigger the Google Analytics event from GTM.


Where we send the entire payload to Google Analytics with an event.


Alternative pageview tracking with custom dimensions

Let’s assume you cannot rely on data attributes and events and your only option is adding parameters to links – it is doable and here is how to do it.

Your internal campaign directs to a page on your site: (old URL) which you should change to …*250

Follow up steps …

Read Url fragment – URL type variable where we read everything after #.


Custom dimension value extract from URL fragment (you can extract the values to one dimensions or parse the values to separate dimensions) – note that we split the entire string by ‘&’ and use the index 0 which is the 1st item and will in our case return the string ‘intcmp’:

function() {
var myTempString = {{read URL fragment}};
if(myTempString && myTempString.indexOf('intcmp')>-1){
return myTempString.split('&')[0];

An All pages for the pageview tag will suffice. If the fragment values do not exist nothing will be passed as custom dimensions values – will not be processed.

Use a Google Analytics Universal template tag with the following settings:


And this is it – happy tracking!

Reporting on AdBlock usage with Google Analytics

Ad blocking is a really hot topic these days. Arguably there are two completely opposite stories to follow up on yet we are not dealing with that this time. This post explains how to report on ad blocking occurrence on the site and how it affects your ‘potential’ earnings as a publisher.

There are 3 main steps to this process:

  1. Detect ad blockers and send an event to Google Analytics (we will use it later on in a segment)
  2. Make the number of page ad slots available – ideally using dataLayer (if using GTM)
  3. Create the Custom metric(s) in Google Analytics interface and create the custom reports / dashboards

1. Detect AdBlockers

There are already numerous ways to detect clients / users with ad blocking apps activated so I will only list a few:

You will notice that almost all detection kits use a ‘dummy’ / ‘fake’ ad related file which will hopefully trigger an ad blocking app and this should fire a GA event. You can of course adapt it to detect your real ads being blocked without the need to add the fake script.

The logic

Using any of the for mentioned scripts fire a Google Analytics event e.g. in case you are using GTM push the info via dataLayer:

window.dataLayer = window.dataLayer || [];
'event' : 'trackEvent',
'eventCategory': 'Adblock',
'eventAction': 'Active'

Create a Google Analytics Event template tag using these values which is triggered on the custom event trackEvent and you’re almost done (variables and triggers should be created as well):


2. Make the number of page ad slots available

Again if using GTM just add the information to dataLayer which will represent the number of ad slots available on a single page. The idea is to simply use getElementsByClassName() which will return an object which has a property length – use this logic to obtain the number  of ad slots available on a specific page (the value which we are looking for is length +1 as the indexing starts at 0).

Easy as:

var adSlotIndex = document.getElementsByClassName('elementClassWhichContainsAnAd').length;

One thing worth noting is that you will probably want to send this info after DOM is ready so choose how to send this custom metric carefully – options are to send it with a pageview (so PV tracking should be DOM ready) or use an event for more flexibility just make sure non interaction is set to true.

In addition you can send another custom metric which will be currency type which will be calculated as total Ad Slots On Page * Average Revenue Per Impression – reporting with currency gives more weight to the whole concept.


3. GA prerequisites and building the dashboard

First take care of the segment – Session level segment which will be Event Category == AdBlock and Event Action == Active. This will allow reporting on sessions where AdBlock was active – in specific number of ad impressions or better say ads that were supposed to be delivered you could not be as they were … blocked. This segment can be applied to standard / custom reports, dashboards and used in API exports.

Secondly create the custom metric(s) on GA property level.

And now it is all up to you to show the data best way you can – the way it will make you do something to battle this revenue consuming trend.


Some reports details to consider: browser, browser version, geography based dimensions, content grouping (LP or page – to determine where this revenue source is most sensitive) – you will probably find more useful dimensions.

Hope this helps in determining how much money you loose from ad blockers:)

Happy tracking!

Time to complete a goal or transaction using GTM and Google Analytics

Here is a quick overview of how to track the time needed for a user to finalize a desired activity inside a session using Google Tag Manager and Google Analytics. The example in this article is a simplified overview of various hits and methods on how we can achieve process tracking inside Google Analytics. By default Analytics measures Session length / duration and time on page which is quite challenging in this cases and rarely applicable thus one may be forced to use features like custom metrics and / or user timing hits.

Case – time from session start to lead generation form submit

A user starts a session and is expected to fill and submit a lead generation form. We would really like to know how long this process usually takes (not the entire multichannel / multi device experience in this case but just the in session experience).  The experience will be highly affected by previous experience with the site – so using some segments while analysing would come in quite handy.

The idea on how to fetch these values is quite simple. Drop a cookie once a session starts, or in some specific cases when an on site process starts (e.g. checkout) – where the cookie value will be the session / process start time. After the user has completed the process – successfully completed the desired action (we basically mimic Analytics goal behaviour – so it is either a destination or an event based trigger in GTM) we send a User timing hit or an event hit with a time type custom metric.


The procedure

What is needed:

1. Cookie tag – Custom HTML
On session start we set a session level cookie.

var d = new Date().getTime();
document.cookie = "sessionStart=" + d + "; path=/;";

Trigger – Pageview using a 1st party cookie variable sessionStart (so fire only if sessionStart is undefined).
Variable – 1st party cookie – sessionsStart ({{gtm sessionStart}}).

trigger first page in a session

 2. Google Analytics pageview tag – Template tag – Universal Analytics

This is a basic GA universal pageview tag yet I added a hitCallback inside ‘Fields to set’ to safely set a clientId as a custom dimension (user level – do not forget to dreate the custom dimension inside GA admin) in an additional event tag (ty Simo!) – this will fire a Google Analytics event tag only when the Pageview tag has fired successfully. so the setup looks like this:

universal analytics main pageview tag

Trigger – All pages (default trigger).
Variable – custom js variable which send a custom event via dataLayer push – this event is used for the Utility Event responsible for adding a custom dimension with clientId value.

check if ua pageview fired

function() {
return function(){dataLayer.push({'event': 'pageViewFired'});}

3. Google Analytics Event tag – Template tag – Universal Analytics

A simple event tag which only purpose is to set the Custom Dimension value of the users clientId (this is used to further analyse time for each process based on the client Id – some randomization could be utilized if a user is expected to have multiple conversions or even add a process end time as a custom dimension or use time dimensions in GA).

event tag set cid

Trigger – event equals pageViewFired.
Variable – use a custom JS variable which will fetch the clientId value.

function() {
return ga.getAll()[0].get('clientId');

4. Google Analytics User timing tag – Template tag – Universal Analytics

This is where we send info to GA that the process has successfully ended and pass the time value. So the setup looks like this:

user timing hit

Trigger – any which identifies the session has resulted in a goal completion. For this case I used a simple custom event – trackConversion – dataLayer.push({‘event’:’trackConversion’});

Calculation and variables – as you noticed a different variable is used for the custom metric and user timing value. The reason for this is that user timing hit requires a value in milliseconds and custom metrics in seconds. The calculation is pretty simple.  You need 2 variables:

User timing value

function (){
var endTime = new Date().getTime(); // this could easily be a separate variable
return endTime - {{gtm sessionStart}};

and Custom metric value

function (){
var endTime = new Date().getTime(); // this could easily be a separate variable
return (endTime - {{gtm sessionStart}})/1000;

And that’s basically it – one word of caution though user timing hits are prone to sampling so consider sending the timing info through events with CD and CM defined.

When you are done setting this up the example report could be something like this:

report example


Hope the article was useful and of course happy tracking!