Category Archives: Google Analytics

Quick tips to evaluate AdWords based on Profit in Google Analytics

In this article I will try to explain 2 methods which allow a more ‘accurate’ base of evaluating AdWords efforts. Word of caution we are still in the last non direct model so once you do any of the 2 methods revert back to MCF reports in order to see the cross campaign AdWords influence.

Profit using Calculated metrics

In this case we will use the dreaded on average the client has a 10% margin and in addition the client pays a fee of 15% on top of Adwords spend. The end result is something in line with Net Profit = (Revenue * 0.1) – (AdWords spend * 1.15)  – note that this is by no means an accurate representation of your profits yet it is definitely a step closer than for instance basing all on ROAS (reasons why not ROAS are nicely described here  –


  1. Ecommerce tracking
  2. AdWords and Analytics are connected
  3. Understand this is only applicable where your margin is evenly distributed through your entire assortment (no big outliers allowed:))

Step 1 

Go to view settings > Calculated metrics:Calculated metrics

Create a new metric using this formula (name it however you want but use Currency for formatting):

{{Product Revenue}} * 0.1 – {{Cost}} * 1.15

Where 0.1 is Gross Profit based on 10% margin and Cost is based on a 15% fee.

There is no step 2:) 

Well there actually is but it is just creating a Custom report where you use the newly created metric. If you like the idea of having these calculated metrics in your reports there are some others you can easily add:

  • Profit per transaction (Currency) – ( {{Product Revenue}} * 0.1 – {{Cost}} * 1.15 ) / {{Transactions}}
  • POAS (Percentage or Currency) – ( {{Product Revenue}} * 0.1 – {{Cost}} * 1.15 ) / {{Cost}} * 1.15

Important! – you need to decide if you are going to use Revenue or product revenue as the ingredients are different for almost each GA ecommerce implementation. Revenue may have shipping, taxes and similar inside yet product revenue may have only a fraction of it. 

The downside of using calculated metrics is # of Calculated metrics available (5 per view for standard) and these can only be used (currently) inside non standard reports.

The end result is usually a custom report:

Screen Shot 2016-02-22 at 23.08.02

You may notice a clear difference when looking at ROAS and a clear profit metric – much much easier to scan the report – IMHO.

Profit using data import

MAJOR UPDATE – thanks to Yehoshua Coren!

When using Enhanced ecommerce if you use data import and widen on product level you need to do some additional implementation steps in order to stop inflating the custom metric Value. By default this would happen:

Product Click Event > custom metric would be set to the value from the data import table
Product Add To cart > custom metric would be set to the value from the data import table
And so on – so each EE event passed to GA would increase the total product profit continuously (unfortunately this is how EE works).

So before you do any import your dataLayer pushes would need to contain the custom metric with the value of 0 – note the metric index number!:

'metric3': 0

For all non purchase event hits such as product impressions:

