Expand my Community achievements bar.

SOLVED

counting page views per visitor

Avatar

Level 7

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)
}

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Michael_Soprano 

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

View solution in original post

3 Replies

Avatar

Community Advisor

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.

Avatar

Correct answer by
Community Advisor

Hi @Michael_Soprano 

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