Showing a Variation Change Only in the First Visit

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 of the first visit.

How to

1. Create your experience and changes

Once you created your experience, open the visual editor.

2. Create your Changes in the Visual Editor

3. 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;
    }
    else
    {
        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));
};
  

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

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

5. 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. 
  
} 
  

6. Activate your experience

7. Check that is running

You are done!

Have more questions? Submit a request

Comments