Showing a Variation Change Only in the First Visit


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.


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:

    function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
        begin += 2;
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
        end = dc.length;
    // because unescape has been deprecated, replaced with decodeURI
    //return unescape(dc.substring(begin + prefix.length, end));
    return decodeURI(dc.substring(begin + prefix.length, end));

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:

    var myCookie = getCookie("divshown");

if (myCookie == null) {
  console.log('no cookie found');
  var nbYearsToAdd = 1;

  var DateinaYear = new Date();
  DateinaYear.setFullYear(DateinaYear.getFullYear() + nbYearsToAdd);

  document.cookie = "divshown=true; " + DateinaYear;

  // replace this line with your already existing variation code. 

Activate your experience

Check that is running

You are done!

Have more questions? Submit a request