How to Enable Survey Targeting Based on a Global Timer

 

Suppose you have several pages planned across the customer's journey or different URLs across subdomains. In that case, Qualaroo provides the option to display a survey across your web properties after a total of seconds.
 

For example, if you’re doing UX research around a specific task, being able to ask users a question after they’ve been on several different pages, not just one, for any amount of time is a powerful tool.
 

Implementing a global timer

The following code will set a timer for 30 seconds. This timer can be started on any page or subdomain and will keep counting down properly even if the user navigates to other pages or subdomains.

 

// set a cookie if not set
if (!document.cookie.split(';').filter(function(item) {
    return item.trim().indexOf('qualOnSiteTimer=') == 0
}).length) {
    var now = new Date();
    now.setSeconds( now.getSeconds() + 30 ); // 30 seconds to expire
    document.cookie = "qualOnSiteTimer=" + now.toUTCString() + "; expires=" + now.toUTCString() + "; path='/'";
}
// setTimeout based on remaining time
var cookieValue = document.cookie.replace(/(?:(?:^|.*;s*)qualOnSiteTimers*=s*([^;]*).*$)|^.*$/, "$1");
if (cookieValue !== '') {
    var t1 = new Date();
    var t2 = new Date(cookieValue);
    var dif = t1.getTime() - t2.getTime();
    var ms_to_timeout = Math.abs(dif);
    setTimeout(function() {
        _kiq.push(['set', { time_to_show: true }])
    }, ms_to_timeout)
}

 

In order for the above to work, you need to add a custom property to your survey’s targeting that should be:

 

How does this work?

 

The above code starts by checking for the name of a cookie called qualOnSiteTimer and creating one if it’s not found. You can change the name anything you want.

 

The value of the cookie is a timestamp 30 seconds from now. You can also change this to anything you want.


On each page load that includes this code, the difference of the time to expiry for the cookie will be calculated based on the current time and create a new on-page timer for that length of time. If the user is still on this page when the timer elapses, a custom property, called “time_to_show,” is set and your survey will fire. If they move to another page, the calculation for a new time out will run again and again until the time runs out.

 

That is all about survey targeting based on a global timer.

 

 

Was this information helpful?
© 2005 - 2024 ProProfs
-