Comment
02-06-2021
- Mark as New
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Interesting approach. I have some concerns with it as written though.
The code block :
var setVariables = Object.keys(s).filter(function (k) {
return /^((eVar|hier|prop)[0-9]+|products)$/.test(k);
});
- This fails to include a handful of variables, ['channel', 'campaign', 'state', 'zip', 'pageType', 'purchaseID', 'transactionID', 'list1', 'list2', 'list3', ...maybe some others]. As it stands, these variables would not get cleared.
- The s object has a ton of keys on it. It would me more code, but more performant to run some for loops to create the array that gets returned here.
I think that a better implementation for a clearVars function with exclusions would be to overwrite s.clearVars as such:
// This should be run at the top of AA Custom Code
s.clearVars = function() {
var clearVarsExclusions = _satellite.getVar('clearVarsExclusions') || [];
var clearVarsAdditions = _satellite.getVar('clearVarsAdditions') || [];
var aaVars = [
'chanel',
'events',
'products',
'purchaseID',
'transactionID',
'state',
'zip',
'campaign'].filter(function(variable){
return (clearVarsExclusions.indexOf(variable) === -1);
});
var genVars = function(prefix, limit, exclusions){
var variables = [];
for (var i=1; i<=limit; i++) {
var variable = prefix+i;
(exclusions.indexOf(variable) === -1) && variables.push(variable);
}
return variables;
};
aaVars.concat(
clearVarsAdditions,
genVars('prop', 75, clearVarsExclusions),
genVars('eVar', 250, clearVarsExclusions),
genVars('list', 3, clearVarsExclusions),
genVars('hier', 250, clearVarsExclusions)
).forEach(function(variable){
s[variable] = void 0;
});
}
Beyond being more performant, this allows the use of the AA Extension's Clear Variables action if desired. If you would rather call s.clearVars from a postTrackCallback, this solution would support that as well.
Oddly enough, the s.clearVars function in AppMeasurement.js does not clear s.pageName. The solution above allows the specification of an array of variables to include when clearing.
If I were to take this one step further, I would
- put this code into an extension so that no changes would need to be made in AA custom code.
- also add a UI for management of the exclusion and addition lists.
- add the option to call the function after every beacon (via register postTrackCallback).
- possibly add some functionality for clearing context variables.
Just my $0.02