Skip to content

Commit

Permalink
make stale reference-proof (#116)
Browse files Browse the repository at this point in the history
* Co-authored-by: Pooya Jaferian <[email protected]>
  • Loading branch information
silesky authored Apr 15, 2023
1 parent 8879ab5 commit 081faba
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions template/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
// stored as the first argument, so we can replay the data.
analytics.factory = function(method){
return function(){
if (window.analytics.initialized) {
// Sometimes users assigned analytics to a variable before analytics is done loading, resulting in a stale reference.
// If so, proxy any calls to the 'real' analytics instance.
return window.analytics[method].apply(window.analytics, arguments);
}
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
analytics.push(args);
Expand Down

0 comments on commit 081faba

Please sign in to comment.