Event tracking with Google Tag Manager

Use Google Tag Manager to trigger tags in response to specific actions in your digital workplace.

Sections in this article: 

Considerations and caveats

Google Tag Manager

Google Tag Manager script must be active in your digital workplace.

Google Tag Manager variables

Make sure that your Google Tag Manager container has the appropriate variables enabled for the trigger action you are using. For example, if you want to track clicks, go to the Variable page and make sure that all the Clicks options are selected. 

Google Tag Manager container

After making changes to your container, do not forget to publish them to make them live.

Event tracking using Google APIs

If you are familiar with JavaScript, you do event tracking using Google Analytics APIs.

How to track click events with Google Tag Manager

  1. Identifying the element. You must first set up a generic click trigger that you can then use to identify the unique property of the element you want to track.
    1. In Google Tag Manager, create a new click trigger on all elements, and for all clicks. 
    2. Enter preview mode.
    3. In a new tab of the same browser, go to the location of your digital workplace that has the element you want to track clicks on.
    4. Ctrl-click the element you want to track to open any link in a new tab and avoid navigating away from the current page.
    5. In the Tag Manager panel at the bottom of the window, you should see a click recorded in the Summary column. Select this click event and then select the Variables tab.
    6. From the list of Variables, identify which are unique to this element.
      • Click Text, Click URL, and Click Classes are all variables that could potentially be unique.
      • You should also verify that multiple elements may not correspond to the element you are interested in.
      • Some elements may not have a unique identifier by default.
  2. Creating a more specific trigger. Once you know how to identify your element, go back to your generic trigger and update it. Instead of All Clicks, it should only trigger on Some Clicks, with the conditions corresponding to the unique property of the element you are tracking clicks on. You will need to attach this trigger to a tag before you can test it.
  3. Adding a tag to the trigger and testing. Create a new tag that corresponds to your trigger. When configuring this tag:
    • Select a Tag Type of  Google Analytics Universal Analytics.
    • Select a Track Type of Event and enter values into the Category and Action fields.
    • Make sure that the Google Analytics settings correspond to your Google Analytics Tracking ID.
    • Add your specific trigger to the Triggering section of the tag.

Once you create the tag, refresh your preview and digital workplace window. The Tag Manager panel should display your tag under the Summary as Tags Not Fired. Select the element, and the Summary should update to showing that the tag was fired. If it doesn't, verify whether its condition has been met (you can select the unfired tag, in Summary, to see what the condition is, compare this to the associated click's variables).

How to track the use of broken links within a digital workplace

Sometimes links to other locations within your digital workplace become invalid. In these cases, users who click a link arrive at a page with a Page Not Found message. You can track these occurrences and the referring page using Google Tag Manager to send events to your Google Analytics dashboard.

In Google Tag Manager:

  1. Create a new User-Defined variable with the following properties:
    • Type: DOM Element
    • Selection Method: ID
    • Element ID: errorpage-message
  2. Create a trigger with the following properties:
    • Type: Page View
    • Fires on: Some page views
    • Condition: Variable from step 1 contains This page does not exist
  3. Create a tag with the following properties:
    • Type: Google Analytics Universal Analytics
    • Track Type: Event
    • Category: Page Not Found (or whatever name fits your categorization)
    • Action: {{Referrer}} to {{Page Path}} (this is where the URL originated from and where it was trying to go to)
    • Google Analytics: Your Google Analytics tracking ID.

You can now view occurrences of this event on your Google Analytics dashboard by going to Behavior > Events > Overview and selecting the Page Not Found category (or the name you entered for it). Then select a Primary Dimension of Event Action to see a list of URLs that have links that result in a Page not Found message.