Skip to content

Instantly share code, notes, and snippets.

@JoeDoyle23
Last active December 10, 2019 16:58
Show Gist options
  • Save JoeDoyle23/19b9d7ebd6f59ae70b8dcdb8ab3d1b34 to your computer and use it in GitHub Desktop.
Save JoeDoyle23/19b9d7ebd6f59ae70b8dcdb8ab3d1b34 to your computer and use it in GitHub Desktop.
dynamic shim load with callback
function loadUserLeapAndRun(callback) {
if (!window.UserLeap) {
window.UserLeap = function(){U._queue.push(arguments)}
let U = window.UserLeap;U.appId = 'xxxxxxxxx';U._queue = [];
let a=document.createElement('script');
a.async=1;a.src='https://cdn.userleap.com/shim.js?id='+U.appId;
p=document.getElementsByTagName('script')[0];
p.parentNode.insertBefore(a, p);
}
}
if (some_app_state) {
// loads the shim.js if not already loaded and executes the setUserId operation
loadUserLeapAndRun();
UserLeap('setUserId', '[INSERT (ANONYMIZED) USER ID]');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment