Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuhui/f4fe9a4827ceabffcd847e286235ae21 to your computer and use it in GitHub Desktop.
Save yuhui/f4fe9a4827ceabffcd847e286235ae21 to your computer and use it in GitHub Desktop.
Adobe Analytics: clear variables' values and events after beacons have been sent, instead of using s.clearVars().
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 = [
'pagename', // page name
'hier1', // page hierarchy 1
'server', // site server
'channel', // site section
// ... other variables
];
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|list|prop)[0-9]+|(purchase|transaction)ID|campaign|channel|pageType|products|state|zip)$/.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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment