@segment/snippet
Advanced tools
Comparing version 5.0.1 to 5.1.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 \'screen\',\n \'once\',\n \'off\',\n \'on\',\n \'addSourceMiddleware\',\n \'addIntegrationMiddleware\',\n \'setAnonymousId\',\n \'addDestinationMiddleware\',\n \'register\'\n ];\n\n // create buffered page context object\n function p() {\n var c = document.querySelector("link[rel=\'canonical\']");\n return {\n __t: \'bpc\',\n c: (c && c.getAttribute(\'href\')) || undefined,\n p: location.pathname,\n u: location.href,\n s: location.search,\n t: document.title,\n r: document.referrer,\n }\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(e){\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[e].apply(window.analytics, arguments);\n }\n var args = Array.prototype.slice.call(arguments);\n // Add buffered page context object so page information is always up-to-date\n if ([\'track\', \'screen\', \'alias\', \'group\', \'page\', \'identify\'].indexOf(e) > -1) {\n args.push(p());\n }\n args.unshift(e);\n analytics.push(args);\n return analytics;\n };\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 t = document.createElement(\'script\');\n t.type = \'text/javascript\';\n t.async = true;\n t.src = "https://' + | ||
__p += '(function() {\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 \'screen\',\n \'once\',\n \'off\',\n \'on\',\n \'addSourceMiddleware\',\n \'addIntegrationMiddleware\',\n \'setAnonymousId\',\n \'addDestinationMiddleware\',\n \'register\'\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(e) {\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[e].apply(window.analytics, arguments);\n }\n var args = Array.prototype.slice.call(arguments);\n \n // Add buffered page context object so page information is always up-to-date\n if ([\'track\', \'screen\', \'alias\', \'group\', \'page\', \'identify\'].indexOf(e) > -1) {\n var c = document.querySelector(\'link[rel=\\\'canonical\\\']\');\n args.push({\n __t: \'bpc\',\n c: c && c.getAttribute(\'href\') || undefined,\n p: location.pathname,\n u: location.href,\n s: location.search,\n t: document.title,\n r: document.referrer\n });\n }\n\n args.unshift(e);\n analytics.push(args);\n return analytics;\n };\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 t = document.createElement(\'script\');\n t.type = \'text/javascript\';\n t.async = true;\n t.src = \'https://' + | ||
((__t = ( settings.host )) == null ? '' : __t) + | ||
'' + | ||
((__t = ( settings.ajsPath )) == null ? '' : __t) + | ||
'";\n\n // Insert our script next to the first script element.\n var first = document.getElementsByTagName(\'script\')[0];\n first.parentNode.insertBefore(t, first);\n analytics._loadOptions = options;\n };\n analytics._writeKey = \'' + | ||
'\';\n\n // Insert our script next to the first script element.\n var first = document.getElementsByTagName(\'script\')[0];\n first.parentNode.insertBefore(t, first);\n analytics._loadOptions = options;\n };\n analytics._writeKey = \'' + | ||
((__t = ( settings.apiKey )) == null ? '' : __t) + | ||
'\';\n\n ' + | ||
((__t = ( settings.optionalCDN )) == null ? '' : __t) + | ||
'\n\n // Add a version to keep track of what\'s in the wild.\n analytics.SNIPPET_VERSION = \'5.0.1\';\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 = \'5.1.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) + | ||
'\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 ' + | ||
((__t = ( settings.page )) == null ? '' : __t) + | ||
'\n})();\n'; | ||
'\n})();'; | ||
return __p | ||
} |
module.exports=function(settings) { | ||
var __t, __p = ''; | ||
__p += '!function(){function p(){var c=document.querySelector("link[rel=\'canonical\']");return{__t:"bpc",c:c&&c.getAttribute("href")||void 0,p:location.pathname,u:location.href,s:location.search,t:document.title,r:document.referrer}}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","screen","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware","register"];analytics.factory=function(e){return function(){if(window.analytics.initialized)return window.analytics[e].apply(window.analytics,arguments);var n=Array.prototype.slice.call(arguments);["track","screen","alias","group","page","identify"].indexOf(e)>-1&&n.push(p());n.unshift(e);analytics.push(n);return analytics}};for(var n=0;n<analytics.methods.length;n++){var key=analytics.methods[n];analytics[key]=analytics.factory(key)}analytics.load=function(key,n){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","screen","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware","register"];analytics.factory=function(e){return function(){if(window.analytics.initialized)return window.analytics[e].apply(window.analytics,arguments);var i=Array.prototype.slice.call(arguments);if(["track","screen","alias","group","page","identify"].indexOf(e)>-1){var c=document.querySelector("link[rel=\'canonical\']");i.push({__t:"bpc",c:c&&c.getAttribute("href")||void 0,p:location.pathname,u:location.href,s:location.search,t:document.title,r:document.referrer})}i.unshift(e);analytics.push(i);return analytics}};for(var i=0;i<analytics.methods.length;i++){var key=analytics.methods[i];analytics[key]=analytics.factory(key)}analytics.load=function(key,i){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://' + | ||
((__t = ( settings.host )) == null ? '' : __t) + | ||
'' + | ||
((__t = ( settings.ajsPath )) == null ? '' : __t) + | ||
'";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(t,i);analytics._loadOptions=n};analytics._writeKey="' + | ||
'";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=i};analytics._writeKey="' + | ||
((__t = ( settings.apiKey )) == null ? '' : __t) + | ||
'";' + | ||
((__t = ( settings.optionalCDN )) == null ? '' : __t) + | ||
';analytics.SNIPPET_VERSION="5.0.1";\n' + | ||
';analytics.SNIPPET_VERSION="5.1.0";\n' + | ||
((__t = ( settings.load )) == null ? '' : __t) + | ||
@@ -13,0 +13,0 @@ '\n' + |
{ | ||
"name": "@segment/snippet", | ||
"author": "Segment.io <friends@segment.com>", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"repository": "git://github.com/segmentio/snippet.git", | ||
@@ -18,2 +18,4 @@ "description": "Templating methods for rendering the analytics.js snippet.", | ||
"test": "make test", | ||
"fixture": "make fixture", | ||
"lint": "make lint", | ||
"example": "cd ./example && yarn start", | ||
@@ -20,0 +22,0 @@ "e2e-tests": "yarn jest --runTestsByPath --forceExit e2e-tests/*", |
@@ -56,6 +56,7 @@ # snippet | ||
### Installation + Running Tests | ||
### Installation + QA | ||
``` | ||
nvm use | ||
yarn install | ||
make lint | ||
make test | ||
@@ -69,3 +70,4 @@ ``` | ||
## Publishing to `npm` | ||
## Releasing a new version | ||
1. Publish to `npm` | ||
``` | ||
@@ -78,1 +80,3 @@ git co master && git pull --ff-only | ||
``` | ||
2. Create a new github release | ||
https://github.com/segmentio/snippet/releases |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15245
80
0
1