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?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
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 Digital | Terryn Winter Analytics
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.
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 Digital | Terryn Winter Analytics
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?
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 Digital | Terryn Winter Analytics