Showing a Variation Change Only in the First Visit

THIS ARTICLE WILL HELP YOU:

Purpose

Sometimes we would like to run a variation change just on the first visit. This article allows to only show a change created on the Visual Editor only for the first visit.

Steps

Create your experience and changes:

Once you created your experience, open the visual editor.

Create your Changes in the Visual Editor

Insert the JS libraries on your variation.

Hover over the variation name where you want to execute your changes only once.  Select the "Custom JS" menu item. Enter the following code and assign the right number to the variable numberOfViews.


/* Added for Overview Test to show changes one time.
Insert on the Customer Javascript Section */

numberOfViews = "1";

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
var name = cname + "=";
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);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

// Get the old visit count, or 0 if this is his first time
var visits = getCookie("visits") || 0;
// Add 1 to it
visits++;
// Save the updated cookie
setCookie("visits", visits);

function shouldDisplayChanges(){
return (getCookie("visits") == numberOfViews || getCookie("visits") === null);
}

Modify your variation code in the "Code Editor "area.

Access your "Code Editor", by selecting the corresponding menu item of your variation menu. 

Edit your variation code

Edit your variation code integrating with the following code:

 
if (shouldDisplayChanges()) {
/* Wrap all your code in the Code Editor after your changes
have been completed around this if clause */
}

Activate your experience

Check that is running

You are done!