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

Run experience once only

Avatar

Avatar
Validate 1
Level 1
davidm59064921
Level 1

Likes

3 likes

Total Posts

2 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 1
davidm59064921
Level 1

Likes

3 likes

Total Posts

2 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
davidm59064921
Level 1

10-08-2018

Hi,

I have a Target activity with control experience, and then 2 other (B and C) experiences im serving.

For the 3rd or C experience, I want it to run only once per user session.

Example: The user comes to the page, sees the experience, navigates away from the page, THEN comes back to the page. When the user comes BACK to the page, i do not want the experience to run again.

Is there a quick easy way to do this? Possibly a code example or snippet?

thank you,

David

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 5
Level 2
yannickschwarz
Level 2

Likes

5 likes

Total Posts

4 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Boost 5
Level 2
yannickschwarz
Level 2

Likes

5 likes

Total Posts

4 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
yannickschwarz
Level 2

10-08-2018

Hi David,

My suggestion would be to cookie those visitors on first visit to the experience, and then add an IF/ELSE rule to prevent your code from firing, if the cookie is found, on their second visit.

I am sure there are other more advanced solutions, but this has worked for me in the past .

Good luck:

CODE:

/* Create Cookie */


    function createCookie(name,value,days) {

        if (days) {

            var date = new Date();

            date.setTime(date.getTime()+(days*24*60*60*1000));

            var expires = "; expires="+date.toGMTString();

        }

        else var expires = "";

        document.cookie = name+"="+value+expires+"; path=/";

    };

    /* Read Cookie */

    function readCookie(name) {

        var nameEQ = name + "=";

        var ca = document.cookie.split(';');

        for(var i=0;i < ca.length;i++) {

            var c = ca[i];

            while (c.charAt(0)==' ') c = c.substring(1,c.length);

            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

        }

        return null;

    };

$(document).ready(function () {

     if (readCookie('cookiename') == 'cookievalue') {

          console.log('do nothing')

     } else {

          // Put the rest of your experience code here //

         createCookie('cookiename','cookievalue',90)

          console.log(' code was fired and cookie was created');
     };
});

Answers (1)

Answers (1)

Avatar

Avatar
Validate 1
Level 2
mohan_vamsy
Level 2

Likes

5 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 2
mohan_vamsy
Level 2

Likes

5 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile
mohan_vamsy
Level 2

18-10-2019

Pasting the whole HTML code helps in this case? And if I set my cookie expiry to 1 instead of 90, the same user who comes next day will be able to see the experience again? Actual Intention is to show a popup only once in a day for a user( if he closes the popup without performing the desired CTA). The same experience should be shown to him on the next day, but never on the same day.