-
-
Save LMG23/4123fd927b63d7acdc33f32a24ea24a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.usabilla_live("setEventCallback", function(category, action, label, value) { | |
if(action != "Campaign:Open") { | |
return; | |
} | |
window.addEventListener("message", function(event) { | |
// Listen to messages from the Usabilla Cloudfront domain | |
if(!/d6tizftlrpuof\.cloudfront\.net/.test(event.origin)) { | |
return; | |
} | |
try { | |
var data = JSON.parse(event.data); | |
// On the final page | |
if(data.type === "pageSwitch" && data.end) { | |
for(var key in data.data) { | |
var ubdata = {data, 'category': category, 'action': action, 'label': label, 'value': value} | |
$('body').trigger('usabilla_update', ubdata) // event category | |
key, // event action | |
data.data[key] // event label | |
); | |
} | |
} | |
} catch(e) { | |
// Ignore errors, usually JSON decode problems | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment