parm530
8/7/2019 - 2:29 PM

GTM

GTM - Google Tag Manager

Used to collect all the tags your site uses instead of writing the tags in the html page so that you only need to include the 1 google tag manager link.

  • A tag is used to collect and report an interaction to Google Analytics, or some other reporting tool.
  • A trigger is used to observe an interaction and to decide whether a tag should be fired or not.
  • A variable is used to capture some information off the page and provide that info to the triggers or tags when needed.
  • Google Tag Manager can automatically “listens” for actions happening on the page. When an interaction occurs, GTM will compare it against a list of expected interactions, aka triggers, and if a match is found, GTM will take action and fire the corresponding tag.
  • Click trigger listens for any click on the page (on any type of elements)
  • Form Submission fires when a form is successfully validated and submitted
  • History Change fires when the browser history changes, i.e. a page change Custom Event trigger listens to the events being pushed via the dataLayer
  • JavaScript Error fires when the scripts errors out
  • Timer fires after an interval of time

Using analaytics.js to send custom dimension value

ga('set', 'dimension1', 'hello-from-new-user-sign-up');         
ga('send', 'event', 'category', 'action', {
    'dimension1': 'hello-from-new-user-sign-up'
});

Using GTM

window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    'event': 'newUser',
    'destination': window.location.pathname.replace(/\//g, "_")
});