Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@segment/snippet

Package Overview
Dependencies
Maintainers
300
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/snippet - npm Package Compare versions

Comparing version 5.2.0 to 5.2.1

4

dist/max.template.js
module.exports=function(settings) {
var __t, __p = '';
__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://' +
__p += '(function() {\n // define the key where the global analytics object will be accessible\n // customers can safely set this to be something else if need be\n var globalAnalyticsKey = "' +
((__t = ( settings.globalAnalyticsKey )) == null ? '' : __t) +
'"\n\n // Create a queue, but don\'t obliterate an existing one!\n var analytics = window[globalAnalyticsKey] = window[globalAnalyticsKey] || [];\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[globalAnalyticsKey].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[globalAnalyticsKey][e].apply(window[globalAnalyticsKey], 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.setAttribute("data-global-segment-analytics-key", globalAnalyticsKey)\n t.src = "https://' +
((__t = ( settings.host )) == null ? '' : __t) +

@@ -5,0 +7,0 @@ '' +

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","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://' +
__p += '!function(){var i="' +
((__t = ( settings.globalAnalyticsKey )) == null ? '' : __t) +
'",analytics=window[i]=window[i]||[];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[i].initialized)return window[i][e].apply(window[i],arguments);var n=Array.prototype.slice.call(arguments);if(["track","screen","alias","group","page","identify"].indexOf(e)>-1){var c=document.querySelector("link[rel=\'canonical\']");n.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})}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.setAttribute("data-global-segment-analytics-key",i);t.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=i};analytics._writeKey="' +
'";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r);analytics._loadOptions=n};analytics._writeKey="' +
((__t = ( settings.apiKey )) == null ? '' : __t) +

@@ -9,0 +11,0 @@ '";' +

@@ -58,2 +58,3 @@ 'use strict';

options || (options = {});
options.globalAnalyticsKey || (options.globalAnalyticsKey = 'analytics');
options.apiKey || (options.apiKey = 'YOUR_API_KEY');

@@ -60,0 +61,0 @@ options.host || (options.host = 'cdn.segment.com');

{
"name": "@segment/snippet",
"author": "Segment.io <friends@segment.com>",
"version": "5.2.0",
"version": "5.2.1",
"repository": "git://github.com/segmentio/snippet.git",

@@ -6,0 +6,0 @@ "description": "Templating methods for rendering the analytics.js snippet.",

@@ -1,2 +0,2 @@

# snippet
# @segment/snippet

@@ -16,2 +16,5 @@ Render the analytics.js snippet.

yarn add @segment/snippet
# pnpm
pnpm add @segment/snippet
```

@@ -70,6 +73,6 @@ ## Example

## Releasing a new version
## Releasing
1. Publish to `npm`
```
git co master && git pull --ff-only
```sh
git checkout master && git pull --ff-only
npm version <patch|minor|major>

@@ -80,3 +83,8 @@ git push --follow-tags

```
2. Create a new github release
https://github.com/segmentio/snippet/releases
2. Create a [new github release](https://github.com/segmentio/snippet/releases).
3. Bump package version on [segmentio/app](https://github.com/segmentio/app/blob/main/packages/app/package.json).
4. Update _all_ example snippets on [public docs repo](https://github.com/segmentio/segment-docs) via search + replace
- Get example snippet by runnings `yarn fixture` and observing generated `tmp.fixture.*.js` files.
- Tip: double-check that the fixture's `SNIPPET_VERSION` refers to the new npm version.

@@ -38,2 +38,8 @@ declare module '@segment/snippet' {

useHostForBundles?: boolean
/**
* They key at which the global Analytics object will become accessible on the
* window namespace
*/
globalAnalyticsKey?: string
}

@@ -40,0 +46,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc