Profile script visit count incrementation | Community
Skip to main content
Level 2
April 27, 2021

Profile script visit count incrementation

  • April 27, 2021
  • 5 replies
  • 2957 views

Hi,

 

I'm trying the code below in a profile script but it is never incremented.

 

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

 

For test it faster, i override the sessionIdLifetime at 30 sec.

The sessionId change works fine.

But visitCount is always blocked at 1.

 

Do you know why ?

 

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

5 replies

TienzenAuthor
Level 2
April 27, 2021

It seems the value of user.getLocal('lastSessionId') always start in the IF condition with "null"

 

in the mboxTrace this variable is identified with user.123456789.lastSessionId

 

I don't know how to get the right lastSessionId stored in the IFcondition?

Pawan-Gupta
Level 8
April 27, 2021

did you set 'visitCount' first before getting the value?? because first time it will start with 0 but before return you have to set it to user or somewhere in local storage so that next time 'visitCount' will return saved value rather going to 0 you can read for user.

 

also refer - https://experienceleague.adobe.com/docs/target/using/audiences/visitor-profiles/variables-profiles-parameters-methods.html?lang=en#section_8F25958273164EBAA6DC659302993FD3 

TienzenAuthor
Level 2
April 29, 2021

Hi, i tried to store the value in local storage and it's work fine when user is in the same session.

But when a new session starts, the storage is deleted and comes back to 0...

Have you got an idea ?

ambikaTewari_ATCI
Community Advisor
Community Advisor
April 29, 2021
Hi , can you try this to increment the profile script visit count >>>> var count = user.get("tgtvisitCount") || 0; count+=1; return count;
Pawan-Gupta
Level 8
April 29, 2021

why don't you try the combination of these three to achieve your requirement (something as below, just coded roughly)

 

if(user.isFirstSession){

    user.setLocal("lastsession",user.sessionId);

   return (user.get('visitCount') || 0) + 1;

}else if(user.isNewSession){

    if(user.getLocal("lastsession")!=user.sessionId){

           user.setLocal("lastsession",user.sessionId);

           return (user.get('visitCount') || 0) + 1;

    }

}

TienzenAuthor
Level 2
April 30, 2021
Thanks for your help. Unfortunatly, i didn't see improvement in my test. Maybe i have got a problem with the way i'm doing my test and the result expected. Because all visit count sample script i found on the web or yours, seems to work in theory..
TienzenAuthor
Level 2
April 30, 2021
Thx. The incrementation works but this does not solve my problem, because it increment at each page loading, and i only want to increment just in case a new session starts