Skip to main content
Michael_Soprano
Level 10
April 18, 2024
Solved

counting page views per visitor

  • April 18, 2024
  • 3 replies
  • 840 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Asheesh_Pandey

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

3 replies

NimashaJain
Adobe Employee
Adobe Employee
May 13, 2024

@asheesh_pandey Can you look in the script?

Asheesh_Pandey
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 13, 2024

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.

- Asheesh
Asheesh_Pandey
Community Advisor and Adobe Champion
Asheesh_PandeyCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
May 20, 2024

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

- Asheesh