About Margarita Evtimova

is a Google Analytics fan, who also loves SEO, conversion optimization, online marketing and social media. You can follow her on Twitter and LinkedIn.

Check Geo Location for Specific Pages in Google Analytics

Here’s a recent question I got:

“We have a website domain.com, but there’s a specific set of pages at domain.com/demo that are used for a presentation tool for potential customers. We need to see for the visitors who view these special pages, which US states they are coming from.”

Let’s build an advanced segment to achieve this.

Open Google Analytics and click on + Add Segment at the top and the red + New Segment. Give your segment a name, like Demo pages, choose Conditions from the left pane and filter for Sessions – Include – Page – Contains – /demo/

demo pages segment

Then go to Geo -> Location report with your new segment applied. Click on United States and you’ll get the list of states (called Region in GA):

states segment applied

 

You can go to any other standard or custom report with the same segment applied to check what’s special about these potential customers.

This is just a simple example of how powerful the advanced segments can be.

Track onclick event handler value with Google Tag Manager

It’s not very common but you may stumble upon a case where you need to record the value of an onclick event handler.

Usually you have a JavaScript function and the “onClick” event handler executes a piece of JS when an element is clicked on. It can be added to elements like <a> tags, form buttons, check boxes, <div> tags, etc. Here’s an actual example:

&lt;script&gt;
function inform(){
alert("You have activated me by clicking the grey button! Note that the event handler is added within the event that it handles, in this case, the form button event tag")
}
&lt;/script&gt;

&lt;form&gt;
&lt;input id="click-me-button" type="button" name="test" value="Click me" onclick="inform()"&gt;
&lt;/form&gt;

On this test page we have a button that will show an alert when clicked. And we want to record an event with some category that we define and the onclick value as action (it will dynamically change if you have different onclick event handlers).

Let’s build our variable first:

function() {
var field = {{Click Element}}.getAttribute('onclick');
return field;
}

It will get the onclick value of the element you’re clicking.

onclick variable

Now let’s enter Preview & Debug mode and see if it does what we need – click on the button and explore the variables list:

onclick GTM preview

Looks good! Now we can build a simple event tag in GTM, firing on the click of this button:

tag settings

Publish the workspace and start gathering data:

real time results

So, that’s it! What kind of onclick event handlers do you need to track?

5 Google Analytics posts you don’t want to miss in August

Here’s again the last post of the month saved for the top 5 interesting Google Analytics related resources I found on other sites. Here are the five for August – you may want to bookmark those as they can be very useful:

Introducing the Google Analytics Demo Account

In the beginning of the month Google Analytics launched a fully functional Demo Account, available to everyone, with real ecommerce data from the Google Merchandise Store. Avinash published a great post about it, explaining how to get access and jump-start your learning: Be Real-World Smart: A Beginner’s Advanced Google Analytics Guide

Two Steps To Correctly Tracking Subdomains in Google Analytics

This LunaMetrics article shows how to properly implement subdomain tracking in Google Tag Manager, along with example scenarios. Check out the reasons why you need (or don’t) subdomain tracking and what to do next.

Troubleshooting Cross-Domain Tracking In Google Analytics

In this post Simo shows the easiest way to implement cross-domain tracking – through Google Tag Manager. You can use his short checklist to identify issues and make sure cross-domain tracking is working.

GTM Match Table Variable Generator (Lookup Tables & Beyond)

Despite being an extremely useful feature in Google Tag Manager, the lookup table Variable can be tedious to configure and it supports exact-match only. You can use this template by Seer Interactive to easily create a big lookup table or get regex support.

Enterprise-Class Tag Management: Announcing Workspaces

Google announced a major update to Google Tag Manager introducing workspaces and interface changes. Simo Ahava published two quite comprehensive articles on the same day which can be used as walk-throughs for the new features:

P.S. Got a Google Analytics question? Send it to me and I’ll try to answer it on the blog.

Sogou Explorer and Baidu Browser are hidden in Google Analytics

If your website serves the Chinese market you’d want it to work well and render properly for your customers. I was checking the browser stats for a Chinese website and my colleagues were surprised to see that two of the popular Chinese browsers are missing from the list: Sogou Explorer and Baidu browser.

So I installed them to check what’s exactly going on for these two. Let’s start with Sogou Explorer by opening the developer tools console on the Network tab (you can check Preserve log box) and loading our website with custom campaign parameters like ganotes.com/?utm_source=test&utm_medium=test&utm_campaign=test. Search for ‘collect’ which is a part of the GA hit and look at the headers:

Sogou user agent

The user-agent shows a long string: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0

When we go to Google Analytics to check how the traffic from this specific source / medium is recorded we see:

Sogou in GA

and the browser version is:

Sogou version in GA

So, in my case my session from Sogou Explorer is recorded as a session from Chrome 49.0.2623.22, that’s why there’s nothing mentioning Sogou in Google Analytics Browser report. Depending on its internal logic, sometimes it will show up as Chrome and sometimes as Internet Explorer.

Now, let’s do the same for Baidu Browser.

Baidu user agent

The user-agent shows a similar string: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36

When we go to Google Analytics to check how the traffic from this specific source / medium is recorded we see:

Baidu in GA

and the browser version is:

Baidu version in GA

Similar to Sogou Explorer, Baidu browser is recorded in GA as Chrome 43.0.2357.124, and there’s no way to distinguish between real Chrome sessions and these ‘fake’ ones.

Running Hotjar polls on specific events through Google Tag Manager

Recently I had to run a Hotjar poll after a successful signup uncovering hooks. We wanted to ask users what persuaded them to sign up. But our registration is not happening on a dedicated thank-you page – there’s a GTM data layer event which is loaded when a signup happens.

For Plus and Business accounts (paid) Hotjar offers an option in poll settings called JavaScript Triggers. So that’s what we’ll use here. Let’s build a new poll by going to Polls – New and give it a name.

On the Targeting step we’ll click On pages I specify and select the last option (unfortunately it will be active in paid plans only)

Hotjar polls JS trigger

We’ll call the Hotjar event ‘success’, so that’s what I’ll enter here:

poll settings

Finish the rest of the poll setup: Question, Appearance and Behavior, and let’s head to Google Tag Manager to add the special JavaScript trigger that will show the poll on the specific event we want.

Start by creating a new Custom HTML tag in GTM. Give it a name and paste the following in the HTML box:

<script>
hj(‘trigger’, ‘success’);
</script>

It comes from the Hotjar documentation on JavaScript triggers.

Here’s our tag, where I’ve selected an existing datalayer event for trrigger:

Hotjar poll tag in GTM

That’s it – just save and publish the tag in GTM and enable your poll in Hotjar!