How to create a tag firing priority in Google Tag Manager

Author:

Creating a tag firing priority in Google Tag Manager (GTM) is an essential aspect of ensuring that tags fire in the correct order on your website or app. GTM allows you to manage tags (such as analytics, marketing, and tracking scripts) in a more organized and efficient manner, giving you control over when and how they are triggered. Firing priority ensures that specific tags are triggered before or after others, which can be crucial for certain tracking implementations.

Here’s a step-by-step guide to creating tag firing priority in Google Tag Manager.

1. Understanding Tag Firing and Triggers

Before diving into the details of tag firing priorities, it’s important to understand the basic concepts of tags and triggers within GTM:

  • Tags: These are snippets of code, such as JavaScript or tracking pixels, that are triggered based on certain conditions or events on your site. Tags could be for services like Google Analytics, Facebook Pixel, or AdWords.
  • Triggers: Triggers define when and where a tag should fire. For example, a pageview trigger fires a tag when the page is loaded, and a click trigger fires a tag when a user clicks a button.
  • Firing Order: Tags can be configured to fire based on the conditions or events defined by triggers. In some cases, you may want certain tags to fire before or after others, especially when dealing with complex setups like conversion tracking or cross-domain tracking.

2. Why Set Firing Priority?

Setting firing priorities is crucial for several reasons:

  • Avoiding conflicts: Some tags may conflict with each other if fired in the wrong order. For instance, a tag that modifies cookies may need to fire before a Google Analytics tag that reads those cookies.
  • Accuracy of Data: If a tag depends on another tag firing first (like a remarketing pixel that depends on a Google Analytics event), the order of firing can impact the accuracy of your data collection and reporting.
  • Performance Optimization: The order in which tags fire can impact the page load time. You may want to ensure that non-essential tags (such as marketing or tracking scripts) fire last, without blocking other important content from loading first.

3. Setting Tag Firing Priority in Google Tag Manager

Currently, GTM does not provide a direct way to define a firing priority in the same way it allows you to define triggers or variables. However, there are workarounds and best practices that can help you achieve control over the firing order.

Method 1: Managing Trigger Priority Using Trigger Configuration

One common method of setting firing priorities in GTM is by using the trigger priority feature. Trigger priority helps you control when a tag is fired relative to other tags based on the trigger’s conditions. This is done by setting up custom triggers.

Steps to set trigger priority:

  1. Create Tags with Specific Triggers: Each tag should have its own trigger based on the action you want to track (such as pageview, button click, or custom event).
  2. Set Custom Trigger Firing Order:
    • Click on Triggers in the GTM interface.
    • Select New Trigger.
    • Choose the appropriate trigger type, such as Page View or Click.
    • In the Trigger Configuration section, choose conditions for firing the trigger.
  3. Modify the Trigger’s Firing Order:
    • Use built-in variables like {{Page Path}}, {{Page URL}}, or custom JavaScript variables to control when the trigger fires.
    • For example, if you want a tag to fire only on the first page view or only after a specific button is clicked, create a custom event trigger and configure it to fire only when the condition is met.
  4. Manage Multiple Triggers for the Same Tag: You can apply multiple triggers for a single tag, which can help control when the tag fires based on different conditions. If you need a tag to fire at different stages of page load or after specific user interactions, multiple triggers can be helpful.

Method 2: Using the “Tag Firing Priority” Field in Custom HTML Tags

For custom HTML tags, you can implement a firing priority by using JavaScript code to control the flow of events. The window.dataLayer.push() command can be used to define when data is passed to the data layer, triggering subsequent tags.

Steps to set up firing priority using custom HTML tags:

  1. Create Custom HTML Tags:
    • Navigate to Tags and select New.
    • Choose Tag Configuration and select Custom HTML.
  2. Add Custom JavaScript for Prioritization:
    • Inside the tag, use JavaScript to define the order in which the tags will fire. For example, you can ensure that the page tracking tag is fired before the remarketing pixel.
    • Example JavaScript code snippet:
      javascript
      window.addEventListener('load', function() {
      // Tag 1 fires first (pageview tracking)
      dataLayer.push({ event: 'pageview' });

      // Tag 2 fires after Tag 1
      setTimeout(function() {
      dataLayer.push({ event: 'remarketing' });
      }, 500); // 500 milliseconds delay
      });

    This ensures that Tag 1 (pageview tracking) fires first, and Tag 2 (remarketing) fires with a slight delay, after Tag 1 is completed.

Method 3: Using the “Tag Sequencing” Feature

In Google Tag Manager, Tag Sequencing allows you to define when one tag should fire before or after another. This can be very useful when managing complex tags that depend on the firing order. This feature is available for certain tag types like Google Analytics and other integrated tags.

Steps to use tag sequencing:

  1. Open the Tag Configuration:
    • In GTM, go to Tags and select the tag you want to configure.
    • Click on Tag Configuration and scroll to the Advanced Settings.
  2. Enable Tag Sequencing:
    • Under Advanced Settings, find the Tag Sequencing section.
    • Check the option for Fire a tag before or after this tag.
    • Specify the tag you want to fire before or after.

    For example, if you want your Google Analytics pageview tag to fire before your Facebook Pixel tag, you can set the Facebook Pixel tag to fire after the Google Analytics tag.

  3. Set Delays (Optional):
    • You can also set a delay for the next tag to fire by specifying the delay time in milliseconds. This is useful for ensuring that non-essential tags, like marketing pixels, do not block the loading of important content.

Method 4: Using Custom Events for Advanced Control

For more granular control over firing order, consider using custom events within the data layer. Custom events provide a way to specify exactly when a tag should fire based on specific user actions or conditions.

Steps to use custom events:

  1. Push Custom Events into the Data Layer:
    • In the code of your website, push custom events into the data layer to trigger specific actions.
    • Example:
      javascript
      window.dataLayer = window.dataLayer || [];
      window.dataLayer.push({ event: 'customEvent' });
  2. Create Custom Event Triggers:
    • In GTM, create a trigger based on the custom event by selecting the Custom Event trigger type.
    • Specify the event name (e.g., customEvent) that corresponds to the event pushed into the data layer.
  3. Prioritize Tag Firing with Custom Events:
    • You can use multiple custom events to control the firing order by ensuring that one event pushes the next tag to fire.

4. Best Practices for Managing Tag Firing Priority

  • Prioritize Critical Tags First: Tags that are essential for tracking conversions (e.g., Google Analytics, AdWords) should fire early, while marketing pixels or less critical tags can fire later.
  • Minimize Conflicts: Ensure that tags that affect the same elements (such as cookies or local storage) do not conflict with each other.
  • Use Tag Sequencing for Important Dependencies: If one tag depends on the successful firing of another, always use GTM’s tag sequencing or custom events to ensure the correct order.
  • Test Before Deployment: Always test your setup in the GTM Preview mode to confirm that tags fire in the correct order without causing issues.
  • Monitor Performance: Be mindful of the impact that tag firing order may have on the performance of your website. Non-essential tags should be delayed to prevent any interference with page loading.

Conclusion

Creating a tag firing priority in Google Tag Manager requires an understanding of how tags and triggers work, and how to leverage advanced features like custom triggers, tag sequencing, and custom events. While GTM doesn’t provide a direct priority setting, using these techniques can give you fine-grained control over when and how your tags fire, improving your website’s performance and ensuring accurate data collection.