Do you have several pages planned in your customer journey? How about different URLs across subdomains?
If you answered yes, this article will show you an amazing way to display a survey after a total number of seconds across your web properties.
Background
Qualaroo offers the capability to display an intercept survey after a certain time on a page right out of the box. However, 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, on any 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*)qualOnSiteTimer\s*\=\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:
time_to_show=true
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. The name can be changed to 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 be run again and again until the time runs out.
Go ahead and give this powerful targeting technique a shot! Reach out to support@qualaroo.com with any questions at all. We’re happy to help!
Comments
0 comments
Article is closed for comments.