DEV Community

Ochtum
Ochtum

Posted on

Firing order of tags in Google Tag Manager

1. Target Audience for This Article

  • Beginners in Google Tag Manager
  • Those who want to create custom events
  • Those who want to write custom HTML tags
  • People who have set tag firing priority but it's not working as expected
  • People who are unsure about the differences between tag firing priority and tag sequencing

2. Introduction

This article is written for beginners in Google Tag Manager (GTM) and aims to explain the concept of tag firing priority, which can easily become a trap if misunderstood.

The issue lies in how the Japanese version of the official documentation can be interpreted — it may give the impression that simply setting tag firing priority ensures proper execution order.

However, when reading the official documentation in English, it clearly states:
“To control more precisely, use tag sequencing to specify which tags should fire before or after others.”

This implies that Google does not guarantee precise control over tag firing using only "Tag firing priority."

For instance, if different triggers are used, or if a tag fires multiple custom events, then tags triggered by those events may not necessarily respect the defined priority.

So how exactly does tag firing work, and how should we handle custom events?


3. What Exactly is a Custom Event?

Custom events can generally be categorized into three types:

  1. Events used to create triggers in GTM
  2. Events used to fire those triggers
  3. Events sent to Google Analytics as custom events

Items (1) and (2) work as a pair.

To begin, you use JavaScript to push a custom event to the dataLayer, like this:

dataLayer.push({'event': 'custom_event'});
Enter fullscreen mode Exit fullscreen mode

This script is usually placed inside a Custom HTML tag that fires on a page view or initialization event.

Since you use JavaScript, it's also possible to create highly flexible custom events using addEventListener, etc.

Next, you create a new trigger in GTM, set its type to “Custom Event,” and specify the same event name that you pushed to the dataLayer. Then, you attach this trigger to any tag you want to fire.

As for events sent to Google Analytics as custom events, you can do this by using a tag of type Google Analytics: GA4 Event and giving it any custom event name.

More details are available in the GA documentation.

Note: You can also use gtag functions within Custom HTML to send custom events, but this requires using both GTM and GA tags in tandem.


4. Understanding Tag Firing Order

There are three main concepts for controlling tag firing order. In increasing order of granularity:

  1. Firing tags using different triggers
  2. Using tag sequencing
  3. Using tag firing priority

Keep in mind that (3) may not work as expected if the tags are triggered by different triggers.

(1) Firing Tags Using Triggers

You can use built-in triggers such as "Page View," or define new ones like "DOM Ready" or "Window Loaded" to control when a tag fires.

You can also create your own custom events and use those as triggers. This involves pushing an object containing an event property to the dataLayer.

This method is useful when you want to conditionally fire tags — for example, based on whether a specific form field is shown or depending on the user’s selection on a previous page.

Here’s an example:

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({'event': 'your_custom_event_name'});
</script>
Enter fullscreen mode Exit fullscreen mode

To use this, create a trigger of type “Custom Event” in GTM and specify the name you used in the dataLayer.push() call. Then, assign this trigger to your tag.

Custom Event Trigger Example

(2) Tag Sequencing

This is useful when there is a dependency between tags.

If you have large processing logic that you'd like to break into separate tags or want to reuse initialization logic, tag sequencing makes it easier.

You can configure one tag to fire only after another completes, or set a tag to fire before another.

(3) Tag Firing Priority

When multiple tags are set to fire from the same trigger (e.g., a Page View), the one with the higher priority number will attempt to fire first. The default value is 0.

For example, advertising platforms like Facebook may instruct you to “place this tag near the top” or “at the end.” This is where firing priority helps.


5. Conclusion

Using Google Tag Manager becomes increasingly beneficial if you often need to insert or update scripts on your site. Common scenarios include:

  1. You're currently using or plan to use web advertising for traffic
  2. You manage multiple sites and want a scalable way to handle changes
  3. You run an e-commerce site and want to analyze user behavior
  4. You have a unique site or web app where standard tracking doesn’t suffice

In particular, point (4) is quite relevant for web applications — you may have a multi-tenant setup and need to analyze by tenant, or perhaps you've changed your UI and need to update your scripts accordingly.

In such cases, GTM becomes a powerful tool.

Moreover, working with GTM is a great way to learn JavaScript. If you manage your own website, this is a great opportunity to give it a try.

Top comments (0)