GTM AutoTagging

View on Github

The Automatic page and click tracking is a tag for AT Internet's SmartTag that helps you tag all your sites and links with GTM and a few lines of JavaScript that can be called on each page.

Benefits

When you can't afford to set the tagging with the technical teams, implementing the GTM tag in the header of your site will be your only technical move.
Page and click names will match your URL structure, which means you will be able to work hand in hand with SEO teams regarding analysis.

Getting started

To get started, all you have to do is check whether you have installed the AT Internet JavaScript SmartTag on your website with the Pages and Clicks plugins.

Then check out the code and do not forget to change specific strings to match your site configuration such as site number, domain names, level 2 site IDs.

You can download the script with the download button down below, if you want to propose improvements you can push new contents on the GitHub repository here.

Category:

Description

Prerequisites

  1. Deploy the SmartTag in Tag Composer with Pages and Clicks plugins and the “ignore empty chapters” box ticked.
  2. Set up or use a Tag Manager account and add its tracking code to your site.
  3. Download the master zip in the top description.

 

Pagetagging.HTML

Tag

Sets a page name based on the URL structure, and a level 2 site based on the domain of the current URL.
Any folder after the third one that isn’t the page, will be added to the third chapter separated by a slash.

Please be sure to edit the following parts :

  • Line 1 : the site number (here 123456) so it matches yours
  • Line 36 : the URL(s) of your homepage(s) in every format they can be called (with or without the extension file)
  • Line  103 to 107 : the hostname defining your level 2 sites

 

Trigger

Create a trigger to call it on either DOM ready or Page view in GTM.

 

LinkTagging.HTML

Tag

Sets attributes to each link with the following informations :

  • Link type: with the data-click-type attribute based on the href value
  • Link position: with the data-click-position attribute based on the iteration of each link in the page
  • Link name: with the data-click-name attribute based on the page name previously identified with the page tagging and the inner text of the link
  • Link level 2: with the data-click-s2 attribute based on the current page level 2 site id

Please be sure to edit the following parts :

  • Line 5 : the domain to define exit clicks
  • The other criterias of the link type part, so it matches your urls.

 

Trigger

The trigger on this tag will be DOM ready or Page view.
It will use a tag sequencing in its advanced parameters to load it after the page tag.
This way variables such as s2 and page name can be used in link tagging.

 

GTMClickINIT.HTML

Variables

Allows us to stock information in HTML attributes (name, position, type and s2).
These details can be accessed in a Tag with GTM variables, here we will have to declare 4 Data Layer variables:

  • Click Name: calling gtm.element.dataset.clickName
  • Click Position: calling gtm.element.dataset.clickPosition
  • Click S2: calling gtm.element.dataset.clickS2
  • Click Type: calling gtm.element.dataset.clickType

Please note the datalayer variables called will match the HTML attributes such as gtm.element.dataset.clickType getting the data-click-type attribute of the targeted element.

 

Tag

Tag Manager variables must be called in this format  ‘{{My variable name}}’.

Based on these variables the GTMClickInit file gets as click label : the current page and the link’s inner text with its position in the page.

 

Trigger

Google Tag Manager has its own clickListener Trigger, so you can directly set your tag to be fired on any clicked link.

Reviews

There are no reviews yet.

Be the first to review “GTM AutoTagging”

Your email address will not be published.

This field can't be Empty
This field can't be Empty
This field can't be Empty
This field can't be Empty