DTM – find the rule that does …

Yet another article about DTM… I guess by now I can’t even get away with calling it a “mini series” anymore, can I?!

Today, I want to share a tip that came in handy a couple of weeks ago while troubleshooting a relatively complex implementation with a lot of rules.

The topic: I know that I am setting a “variable” or event somewhere — say event2. How can I find out which rule is doing that?

There are actually two ways, and I shall describe them both.

The Men Who Stare at Code

(Apologies for the non-inclusive title, I just couldn’t resist the movie title connection here.)

The easiest way to find where you’re setting a “variable” or event is to use the browser’s built-in tools. Let me show you how to do it with Chrome.

First, open the “Sources” tab in the “Developer Tools” and find the files loaded from “assets.adobedtm.com”. Under there, you’ll find one or two files that are called “satelliteLib-xyz”. Select the staging file. (I’m presuming you’re in staging)

Beautify the code (see tip #4 in David Vallejo’s article on debugging your GTM). Now you can use CTRL-F to search for the “variable” or event you’re looking for.

[Screenshot]
Searching in beautified Sources view
From there, just scroll up very slightly, until you find the name of the rule.

[Screenshot]
Name of the rule in question
That was almost too easy, wasn’t it?

Complicated

Remember that you can see all the rules in the Console?

If we can see them, then we can iterate through them, right?

Now this is ugly:

[Screenshot]
Code that finds events
And what does it do?

Well, if you copy it into the console, then execute it, you get output like this:

[Screenshot]
Events found
Ugly, but with a huge collection of rules, this might just be useful.

The snippet works for Event-based and Direct Call Rules, but it has to be modified a little bit for Page Load Rules.

[Screenshot]
Find events in PAge Load Rules

Notes

You can check what rules look like by just typing _satellite.rules, _satellite.directCallRules, or _satellite.pageLoadRules into your console and inspecting the resulting objects. I’m sure you’ll find a similar way to look for eVars or props…

5 thoughts on “DTM – find the rule that does …

  1. This is great stuff, thanks for sharing Jan!

    I ended up tweaking the Direct Call rule script slightly so that it returns the name of the Rule, rather than the array location:

    //capture the events that are called in direct call rules
    var srs = _satellite.directCallRules;
    for(rule in srs) {
      for(trig in srs[rule].trigger) {
        for(argument in srs[rule].trigger[trig].arguments) {
          for(arg in srs[rule].trigger[trig].arguments[argument]) {
            for(ae in srs[rule].trigger[trig].arguments[argument].addEvent) {
              _satellite.notify("Rule "+srs[rule].name+" sends event "+srs[rule].trigger[trig].arguments[argument].addEvent[ae],3);
            }
          }
        }
      }
    }

    Like

    1. Here’s a cleaner version for PLRs:

      _satellite.pageLoadRules.forEach(function(obj,index) {
      	var rulename = obj.name;
      	if (obj.trigger) {
      		obj.trigger.forEach(function(obj,index) {
      			if (obj.command == "setVars") {
      				if (obj.arguments) {
      					obj.arguments.forEach(function(obj,index){
      						for (var key in obj) {
      							_satellite.notify(rulename + ": " + key + " > " + obj[key]);
      						}
      					});
      				}
      			}
      		});
      	}
      });
      

      Like

      1. And a cleaner version for EBRs:

        _satellite.rules.forEach(function(obj,index){
        	var rulename = obj.name;
        	if (obj.trigger) {
        		obj.trigger.forEach(function(obj,index){
        			if (obj.command == "trackLink" || obj.command == "trackPageView") {
        				if (obj.arguments) {
        					obj.arguments.forEach(function(obj,index){
        						if (obj.addEvent) {
        							var output = rulename + ": ";
        							obj.addEvent.forEach(function(obj,index){
        								output += obj + ", ";
        							});
        							_satellite.notify(output, 3);
        						}
        						if (obj.setVars) {
        							for (var key in obj.setVars) {
        								_satellite.notify(rulename + ": " + key + " > " + obj.setVars[key]);
        							}
        						}
        					});
        				}
        			}
        		});
        	}
        });
        

        Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.