Expand my Community achievements bar.

SOLVED

Count the number of visits

Avatar

Level 2

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?

Topics

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor and Adobe Champion

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

View solution in original post

4 Replies

Avatar

Community Advisor

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.

Avatar

Community Advisor and Adobe Champion

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

Avatar

Level 2

Hello, and thank you for your replies.

I changed my scripts and renamed it as follows:

Screenshot 2023-07-05 at 09.47.54.png

 

But the result is always "1":

Screenshot 2023-07-05 at 09.52.32.png

 

Do you have any suggestion?

Avatar

Correct answer by
Community Advisor and Adobe Champion

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