1 Reply Latest reply on May 12, 2016 2:04 PM by Sanford Whiteman

    Show lightbox every X visit to site

      Hey everyone,


      Just wondering if anyone has had any success implementing rules when to show a lightbox?


      We want to show lightbox every 4th time a user visits the site.


      Appreciate any help here!


      Many thanks,

        • Re: Show lightbox every X visit to site
          Sanford Whiteman

          Michelle, here's a handy utility function that lets you check if a visitor is on their nth visit to the site (where visit is defined as a new browser session):


          (function(global) {
            var propCurrent = 'MM_Session',
              propAll = 'MM_SessionHistory',
              currentSession = sessionStorage.getItem(propCurrent),
              allSessions = JSON.parse(localStorage.getItem(propAll) || '[]'),
              ts = new Date().getTime();
            if (!currentSession) {
              currentSession = sessionStorage.setItem(propCurrent, ts);
              allSessions.push(ts), localStorage.setItem(propAll, JSON.stringify(allSessions));
            global.isEveryNthSession = function isEveryNthSession(n) {
              return (allSessions.length % n == 0);


          You use the function like this:


          if ( isEveryNthSession(4) ) {
            // do something on every 4th visit, like pop up a lightbox