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,
Michelle
Michelle, here's a handy utility function that lets you check if a visitor is on their βnβth visit to the site (where visit is defined as a new browser session):
<script>
(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);
}
})(window);
</script>
You use the function like this:
if ( isEveryNthSession(4) ) {
// do something on every 4th visit, like pop up a lightbox
}