Google Tag Manager: Unobvious and Useful Trigger Settings

Otzyvmarketing marketer Stanislav Romanov told how to use Google Tag Manager (GTM) to set up analytics and track file downloads from the site. This article is for those who know the basics of the JavaScript language and have already worked with GTM.



What is dataLayer



DataLayer is a regular JavaScript variable. You can write data to it, then transfer it to Google services:







The variable name can be changed - instead of the dataLayer



variable, the name dataOlga



:







Difference between dataLayer = [] and dataLayer.push ()



If you declare dataLayer=[]



, then in the computer's memory this name will refer to the whole array. Thus, assigning a variable to new data means simply overwriting the values. Access to variables from the first array is lost.



It looks something like this:







At the same time, dataLayer.push()



is neither a variable nor an array. This is a method that can be applied to any array and either get something at the output, or somehow change the array itself. In other words, we take the dataLayer array and apply the push()



method to it - we get dataLayer.push()



. Push



does not overwrite the data, as in the case of an override of the array, but adds new values ​​to the array.



When working with GTM, it’s best to use the push



method like this:







In this form, push



must be used to additionally check whether the dataLayer



variable was generally set as an array. Checking helps to avoid unnecessary errors when the site is running.



How to configure analytics on single-page



GTM allows you to easily synchronize the work of a single page with Google Analytics. By single-page, I mean a site where all pages have a single shell, and new data appears on the site dynamically through AJAX. It interferes with the normal operation of GA, so you can not do without a GTM trigger:







After creating the trigger, apply it to Universal Analytics:







Now GA will be able to receive data not only when the user enters or leaves the page, but in all other cases of dynamic data overload.



True, the method described above is not suitable for sites that use various get-request variables and “spoil” the URL. For such complicated addresses, you will have to configure GTM in a more tricky way.



1. Set up variables



We go into the settings of the "Variables" section and select New History Fragment and History Source - they are needed to save the URL along with get-requests and check them.

After that, you will have to work with JavaScript and create your own variable getPathWithFragment



, into which we write the URL. The address will go to GA and thus help Google analytics figure out when the URL actually changes:







The code returns the path, string, and hash of the URL.



2. Create a trigger



After setting up the trigger History fragment change, select its type. Here you should take History change and select popstate activation. All these manipulations will allow you to record the change in the active history record:







3. Customize the tag



Next, configure Universal Analytics. In the settings, select Page and the getPathWithFragment



variable that was created earlier:







That's all, it remains only to add the History fragment change trigger and check the tag operation.



4. What is the tag for?



If the user who visits the site clicks on the link that is needed to load the new data of the dynamic page, the created trigger is triggered and, as a result, the GA tag. Thanks to this, the data goes smoothly to Google analytics.



How to track outgoing links and file downloads



Tracking links is very useful. So you can find out where the user goes from the site and how often he does it. The GTM setup in this case is slightly different from what was described above. For tracking, you need to create a variable in which the system will record all the data necessary for analytics. Recording will occur when the trigger fires.



1. Create a variable



We need to declare a new variable that will register the event. You can call it Click_URL_Hostname. Since the variable will contain the address, its type will be the URL. In this case, it is better to remove www to avoid doubling the information:







2. Create a trigger



Select the type of "Only links." As a condition, select the previously created Click_URL_Hostname variable:







3. Create a tag



We create a tag that will track user actions and repeat the algorithm described above:







If everything is done correctly, then the tag should work. Of course, it needs to be checked using the debugger. Note that UA is a constant in which the analytics ID is written. This is a common trick for programmers: use constants instead of numbers, so that mass replacements are easy to make.



How to track file downloads using Google Tag Manager



If you need to find out how, when and with what frequency users download files, use one of the analytics systems or configure GTM.



Create a trigger, select “Links only” as the type. Next, configure Click URL activation:







Such a GTM setup will allow you to fix downloading files with the extension xlsx, pdf, docx, zip and csv.



After that, you can create a tag by selecting the "Event" type and setting the parameters. We already did something similar above when we tracked outgoing links.



Expert Opinions: Why Choose Google Tag Manager



Dmitry Nichiporov, paid traffic specialist at Elama.

“Marketers are important to monitor advertising campaigns. To measure the diverse results of advertising, you need full analytics. With proper settings, advertising statistics can optimize the budget, make the campaign more effective, increase CTR and even lower the price of attracting customers.



In my opinion, GTM is an indispensable and very convenient system that allows flexible tag management. It is enough to configure the code correctly once, and then without any difficulty get the necessary data about the site and clients.



I usually use GTM when I need to install analytics on the site, check the effectiveness of call tracking and chats, and fix certain conversions. Often I use GTM when conducting advertising campaigns for online stores.



It is clear that for companies that do not have a full-time programmer, GTM will be an indispensable tag manager. After all, no special knowledge is required to use it. A fairly basic understanding of how html and js work.



At the same time, GTM will be useful both to ordinary specialists, marketers and advertisers, as well as to large companies and agencies that are engaged in online advertising. ”



Denis Lisogorya, digital analyst at OWOX BI.

“GTM is a great way to simplify your work with analytics on the site. This is an indispensable thing to track and analyze user behavior. With it, you can easily control the process of collecting data from the site by editing and setting tags.



Most of all I like that usually the developer’s participation is required only once - to install the code on the site, and all other manipulations can be done in the GTM interface. This minimizes your dependence on developers. GTM also allows you to use a huge number of ready-made integrations with other services, it has a testing and debugging mode, which makes it possible to test the tags before adding them to the site, as well as many other goodies.



I think that for specialists who are engaged in data collection, they want to quickly influence the change in data requirements or changes on the site, they want to save the budget - it’s worth taking a closer look at this tool. It is important to note that there are a lot of different information on working with GTM, there is an official forum and help where you can always find the answer to your question.



At the moment, there is a Community Template Gallery where you will find tag templates that help solve almost any task, for example, configure data collection for advanced e-commerce. In short, GTM is an ocean of opportunity! ”



From the editors






All Articles