Check Geo Location for Specific Pages in Google Analytics

Here’s a recent question I got:

“We have a website, but there’s a specific set of pages at 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:

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;input id="click-me-button" type="button" name="test" value="Click me" onclick="inform()"&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 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.

Event-based goals: which page a user converted on

Let’s look at the common scenario where you track goals with events. This could be a contact form submission, newsletter subscription, phone number click or other type of interaction where you don’t have a distinct URL to use for destination URL in GA goals settings. You can have the form / link on multiple pages on your site and you want to understand which page a visitor was on when they completed the conversion.

Our example is a hotel booking website where we have a Live Chat button on every page. A simple way to check you conversion numbers is to compare them with the unique events for the same event category and/or action / label. Let’s go to Conversions – Goals – Overview and see how many conversions we have for the Live chat click goal:

goal completions

Now, we’ll check Behavior – Events – Top Events and filter for the same event dimensions we’re using in the goal settings:

event category

So far, great – they match. At this point, simply select Page as secondary dimension and sort by Unique Events column:

event pages

This is the list we want – almost 40% of the users who clicked the Live Chat button were on the home page, and another 30% were on contact-us and rooms pages. You can export the list and group the pages or analyze further.