analytics.js-loader
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -0,1 +1,5 @@ | ||
# 2.1.2 (2016-01-31) | ||
* fix loader to compensate for segment queue object | ||
# 2.1.1 (2016-01-01) | ||
@@ -2,0 +6,0 @@ |
26
index.js
@@ -90,3 +90,27 @@ module.exports = load; | ||
return analytics; | ||
/* | ||
* The analytics.js-loader module returns the "initial" analytics | ||
* object, which is basically just a queue to hold events until the | ||
* "real" one is loaded with a global script. Problem is, the "real" | ||
* one simply replaces `window.analytics`, and doesn't change over | ||
* this initial "queue" object, meaning that nothing gets registered | ||
* after the "real" one is loaded - things just keep adding to the queue. | ||
* | ||
* This is why we save off `initialAnalytics`, and then always run | ||
* methods through `window.analytics`, which might be the queue, and | ||
* might be the real one. | ||
*/ | ||
var initialAnalytics = analytics; | ||
var actualAnalytics = {}; | ||
window.analytics = initialAnalytics; | ||
initialAnalytics.methods.forEach(function(method) { | ||
actualAnalytics[method] = function() { | ||
window.analytics[method].apply(window.analytics, arguments); | ||
} | ||
}); | ||
return actualAnalytics; | ||
} |
{ | ||
"name": "analytics.js-loader", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Asynchronously load segment.com analytics.js with an npm module", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
6210
98