How does DTM know which rule is more specific?

Here’s a simple question:

If I have two Page Load Rules setting the same variable, and if both rules fire, which one wins?

Hm…

I might have a standard PLR that fires on every single page of my site. This rule might use the URL of the current page to compute some kind of page name. This page name is then written into s.pageName.

(Note: while this is not recommended, it happens quite a lot in practice.)

Another rule — say one specific for product detail pages — sets s.pageName according to a slightly different algorithm.

This is a fairly common scenario.

“Hierarchical rule sets”, in which some data is processed the same way everywhere, while other rules cover more specific cases, is one of the normal ways to deploy Analytics using Tag Management Systems.

Do we know?

When I was asked this question for the very first time, I thought “well, there’s obviously going to be an order, right?!”, hoping there would be one. Nothing is worse than non-deterministic behaviour when you want to program…

So is there? Does DTM follow some order when it works through the rules it has to fire? And is that order always the same?

Turns out, yes, there is an order. In essence, the rules are stored in a Javascript array.

[Screenshot]

4 Page Load Rules in DTM

Funny enough this is the exact same order that you see in the UI in DTM itself.

[Screenshot]

The same 4 PLRs in the DTM UI

Looks alphabetical to me, doesn’t it?

And so there is our answer: the rules are stored in alphabetical order, and DTM executes them in that order, too.

No, sorry, scratch that…

The rules are stored in alphabetical order, and when DTM traverses them to see which one to execute, it does so in the same order.

Wow, that was a short post, wasn’t it? Finally a simple answer to a simple question!

About

German expat living in Switzerland (formerly UK and France). Consultant and member of the Multi-Solutions Group at Adobe, working with the Digital Marketing Suite. Father of 4 girls.

Tagged with: , ,
Posted in DTM
8 comments on “How does DTM know which rule is more specific?
  1. Lukáš Čech says:

    When I asked Rudi and Jeff, they told me that I shouldn’t rely on this, because they cannot confirm this won’t change in the future.

    Like

  2. I’ve actually seen that often it’s whichever rule you saved most recently that executes first.

    Like

    • Jan Exner says:

      Ah. I haven’t seen that so far.

      When that happens, do the rules get listed in the order you described in the DOM? Or still alphabetically?

      Like

    • craemer@adobe.com says:

      Same observation here. I updated/saved two rules that fire on the same page. That affected the actual rule order… -> seems like it first fires the rule that was most recently saved (and published). DTM debugger confirms that theory. The “older” the rule the earlier it gets fired (so long as they have the same trigger)

      Like

  3. Cleve Young says:

    I was looking at this exact thing the other day. Using the DTM Switch plugin I watched the rules fire in descending alphabetical order. I tried changing some rule names to change the order, and the updated rules rearranged to fire in their new alphabetical order.

    Something else to keep in mind – just because a rule starts before another rule doesn’t guarantee it finishes before that following rule. There are ways to get rules to fire (and finish) in the order you prefer or to have rules check if a variable has already been set by a separate rule, but they can get complex, confusing, and potentially unstable over time so I avoid that if at all possible.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 1,398 other followers

%d bloggers like this: