Skip to content

Instantly share code, notes, and snippets.

@joelverhagen
Created December 13, 2019 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelverhagen/1e2b1d9a641735abebb08ee5b5d3a431 to your computer and use it in GitHub Desktop.
Save joelverhagen/1e2b1d9a641735abebb08ee5b5d3a431 to your computer and use it in GitHub Desktop.
nuget.enableUsabilla = function (obfuscatedPath) {
// If there is an obfuscated path, hook into the outgoing AJAX request containing the feedback and obfuscate
// the URL data. This approach was provided by the Usabilla technical support.
if (obfuscatedPath) {
var obfuscatedUrl = document.createElement('a');
obfuscatedUrl.href = window.location.href;
if (obfuscatedPath.substring(0, 1) != "/") {
obfuscatedUrl.pathname = "/" + obfuscatedPath;
} else {
obfuscatedUrl.pathname = obfuscatedPath;
}
window.usabilla_live("setEventCallback", function (category, action, label, value, eventdata) {
if (action != "Feedback:Open") {
return;
}
function sendWithObfuscation(vData) {
var data = JSON.parse(vData);
data.url = obfuscatedUrl.href;
vData = JSON.stringify(data);
arguments[0] = vData;
realSend.apply(this, arguments);
}
var realSend = XMLHttpRequest.prototype.send;
var ub_window = document.getElementById("lightningjs-frame-usabilla_live_feedback").contentWindow;
ub_window.XMLHttpRequest.prototype.send = sendWithObfuscation;
if (window.XDomainRequest) {
realSend = XDomainRequest.prototype.send;
ub_window.XDomainRequest.prototype.send = sendWithObfuscation;
}
});
}
// Hide the default feedback button.
window.usabilla_live("hide");
// Wire-up and show the custom feedback button.
document.getElementById("usbl-integrated-button").addEventListener("click", function (event) {
event.preventDefault();
window.usabilla_live("click");
});
document.getElementById("usabilla-button").style.display = "block";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment