Data Layer

Variable from site can be sent to GTM through Data Layer. There are two method to work with dataLayer

Static Initialization in <head> tag (or previous GTM container’s call) – View Source of this page:


After page loaded (or after GTM container called):

Try to click this link




dataLayer is a javascript array and it can store one or more multiple object…makes it a complex Array, for example:

dataLayer=[ {



















Read more:

Trigger and Event Tracking

Hello, this page get tracked for a multiple purpose, including:
1. Tracking on Button (Event Tracking)

2. Event Tracking on Outgoing Link



Internal Link Sample

3. Event Tracking on Download Link

Download Digital Metrics Playbook

Download Social Media Strategy by Hootsuite

This is a Test TXT File 

4. Youtube Tracking


Script for youtube checker

Script for listener


  1. Create Custom Variable for checker (yt_checker)
  2. Create Trigger with “DOM Ready” and filter where yt_checker set to true i named it “yt_checktrigger”
  3. Create new Custom HTML tag, use listener scipt above and use “yt_checktrigger” as Trigger
  4. The listener script send 4 parameter:
    1. eventName: ‘youtube’
    2. eventCategory: ‘Youtube Videos’
    3. eventAction: <<theVideo Title>>
    4. eventLabel: <<theVideo event info / length>>

      You need to create DataLaer Variable for eventCategory, eventAction, and eventLabel

  5. Create new trigger, its a Custom Event, and use event name ‘youtube’. i named this trigger ‘YT_Action’
  6. Create new tag, set to Analytics Event, then assign Category, Action, Label as parameter on step 4. Use ‘custom event’ as trigger and set to ‘YT_Action’
  7. Preview and Publish

Let Google Tag Manager and Javascript

You just saw a Google Tag Manager fire a custom javascript alert !

Here’s how i am doing it:

1. Create Variable

Simple Google Tag Variable

2. Create Trigger

Simple Google Tag Trigger

3. Create Tag

Simple Google Tag Manager

Real World Example…… Sky is your limit, isn’t ?
you want to see the alert pop-up triggered by GTM again.. click here

So the keypoint here:

  • Function you create on a tag can be accessible on your page
  • You need to use {{variablename}} format to access GTM variable

How about retrieve GTM Variables.. like here

There are two types of Javascript Variable in Google Tag Manager’s Variable

1. Custom Javascript

Basically this is function that you code inside GTM:

Google Tag Manager Custom Javascript Variable

2. Javascript Variable

Basically this is a global variable in your page that detected by GTM. It would set as undefined when global variable not exist.
Tips: You can also set this variable from Custom HTML Tag

Google Tag Manager Javascript Variable