Comment

Avatar

Level 4

01-12-2019

Correct, I don't use s.clearVars() because it's so destructive.

 

Instead, I use s.registerPostTrackCallback() like so:

 

s.registerPostTrackCallback(function(requestUrl, s) {

  _satellite.logger.warn('s.registerPostTrackCallback() called');

 

  // unset variables and events that are not needed after sending a beacon

  // BUT LEAVE BEHIND variables that should remain, e.g. those that are set in the Adobe Analytics extension itself

 

  var doNotUnsetVariables = [

    // list of variables to keep between hits, including pageName, hierN, server, channel, etc.

  ];

  var doNotUnsetVariablesRegExp = new RegExp('^(' + doNotUnsetVariables.join('|') + ')$');

 

  // find and erase all unneeded variables: eVar's, hier's, prop's, products

  var setVariables = Object.keys(s).filter(function (k) {

    return /^((eVar|hier|prop)[0-9]+|products)$/.test(k);

  });

  var unsetVariables = setVariables.filter(function (k) {

    return !doNotUnsetVariablesRegExp.test(k);

  });

  unsetVariables.forEach(function (v) {

    s[v] = '';

  });

 

  // erase all success events

  s.events = '';

}, s);

 

I'm not sure if there's a better way to clear variables selectively, but this works for me.

 

However, due to Launch's asynchronous firing, if I fire two s.tl()'s together, there's a very high chance that the subsequent s.tl() will send variables that were in the first s.tl(), even though I don't want them to be.