Skip to main content
Level 2
Apr 20, 2023 6:33 AM UTC
Solved

Reset profile script value on session expiration

Hello All,

I have a scenario where a user journey consists of three pages. When a user visits page one, a value of 1 is set. Likewise, when the user visits page two, the value is set to 2, and the same applies to page three.Based on this value, I will display a particular experience on the home/logout page.

 

However, if the user remains inactive for more than 30 minutes, or if the current session expires, the value should be reset to '0'.

Here is my current script:

var journeyPage = user.get("journeyDrop"); if (page.url.indexOf('https://example.com/form.html') > -1) { journeyPage = 1; }else if (page.url.indexOf('https://example.com/plans.html') > -1) { journeyPage = 2; }else if (page.url.indexOf('https://example.com/success.html') > -1) { journeyPage = 3; } return journeyPage


 Thanks in advance!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
nnakirikanti
nnakirikantiAccepted solution
Community Advisor
Apr 22, 2023 5:30 PM UTC

 You can reset at the start of new session, I can think of two options:

1) Use SessionId

 

 

 

 

if(user.sessionId!=user.getLocal('lastSessionId')) { user.setLocal('lastSessionId', user.sessionId); //Pseudo Code } else{ //Pseudo Code }

 

 

 

 

 2) Use user.isNewSession

   

 

 

 

if(user.isNewSession){ //Pseudo Code } else{ //Pseudo Code }

 

 

 

 

4 replies

nnakirikanti
Community Advisor
nnakirikantiCommunity AdvisorAccepted solution
Community Advisor
Apr 22, 2023 5:30 PM UTC

 You can reset at the start of new session, I can think of two options:

1) Use SessionId

 

 

 

 

if(user.sessionId!=user.getLocal('lastSessionId')) { user.setLocal('lastSessionId', user.sessionId); //Pseudo Code } else{ //Pseudo Code }

 

 

 

 

 2) Use user.isNewSession

   

 

 

 

if(user.isNewSession){ //Pseudo Code } else{ //Pseudo Code }

 

 

 

 

Translate
Level 2
Apr 25, 2023 10:17 AM UTC

Thank you, @nnakirikanti ,
The first method was effective, and I utilized it successfully.


However, when I attempted the second approach, it did not record a value of  "0"(on new session), any idea?
My second approach code:

 

 

var journeyPage = user.get("journeyDrop"); if (profile.isNewSession) { journeyPage = 0; } else if (page.url.indexOf("https://example.com/form.html") > -1) { journeyPage = 1; } else if (page.url.indexOf("https://example.com/plans.html") > -1) { journeyPage = 2; } else if (page.url.indexOf("https://example.com/success.html") > -1) { journeyPage = 3; } return journeyPage;

 

 

 

 

 

Translate
nnakirikanti
Community Advisor
Community Advisor
Apr 25, 2023 12:55 PM UTC

my bad use "user.isNewSession"

Translate
Level 2
Apr 25, 2023 1:04 PM UTC

Cool, It's fine now. Can you just correct("profile.isNewSession" to "user.isNewSession") this in comment (i.e, marked as correct reply).
Thank you once again for your response.

Translate