Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Profile script visit count incrementation

Avatar

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile
Tienzen
Level 2

27-04-2021

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 ?

 

Replies

Avatar

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile
Tienzen
Level 2

27-04-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?

Avatar

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile
rush_pawan
Level 7

27-04-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-p... 

Avatar

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile
Tienzen
Level 2

29-04-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 ?

Avatar

Avatar
Give Back 5
Level 4
LordOfTheRings
Level 4

Likes

62 likes

Total Posts

126 posts

Correct Reply

22 solutions
Top badges earned
Give Back 5
Validate 10
Validate 1
Contributor
Shape 1
View profile

Avatar
Give Back 5
Level 4
LordOfTheRings
Level 4

Likes

62 likes

Total Posts

126 posts

Correct Reply

22 solutions
Top badges earned
Give Back 5
Validate 10
Validate 1
Contributor
Shape 1
View profile
LordOfTheRings
Level 4

29-04-2021

Hi , can you try this to increment the profile script visit count >>>> var count = user.get("tgtvisitCount") || 0; count+=1; return count;

Avatar

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile
rush_pawan
Level 7

29-04-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;

    }

}

Avatar

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile
Tienzen
Level 2

30-04-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

Avatar

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile
Tienzen
Level 2

30-04-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..

Avatar

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Boost 100
Level 7
rush_pawan
Level 7

Likes

120 likes

Total Posts

192 posts

Correct Reply

77 solutions
Top badges earned
Boost 100
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile
rush_pawan
Level 7

30-04-2021

Did you check the setting call for 'visitCount' because you are using user.get('visitCount') so this value should be save before you get it. i mentioned same in my first reply!!

Avatar

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile

Avatar
Give Back 5
Level 2
Tienzen
Level 2

Like

1 like

Total Posts

12 posts

Correct Reply

1 solution
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 1
Boost 1
View profile
Tienzen
Level 2

30-04-2021

I think i don't really know how to check the setting...

For me the user.get('visitCount') is set by the "return" statement and is reachable from the second time.

 

If i put just this line in the profile script, the incrementation will work :

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

 

But once i add session instruction the incrementation is down..