Last active
March 4, 2022 03:46
-
-
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().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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