How can we help?

Ask a question or search our knowledge base:

 

 

Using the JavaScript snippet in a Single Page App

If you have a single page app, begin by installing the JavaScript snippet as outlined in our tutorial with these lines removed:

var _user_id = '<a unique user id, or empty string if unknown>';
var _session_id = '<a unique session id>';

var _sift = window._sift = window._sift || [];
_sift.push(['_setAccount', 'your JavaScript API key']);
_sift.push(['_setUserId', _user_id]);
_sift.push(['_setSessionId', _session_id]);
_sift.push(['_trackPageview']);

 

As users navigate your site, you can fire the snippet after each URL change with a function like this:  

function siftPageview(session_id, user_id) {
var _sift = window._sift = window._sift || [];
_sift.push(['_setAccount', jsApiKey]);
_sift.push(['_setUserId', user_id]);
_sift.push(['_setSessionId', session_id]);
_sift.push(['_trackPageview']);
}

 

When you don't have or know the user's id, set the value to the empty string. If it's possible for an employee to log in as ("spoof") a customer, do not fire the JS snippet for those events.

Have more questions? Submit a request