I have a use-case connected with counting page-views. That data element should live as long as a particular visitor. I was trying to set this up as Data Element in UI but then I thought that it might be user setting this up as a rule.
Why that custom code in rule does not work? It always returns 0 .....
if(!_satellite.setVar('PageViewCount', 0)) {
_satellite.setVar('PageViewCount', 0);
} else {
let vaar = _satellite.getVar('PageViewCount')
vaar= vaar+ 1
_satellite.setVar('PageViewCount', 0);
console.log(vaar)
}
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Made minor changes in your code to make it work. Can set it on every page load.
if((_satellite.getVar('pageViewCount') == undefined)) {
_satellite.setVar('pageViewCount', 1);
} else {
var initialCount = _satellite.getVar('pageViewCount')
var latestCount = initialCount + 1
_satellite.setVar('pageViewCount', latestCount);
console.log(latestCount)
}
another option is to set long term user cookie using TAG and overwrite that with increment value on each page load.
Thanks,
Asheesh
Views
Replies
Total Likes
@Asheesh_Pandey Can you look in the script?
Views
Replies
Total Likes
HI Michael, it would be great if you can share your use case details. How you want to use data? I have few thoughts to solve this but will wait for your response.
Views
Replies
Total Likes
Made minor changes in your code to make it work. Can set it on every page load.
if((_satellite.getVar('pageViewCount') == undefined)) {
_satellite.setVar('pageViewCount', 1);
} else {
var initialCount = _satellite.getVar('pageViewCount')
var latestCount = initialCount + 1
_satellite.setVar('pageViewCount', latestCount);
console.log(latestCount)
}
another option is to set long term user cookie using TAG and overwrite that with increment value on each page load.
Thanks,
Asheesh
Views
Replies
Total Likes