Count the number of visits | Community
Skip to main content
Level 2
July 3, 2023
Solved

Count the number of visits

  • July 3, 2023
  • 2 replies
  • 2224 views

I'm trying to use this snippet in a profile script to count the the number of visits:

 

if(user.sessionId!=user.getLocal('lastSessionId')) { user.setLocal('lastSessionId', user.sessionId); return (user.get('visitCount') || 0) + 1; }

 

 

For example:
* in the first visits the value expected is "1"

* in the second is "2"
* ...

 

Even if I wait 30m or more for the session to expire and I go back to a page on the site, the value I see is always 1. Can you help me figure out if there is an error?

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 PratheepArunRaj

Dear @jack_hala ,

Did you use the old script and changed only the name to validate? If not, try that as well.

If the visit count didn't increment, then please check the Visitor ID for both sessions. Because the Visitor ID should be the same for both sessions for the profile script to work properly.

Thank You, Pratheep Arun Raj B (Arun) | NextRow DigitalTerryn Winter Analytics

2 replies

Perrin_Ennen
Community Advisor
Community Advisor
July 3, 2023

Hi @jack_hala,

Can you try to change your return as follows?

 

if(mbox.name == 'target-global-mbox' && user.sessionId!=user.getLocal('lastSessionId')) { user.setLocal('lastSessionId', user.sessionId); return (profile.get('visitCount') || 0) + 1; // changend line }

 

Hope this helps you.

PratheepArunRaj
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
July 4, 2023

Dear @jack_hala,

What is the name of the profile script? It should be 'visitCount'.

If it is fine, it should work. Else, please try out the code given by @perrin_ennen with the same name.

Thank You, Pratheep Arun Raj B (Arun) | NextRow DigitalTerryn Winter Analytics

Thank You, Pratheep Arun Raj B (Arun) | Xerago | Terryn Winter Analytics
Jack_HalaAuthor
Level 2
July 5, 2023

Hello, and thank you for your replies.

I changed my scripts and renamed it as follows:

 

But the result is always "1":

 

Do you have any suggestion?

PratheepArunRaj
Community Advisor and Adobe Champion
PratheepArunRajCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
July 5, 2023

Dear @jack_hala ,

Did you use the old script and changed only the name to validate? If not, try that as well.

If the visit count didn't increment, then please check the Visitor ID for both sessions. Because the Visitor ID should be the same for both sessions for the profile script to work properly.

Thank You, Pratheep Arun Raj B (Arun) | NextRow DigitalTerryn Winter Analytics

Thank You, Pratheep Arun Raj B (Arun) | Xerago | Terryn Winter Analytics