analytics.js-loader
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,5 @@ | ||
# 1.0.1 (2015-02-10) | ||
* fix snippet integration, do no try to be smart | ||
# 1.0.0 (2015-01-29) | ||
@@ -2,0 +6,0 @@ |
20
index.js
module.exports = load; | ||
function load(opts) { | ||
if (global.analytics) { | ||
return global.analytics; | ||
} | ||
// Create a queue, but don't obliterate an existing one! | ||
@@ -12,4 +8,16 @@ var analytics = global.analytics = global.analytics || []; | ||
// If the real analytics.js is already on the page return. | ||
if (analytics.initialize) return analytics; | ||
if (analytics.initialize) return; | ||
// If the snippet was invoked already show an error. | ||
if (analytics.invoked) { | ||
if (window.console && console.error) { | ||
console.error('Segment snippet included twice.'); | ||
} | ||
return; | ||
} | ||
// Invoked flag, to make sure the snippet | ||
// is never invoked twice. | ||
analytics.invoked = true; | ||
// A list of the methods in Analytics.js to stub. | ||
@@ -80,4 +88,2 @@ analytics.methods = [ | ||
analytics.page(); | ||
return analytics; | ||
} |
{ | ||
"name": "analytics.js-loader", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Asynchronously load segment.com analytics.js with an npm module", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# analytics.js-loader | ||
Asynchronously load segment.com's | ||
[analytics.js](https://segment.com/docs/libraries/analytics.js/). | ||
This is the [segment.com snippet](https://segment.com/docs/libraries/analytics.js/quickstart/#step-1-copy-the-snippet) as a module. | ||
@@ -19,7 +16,7 @@ | ||
```js | ||
var analytics = require('analytics.js-loader')({ | ||
require('analytics.js-loader')({ | ||
writeKey: 'YOUR_WRITE_KEY' | ||
}); | ||
analytics.identify('1e810c197e', { | ||
global.analytics.identify('1e810c197e', { | ||
name: 'Bill Lumbergh', | ||
@@ -29,3 +26,3 @@ email: 'bill@initech.com' | ||
analytics.track('Signed Up', { | ||
global.analytics.track('Signed Up', { | ||
plan: 'Startup', | ||
@@ -32,0 +29,0 @@ source: 'Analytics Academy' |
4687
75
32