Skip to content

Commit

Permalink
Update segment snippet to 4.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dionlarson committed Feb 9, 2021
1 parent 2a54279 commit c36082e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.onRenderBody = function (_ref, pluginOptions) {

var includeTrackPage = !trackPage ? "" : "analytics.page();";

var snippet = "!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(){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=\"" + host + "/analytics.js/v1/\"+t+\"/analytics.min.js\";var a=document.getElementsByTagName(\"script\")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION=\"4.1.0\";\n " + (delayLoad || manualLoad ? "" : "analytics.load('" + writeKey + "');") + "\n }}();";
var snippet = "!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://cdn.segment.com/analytics.js/v1/\" + key + \"/analytics.min.js\";var n=document.getElementsByTagName(\"script\")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics.SNIPPET_VERSION=\"4.13.1\";\n " + (delayLoad || manualLoad ? "" : "analytics.load('" + writeKey + "');") + "\n }}();";

var delayedLoader = "\n window.segmentSnippetLoaded = false;\n window.segmentSnippetLoading = false;\n\n window.segmentSnippetLoader = function (customDelay, callback) {\n if (!window.segmentSnippetLoaded && !window.segmentSnippetLoading) {\n if (!customDelay) { window.segmentSnippetLoading = true; }\n\n function loader() {\n if (window.segmentSnippetLoaded) { return; }\n window.analytics.load('" + writeKey + "');\n window.segmentSnippetLoading = false;\n window.segmentSnippetLoaded = true;\n if(callback) {callback()}\n };\n\n setTimeout(\n function () {\n \"requestIdleCallback\" in window\n ? requestIdleCallback(function () {loader()})\n : loader();\n },\n customDelay ? " + delayLoadTime + " || 1000 : 1000\n );\n }\n }\n window.addEventListener('load',function () {window.segmentSnippetLoader(true)}, { once: true });\n window.addEventListener('scroll',function () {window.segmentSnippetLoader(false)}, { once: true });\n window.addEventListener('mousedown',function () {window.segmentSnippetLoader(false)}, { once: true });\n window.addEventListener('touchstart',function () {window.segmentSnippetLoader(false)}, { once: true });\n ";

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-plugin-segment-js",
"description": "Easily add Segment JS snippet to your website",
"version": "3.7.4",
"version": "3.8.0",
"main": "gatsby-ssr.js",
"repository": "[email protected]:MakeSchool/gatsby-plugin-segment.git",
"author": "Dion Larson <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
// NOTE: do not remove per https://github.com/benjaminhoffman/gatsby-plugin-segment-js/pull/18
const includeTrackPage = !trackPage ? "" : "analytics.page();";

// Segment's minified snippet (version 4.1.0)
const snippet = `!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(){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="${host}/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
// Segment's minified snippet (version 4.13.1)
const snippet = `!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://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.13.1";
${delayLoad || manualLoad ? `` : `analytics.load('${writeKey}');` }
}}();`;

Expand Down

0 comments on commit c36082e

Please sign in to comment.