Skip to content

Instantly share code, notes, and snippets.

@sperand-io
Created April 24, 2019 17:45
Show Gist options
  • Save sperand-io/b160e885340fef9d4f62eae9cf04a319 to your computer and use it in GitHub Desktop.
Save sperand-io/b160e885340fef9d4f62eae9cf04a319 to your computer and use it in GitHub Desktop.
Auryc update
// adds a check (`g.auryc[fn] !== wrapper`) to prevent the recursion when auryc isn’t loaded yet
// fixed the usage of `arguments`
function safeInvoke(g, fn) {
return function wrapper() {
if (g.auryc && typeof g.auryc[fn] !== 'undefined' && g.auryc[fn] !== wrapper) {
g.auryc[fn].call(this, Array.prototype.slice.call(arguments, 0));
}
else {
g.aurycReadyCb.push(function () {
g.auryc[fn].call(this, Array.prototype.slice.call(arguments, 0));
});
}
}
}
(function (g) {
g.aurycReadyCb = g.aurycReadyCb || [];
g.auryc = g.auryc || {};
var fns = ['identify', 'addUserProperties', 'track', 'addSessionProperties', 'pause', 'resume'];
each(fns, function (fn) {
g.auryc[fn] = safeInvoke(g, fn);
});
})(window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment