Engineering

2 most common issues with Google Analytics and Google Tag Manager

Introduction

This is an article from a series of articles about Google Analytics. If you want to know how to implement GA from scratch check 1st article: How to implement Google Analytics via Google Tag Manager. If you want to know how to implement e-commerce plugin check 2nd article E-commerce plugin in Google Analytics via Google Tag Manager.

Problem with doubled events in statistics

Case nr 1

Problem with doubled events in statistics - when you see in analytics that some events are incomparably bigger and you have suspicion that they can be wrongly measured.

The source of the problem can lay in the fact that i.e. 2 events are tracking the same action - like add to cart - one event is for e-commerce plugin and a second event is a normal event. To avoid such mess in statistics you can change Non-Interactive Hit parameter in one of the events (in our case it was e-commerce event). An important thing about the parameter Non-Interactive Hit - the default here is False but if you will have more advanced settings in GTM and maybe you will have more tags and triggers - then you can start to observe duplicated events in Google Console. So if you want to turn off tracking from tag set it to true.

Screenshot_2021-11-05_at_12.12.50.png

The user path is messed up

Case nr 2

The user path is messed up - when it looks like the user's path is switching between paid search and organic search in one session

When you see information that user comes from paid search and once from organic search in the same session it is clearly wrong. It is messing up the statistics and it is hard to evaluate paid ads - if they working or not. It was really hard to find the reason of this behaviour and the solution came by trial and error method.

Screenshot_2021-12-27_at_09.02.48.png The source of the problem can lay in auto-tagging feature from Google.

To see more details about auto-taging see this page.

For our case, what you have to know, is that it works in that way that in the collect requests (sending by google analytics automatically) GA is sending gclid paramter which keeps the information about the user. But when a user is visiting the page with gclid added i.e via paid ad - you have to make sure that you will not lose this id during the navigation through the shop. To do it you have to add to the events new parameters: pagePath and originalLocation.


const location = useLocation();
const pagePath = location ? location.pathname || '' : '';

const originalLocation = document.location.protocol + '//' +
                            document.location.hostname +
                            document.location.pathname +
                            document.location.search

Screenshot_2021-12-23_at_15.18.27.png

As you can see we are able to set in value variables {{originalLocation}} and {{Page Path}} - this is because they are added to GTM variables (if you don't know how to do it check 1st article from the series of Google Analytics).

And that's it - know you should see a nice user path.

Screenshot_2021-12-27_at_09.02.28.png

Implementing GA on your own can give you a lot of flexibility but also requires you to solve few problems. Feel free to reach me if you have other problems related to GA or GTM - we can try to solve them together.