@segment/snippet
Advanced tools
Comparing version 4.15.3 to 4.16.0
module.exports=function(settings) { | ||
var __t, __p = ''; | ||
__p += '(function(){\n\n // Create a queue, but don\'t obliterate an existing one!\n var analytics = window.analytics = window.analytics || [];\n\n // If the real analytics.js is already on the page return.\n if (analytics.initialize) return;\n\n // If the snippet was invoked already show an error.\n if (analytics.invoked) {\n if (window.console && console.error) {\n console.error(\'Segment snippet included twice.\');\n }\n return;\n }\n\n // Invoked flag, to make sure the snippet\n // is never invoked twice.\n analytics.invoked = true;\n\n // A list of the methods in Analytics.js to stub.\n analytics.methods = [\n \'trackSubmit\',\n \'trackClick\',\n \'trackLink\',\n \'trackForm\',\n \'pageview\',\n \'identify\',\n \'reset\',\n \'group\',\n \'track\',\n \'ready\',\n \'alias\',\n \'debug\',\n \'page\',\n \'once\',\n \'off\',\n \'on\',\n \'addSourceMiddleware\',\n \'addIntegrationMiddleware\',\n \'setAnonymousId\',\n \'addDestinationMiddleware\'\n ];\n\n // Define a factory to create stubs. These are placeholders\n // for methods in Analytics.js so that you never have to wait\n // for it to load to actually record data. The `method` is\n // stored as the first argument, so we can replay the data.\n analytics.factory = function(method){\n return function(){\n var args = Array.prototype.slice.call(arguments);\n args.unshift(method);\n analytics.push(args);\n return analytics;\n };\n };\n\n // For each of our methods, generate a queueing stub.\n for (var i = 0; i < analytics.methods.length; i++) {\n var key = analytics.methods[i];\n analytics[key] = analytics.factory(key);\n }\n\n // Define a method to load Analytics.js from our CDN,\n // and that will be sure to only ever load it once.\n analytics.load = function(key, options){\n // Create an async script element based on your key.\n var script = document.createElement(\'script\');\n script.type = \'text/javascript\';\n script.async = true;\n script.src = "https://' + | ||
__p += '(function(){\n\n // Create a queue, but don\'t obliterate an existing one!\n var analytics = window.analytics = window.analytics || [];\n\n // If the real analytics.js is already on the page return.\n if (analytics.initialize) return;\n\n // If the snippet was invoked already show an error.\n if (analytics.invoked) {\n if (window.console && console.error) {\n console.error(\'Segment snippet included twice.\');\n }\n return;\n }\n\n // Invoked flag, to make sure the snippet\n // is never invoked twice.\n analytics.invoked = true;\n\n // A list of the methods in Analytics.js to stub.\n analytics.methods = [\n \'trackSubmit\',\n \'trackClick\',\n \'trackLink\',\n \'trackForm\',\n \'pageview\',\n \'identify\',\n \'reset\',\n \'group\',\n \'track\',\n \'ready\',\n \'alias\',\n \'debug\',\n \'page\',\n \'once\',\n \'off\',\n \'on\',\n \'addSourceMiddleware\',\n \'addIntegrationMiddleware\',\n \'setAnonymousId\',\n \'addDestinationMiddleware\'\n ];\n\n // Define a factory to create stubs. These are placeholders\n // for methods in Analytics.js so that you never have to wait\n // for it to load to actually record data. The `method` is\n // stored as the first argument, so we can replay the data.\n analytics.factory = function(method){\n return function(){\n if (window.analytics.initialized) {\n // Sometimes users assigned analytics to a variable before analytics is done loading, resulting in a stale reference.\n // If so, proxy any calls to the \'real\' analytics instance.\n return window.analytics[method].apply(window.analytics, arguments);\n }\n var args = Array.prototype.slice.call(arguments);\n args.unshift(method);\n analytics.push(args);\n return analytics;\n };\n };\n\n // For each of our methods, generate a queueing stub.\n for (var i = 0; i < analytics.methods.length; i++) {\n var key = analytics.methods[i];\n analytics[key] = analytics.factory(key);\n }\n\n // Define a method to load Analytics.js from our CDN,\n // and that will be sure to only ever load it once.\n analytics.load = function(key, options){\n // Create an async script element based on your key.\n var script = document.createElement(\'script\');\n script.type = \'text/javascript\';\n script.async = true;\n script.src = "https://' + | ||
((__t = ( settings.host )) == null ? '' : __t) + | ||
@@ -11,3 +11,3 @@ '' + | ||
((__t = ( settings.optionalCDN )) == null ? '' : __t) + | ||
'\n\n // Add a version to keep track of what\'s in the wild.\n analytics.SNIPPET_VERSION = \'4.15.3\';\n\n // Load Analytics.js with your key, which will automatically\n // load the tools you\'ve enabled for your account. Boosh!\n ' + | ||
'\n\n // Add a version to keep track of what\'s in the wild.\n analytics.SNIPPET_VERSION = \'4.16.0\';\n\n // Load Analytics.js with your key, which will automatically\n // load the tools you\'ve enabled for your account. Boosh!\n ' + | ||
((__t = ( settings.load )) == null ? '' : __t) + | ||
@@ -14,0 +14,0 @@ '\n\n // Make the first page call to load the integrations. If\n // you\'d like to manually name or tag the page, edit or\n // move this call however you\'d like.\n ' + |
module.exports=function(settings) { | ||
var __t, __p = ''; | ||
__p += '!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methods[e];analytics[key]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://' + | ||
__p += '!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(t){return function(){if(window.analytics.initialized)return window.analytics[t].apply(window.analytics,arguments);var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var key=analytics.methods[t];analytics[key]=analytics.factory(key)}analytics.load=function(key,t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src="https://' + | ||
((__t = ( settings.host )) == null ? '' : __t) + | ||
'' + | ||
((__t = ( settings.ajsPath )) == null ? '' : __t) + | ||
'";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics._writeKey="' + | ||
'";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(e,i);analytics._loadOptions=t};analytics._writeKey="' + | ||
((__t = ( settings.apiKey )) == null ? '' : __t) + | ||
'";' + | ||
((__t = ( settings.optionalCDN )) == null ? '' : __t) + | ||
';analytics.SNIPPET_VERSION="4.15.3";\n' + | ||
';analytics.SNIPPET_VERSION="4.16.0";\n' + | ||
((__t = ( settings.load )) == null ? '' : __t) + | ||
@@ -13,0 +13,0 @@ '\n' + |
@@ -0,1 +1,34 @@ | ||
4.15.3 / 2021-09-20 | ||
================== | ||
* Add `useHostForBundles` [#78](https://github.com/segmentio/snippet/pull/78) and `optionalCDN` [#76](https://github.com/segmentio/snippet/pull/76) properties to allow flexible configuration of custom proxies for those customers using AJS 2.0 | ||
* Adding an example app for testing [#74](https://github.com/segmentio/snippet/pull/74) & [#75](https://github.com/segmentio/snippet/pull/75) | ||
4.15.0 / 2021-09-16 | ||
================== | ||
* Add a `_cdn` property [#73](https://github.com/segmentio/snippet/pull/73) | ||
4.14.2 / 2021-07-6 | ||
================== | ||
* Add load options to the snippet generator [#66](https://github.com/segmentio/snippet/pull/66) | ||
4.14.1 / 2021-07-5 | ||
================== | ||
* Dependency upgrades [#53](https://github.com/segmentio/snippet/pull/53) | ||
4.14.0 / 2021-06-30 | ||
================== | ||
* Add Typescript definitions [#55](https://github.com/segmentio/snippet/pull/55) | ||
4.13.2 / 2021-02-25 | ||
================== | ||
* Add `_writeKey` property to the snippet [#58](https://github.com/segmentio/snippet/pull/58) | ||
4.13.1 / 2020-08-12 | ||
@@ -2,0 +35,0 @@ ================== |
@@ -36,7 +36,2 @@ /* eslint-env node */ | ||
}, | ||
sl_ie_9: { | ||
base: 'SauceLabs', | ||
browserName: 'internet explorer', | ||
version: '9' | ||
}, | ||
sl_ie_10: { | ||
@@ -43,0 +38,0 @@ base: 'SauceLabs', |
{ | ||
"name": "@segment/snippet", | ||
"author": "Segment.io <friends@segment.com>", | ||
"version": "4.15.3", | ||
"version": "4.16.0", | ||
"repository": "git://github.com/segmentio/snippet.git", | ||
@@ -6,0 +6,0 @@ "description": "Templating methods for rendering the analytics.js snippet.", |
@@ -5,9 +5,9 @@ [![Circle CI](https://circleci.com/gh/segmentio/snippet.svg?style=svg&circle-token=07550326ba99d575a07600ec4d8a9593120ef509)](https://circleci.com/gh/segmentio/snippet) | ||
Render the analytics.js snippet. | ||
Render the analytics.js snippet. | ||
The recommended way to use analytics.js is to follow the [analytics.js quickstart guide](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/). If you absolutely need to generate a snippet dynamically, this is an alternate solution. Note that when using this in-browser, the global `analytics` object will not be defined until the snippet is rendered and executed. | ||
The recommended way to use analytics.js is to follow the [analytics.js quickstart guide](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/). If you absolutely need to generate a snippet dynamically, this is an alternate solution. Note that when using this in-browser, the global `analytics` object will not be defined until the snippet is rendered and executed. | ||
This package is supported on IE8+, Chrome, Firefox, Safari 9, Microsoft Edge, Node.js 0.10+ | ||
This package is supported on IE8+, Chrome, Firefox, Safari 9, Microsoft Edge, Node.js 0.10+ | ||
For IE7 support, install a global `JSON` polyfill on the page prior to loading this package. | ||
For IE7 support, install a global `JSON` polyfill on the page prior to loading this package. | ||
@@ -36,9 +36,10 @@ ## Example | ||
Returns the maxified version of the analytics.js snippet given a set of `options`: | ||
Returns the maxified version of the analytics.js snippet given a set of `options`: | ||
* `host`: the domain name where the analytics.js script is hosted. | ||
* `apiKey`: the `apiKey` to load in the snippet. | ||
* `page`: the options to pass to `analytics.page`. if `page` is `false`, then the `page()` call will be omitted. | ||
* `load`: if set to `false` the `load()` call will be omitted. This is useful for if you want dynamically control the load process on the client-side for things like GDPR. | ||
* `ajsPath`: override the default analytics.min.js location | ||
* `host`: the domain name where the analytics.js script is hosted. | ||
* `useHostForBundles`: If set to `true`, the snippet will include the `_cdn` property to tell analytics.js where to fetch bundles from. | ||
* `apiKey`: the `apiKey` to load in the snippet. | ||
* `page`: the options to pass to `analytics.page`. if `page` is `false`, then the `page()` call will be omitted. | ||
* `load`: if set to `false` the `load()` call will be omitted. This is useful for if you want dynamically control the load process on the client-side for things like GDPR. | ||
* `ajsPath`: override the default analytics.min.js location | ||
@@ -48,2 +49,2 @@ | ||
Returns the minified version of the snippet. | ||
Returns the minified version of the snippet. |
@@ -51,2 +51,7 @@ (function(){ | ||
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); | ||
@@ -53,0 +58,0 @@ args.unshift(method); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29058
439
48
1