Posts

Subdomain

Tidy up your subdomain and multidomain web metrics with Google Tag Manager

Subdomain

SITUATION Let’s suppose that you have two sites to track, a main site and its subdomain

  • www.mysite.xyz
  • thirdlevel.mysite.xyz (for example it can be a specific product minisite or an ecommerce platform, a campaign landing page, etc.)

OBJECTIVE You want to monitor both all visits under one main Google Analytics profile (now called view) and also each single site separately. So you are planning to have at least three GA views.

PROCEDURE A standard way to distinguish pages after multidomain tracking can be made through a view where the hostname is added to the URI: this way pages will be distinguished by their hostname (normally absent on GA) as follows:

  • www.mysite.xyz/index.php
  • thirdlevel.mysite.xyz/index.php
  • etc…

Here is an alternative approach through Google Tag Manager:

1. Create a GTM container for the whole web property

2. On the container create two different GATC tags, each bringing data to the same GA property ID (UA-xxxxxxxxx-x). You can call GATC-main and GATC-third-level (you can use spaces if you like)

3. Mind the Rules! Each GATC tag need to have a Rule that activate it only when the visitor is on the relative site. For example, GATC-third-level tag will have the following rule:

GTM Rule

The Rule fire the tag only when the visitor is on the thirdlevel domain

4. Now just one more step – the most important – add a virtual page to GATC-third-level:

4.1 Before doing that create a Macro called path (or any other name) to collect URL / Path

GTM URL Path Macro

Add a URL Path Macro on GTM

4.2 Then add it to the Virtual Page Path

GA virtual page path gtm

Collect subdomain metrics under a virtual folder on GA through GTM

PLEASE NOTE – If you don’t follow this step, your pageviews will merge together when having the same name (e.g. index.php pageviews from the main domain will be summed up to index.php pageviews from the subdomain). You can still create separate profiles (views) for each site using a filter that distinguish traffic to the hostname (e.g. mysite vs thirdlevel.mysite) but you will not be able to have the whole view under one profile (mysite + thirdlevel.mysite but differentiated with a virtual folder).

5. change the Rule TO GATC-main tag in order to activate it only when the visitor is on your main domain (not the third-level); no need to add Virtual Page Path to GATC-main tag.

6. Now let’s move from Tag Manager to Analytics and add two more Views to your web property. The default view will collect all metrics (main domain and third-level) whilst two more will be for each site separately.

6.1 You just have to create a new view, e.g. “Main site only” and Filter out all visits that starts with subfolder “/yoursiteonthirdlevel/”

6.2 For the other view “Third-level only” instead the FIlter has to include only subfolder starting with “/yoursiteonthirdlevel/” as shown above:

filter-subdomain

Apply a filter to your subdomain GA View

Done!

PROCEDURE FOR MULTIDOMAIN TRACKING The same procedure is valid also for multidomain tracking

  • mysite1.xyz
  • mysite2.xyz
  • subdomain.myxite2.xyz
  • etc.

CROSSDOMAIN Don’t forget to add also crossdomain tracking following the procedure suggested by Google to let cookies move across all your funnel. If you don’t take this step, you will not be able to measure campaign performance attributing value to each digital marketing channel. Good luck!

Google Databoard

The continuing r-evolution of Google services/tools and its benefits for the marketing industry: Think Insights & Databoard

Google Databoard

Marketing paid services are struggling against the fact that Google offers the same tools at no cost. From analytical tools to tag management, from videoconferences to market researches, Google is offering to business a wide range of fundamental marketing (and web marketing) tools and services that improve day by day.

For example, Google Tag Manager has been launched silently in October 2012 and “is now (July 2013) serving twice the amount of traffic it was in April 2013”. At the same time, Google is planning to standardise one of GTM’s core features, the Data Layer, through a specific “Customer Experience Digital Data Community” Group born on the W3C site (source: Analytics Blog).

Whilst Google is closing down many services (among the others Wave, Buzz, Reader, Latitude) or reshaping functions and integrating tools – for example website optimizer integrated into Google Analytics, GA Conversions Goals can be imported into Adwords, Adwords remarketing lists can be done through GA and G+ gaining centrality on all aspects, from being considered a top SEO ranking factor to pushing communication through Hangouts – it keeps on launching new services whose strengths are: cool, free, easy, accessible.

A recent site that worth a visit, mostly by marketers and communicators, is Think Insights, a collection of market research for many industries. Among cool examples here’s a Japan-based English language school whose classroom are made through Google Hangouts.

It includes also the Databoard, that “lets you explore insights from Google research studies, share them with others, and create your own custom infographics”. Unfortunately at the moment data are available only for the US.

Through Databoard, as an example, I’ve made for you an infographic showing key facts about use of smartphones in the US (2013). It’s time for you to build your own infographic!

 

 

Google Tag Manager

Event Tracking Automation for Google Tag Manager: downloads, outbound links, email, podcasts

