@segment/analytics.js-core
Advanced tools
Comparing version 4.0.6 to 4.0.7
'use strict'; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var pageDefaults_1 = require("./pageDefaults"); | ||
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
var lodash_pick_1 = __importDefault(require("lodash.pick")); | ||
var component_url_1 = __importDefault(require("component-url")); | ||
var component_url_1 = require("component-url"); | ||
var _analytics = global.analytics; | ||
@@ -38,2 +21,3 @@ /* | ||
var bindAll = require('bind-all'); | ||
var clone = require('./utils/clone'); | ||
var extend = require('extend'); | ||
@@ -43,5 +27,9 @@ var cookie = require('./cookie'); | ||
var debug = require('debug'); | ||
var defaults = require('@ndhoule/defaults'); | ||
var each = require('./utils/each'); | ||
var foldl = require('@ndhoule/foldl'); | ||
var group = require('./group'); | ||
var is = require('is'); | ||
var isMeta = require('@segment/is-meta'); | ||
var keys = require('@ndhoule/keys'); | ||
var memory = require('./memory'); | ||
@@ -51,2 +39,4 @@ var nextTick = require('next-tick'); | ||
var on = require('component-event').bind; | ||
var pageDefaults = require('./pageDefaults'); | ||
var pick = require('@ndhoule/pick'); | ||
var prevent = require('@segment/prevent-default'); | ||
@@ -73,3 +63,3 @@ var store = require('./store'); | ||
var self = this; | ||
this.on('initialize', function (_, options) { | ||
this.on('initialize', function (settings, options) { | ||
if (options.initialPageview) | ||
@@ -142,11 +132,9 @@ self.page(); | ||
var self = this; | ||
Object.keys(settings).forEach(function (key) { | ||
var Integration = self.Integrations[key]; | ||
each(function (_opts, name) { | ||
var Integration = self.Integrations[name]; | ||
if (!Integration) | ||
delete settings[key]; | ||
}); | ||
delete settings[name]; | ||
}, settings); | ||
// add integrations | ||
Object.keys(settings).forEach(function (key) { | ||
var opts = settings[key]; | ||
var name = key; | ||
each(function (opts, name) { | ||
// Don't load disabled integrations | ||
@@ -165,3 +153,3 @@ if (options.integrations) { | ||
self.add(integration); | ||
}); | ||
}, settings); | ||
var integrations = this._integrations; | ||
@@ -173,3 +161,3 @@ // load user now that options are set | ||
var readyCallCount = 0; | ||
var integrationCount = Object.keys(integrations).length; | ||
var integrationCount = keys(integrations).length; | ||
var ready = function () { | ||
@@ -190,11 +178,10 @@ readyCallCount++; | ||
var initialPageSkipped = false; | ||
Object.keys(integrations).forEach(function (key) { | ||
var integration = integrations[key]; | ||
each(function (integration) { | ||
if (options.initialPageview && | ||
integration.options.initialPageview === false) { | ||
// We've assumed one initial pageview, so make sure we don't count the first page call. | ||
var page_1 = integration.page; | ||
var page = integration.page; | ||
integration.page = function () { | ||
if (initialPageSkipped) { | ||
return page_1.apply(this, arguments); | ||
return page.apply(this, arguments); | ||
} | ||
@@ -225,3 +212,3 @@ initialPageSkipped = true; | ||
} | ||
}); | ||
}, integrations); | ||
// backwards compat with angular plugin and used for init logic checks | ||
@@ -274,6 +261,4 @@ this.initialized = true; | ||
// Add the initialize integrations so the server-side ones can be disabled too | ||
// NOTE: We need to merge integrations, not override them with assign | ||
// since it is possible to change the initialized integrations at runtime. | ||
if (this.options.integrations) { | ||
msg.integrations = __assign(__assign({}, this.options.integrations), msg.integrations); | ||
defaults(msg.integrations, this.options.integrations); | ||
} | ||
@@ -323,6 +308,4 @@ this._invoke('identify', new Identify(msg)); | ||
// Add the initialize integrations so the server-side ones can be disabled too | ||
// NOTE: We need to merge integrations, not override them with assign | ||
// since it is possible to change the initialized integrations at runtime. | ||
if (this.options.integrations) { | ||
msg.integrations = __assign(__assign({}, this.options.integrations), msg.integrations); | ||
defaults(msg.integrations, this.options.integrations); | ||
} | ||
@@ -381,5 +364,3 @@ this._invoke('group', new Group(msg)); | ||
// Add the initialize integrations so the server-side ones can be disabled too | ||
// NOTE: We need to merge integrations, not override them with assign | ||
// since it is possible to change the initialized integrations at runtime. | ||
msg.integrations = __assign(__assign({}, this._mergeInitializeAndPlanIntegrations(planIntegrationOptions)), msg.integrations); | ||
defaults(msg.integrations, this._mergeInitializeAndPlanIntegrations(planIntegrationOptions)); | ||
this._invoke('track', new Track(msg)); | ||
@@ -402,17 +383,9 @@ this.emit('track', event, properties, options); | ||
Analytics.prototype.trackClick = Analytics.prototype.trackLink = function (links, event, properties) { | ||
var _this = this; | ||
var elements = []; | ||
if (!links) | ||
return this; | ||
// always arrays, handles jquery | ||
if (links instanceof Element) { | ||
elements = [links]; | ||
} | ||
else if ("toArray" in links) { | ||
elements = links.toArray(); | ||
} | ||
else { | ||
elements = links; | ||
} | ||
elements.forEach(function (el) { | ||
if (type(links) === 'element') | ||
links = [links]; | ||
var self = this; | ||
each(function (el) { | ||
if (type(el) !== 'element') { | ||
@@ -427,7 +400,6 @@ throw new TypeError('Must pass HTMLElement to `analytics.trackLink`.'); | ||
el.getAttribute('xlink:href'); | ||
_this.track(ev, props); | ||
// @ts-ignore | ||
self.track(ev, props); | ||
if (href && el.target !== '_blank' && !isMeta(e)) { | ||
prevent(e); | ||
_this._callback(function () { | ||
self._callback(function () { | ||
window.location.href = href; | ||
@@ -437,3 +409,3 @@ }); | ||
}); | ||
}); | ||
}, links); | ||
return this; | ||
@@ -453,3 +425,2 @@ }; | ||
Analytics.prototype.trackSubmit = Analytics.prototype.trackForm = function (forms, event, properties) { | ||
var _this = this; | ||
if (!forms) | ||
@@ -460,15 +431,15 @@ return this; | ||
forms = [forms]; | ||
var elements = forms; | ||
elements.forEach(function (el) { | ||
var self = this; | ||
each(function (el) { | ||
if (type(el) !== 'element') | ||
throw new TypeError('Must pass HTMLElement to `analytics.trackForm`.'); | ||
var handler = function (e) { | ||
function handler(e) { | ||
prevent(e); | ||
var ev = is.fn(event) ? event(el) : event; | ||
var props = is.fn(properties) ? properties(el) : properties; | ||
_this.track(ev, props); | ||
_this._callback(function () { | ||
self.track(ev, props); | ||
self._callback(function () { | ||
el.submit(); | ||
}); | ||
}; | ||
} | ||
// Support the events happening through jQuery or Zepto instead of through | ||
@@ -483,3 +454,3 @@ // the normal DOM API, because `el.submit` doesn't bubble up events... | ||
} | ||
}); | ||
}, forms); | ||
return this; | ||
@@ -514,3 +485,3 @@ }; | ||
/* eslint-enable no-unused-expressions, no-sequences */ | ||
properties = lodash_clonedeep_1.default(properties) || {}; | ||
properties = clone(properties) || {}; | ||
if (name) | ||
@@ -522,12 +493,8 @@ properties.name = name; | ||
// TODO: Eventually move these entirely to `options.context.page` | ||
// FIXME: This is purposely not overriding `defs`. There was a bug in the logic implemented by `@ndhoule/defaults`. | ||
// This bug made it so we only would overwrite values in `defs` that were set to `undefined`. | ||
// In some cases, though, pageDefaults will return defaults with values set to "" (such as `window.location.search` defaulting to ""). | ||
// The decision to not fix this bus was made to preserve backwards compatibility. | ||
var defs = pageDefaults_1.pageDefaults(); | ||
properties = __assign(__assign({}, properties), defs); | ||
var defs = pageDefaults(); | ||
defaults(properties, defs); | ||
// Mirror user overrides to `options.context.page` (but exclude custom properties) | ||
// (Any page defaults get applied in `this.normalize` for consistency.) | ||
// Weird, yeah--moving special props to `context.page` will fix this in the long term. | ||
var overrides = lodash_pick_1.default(properties, Object.keys(defs)); | ||
var overrides = pick(keys(defs), properties); | ||
if (!is.empty(overrides)) { | ||
@@ -545,6 +512,4 @@ options = options || {}; | ||
// Add the initialize integrations so the server-side ones can be disabled too | ||
// NOTE: We need to merge integrations, not override them with assign | ||
// since it is possible to change the initialized integrations at runtime. | ||
if (this.options.integrations) { | ||
msg.integrations = __assign(__assign({}, this.options.integrations), msg.integrations); | ||
defaults(msg.integrations, this.options.integrations); | ||
} | ||
@@ -592,6 +557,4 @@ this._invoke('page', new Page(msg)); | ||
// Add the initialize integrations so the server-side ones can be disabled too | ||
// NOTE: We need to merge integrations, not override them with assign | ||
// since it is possible to change the initialized integrations at runtime. | ||
if (this.options.integrations) { | ||
msg.integrations = __assign(__assign({}, this.options.integrations), msg.integrations); | ||
defaults(msg.integrations, this.options.integrations); | ||
} | ||
@@ -695,5 +658,3 @@ this._invoke('alias', new Alias(msg)); | ||
var failedInitializations = self.failedInitializations || []; | ||
Object.keys(self._integrations).forEach(function (key) { | ||
var integration = self._integrations[key]; | ||
var name = integration.name; | ||
each(function (integration, name) { | ||
var facadeCopy = extend(true, new Facade({}), facade); | ||
@@ -757,3 +718,3 @@ if (!facadeCopy.enabled(name)) | ||
} | ||
}); | ||
}, self._integrations); | ||
} | ||
@@ -782,8 +743,11 @@ }; | ||
}; | ||
/** | ||
* Parse the query string for callable methods. | ||
* | ||
* @api private | ||
*/ | ||
Analytics.prototype._parseQuery = function (query) { | ||
// Parse querystring to an object | ||
var parsed = component_url_1.default.parse(query); | ||
var q = parsed.query | ||
.split('&') | ||
.reduce(function (acc, str) { | ||
var q = parsed.query.split('&').reduce(function (acc, str) { | ||
var _a = str.split('='), k = _a[0], v = _a[1]; | ||
@@ -827,3 +791,3 @@ acc[k] = decodeURI(v).replace('+', ' '); | ||
Analytics.prototype.normalize = function (msg) { | ||
msg = normalize(msg, Object.keys(this._integrations)); | ||
msg = normalize(msg, keys(this._integrations)); | ||
if (msg.anonymousId) | ||
@@ -833,3 +797,3 @@ user.anonymousId(msg.anonymousId); | ||
// Ensure all outgoing requests include page data in their contexts. | ||
msg.context.page = __assign(__assign({}, pageDefaults_1.pageDefaults()), msg.context.page); | ||
msg.context.page = defaults(msg.context.page || {}, pageDefaults()); | ||
return msg; | ||
@@ -836,0 +800,0 @@ }; |
'use strict'; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
/** | ||
@@ -22,6 +7,7 @@ * Module dependencies. | ||
var bindAll = require('bind-all'); | ||
var clone = require('./utils/clone'); | ||
var cookie = require('@segment/cookie'); | ||
var debug = require('debug')('analytics.js:cookie'); | ||
var defaults = require('@ndhoule/defaults'); | ||
var topDomain = require('@segment/top-domain'); | ||
var MAX_AGE_ONE_YEAR = 31536000000; | ||
/** | ||
@@ -45,9 +31,9 @@ * Initialize a new `Cookie` with `options`. | ||
domain = null; | ||
var defaults = { | ||
maxage: MAX_AGE_ONE_YEAR, | ||
this._options = defaults(options, { | ||
// default to a year | ||
maxage: 31536000000, | ||
path: '/', | ||
domain: domain, | ||
path: '/', | ||
sameSite: 'Lax' | ||
}; | ||
this._options = __assign(__assign({}, defaults), options); | ||
}); | ||
// http://curl.haxx.se/rfc/cookie_spec.html | ||
@@ -73,3 +59,3 @@ // https://publicsuffix.org/list/effective_tld_names.dat | ||
value = window.JSON.stringify(value); | ||
cookie(key, value === 'null' ? null : value, lodash_clonedeep_1.default(this._options)); | ||
cookie(key, value === 'null' ? null : value, clone(this._options)); | ||
return true; | ||
@@ -99,3 +85,3 @@ } | ||
try { | ||
cookie(key, null, lodash_clonedeep_1.default(this._options)); | ||
cookie(key, null, clone(this._options)); | ||
return true; | ||
@@ -102,0 +88,0 @@ } |
'use strict'; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
var lodash_assignin_1 = __importDefault(require("lodash.assignin")); | ||
/* | ||
* Module dependencies. | ||
*/ | ||
var clone = require('./utils/clone'); | ||
var cookie = require('./cookie'); | ||
var debug = require('debug')('analytics:entity'); | ||
var defaults = require('@ndhoule/defaults'); | ||
var extend = require('@ndhoule/extend'); | ||
var memory = require('./memory'); | ||
@@ -73,3 +60,3 @@ var store = require('./store'); | ||
return this._options; | ||
this._options = __assign(__assign({}, this.defaults), options); | ||
this._options = defaults(options || {}, this.defaults || {}); | ||
}; | ||
@@ -176,3 +163,3 @@ /** | ||
: this._traits; | ||
return ret ? isodateTraverse(lodash_clonedeep_1.default(ret)) : {}; | ||
return ret ? isodateTraverse(clone(ret)) : {}; | ||
}; | ||
@@ -198,8 +185,6 @@ /** | ||
var current = this.id(); | ||
if (current === null || current === id) { | ||
traits = lodash_assignin_1.default(this.traits(), traits); | ||
} | ||
if (id) { | ||
if (current === null || current === id) | ||
traits = extend(this.traits(), traits); | ||
if (id) | ||
this.id(id); | ||
} | ||
this.debug('identify %o, %o', id, traits); | ||
@@ -206,0 +191,0 @@ this.traits(traits); |
@@ -1,1 +0,10 @@ | ||
export {}; | ||
declare var bindAll: any; | ||
declare var clone: any; | ||
/** | ||
* HOP. | ||
*/ | ||
declare var has: (v: string | number | symbol) => boolean; | ||
/** | ||
* Initialize `Memory` store | ||
*/ | ||
declare function Memory(): void; |
'use strict'; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
* Module Dependencies. | ||
*/ | ||
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
var bindAll = require('bind-all'); | ||
var clone = require('./utils/clone'); | ||
/** | ||
@@ -29,3 +25,3 @@ * HOP. | ||
Memory.prototype.set = function (key, value) { | ||
this.store[key] = lodash_clonedeep_1.default(value); | ||
this.store[key] = clone(value); | ||
return true; | ||
@@ -39,3 +35,3 @@ }; | ||
return; | ||
return lodash_clonedeep_1.default(this.store[key]); | ||
return clone(this.store[key]); | ||
}; | ||
@@ -42,0 +38,0 @@ /** |
@@ -1,4 +0,3 @@ | ||
export declare const SourceMiddlewareChain: () => void; | ||
export declare const IntegrationMiddlewareChain: () => void; | ||
export declare const DestinationMiddlewareChain: () => void; | ||
export declare const middlewareChain: (dest: any) => (run: any, facade: any, callback: any) => void; | ||
declare var Facade: any; | ||
declare function middlewareChain(dest: any): (run: any, facade: any, callback: any) => void; | ||
declare function executeChain(run: any, payload: any, middlewares: any, index: any): void; |
@@ -1,10 +0,5 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.middlewareChain = exports.DestinationMiddlewareChain = exports.IntegrationMiddlewareChain = exports.SourceMiddlewareChain = void 0; | ||
var segmentio_facade_1 = __importDefault(require("segmentio-facade")); | ||
exports.SourceMiddlewareChain = function SourceMiddlewareChain() { | ||
var apply = exports.middlewareChain(this); | ||
'use strict'; | ||
var Facade = require('segmentio-facade'); | ||
module.exports.SourceMiddlewareChain = function SourceMiddlewareChain() { | ||
var apply = middlewareChain(this); | ||
this.applyMiddlewares = function (facade, integrations, callback) { | ||
@@ -20,4 +15,4 @@ return apply(function (mw, payload, next) { | ||
}; | ||
exports.IntegrationMiddlewareChain = function IntegrationMiddlewareChain() { | ||
var apply = exports.middlewareChain(this); | ||
module.exports.IntegrationMiddlewareChain = function IntegrationMiddlewareChain() { | ||
var apply = middlewareChain(this); | ||
this.applyMiddlewares = function (facade, integration, callback) { | ||
@@ -29,4 +24,4 @@ return apply(function (mw, payload, next) { | ||
}; | ||
exports.DestinationMiddlewareChain = function DestinationMiddlewareChain() { | ||
var apply = exports.middlewareChain(this); | ||
module.exports.DestinationMiddlewareChain = function DestinationMiddlewareChain() { | ||
var apply = middlewareChain(this); | ||
this.applyMiddlewares = function (facade, integration, callback) { | ||
@@ -39,3 +34,3 @@ return apply(function (mw, payload, next) { | ||
// Chain is essentially a linked list of middlewares to run in order. | ||
exports.middlewareChain = function middlewareChain(dest) { | ||
function middlewareChain(dest) { | ||
var middlewares = []; | ||
@@ -65,3 +60,3 @@ // Return a copy to prevent external mutations. | ||
}; | ||
}; | ||
} | ||
// Go over all middlewares until all have been applied. | ||
@@ -75,4 +70,4 @@ function executeChain(run, payload, middlewares, index) { | ||
// Check if the payload is still a Facade. If not, convert it to one. | ||
if (!(payload instanceof segmentio_facade_1.default)) { | ||
payload = new segmentio_facade_1.default(payload); | ||
if (!(payload instanceof Facade)) { | ||
payload = new Facade(payload); | ||
} | ||
@@ -92,1 +87,2 @@ var mw = middlewares[index]; | ||
} | ||
module.exports.middlewareChain = middlewareChain; |
@@ -1,18 +0,3 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var lodash_includes_1 = __importDefault(require("lodash.includes")); | ||
/** | ||
@@ -22,2 +7,6 @@ * Module Dependencies. | ||
var debug = require('debug')('analytics.js:normalize'); | ||
var defaults = require('@ndhoule/defaults'); | ||
var each = require('./utils/each'); | ||
var includes = require('@ndhoule/includes'); | ||
var map = require('./utils/map'); | ||
var type = require('component-type'); | ||
@@ -39,5 +28,5 @@ var uuid = require('uuid/v4'); | ||
function normalize(msg, list) { | ||
var lower = list === null || list === void 0 ? void 0 : list.map(function (s) { | ||
var lower = map(function (s) { | ||
return s.toLowerCase(); | ||
}); | ||
}, list); | ||
var opts = msg.options || {}; | ||
@@ -50,12 +39,12 @@ var integrations = opts.integrations || {}; | ||
// integrations. | ||
Object.keys(opts).forEach(function (key) { | ||
each(function (value, key) { | ||
if (!integration(key)) | ||
return; | ||
if (!has.call(integrations, key)) | ||
integrations[key] = opts[key]; | ||
integrations[key] = value; | ||
delete opts[key]; | ||
}); | ||
}, opts); | ||
// providers. | ||
delete opts.providers; | ||
Object.keys(providers).forEach(function (key) { | ||
each(function (value, key) { | ||
if (!integration(key)) | ||
@@ -67,8 +56,8 @@ return; | ||
return; | ||
integrations[key] = providers[key]; | ||
}); | ||
integrations[key] = value; | ||
}, providers); | ||
// move all toplevel options to msg | ||
// and the rest to context. | ||
Object.keys(opts).forEach(function (key) { | ||
if (lodash_includes_1.default(toplevel, key)) { | ||
each(function (_value, key) { | ||
if (includes(key, toplevel)) { | ||
ret[key] = opts[key]; | ||
@@ -86,10 +75,10 @@ } | ||
ret.context = context; | ||
ret = __assign(__assign({}, msg), ret); | ||
ret = defaults(ret, msg); | ||
debug('->', ret); | ||
return ret; | ||
function integration(name) { | ||
return !!(lodash_includes_1.default(list, name) || | ||
return !!(includes(name, list) || | ||
name.toLowerCase() === 'all' || | ||
lodash_includes_1.default(lower, name.toLowerCase())); | ||
includes(name.toLowerCase(), lower)); | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
import { PageDefaults } from './types'; | ||
/** | ||
* Return a default `options.context.page` object. | ||
* | ||
* https://segment.com/docs/spec/page/#properties | ||
*/ | ||
export declare const pageDefaults: () => PageDefaults; | ||
export {}; |
@@ -1,20 +0,33 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pageDefaults = void 0; | ||
var lodash_includes_1 = __importDefault(require("lodash.includes")); | ||
var component_url_1 = __importDefault(require("component-url")); | ||
/* | ||
* Module dependencies. | ||
*/ | ||
var canonical = require('@segment/canonical'); | ||
var includes = require('@ndhoule/includes'); | ||
var url = require('component-url'); | ||
/** | ||
* Return a default `options.context.page` object. | ||
* | ||
* https://segment.com/docs/spec/page/#properties | ||
*/ | ||
function pageDefaults() { | ||
return { | ||
path: canonicalPath(), | ||
referrer: document.referrer, | ||
search: location.search, | ||
title: document.title, | ||
url: canonicalUrl(location.search) | ||
}; | ||
} | ||
/** | ||
* Return the canonical path for the page. | ||
*/ | ||
var canonicalPath = function () { | ||
var canon = document.querySelector("link[rel='canonical']"); | ||
function canonicalPath() { | ||
var canon = canonical(); | ||
if (!canon) | ||
return window.location.pathname; | ||
var href = canon.getAttribute("href"); | ||
var parsed = component_url_1.default.parse(href); | ||
var parsed = url.parse(canon); | ||
return parsed.pathname; | ||
}; | ||
} | ||
/** | ||
@@ -24,29 +37,13 @@ * Return the canonical URL for the page concat the given `search` | ||
*/ | ||
var canonicalUrl = function (search) { | ||
var canon = document.querySelector("link[rel='canonical']"); | ||
if (canon) { | ||
var href = canon.getAttribute("href"); | ||
return lodash_includes_1.default(href, '?') ? href : href + search; | ||
} | ||
function canonicalUrl(search) { | ||
var canon = canonical(); | ||
if (canon) | ||
return includes('?', canon) ? canon : canon + search; | ||
var url = window.location.href; | ||
var i = url.indexOf('#'); | ||
return i === -1 ? url : url.slice(0, i); | ||
}; | ||
/** | ||
* Return a default `options.context.page` object. | ||
* | ||
* https://segment.com/docs/spec/page/#properties | ||
} | ||
/* | ||
* Exports. | ||
*/ | ||
exports.pageDefaults = function () { | ||
var path = canonicalPath(); | ||
var referrer = document.referrer, title = document.title; | ||
var search = location.search; | ||
var url = canonicalUrl(search); | ||
return { | ||
path: path, | ||
referrer: referrer, | ||
search: search, | ||
title: title, | ||
url: url | ||
}; | ||
}; | ||
module.exports = pageDefaults; |
@@ -1,1 +0,11 @@ | ||
export {}; | ||
declare var bindAll: any; | ||
declare var defaults: any; | ||
declare var store: any; | ||
/** | ||
* Initialize a new `Store` with `options`. | ||
* | ||
* @param {Object} options | ||
*/ | ||
declare function Store(options?: { | ||
enabled: boolean; | ||
}): void; |
'use strict'; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
@@ -18,2 +6,3 @@ * Module dependencies. | ||
var bindAll = require('bind-all'); | ||
var defaults = require('@ndhoule/defaults'); | ||
var store = require('@segment/store'); | ||
@@ -35,3 +24,3 @@ /** | ||
options = options || {}; | ||
options = __assign({ enabled: true }, options); | ||
defaults(options, { enabled: true }); | ||
this.enabled = options.enabled && store.enabled; | ||
@@ -38,0 +27,0 @@ this._options = options; |
export interface SegmentAnalytics { | ||
Integrations: { | ||
[name: string]: (options: SegmentOpts) => void; | ||
[name: string]: unknown; | ||
}; | ||
@@ -8,14 +8,2 @@ options: InitOptions; | ||
VERSION: any; | ||
page: (category?: string, name?: string, properties?: any, options?: any, fn?: unknown) => void; | ||
_options: (options: Object) => void; | ||
_sourceMiddlewares: unknown; | ||
_integrationMiddlewares: unknown; | ||
_destinationMiddlewares: unknown; | ||
_integrations: unknown; | ||
_readied: boolean; | ||
_timeout: number; | ||
_user: unknown; | ||
log: (args: string) => void; | ||
on: (event: string, callback: (settings: unknown, options: InitOptions) => void) => void; | ||
_parseQuery: (queryString: string) => void; | ||
} | ||
@@ -30,3 +18,2 @@ export interface IntegrationsSettings { | ||
secure?: boolean; | ||
sameSite?: string; | ||
} | ||
@@ -39,3 +26,3 @@ export interface MetricsOptions { | ||
} | ||
export interface StoreOptions { | ||
interface StoreOptions { | ||
enabled?: boolean; | ||
@@ -86,3 +73,3 @@ } | ||
providers?: { | ||
[key: string]: string | boolean; | ||
[key: string]: string; | ||
}; | ||
@@ -99,1 +86,2 @@ context?: unknown; | ||
} | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
# 4.0.6 / 2021-03-18 | ||
# 4.0.7 / 2021-03-18 | ||
@@ -3,0 +3,0 @@ - Fix Potential DOM-based XSS via prototype pollution |
{ | ||
"name": "@segment/analytics.js-core", | ||
"author": "Segment <friends@segment.com>", | ||
"version": "4.0.6", | ||
"version": "4.0.7", | ||
"description": "The hassle-free way to integrate analytics into any web application.", | ||
@@ -6,0 +6,0 @@ "types": "lib/index.d.ts", |
189273
56
4654