GTM(Google Tag Manager)

GTM is a tracking code manager developed by Google, which can add and update its own code on the platform for conversion tracking, website analysis, remarketing and other purposes.

advantages

  • Flexibility to deploy updates without modifying the project source code
  • Website statistical analysis code can be unified management
  • Powerful, you can add JS, HTML, images and other templates, highly integrated with third-party tools
  • Convenient debugging

How to use

On marketingplatform.google.com/about/ GTM research have a free version, can register and open account, after the GTM research will give you a js code block, need each HTML page you put inside the < head > tag, similar to the following code, There will be a GTM-XXxxx which is the ID of your GTM Container. You need to replace it with the ID of your own container

<! -- Google Tag Manager --><script>(function(w,d,s,l,i){w[l]=w[l]||[]; w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l! ='dataLayer'?'&l='+l:' '; j.async=true; j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl; f.parentNode.insertBefore(j,f); }) (window.document.'script'.'dataLayer'.'GTM-XXXXX');</script><! -- End Google Tag Manager -->Copy the code

Tag (code snippet)

The most important part of GTM is the ability to deploy Google analytics services within tag, or third-party services, or to embed custom code if some services are not integrated into GTM. You can see that there are quite a few ways to deploy your code in tag.

This is a Trigger.

Each tag must be associated with a trigger that triggers the execution of the tag. For example, if you want some statistics code to report only when a particular URL is accessed, you need to add trigger to specify the condition.

Trigger can be triggered in a number of ways, from when the page loads to when certain DOM elements are visible to when the user clicks a button.

Variable

In most cases, certain information needs to be uploaded for data statistics. For example, e-commerce websites need to count what commodities, quantity and price users have purchased, or what buttons users have clicked. These need to be defined in the form of variables, and tag and trigger can be referenced after setting variables. Trigger can refer to variables to define some triggering conditions, such as when the user is in a certain language. Tag can obtain the value of variable and upload it to the relevant service provider.

Variable also has many types. It can be the URL of the current page, or a value computed by custom JS.

The most commonly used is Data Layer Variable

Datalayer

When the GTM script runs, it creates a global object called a dataLayer. The dataLayer is actually an array. You can use datalayer.push () to add related data, which can be easily retrieved from GTM variable.

For example, if you add an attribute datalayer.push ({pageType:’home’}) that describes the current pageType, you can define the value of Variable in this way

For example, if you add relevant data to the dataLayer after the user buys an item, if a Trigger is triggered before the button is clicked (such as a PageView Trigger), then no information about the item will be available. Therefore, it is very important to clarify the triggering conditions of trigger and the time when variable is added. If the order is out of order, undefined will be obtained, which will affect the accuracy of data statistics.