Update: with GTM v2 many things changed. You can have a look at a comprehensive article by Simo Ahava on how to setup event tracking on Google Tag Manager.


Google Tag Manager

Are you using Google Tag Manager? Great. There’s a way to automate the process of attributing GA Events to ALL your outbound links, downloads, email addresses, even podcasts and phone numbers with no effort, no further scripting needed on your code.

Here I will explain how to do it. A huge credit goes to Ryan @ Blastam that not long ago has written this interesting article with guidelines to automate the process on Google Analytics.

Step 0: GTM IN PLACE + JQUERY!

Open a GTM account and install the code immediately after the opening <body> tag of your website (just in case…)

Be sure to have jQuery JavaScript library working on your site (most CMS already have it, check HTML if you are not sure, it does not have to be the last version).

If jQuery is not installed… don’t worry, we can still do it (see Step 3).

 

Step 1: RULES

Create the general All Pages rule if not already present

url matches RegEx .*

Create another rule that I call Activate Outbound

event equals outbound

Add a rule to tell when GTM has to flash a Tag

Add a rule to tell when GTM has to flash a Tag

Step 2: MACROS

Create the following three  JavaScript Variable:

Name: CategoryGlobal Variable Name: cat
Name: Action; Global Variable Name: act
Name: Label; Global Variable Name: lab

Step 3: TAGS

Create two tags, one for the event tracking and another one for the magic script

Event tracking will be as follow:

GA Event Tracking on Google Tag Manager

GA Event Tracking on Google Tag Manager

(remember to add your GA account code)

The Firing Rule will be Activate Outbound (the one set in Step 1)

Now let’s add the following Script on a new Custom HTML Tag

ONLY if the jQuery library is not on loaded on your site add the following line BEFORE the main code:

<script src=”//code.jquery.com/jquery-1.7.2.js”></script>

If jQuery was already present on your pages then ignore the above code and proceed just adding what follows:

<script type="text/javascript">
if (typeof jQuery != 'undefined') {
 jQuery(document).ready(function($) {
 var filetypes = /.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i;
 var baseHref = '';
 if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');

 jQuery('a').on('click', function(event) {
 var el = jQuery(this);
 var track = true;
 var href = (typeof(el.attr('href')) != 'undefined' ) ? el.attr('href') :"";
 var isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]);
 if (!href.match(/^javascript:/i)) {
 var elEv = []; elEv.value=0, elEv.non_i=false;
 if (href.match(/^mailto:/i)) {
 cat = "email";
 act = "click";
 lab = href.replace(/^mailto:/i, '');
 elEv.loc = href;
 }
 else if (href.match(filetypes)) {
 var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
 cat = "download";
 act = "click-" + extension[0];
 lab = href.replace(/ /g,"-");
 elEv.loc = baseHref + href;
 }
 else if (href.match(/^https?:/i) && !isThisDomain) {
 cat = "outbound";
 act = "click";
 lab = href.replace(/^https?:///i, '');
 elEv.non_i = true;
 elEv.loc = href;
 }
 else if (href.match(/^tel:/i)) {
 cat = "telephone";
 act = "click";
 lab = href.replace(/^tel:/i, '');
 elEv.loc = href;
 }
 else track = false;

 if (track) {
 dataLayer.push({'event':'trackoutbound'});

 if ( el.attr('target') == undefined || el.attr('target').toLowerCase() != '_blank') {
 setTimeout(function() { location.href = elEv.loc; }, 400);
 return false;
 }
 }
 }
 });
 });
}
</script>
 

Step 4: SAVE AND PUBLISH!

Always save after each step taken and at the end Save a new container version and Publish – you can even preview and debug it to check if all tags are firing on the right place (or after the right event).

Is it working?

To check the implementation just go on your website, click on an external link or email or pdf download and at the same time on another browser window check your Google Analytics Real-Time reports on the Events section. You should see, after a few seconds, your event correctly appearing. Later, Events will be properly recorded also under GA Content section and you can create any kind of report/advanced segment/goal with them.

 

Monitor real-time events on GA

Monitor real-time events on GA

Important: to make it work you need jQuery library to be loaded before the above mentioned scripts. So if you don’t have it, download, load on your server and call in the header section. Or you can still avoid this implementation and manually tag each single link/download the old way.

A note: you can change name of variables, rules, tags and macro, but consider to adapt the whole implementation accordingly.

Why it is useful

For example you can measure how many downloads of a pdf enrolment form or clicks to an external website that does not have multi-domain tracking.

The good point of such implementation is that you don’t need to hardcode anything on your pages/posts: it magically does the job for you. It’s been tested on WordPress but it should work on all CMS.

Find out more about GTM…

Update: October 2013

New system to automate tracking all links and form buttons through GTM has been launched. In my view it’s a bit more complex than the above solution, and it needs more work to distinguish between different elements (e.g. a pdf from an outbound link), but it’s the new standard. Detailed post by Lunametrics here or by Justin Cutroni here.