Gaining visibility while working with Extensions and Tags

Bronze Contributor
Bronze Contributor

Hi Team,

I have come across a series of issues recently where is has become progressly harder to determine why a tag doesn't poplate with the correct detail at anyone time.

Asside from utagdb=true, is there any way to broadcast when a tag or extension is being fired (preferably with the UID ref) and also what the state of b object is on entry to the tag/extension in question?

Preferably I would like this as an array of b objects with the UID as a key, so I can present this in an easy to consume debug panel. Thoughts?

 

3 REPLIES 3

Gaining visibility while working with Extensions and Tags

Tealium Expert
Tealium Expert

One way, @dlaidler, would be to amend the function that executes extensions so that it logs the current state of the UDO when it's invoked, and then again after each extension has run.

Something like this would work - you could run it as a DOM Ready extension, or in a bundle tag, basically you want to get this run between the creation of the utag object on the page, and the first extension run:

utag.extension_log = [];

utag.handler.RE = function (a, b, c, d, e, f, g) {
  if (c != "alr" && !this.cfg_extend) {
    return 0;
  }
  utag.DB("RE: " + c);
  if (c == "alr") utag.DB("All Tags EXTENSIONS");
  utag.DB(b);
  if (typeof this.extend != "undefined") {
    g = 0;
    // New bit here..
    utag.extension_log.push({
      id: 0,
      code: "Start " + c,
      udo: JSON.stringify(b)
    });
    for (d = 0; d < this.extend.length; d++) {
      try {
        /* Extension Attributes */
        e = 0;
        if (typeof this.cfg_extend != "undefined") {
          f = this.cfg_extend[d];
          if (typeof f.count == "undefined") f.count = 0;
          if (f[a] == 0 || (f.once == 1 && f.count > 0) || f[c] == 0) {
            e = 1
          } else {
            if (f[c] == 1) { g = 1 };
            f.count++
          }
        }
        if (e != 1) {
          this.extend[d](a, b);
          // New bit here..
          utag.extension_log.push({
            id: d,
            code: this.extend[d].toString(),
            udo: JSON.stringify(b)
          });
          utag.rpt['ex_' + d] = 0
        }
      } catch (er) {
        utag.DB(er);
        utag.rpt['ex_' + d] = 1;
        utag.ut.error({ e: er.message, s: utag.cfg.path + 'utag.js', l: d, t: 'ge' });
      }
    }
    utag.DB(b);
    return g;
  }
};

utag.extension_log will then be an array containing each extension executed, listed by ID, with a copy of the code for ease of reference, and a stringified UDO that you can then parse back into an object to check the state of any specific variables. Should be fairly easy then to use that as a starting point to write something to check the deltas between extensions and track exactly what is being set where..

Gaining visibility while working with Extensions and Tags

Bronze Contributor
Bronze Contributor

Hey @UnknownJ,

Thx for a quick reply, and this is pretty close where I need to be...

I don't seem to be getting a correlation between the ID in the array

id: d

 and the UID present in the UI 

 

ALSO, is there anyway to catch the UDO during Tag fires (in the same array push, IE/ in order extensions & tags)?

Thx in advance, Dan

Gaining visibility while working with Extensions and Tags

Tealium Expert
Tealium Expert

Ah, of course, @dlaidler, sorry, that's just the index in the array.

To get the ID that corresponds to the UI, you need to use the following expression in place of that simple d reference:

utag.handler.cfg_extend[d].id

That'll perform a lookup to the corresponding config entry and retrieve its source ID.

On the question of tag-scoped extensions, I think the following code should work:

for(var tag_id in utag.sender){

  var this_tag = "" + tag_id;

  var reducer = function(extension_list, next_extension){
    extension_list.push(next_extension);
    extension_list.push(function(a,b){
      utag.extension_log.push({
        id: "Tag: " + this_tag,
        code: next_extension.toString(),
        udo: JSON.stringify(b)
      });
    });
    return extension_list;
  };

  if(utag.sender[tag_id].extend){
    utag.sender[tag_id].extend = utag.sender[tag_id].extend.reduce(reducer,[]);
  }

}

There's nothing to link back to the ID in the UI, the tag scoped extensions don't make any mention of it anywhere so there's no way to access that, but effectively what we're doing here is iterating through the array of tag scoped extensions for each tag, and then creating a new array which alternates between running the extension, and simply dumping the UDO into the previously created utag.extension_log array along with the code for that extension.

Edit: That "this_tag" bit doesn't work, never was any good at remembering how to make the iterating key persist in scope for use later, but in general the whole thing still works, it'll just misattribute all your extensions to the last tag unless you fix that bit....

Public