@segment/snippet
Advanced tools
Comparing version 4.1.1 to 4.2.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 ];\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:\' === document.location.protocol\n ? \'https://\' : \'http://\')\n + \'' + | ||
var __t, __p = '', __j = Array.prototype.join; | ||
function print() { __p += __j.call(arguments, '') } | ||
__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 ];\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:\' === document.location.protocol\n ? \'https://\' : \'http://\')\n + \'' + | ||
((__t = ( settings.host )) == null ? '' : __t) + | ||
'/analytics.js/v1/\'\n + key + \'/analytics.min.js\';\n\n // Insert our script next to the first script element.\n var first = document.getElementsByTagName(\'script\')[0];\n first.parentNode.insertBefore(script, first);\n analytics._loadOptions = options;\n };\n\n // Add a version to keep track of what\'s in the wild.\n analytics.SNIPPET_VERSION = \'4.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 analytics.load("' + | ||
'/analytics.js/v1/\'\n + key + \'/analytics.min.js\';\n\n // Insert our script next to the first script element.\n var first = document.getElementsByTagName(\'script\')[0];\n first.parentNode.insertBefore(script, first);\n analytics._loadOptions = options;\n };\n\n // Add a version to keep track of what\'s in the wild.\n analytics.SNIPPET_VERSION = \'4.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 \''; | ||
if (settings.load) { ; | ||
__p += '\'\n analytics.load("' + | ||
((__t = ( settings.apiKey )) == 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 ' + | ||
'");\n \''; | ||
} ; | ||
__p += '\'\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) + | ||
@@ -9,0 +14,0 @@ '\n})();\n'; |
module.exports=function(settings) { | ||
var __t, __p = ''; | ||
var __t, __p = '', __j = Array.prototype.join; | ||
function print() { __p += __j.call(arguments, '') } | ||
__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"];analytics.factory=function(t){return function(){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 e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src=("https:"===document.location.protocol?"https://":"http://")+"' + | ||
((__t = ( settings.host )) == null ? '' : __t) + | ||
'/analytics.js/v1/"+t+"/analytics.min.js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";\nanalytics.load("' + | ||
'/analytics.js/v1/"+t+"/analytics.min.js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";"'; | ||
if (settings.load) { ; | ||
__p += '";\nanalytics.load("' + | ||
((__t = ( settings.apiKey )) == null ? '' : __t) + | ||
'");\n' + | ||
'");"'; | ||
} ; | ||
__p += '";\n' + | ||
((__t = ( settings.page )) == null ? '' : __t) + | ||
@@ -9,0 +14,0 @@ '\n}}();'; |
4.2.0 / 2018-05-03 | ||
================== | ||
* Add `load` option for omitting the `load()` call. | ||
4.1.1 / 2018-02-15 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -55,2 +55,3 @@ 'use strict'; | ||
if (!has.call(options, 'page')) options.page = true; | ||
if (!has.call(options, 'load')) options.load = true; | ||
return options; | ||
@@ -57,0 +58,0 @@ } |
{ | ||
"name": "@segment/snippet", | ||
"author": "Segment.io <friends@segment.com>", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"repository": "git://github.com/segmentio/snippet.git", | ||
@@ -34,4 +34,5 @@ "description": "Templating methods for rendering the analytics.js snippet.", | ||
"sinon": "^1.17.5", | ||
"uglify-js": "~2.4.0" | ||
"uglify-js": "^2.8.29", | ||
"watchify": "^3.11.0" | ||
} | ||
} |
@@ -37,5 +37,6 @@ [![Circle CI](https://circleci.com/gh/segmentio/snippet.svg?style=svg&circle-token=07550326ba99d575a07600ec4d8a9593120ef509)](https://circleci.com/gh/segmentio/snippet) | ||
* `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 | ||
* `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. | ||
@@ -42,0 +43,0 @@ |
@@ -34,3 +34,3 @@ (function(){ | ||
'alias', | ||
'debug', | ||
'debug', | ||
'page', | ||
@@ -84,3 +84,5 @@ 'once', | ||
// load the tools you've enabled for your account. Boosh! | ||
'<% if (settings.load) { %>' | ||
analytics.load("<%= settings.apiKey %>"); | ||
'<% } %>' | ||
@@ -87,0 +89,0 @@ // Make the first page call to load the integrations. If |
Sorry, the diff of this file is not supported yet
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
228335
15
6653
46
24
1