'event': 'trackImpressions',
'ecommerce': {
'impressions': [
'name': 'Triblend Android T-Shirt',
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'list': 'Search Results',
'position': 1,
'metric3': 0
'name': 'Donut Friday Scented T-Shirt',
'id': '67890',
'price': '33.75',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Black',
'list': 'Search Results',
'position': 2,
'metric3': 0

For the purchase event ‘metric3’: 0 should be deleted!

As vaguely mentioned in the first method – using data import can and should be used if there are high margin deviations inside your product inventory.  The basis for this method is product id / sku. Importing per product profits make this method much more reliable in terms of end result – the calculated metric Profit (custom metric) – AdWords spend (Cost). As an additional benefit the Cost is not only applied from AdWords but also from all Cost Data Import sources as well (Facebook, Yandex and similar).

In standard Analytics Profit import works for processing time data widening – in short when a transaction containing products gets recorded in GA and if the scheme for widening exists (data import) each hit gets widened with a Custom metric / dimension of your choice. In this case we are using Product Data Import type which uses product scoped dimensions and metrics – and we need to use Enhanced Ecommerce.

Step 1 – Custom metric

One of the differences between  Custom and Calculated metrics is that Calculated ones are defined on view level and Custom ones on property level.

Define the Gross profit Custom metric in the GA admin:

Custom metric product scope

Step 2 – Create the data import data set 

Just make sure you choose Product Data Import and use the following settings:

Product DataImport screen

We need to widen the product info with the Gross profit metric we will import using a .csv file and we are using product SKU as the primary key – SELECT NO FOR OVERWRITE HIT DATA:

Once you have this solved you need to get the data from your business system and export the data set in a csv file containing, in this case, only two columns of info:

csv data import

Upload the data either from the GA interface or using the API.

Screen Shot 2016-02-22 at 22.57.45Screen Shot 2016-02-22 at 22.58.00

Screen Shot 2016-02-22 at 22.58.17

Step 3 – create the calculated metric(s)

This procedure is the same as in the initial calculated metrics method only. Instead of Revenue / Product Revenue we will use the Gross profit Custom metric instead.

  • Net Profit (Currency) – {{Gross profit}} – {{Cost}} * 1.15
  • Profit per transaction (Currency) – ( {{Gross profit}} – {{Cost}} * 1.15 ) / {{Transactions}}
  • POAS (Percentage or Currency) – ( {{Gross profit}} – {{Cost}} * 1.15 ) / {{Cost}} * 1.15

The application of these metrics is completely the same as seen in the first method – create a custom reports or pull all data out and use some 3rd party tool to do additional analysis and visualizations.

Customer Match – target email users using Google AdWords

In this blog post, we will describe important tips related to the initial set up of email lists in AdWords remarketing. Also, we will show initial results of Customer Match campaign for one of our clients, and the opportunities provided by such targeting.


Customer Match allows you to use a list of email addresses in the remarketing list.

Examples of email addresses collecting:
• collected email addresses from a customer who purchased products from your website
• collected email addresses from a customer  who registered on the website, applications or newsletters
• collected email addresses from a customer  who registered for the loyalty program, on the website or in physical stores.

Tip: try differentiating the list in a similar way as a way in which you have collected email addresses (website, newsletters, applications, brick & mortar) – that is, if you have a sufficient number of individual emails in each list. In future, if needed, you can target them differently.


The procedure of setting up a customer email list are detailed described on Google Support, so, we will keep on real examples and important facts.

All email list should be stored in a CSV format. It is important to check all email addresses for empty space(s) before or after, uppercase, and such. Google recognizes the difference between uppercase/lowercase letters and empty space (such mistakes often happens when users are using mobile phones). After checking and fixing email addresses, you are increasing the possibility of accepted email addresses. Since we reviewed all of our email addresses (for empty spaces, case sensitive, and obvious mistakes in writing), as picture shows, the format of email addresses was accepted 100%.

After checking our email lists in CSV was accepted 100% format of emails

From this customer match (email) list, Google is using only emails of users who are also logged into the Google Account (with that same email). That does not mean that these emails are exclusive to Gmail domain. However, in our experience, about 90% of accepted emails in the list are Gmails.


In our example, we used about 24,000 emails, of which Google accepted (found matching) for nearly 16,000 emails. It is 66% of all available emails.

You need at least 1,000 approved emails in one list to create the campaign, but we recommend a list of at least 10,000 approved emails. Google can serve ads on Google Search, Gmail or Youtube, only to users who are logged in Google account. Otherwise, a campaign might generate a very small number of ad impressions and clicks.

Of course, do not forget to exclude customer lists in all regular campaigns that contain the same target (keywords, Gmail, Youtube) to prevent double targeting.


Results of the Customer Match campaigns

The results are related to the period of 8 days, with 20,300 approved emails. We created seven search campaigns and one GSP campaign. Campaigns are created with the same settings and targeting as well as “regular” campaign.


Results of the Results of Customer Match campaigns


Campaigns achieved 459 clicks with average CTR of 17.61%, which is 40.51% improvement in CTR compared to the regular campaigns.

It is also important to note that 50.88% impressions and 68.63% clicks are coming from mobile devices. In comparison with the regular campaign, a percentage of impressions on mobile devices is 36.67% and 46.33% clicks.

Since users generally stay logged in to their Google account on their mobile devices, these results are not surprising. Therefore, it is important to have a well-optimized mobile web page, and, of course, a sufficient number of accepted emails.


User behavior from Analytics account


According to the data about user behavior from Analytics account, it can be seen that the bounce rate of 28.91% is very low, with 8.10 average number of pages per session. Compared to the regular campaign, bounce rate decreased by 22.8%, while the average number of pages per session increased by 9.65%.


Customer Match campaigns in comparison to regular campaigns


In this period, Customer match campaigns generated an 117% higher ROAS (return on ad spend), although it achieved a significantly lower nominal number of transactions.

Through GSP campaign, you can reach a larger volume of impressions compared to the search campaigns. Considering that users need to log in to their Google account to see their Gmail account, GSP campaign is showing higher impressions of ads. Therefore, we recommend (in the case of a small number of collected email address) to first start with the GSP Customer match campaign.

In our testing, GSP campaigns achieved the best results in comparison to other Customer Match campaign (12.18% Gmail clicks to website CTR compared to 3.55%), however, do not forget that the GSP campaigns are type of display advertising.


In conclusion, although Customer match requires a very large email list, which generates a relatively small number of ads impressions,  it’s worth to advertise through remarketing campaigns with targeted customer email list.

It is also possible to test:
• advertising specific actions intended for customers in the loyalty program,
• sharing of specific action for offline stores,
• special offers of new products, lines, brands, etc.,
• the opening of new physical stores with geographic targeting

So, follow our blog and our social accounts, where we will publish new tests and new possibilities offered by Google AdWords.

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.




How to set up Google Analytics and Google Tag Manager code in WordPress

WordPress is an open source content management system, it is easy to use and  there is a large selection of templates and plugins. WordPress is the most popular and most used CMS system. According to research, WordPress occupies almost 60% of the CMS market. In total of all web sites, WordPress is active on 25% of the market. On the other hand, it is important to have a Google Analytics implemented on your website because it is one of the basic tools to monitor user behavior and you can measure the success of your marketing activities on the Internet.


Since many websites use WordPress, this blog post will show you how to set up Google Analytics and Google Tag Manager codes on WordPress website.

First of all, you need to find and copy Analytics code. Log in into your Google Analytics account, click on the top of the bar on Admin. In the middle column (Property) click on Tracking Info and then on Tracking code. There you will find Analytics code that you need to copy on your website.

Google analytics code

There are many ways in which you can implement Google Analytics code in WordPress, but we will explain the two easiest and least painful ways, which allow the installation of code in the <head> tag, just as Google proposes:

1. Using a plugin – there is a lot of plugins that let you implement Analytics to WordPress site. But one of the easiest method is using the Insert Headers and Footers plugin.

For start, install and activate the plugin. Once you activate it, click on the left side on Settings and then on the Insert Headers and Footers. In the Scripts in Header field you need to paste Analytics code. After that, just click on blue button Save and you are done!



2. Directly in the code – WordPress contains Editor, which allows us to modify the code, which means we can actually implement Analytics code without using the plugin.

So, on the left side, click on Appearence and then on Editor. On the right hand of the Editor, find the file called Theme Header (header.php) and click on it. In the code find </head> tag, just paste Analytics code right before the closing </head> tag and click on blue button Update File.


These are two easiest ways to install Analytics code on your WordPress site.

Implementing Google Tag Manager code

Implementing Google Tag Manager code works in the same way as the installation of Analytics code in second step. Google recommends that the GTM code needs to be placed immediately after the opening <body> tag, so its better paste it directly into the code. So you need to go to Editor (Appearence->Editor), on the right side, find the file Theme Header (header.php) and click on it. In that file, find opening <body> tag and paste GTM code after it.



If you want, you can use plugin too. One of the best plugins is Duracell’s Tomi Google Tag Manager for WordPress. But be careful, some plugins implement GTM code in footer or header.


If the process isn’t entirely clear or you have difficulties with the implementation, we recommend to seek help from your developer.

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!