@esri/telemetry
Advanced tools
Comparing version 4.2.1 to 5.0.0
@@ -1028,38 +1028,24 @@ define((function () { 'use strict'; | ||
function telemetryEnabled() { | ||
function shouldDisableTracking() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var disabled = options.disabled, | ||
portal = options.portal; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
if (disabled || (portal === null || portal === void 0 ? void 0 : portal.eueiEnabled) === false) { | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
if (!portal || hasEueiEnabledAndIsMemberOfOrg(portal) || isRegisteredUserWithoutOrgInUSA(portal) || isAnonymousUserInUSA(portal)) { | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
function hasEueiEnabledAndIsMemberOfOrg(portal) { | ||
return portal.eueiEnabled && portal.user && portal.user.orgId === portal.id; | ||
} | ||
function isRegisteredUserWithoutOrgInUSA(portal) { | ||
return portal.user && !portal.user.orgId && portal.ipCntryCode === 'US'; | ||
} | ||
function isAnonymousUserInUSA(portal) { | ||
return !portal.user && portal.ipCntryCode === 'US'; | ||
} | ||
@@ -1213,7 +1199,7 @@ var storage = { | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
this.disabled = shouldDisableTracking(options); | ||
this.logger = options.logger || this.logger; | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
this.logger.warn('Telemetry Disabled'); | ||
} | ||
@@ -1238,3 +1224,3 @@ var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
this.logger.error(new Error('No trackers configured')); | ||
} | ||
@@ -1268,21 +1254,19 @@ } | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.disabled) { | ||
this.logger.warn('Page view was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var enabledTrackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Page view was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
@@ -1298,25 +1282,20 @@ }); | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
if (this.disabled) { | ||
this.logger.warn('Event was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test) { | ||
return event; | ||
var enabledTrackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Event was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
var eventAttributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking event', JSON.stringify(eventAttributes)); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logEvent(eventAttributes); | ||
}); | ||
@@ -1453,3 +1432,3 @@ Promise.all(promises).then(); | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData, this.logger), {}); | ||
} | ||
@@ -1486,3 +1465,3 @@ }, { | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
function makeEventPayload(omitComplexData, logger) { | ||
return function (acc, _ref5) { | ||
@@ -1496,3 +1475,3 @@ var _ref6 = slicedToArray(_ref5, 2), | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
logger.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
@@ -1499,0 +1478,0 @@ } |
@@ -1028,38 +1028,24 @@ define((function () { 'use strict'; | ||
function telemetryEnabled() { | ||
function shouldDisableTracking() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var disabled = options.disabled, | ||
portal = options.portal; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
if (disabled || (portal === null || portal === void 0 ? void 0 : portal.eueiEnabled) === false) { | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
if (!portal || hasEueiEnabledAndIsMemberOfOrg(portal) || isRegisteredUserWithoutOrgInUSA(portal) || isAnonymousUserInUSA(portal)) { | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
function hasEueiEnabledAndIsMemberOfOrg(portal) { | ||
return portal.eueiEnabled && portal.user && portal.user.orgId === portal.id; | ||
} | ||
function isRegisteredUserWithoutOrgInUSA(portal) { | ||
return portal.user && !portal.user.orgId && portal.ipCntryCode === 'US'; | ||
} | ||
function isAnonymousUserInUSA(portal) { | ||
return !portal.user && portal.ipCntryCode === 'US'; | ||
} | ||
@@ -1213,7 +1199,7 @@ var storage = { | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
this.disabled = shouldDisableTracking(options); | ||
this.logger = options.logger || this.logger; | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
this.logger.warn('Telemetry Disabled'); | ||
} | ||
@@ -1238,3 +1224,3 @@ var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
this.logger.error(new Error('No trackers configured')); | ||
} | ||
@@ -1268,21 +1254,19 @@ } | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.disabled) { | ||
this.logger.warn('Page view was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var enabledTrackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Page view was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
@@ -1298,25 +1282,20 @@ }); | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
if (this.disabled) { | ||
this.logger.warn('Event was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test) { | ||
return event; | ||
var enabledTrackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Event was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
var eventAttributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking event', JSON.stringify(eventAttributes)); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logEvent(eventAttributes); | ||
}); | ||
@@ -1453,3 +1432,3 @@ Promise.all(promises).then(); | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData, this.logger), {}); | ||
} | ||
@@ -1486,3 +1465,3 @@ }, { | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
function makeEventPayload(omitComplexData, logger) { | ||
return function (acc, _ref5) { | ||
@@ -1496,3 +1475,3 @@ var _ref6 = slicedToArray(_ref5, 2), | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
logger.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
@@ -1499,0 +1478,0 @@ } |
@@ -1028,38 +1028,24 @@ define((function () { 'use strict'; | ||
function telemetryEnabled() { | ||
function shouldDisableTracking() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var disabled = options.disabled, | ||
portal = options.portal; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
if (disabled || (portal === null || portal === void 0 ? void 0 : portal.eueiEnabled) === false) { | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
if (!portal || hasEueiEnabledAndIsMemberOfOrg(portal) || isRegisteredUserWithoutOrgInUSA(portal) || isAnonymousUserInUSA(portal)) { | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
function hasEueiEnabledAndIsMemberOfOrg(portal) { | ||
return portal.eueiEnabled && portal.user && portal.user.orgId === portal.id; | ||
} | ||
function isRegisteredUserWithoutOrgInUSA(portal) { | ||
return portal.user && !portal.user.orgId && portal.ipCntryCode === 'US'; | ||
} | ||
function isAnonymousUserInUSA(portal) { | ||
return !portal.user && portal.ipCntryCode === 'US'; | ||
} | ||
@@ -1213,7 +1199,7 @@ var storage = { | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
this.disabled = shouldDisableTracking(options); | ||
this.logger = options.logger || this.logger; | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
this.logger.warn('Telemetry Disabled'); | ||
} | ||
@@ -1238,3 +1224,3 @@ var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
this.logger.error(new Error('No trackers configured')); | ||
} | ||
@@ -1268,21 +1254,19 @@ } | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.disabled) { | ||
this.logger.warn('Page view was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var enabledTrackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Page view was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
@@ -1298,25 +1282,20 @@ }); | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
if (this.disabled) { | ||
this.logger.warn('Event was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test) { | ||
return event; | ||
var enabledTrackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Event was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
var eventAttributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking event', JSON.stringify(eventAttributes)); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logEvent(eventAttributes); | ||
}); | ||
@@ -1453,3 +1432,3 @@ Promise.all(promises).then(); | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData, this.logger), {}); | ||
} | ||
@@ -1486,3 +1465,3 @@ }, { | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
function makeEventPayload(omitComplexData, logger) { | ||
return function (acc, _ref5) { | ||
@@ -1496,3 +1475,3 @@ var _ref6 = slicedToArray(_ref5, 2), | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
logger.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
@@ -1499,0 +1478,0 @@ } |
@@ -1028,38 +1028,24 @@ define((function () { 'use strict'; | ||
function telemetryEnabled() { | ||
function shouldDisableTracking() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var disabled = options.disabled, | ||
portal = options.portal; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
if (disabled || (portal === null || portal === void 0 ? void 0 : portal.eueiEnabled) === false) { | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
if (!portal || hasEueiEnabledAndIsMemberOfOrg(portal) || isRegisteredUserWithoutOrgInUSA(portal) || isAnonymousUserInUSA(portal)) { | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
function hasEueiEnabledAndIsMemberOfOrg(portal) { | ||
return portal.eueiEnabled && portal.user && portal.user.orgId === portal.id; | ||
} | ||
function isRegisteredUserWithoutOrgInUSA(portal) { | ||
return portal.user && !portal.user.orgId && portal.ipCntryCode === 'US'; | ||
} | ||
function isAnonymousUserInUSA(portal) { | ||
return !portal.user && portal.ipCntryCode === 'US'; | ||
} | ||
@@ -1213,7 +1199,7 @@ var storage = { | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
this.disabled = shouldDisableTracking(options); | ||
this.logger = options.logger || this.logger; | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
this.logger.warn('Telemetry Disabled'); | ||
} | ||
@@ -1238,3 +1224,3 @@ var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
this.logger.error(new Error('No trackers configured')); | ||
} | ||
@@ -1268,21 +1254,19 @@ } | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.disabled) { | ||
this.logger.warn('Page view was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var enabledTrackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Page view was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
@@ -1298,25 +1282,20 @@ }); | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
if (this.disabled) { | ||
this.logger.warn('Event was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test) { | ||
return event; | ||
var enabledTrackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Event was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
var eventAttributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking event', JSON.stringify(eventAttributes)); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logEvent(eventAttributes); | ||
}); | ||
@@ -1453,3 +1432,3 @@ Promise.all(promises).then(); | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData, this.logger), {}); | ||
} | ||
@@ -1486,3 +1465,3 @@ }, { | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
function makeEventPayload(omitComplexData, logger) { | ||
return function (acc, _ref5) { | ||
@@ -1496,3 +1475,3 @@ var _ref6 = slicedToArray(_ref5, 2), | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
logger.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
@@ -1499,0 +1478,0 @@ } |
@@ -1032,38 +1032,24 @@ (function (global, factory) { | ||
function telemetryEnabled() { | ||
function shouldDisableTracking() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var disabled = options.disabled, | ||
portal = options.portal; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
if (disabled || (portal === null || portal === void 0 ? void 0 : portal.eueiEnabled) === false) { | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
if (!portal || hasEueiEnabledAndIsMemberOfOrg(portal) || isRegisteredUserWithoutOrgInUSA(portal) || isAnonymousUserInUSA(portal)) { | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
function hasEueiEnabledAndIsMemberOfOrg(portal) { | ||
return portal.eueiEnabled && portal.user && portal.user.orgId === portal.id; | ||
} | ||
function isRegisteredUserWithoutOrgInUSA(portal) { | ||
return portal.user && !portal.user.orgId && portal.ipCntryCode === 'US'; | ||
} | ||
function isAnonymousUserInUSA(portal) { | ||
return !portal.user && portal.ipCntryCode === 'US'; | ||
} | ||
@@ -1217,7 +1203,7 @@ var storage = { | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
this.disabled = shouldDisableTracking(options); | ||
this.logger = options.logger || this.logger; | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
this.logger.warn('Telemetry Disabled'); | ||
} | ||
@@ -1242,3 +1228,3 @@ var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
this.logger.error(new Error('No trackers configured')); | ||
} | ||
@@ -1272,21 +1258,19 @@ } | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.disabled) { | ||
this.logger.warn('Page view was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var enabledTrackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Page view was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
@@ -1302,25 +1286,20 @@ }); | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
if (this.disabled) { | ||
this.logger.warn('Event was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test) { | ||
return event; | ||
var enabledTrackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Event was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
var eventAttributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking event', JSON.stringify(eventAttributes)); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logEvent(eventAttributes); | ||
}); | ||
@@ -1457,3 +1436,3 @@ Promise.all(promises).then(); | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData, this.logger), {}); | ||
} | ||
@@ -1490,3 +1469,3 @@ }, { | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
function makeEventPayload(omitComplexData, logger) { | ||
return function (acc, _ref5) { | ||
@@ -1500,3 +1479,3 @@ var _ref6 = slicedToArray(_ref5, 2), | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
logger.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
@@ -1503,0 +1482,0 @@ } |
@@ -1032,38 +1032,24 @@ (function (global, factory) { | ||
function telemetryEnabled() { | ||
function shouldDisableTracking() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var disabled = options.disabled, | ||
portal = options.portal; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
if (disabled || (portal === null || portal === void 0 ? void 0 : portal.eueiEnabled) === false) { | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
if (!portal || hasEueiEnabledAndIsMemberOfOrg(portal) || isRegisteredUserWithoutOrgInUSA(portal) || isAnonymousUserInUSA(portal)) { | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
function hasEueiEnabledAndIsMemberOfOrg(portal) { | ||
return portal.eueiEnabled && portal.user && portal.user.orgId === portal.id; | ||
} | ||
function isRegisteredUserWithoutOrgInUSA(portal) { | ||
return portal.user && !portal.user.orgId && portal.ipCntryCode === 'US'; | ||
} | ||
function isAnonymousUserInUSA(portal) { | ||
return !portal.user && portal.ipCntryCode === 'US'; | ||
} | ||
@@ -1217,7 +1203,7 @@ var storage = { | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
this.disabled = shouldDisableTracking(options); | ||
this.logger = options.logger || this.logger; | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
this.logger.warn('Telemetry Disabled'); | ||
} | ||
@@ -1242,3 +1228,3 @@ var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
this.logger.error(new Error('No trackers configured')); | ||
} | ||
@@ -1272,21 +1258,19 @@ } | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.disabled) { | ||
this.logger.warn('Page view was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var enabledTrackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Page view was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
@@ -1302,25 +1286,20 @@ }); | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
if (this.disabled) { | ||
this.logger.warn('Event was not logged because telemetry is disabled.'); | ||
return false; | ||
} | ||
if (this.test) { | ||
return event; | ||
var enabledTrackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
if (!enabledTrackers.length) { | ||
this.logger.warn('Event was not logged because no enabled telemetry-plugins are registered.'); | ||
return false; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
var eventAttributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
this.logger.info('Tracking event', JSON.stringify(eventAttributes)); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
var promises = enabledTrackers.map(function (tracker) { | ||
return tracker.logEvent(eventAttributes); | ||
}); | ||
@@ -1457,3 +1436,3 @@ Promise.all(promises).then(); | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData, this.logger), {}); | ||
} | ||
@@ -1490,3 +1469,3 @@ }, { | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
function makeEventPayload(omitComplexData, logger) { | ||
return function (acc, _ref5) { | ||
@@ -1500,3 +1479,3 @@ var _ref6 = slicedToArray(_ref5, 2), | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
logger.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
@@ -1503,0 +1482,0 @@ } |
{ | ||
"name": "@esri/telemetry", | ||
"version": "4.2.1", | ||
"version": "5.0.0", | ||
"description": "A JavaScript Implementation of the ArcGIS Telemetry Specification", | ||
@@ -48,3 +48,3 @@ "main": "dist/telemetry", | ||
}, | ||
"gitHead": "c2e010efdc15982099b4cb16555c4e126c69fcb9" | ||
"gitHead": "63be344edb11bebfba2b0608feffb379e58ba3d7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
15
1
56
661226
7850