@esri/telemetry
Advanced tools
Comparing version 1.5.0 to 1.5.1-beta.0
@@ -60,3 +60,3 @@ 'use strict' | ||
babel({ | ||
exclude: 'node_modules/**', | ||
exclude: ['node_modules/**', '*.test.js'], | ||
presets: ['es2015-rollup', 'stage-1'], | ||
@@ -63,0 +63,0 @@ plugins: ['transform-object-assign', 'transform-es2015-destructuring', 'transform-es2015-function-name', 'transform-es2015-parameters'] |
@@ -7,2 +7,10 @@ # Change Log | ||
## Unreleased | ||
### Changed | ||
* Remove /dist from repo | ||
### Added | ||
* Added Jest test framework and some co-located unit tests | ||
* Add custom attributes and dimensions to Amazon telemetry | ||
## [1.5.0] - 09/27/2019 | ||
@@ -9,0 +17,0 @@ ### Added |
{ | ||
"name": "@esri/telemetry", | ||
"version": "1.5.0", | ||
"version": "1.5.1-beta.0", | ||
"description": "A JavaScript Implementation of the ArcGIS Telemetry Specification", | ||
@@ -18,3 +18,11 @@ "main": "dist/telemetry.js", | ||
], | ||
"author": "Daniel Fenton <dfenton@esri.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Rich Gwozdz", | ||
"email": "rgwozdz@esri.com" | ||
}, | ||
{ | ||
"name": "Daniel Fenton" | ||
} | ||
], | ||
"license": "Apache-2.0", | ||
@@ -21,0 +29,0 @@ "bugs": { |
define('telemetry', function () { 'use strict'; | ||
function request(options, callback) { | ||
var req = new XMLHttpRequest(); //eslint-disable-line | ||
req.addEventListener('load', function () { | ||
callback(req.responseText); | ||
}); | ||
req.open(options.method, options.url); | ||
Object.keys(options.headers).forEach(function (header) { | ||
req.setRequestHeader(header, options.headers[header]); | ||
}); | ||
req.send(options.body); | ||
} | ||
var Storage = { | ||
@@ -64,65 +49,4 @@ storage: {}, | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var COGNITO_KEY = 'TELEMETRY_COGNITO_CREDENTIALS'; | ||
var COGNITO_URL = 'https://cognito-identity.us-east-1.amazonaws.com/'; | ||
function getCredentials(IdentityPoolId, callback) { | ||
@@ -132,37 +56,41 @@ var cached = Storage.get(COGNITO_KEY); | ||
authWithCognito(IdentityPoolId, function (credentials) { | ||
Storage.set(COGNITO_KEY, credentials); | ||
callback(credentials); | ||
}); | ||
} | ||
var options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetId' | ||
}, | ||
body: JSON.stringify({ IdentityPoolId: IdentityPoolId }) | ||
}; | ||
function authWithCognito(IdentityPoolId, callback) { | ||
var options = _extends({}, defaults$$1); | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetId'; | ||
options.body = JSON.stringify({ IdentityPoolId: IdentityPoolId }); | ||
return fetch(COGNITO_URL, options).then(function (response) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
return response.json(); | ||
}).then(function (response) { | ||
var IdentityId = response.IdentityId; | ||
request(options, function (response) { | ||
requestCredentials(JSON.parse(response), callback); | ||
}); | ||
} | ||
var options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity' | ||
}, | ||
body: JSON.stringify({ IdentityId: IdentityId }) | ||
}; | ||
return fetch(COGNITO_URL, options); | ||
}).then(function (response) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
return response.json(); | ||
}).then(function (_ref) { | ||
var Credentials = _ref.Credentials; | ||
function requestCredentials(json, callback) { | ||
var options = _extends({}, defaults$$1); | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetCredentialsForIdentity'; | ||
options.body = JSON.stringify({ IdentityId: json.IdentityId }); | ||
request(options, function (response) { | ||
var json = JSON.parse(response); | ||
callback(json.Credentials); | ||
Storage.set(COGNITO_KEY, Credentials); | ||
return Credentials; | ||
}); | ||
} | ||
var defaults$$1 = { | ||
method: 'POST', | ||
url: COGNITO_URL, | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1' | ||
} | ||
}; | ||
var SESSION_LENGTH = 30 * 60 * 1000; | ||
@@ -394,2 +322,106 @@ var SESSION_KEY = 'TELEMETRY_SESSION'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// | ||
@@ -574,10 +606,3 @@ // AWS Signature v4 Implementation for Web Browsers | ||
/** | ||
* Simple URI parser factory. | ||
* Uses an `a` document element for parsing given URIs. | ||
* Therefore it most likely will only work in a web browser. | ||
*/ | ||
function SimpleUriParser() { | ||
var parser = document ? document.createElement('a') : {}; | ||
/** | ||
@@ -593,2 +618,3 @@ * Parse the given URI. | ||
return function (uri) { | ||
var parser = URL ? new URL(uri) : document.createElement('a'); | ||
parser.href = uri; | ||
@@ -602,13 +628,13 @@ return { | ||
}; | ||
} | ||
function extractQueryParams(search) { | ||
return (/^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg); | ||
if (arg) { | ||
result[arg[1]] = arg[2]; | ||
} | ||
return result; | ||
}, {}) | ||
); | ||
} | ||
function extractQueryParams(search) { | ||
return (/^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg); | ||
if (arg) { | ||
result[arg[1]] = arg[2]; | ||
} | ||
return result; | ||
}, {}) | ||
); | ||
} | ||
@@ -694,43 +720,98 @@ | ||
var METRICS = ['size', 'duration', 'position', 'number', 'count']; | ||
var DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events'; | ||
function formatTelemetryAttributes(_ref) { | ||
var telemetryData = _ref.telemetryData, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$excludeKeys = _ref.excludeKeys, | ||
excludeKeys = _ref$excludeKeys === undefined ? [] : _ref$excludeKeys; | ||
var Amazon = function () { | ||
function Amazon(options) { | ||
classCallCheck(this, Amazon); | ||
return Object.keys(telemetryData).filter(function (key) { | ||
return !excludeKeys.includes(key); | ||
}).map(function (key) { | ||
if (dimensionLookup[key]) { | ||
return { | ||
key: getCustomDimensionKey(dimensionLookup, key), | ||
value: telemetryData[key] }; | ||
} | ||
this.name = 'amazon'; | ||
_extends(this, options); | ||
var session = getUser().session; | ||
if (session.new && !options.test) this.logEvent({ eventType: '_session.start' }); | ||
return { | ||
key: key, | ||
value: getValue(telemetryData, key) | ||
}; | ||
}).reduce(function (acc, _ref2) { | ||
var key = _ref2.key, | ||
value = _ref2.value; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getValue(data, key) { | ||
if (key === 'json') { | ||
return data[key] ? JSON.stringify(data[key]) : 'null'; | ||
} | ||
createClass(Amazon, [{ | ||
key: 'logPageView', | ||
value: function logPageView(page, options) { | ||
var event = createPageView(page, this.previousPage, options); | ||
sendTelemetry(event, this.userPoolID, this.app); | ||
this.previousPage = event.attributes; | ||
return data[key] === undefined ? 'null' : data[key].toString(); | ||
} | ||
function getCustomDimensionKey(lookup, key) { | ||
return 'dimension' + lookup[key]; | ||
} | ||
var METRICS = ['size', 'duration', 'position', 'number', 'count']; | ||
function formatTelemetryMetrtics(telemetryData) { | ||
var metricLookup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return Object.keys(telemetryData).filter(function (key) { | ||
return metricLookup[key] || METRICS.includes(key); | ||
}).map(function (key) { | ||
if (metricLookup[key]) { | ||
return { | ||
key: getCustomMetricKey(metricLookup, key), | ||
value: telemetryData[key] | ||
}; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var events = createEventLog(event); | ||
sendTelemetry(events, this.userPoolID, this.app); | ||
} | ||
}]); | ||
return Amazon; | ||
}(); | ||
function createPageView(page) { | ||
var previousPage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return { | ||
key: key, | ||
value: telemetryData[key] | ||
}; | ||
}).reduce(function (acc, _ref) { | ||
var key = _ref.key, | ||
value = _ref.value; | ||
var session = getUser().session; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getCustomMetricKey(lookup, key) { | ||
return 'metric' + lookup[key]; | ||
} | ||
function createEventLog(_ref) { | ||
var event = _ref.event, | ||
_ref$session = _ref.session, | ||
id = _ref$session.id, | ||
startTimestamp = _ref$session.startTimestamp, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
var metrics = formatTelemetryMetrtics(event, metricLookup); | ||
var eventAttributes = formatTelemetryAttributes({ | ||
telemetryData: event, | ||
dimensionLookup: dimensionLookup, | ||
excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup))) | ||
}); | ||
return { | ||
eventType: 'pageView', | ||
eventType: event.eventType || 'other', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
id: id, | ||
startTimestamp: startTimestamp | ||
}, | ||
@@ -740,53 +821,104 @@ attributes: _extends({ | ||
hostname: window.location.hostname, | ||
path: page || window.location.pathname, | ||
pageUrl: page || window.location.pathname, | ||
pageName: document.title, | ||
previousPageUrl: previousPage.pageUrl, | ||
previousPageName: previousPage.pageName | ||
}, extractAttributes(options)), | ||
metrics: extractMetrics(options) | ||
path: window.location.pathname | ||
}, eventAttributes), | ||
metrics: metrics | ||
}; | ||
} | ||
function createEventLog(event) { | ||
var session = getUser().session; | ||
function createPageViewLog(_ref) { | ||
var page = _ref.page, | ||
_ref$session = _ref.session; | ||
_ref$session = _ref$session === undefined ? {} : _ref$session; | ||
var id = _ref$session.id, | ||
startTimestamp = _ref$session.startTimestamp, | ||
_ref$previousPage = _ref.previousPage, | ||
previousPage = _ref$previousPage === undefined ? {} : _ref$previousPage, | ||
_ref$options = _ref.options, | ||
options = _ref$options === undefined ? {} : _ref$options, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
var metrics = formatTelemetryMetrtics(options, metricLookup); | ||
var attributes = formatTelemetryAttributes({ | ||
telemetryData: options, | ||
dimensionLookup: dimensionLookup, | ||
excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup))) | ||
}); | ||
var _ref2 = document || {}, | ||
referrer = _ref2.referrer, | ||
title = _ref2.title; | ||
var _ref3 = window && window.location ? window.location : {}, | ||
hostname = _ref3.hostname, | ||
pathname = _ref3.pathname; | ||
return { | ||
eventType: event.eventType || 'other', | ||
eventType: 'pageView', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
id: id, | ||
startTimestamp: startTimestamp | ||
}, | ||
attributes: _extends({ | ||
referrer: document.referrer, | ||
hostname: window.location.hostname, | ||
path: window.location.pathname | ||
}, extractAttributes(event)), | ||
metrics: extractMetrics(event) | ||
referrer: referrer, | ||
hostname: hostname, | ||
path: page || pathname, | ||
pageUrl: page || pathname, | ||
pageName: title, | ||
previousPageUrl: previousPage.pageUrl, | ||
previousPageName: previousPage.pageName | ||
}, attributes), | ||
metrics: metrics | ||
}; | ||
} | ||
function extractAttributes(event) { | ||
var attributes = _extends({}, event); | ||
delete attributes.workflow; | ||
METRICS.forEach(function (metric) { | ||
return delete attributes[metric]; | ||
}); | ||
Object.keys(attributes).forEach(function (attr) { | ||
if (attr === 'json') { | ||
attributes[attr] = attributes[attr] ? JSON.stringify(attributes[attr]) : 'null'; | ||
} else { | ||
attributes[attr] = attributes[attr] !== undefined ? attributes[attr].toString() : 'null'; | ||
var DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events'; | ||
var Amazon = function () { | ||
function Amazon(options) { | ||
classCallCheck(this, Amazon); | ||
this.name = 'amazon'; | ||
_extends(this, options); | ||
var session = getUser().session; | ||
if (session.new && !options.test) { | ||
this.logEvent({ eventType: '_session.start' }).catch(function (err) { | ||
console.error('Failed to log _session.start: ' + err.message); | ||
}); | ||
} | ||
}); | ||
return attributes; | ||
} | ||
} | ||
function extractMetrics(event) { | ||
var metrics = {}; | ||
METRICS.forEach(function (metric) { | ||
if (event[metric]) metrics[metric] = event[metric]; | ||
}); | ||
return metrics; | ||
} | ||
createClass(Amazon, [{ | ||
key: 'logPageView', | ||
value: function logPageView(page, options) { | ||
var session = getUser().session; | ||
var telemetryPayload = createPageViewLog({ | ||
page: page, | ||
session: session, | ||
previousPage: this.previousPage, | ||
options: options, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}); | ||
this.previousPage = telemetryPayload.attributes; | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app); | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var session = getUser().session; | ||
var telemetryPayload = createEventLog({ | ||
event: event, | ||
session: session, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}); | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app); | ||
} | ||
}]); | ||
return Amazon; | ||
}(); | ||
@@ -825,7 +957,7 @@ function createHeaders() { | ||
function sendTelemetry(events, userPoolID, app) { | ||
function sendTelemetry(events, userPoolID, app, url) { | ||
var user = getUser(); | ||
events = Array.isArray(events) ? events : [events]; | ||
var options = createTelemetryOptions(events); | ||
getCredentials(userPoolID, function (credentials) { | ||
return getCredentials(userPoolID).then(function (credentials) { | ||
try { | ||
@@ -838,7 +970,10 @@ options.headers = createHeaders(credentials, options); | ||
} | ||
request(options, function (response) { | ||
if (response) { | ||
console.error(JSON.parse(response)); | ||
} | ||
}); | ||
return fetch(DEFAULT_ENDPOINT, options); | ||
}).then(function (response) { | ||
if (response.ok) { | ||
return { success: true }; | ||
} | ||
throw new Error('Telemetry failed. ' + response.status + ', ' + response.statusText); | ||
}).catch(function (err) { | ||
console.error(err.message); | ||
}); | ||
@@ -859,2 +994,41 @@ } | ||
function mapMetricsAndDimensions(_ref) { | ||
var _ref$customTelemetryD = _ref.customTelemetryData, | ||
customTelemetryData = _ref$customTelemetryD === undefined ? {} : _ref$customTelemetryD, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
return Object.keys(customTelemetryData).map(function (key) { | ||
if (dimensionLookup[key]) { | ||
return { | ||
key: getCustomDimensionKey$1(dimensionLookup, key), | ||
value: customTelemetryData[key] }; | ||
} | ||
if (metricLookup[key]) { | ||
return { | ||
key: getCustomMetricKey$1(metricLookup, key), | ||
value: customTelemetryData[key] | ||
}; | ||
} | ||
}).filter(function (val) { | ||
return val; | ||
}).reduce(function (acc, _ref2) { | ||
var key = _ref2.key, | ||
value = _ref2.value; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getCustomDimensionKey$1(lookup, key) { | ||
return "dimension" + lookup[key]; | ||
} | ||
function getCustomMetricKey$1(lookup, key) { | ||
return "metric" + lookup[key]; | ||
} | ||
var Google = function () { | ||
@@ -902,3 +1076,2 @@ function Google() { | ||
} | ||
function buildPageViewObject(page, options) { | ||
@@ -908,3 +1081,3 @@ var dimensions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var pageviewObject = { | ||
var standardTelemetry = { | ||
hitType: 'pageview', | ||
@@ -914,3 +1087,9 @@ page: page || window.location.pathname | ||
return mapMetricsAndDimensions(pageviewObject, options, dimensions, metrics); | ||
var mappedCustomTelemetryData = mapMetricsAndDimensions({ | ||
customTelemetryData: options, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics | ||
}); | ||
return _extends({}, standardTelemetry, mappedCustomTelemetryData); | ||
} | ||
@@ -922,27 +1101,16 @@ | ||
var eventObject = { | ||
var standardTelemetryData = { | ||
hitType: 'event', | ||
eventCategory: event.category || 'none', | ||
eventAction: event.action, | ||
eventLabel: event.label, | ||
nonInteraction: event.nonInteraction | ||
eventLabel: event.label | ||
}; | ||
return mapMetricsAndDimensions(eventObject, event, dimensions, metrics); | ||
var mappedCustomTelemetryData = mapMetricsAndDimensions({ | ||
customTelemetryData: event, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics }); | ||
return _extends({}, standardTelemetryData, mappedCustomTelemetryData); | ||
} | ||
function mapMetricsAndDimensions(inputObject, options, dimensions, metrics) { | ||
var mappedObject = inputObject; | ||
Object.keys(dimensions).forEach(function (dimension) { | ||
mappedObject['dimension' + dimensions[dimension]] = options[dimension]; | ||
}); | ||
Object.keys(metrics).forEach(function (metric) { | ||
mappedObject['metric' + metrics[metric]] = options[metric]; | ||
}); | ||
return mappedObject; | ||
} | ||
var anonymize = function (user) { | ||
@@ -1061,3 +1229,4 @@ if (!user) return undefined; | ||
var attributes = this.preProcess(options); | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes));else if (this.test && !this.disabled) return attributes; | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.test && !this.disabled) return attributes; | ||
@@ -1067,12 +1236,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false; | ||
} else { | ||
this.trackers.forEach(function (tracker) { | ||
try { | ||
tracker.logPageView(page, attributes); | ||
} catch (e) { | ||
console.error(tracker.name + ' tracker failed to log page view.', e); | ||
} | ||
}); | ||
return true; | ||
} | ||
var promises = this.trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
@@ -1086,3 +1253,4 @@ }, { | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event));else if (this.test) return event; | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event)); | ||
if (this.test) return event; | ||
@@ -1092,12 +1260,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false; | ||
} else { | ||
this.trackers.forEach(function (tracker) { | ||
try { | ||
tracker.logEvent(event); | ||
} catch (e) { | ||
console.error(tracker.name + ' tracker failed to log event', e); | ||
} | ||
}); | ||
return true; | ||
} | ||
var promises = this.trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
@@ -1225,3 +1391,3 @@ }, { | ||
user: anonymize(this.user.username), | ||
orgId: anonymize(this.user.orgId), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
@@ -1228,0 +1394,0 @@ userSince: this.user.created, |
@@ -1,2 +0,2 @@ | ||
define("telemetry",function(){"use strict";function e(e,t){var n=new XMLHttpRequest;n.addEventListener("load",function(){t(n.responseText)}),n.open(e.method,e.url),Object.keys(e.headers).forEach(function(t){n.setRequestHeader(t,e.headers[t])}),n.send(e.body)}function t(e,t){var r=q.get(j);if(r&&Date.now()/1e3<r.Expiration)return t(r);n(e,function(e){q.set(j,e),t(e)})}function n(t,n){var i=D({},N);i.headers["X-Amz-Target"]="AWSCognitoIdentityService.GetId",i.body=JSON.stringify({IdentityPoolId:t}),e(i,function(e){r(JSON.parse(e),n)})}function r(t,n){var r=D({},N);r.headers["X-Amz-Target"]="AWSCognitoIdentityService.GetCredentialsForIdentity",r.body=JSON.stringify({IdentityId:t.IdentityId}),e(r,function(e){var t=JSON.parse(e);n(t.Credentials)})}function i(){return{session:o(),id:s()}}function o(){var e=void 0,t=q.get(M);return(!t||Date.now()>t.expiration)&&(e=!0,t=a()),t.expiration=Date.now()+L,q.set(M,t),e&&(t.new=!0),t}function s(){var e=q.get(R);return e||(e=c(),q.set(R,e)),e}function a(){return{id:Math.floor(17592186044416*(1+Math.random())).toString(16),startTimestamp:(new Date).toISOString()}}function c(){return u()+u()+"-"+u()+"-"+u()+"-"+u()+"-"+u()+u()+u()}function u(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function l(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":p(t.signDate)};t.request.method=t.request.method.toUpperCase(),t.request.body?t.payload=t.request.body:t.request.data&&e.payloadSerializer?t.payload=e.payloadSerializer(t.request.data):delete n["content-type"],t.request.headers=w(n,Object.keys(t.request.headers||{}).reduce(function(e,n){return e[n.toLowerCase()]=t.request.headers[n],e},{})),t.sortedHeaderKeys=Object.keys(t.request.headers).sort(),t.request.headers["content-type"]&&(t.request.headers["content-type"]=t.request.headers["content-type"].split(";")[0]),"object"===P(t.request.params)&&w(t.uri.queryParams,t.request.params)}function h(e,t){t.signedHeaders=t.sortedHeaderKeys.map(function(e){return e.toLowerCase()}).join(";"),t.canonicalRequest=String(t.request.method).toUpperCase()+"\n"+encodeURI(t.uri.path)+"\n"+Object.keys(t.uri.queryParams).sort().map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t.uri.queryParams[e])}).join("&")+"\n"+t.sortedHeaderKeys.map(function(e){return e.toLocaleLowerCase()+":"+t.request.headers[e]}).join("\n")+"\n\n"+t.signedHeaders+"\n"+e.hasher.hash(t.payload?t.payload:"")}function f(e,t){t.credentialScope=[p(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+p(t.signDate)+"\n"+t.credentialScope+"\n"+e.hasher.hash(t.canonicalRequest)}function d(e,t){var n=e.hasher.hmac,r=n(n(n(n("AWS4"+e.config.secretAccessKey,p(t.signDate,!0),{hexOutput:!1}),e.config.region,{hexOutput:!1,textInput:!1}),e.config.service,{hexOutput:!1,textInput:!1}),"aws4_request",{hexOutput:!1,textInput:!1});t.signature=n(r,t.stringToSign,{textInput:!1})}function g(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function p(e,t){var n=e.toISOString().replace(/[:\-]|\.\d{3}/g,"").substr(0,17);return t?n.substr(0,8):n}function y(){return function(e){return JSON.stringify(e)}}function v(){function e(e){return/^\??(.*)$/.exec(e)[1].split("&").reduce(function(e,t){return t=/^(.+)=(.*)$/.exec(t),t&&(e[t[1]]=t[2]),e},{})}var t=document?document.createElement("a"):{};return function(n){return t.href=n,{protocol:t.protocol,host:t.host.replace(/^(.*):((80)|(443))$/,"$1"),path:("/"!==t.pathname.charAt(0)?"/":"")+t.pathname,queryParams:e(t.search)}}}function m(){return{hash:function(e,t){t=w({hexOutput:!0,textInput:!0},t);var n=U.SHA256(e);return t.hexOutput?n.toString(U.enc.Hex):n},hmac:function(e,t,n){n=w({hexOutput:!0,textInput:!0},n);var r=U.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(U.enc.Hex):r}}}function w(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":P(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":P(r))?(e[n]=Array.isArray(r)?[]:{},w(e[n],r)):e[n]=r)})}),e}function S(e,t){if(void 0===e||!e)throw new Error(t)}function k(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=i().session;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:r.id,startTimestamp:r.startTimestamp},attributes:D({referrer:document.referrer,hostname:window.location.hostname,path:e||window.location.pathname,pageUrl:e||window.location.pathname,pageName:document.title,previousPageUrl:t.pageUrl,previousPageName:t.pageName},_(n)),metrics:E(n)}}function b(e){var t=i().session;return{eventType:e.eventType||"other",timestamp:(new Date).toISOString(),session:{id:t.id,startTimestamp:t.startTimestamp},attributes:D({referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname},_(e)),metrics:E(e)}}function _(e){var t=D({},e);return delete t.workflow,J.forEach(function(e){return delete t[e]}),Object.keys(t).forEach(function(e){t[e]="json"===e?t[e]?JSON.stringify(t[e]):"null":void 0!==t[e]?t[e].toString():"null"}),t}function E(e){var t={};return J.forEach(function(n){e[n]&&(t[n]=e[n])}),t}function T(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new F(n).sign(t)}function I(e,t){return JSON.stringify({client:{client_id:e,app_title:t.name,app_version_name:t.version||"unknown"},services:{mobile_analytics:{app_id:t.id}}})}function O(n,r,o){var s=i();n=Array.isArray(n)?n:[n];var a=x(n);t(r,function(t){try{a.headers=T(t,a),a.headers["x-amz-Client-Context"]=I(s.id,o)}catch(e){return void console.error(e)}e(a,function(e){e&&console.error(JSON.parse(e))})})}function x(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:Y,method:"POST",body:JSON.stringify({events:e})}}function A(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function z(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return H({hitType:"pageview",page:e||window.location.pathname},t,n,r)}function C(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return H({hitType:"event",eventCategory:e.category||"none",eventAction:e.action,eventLabel:e.label,nonInteraction:e.nonInteraction},e,t,n)}function H(e,t,n,r){var i=e;return Object.keys(n).forEach(function(e){i["dimension"+n[e]]=t[e]}),Object.keys(r).forEach(function(e){i["metric"+r[e]]=t[e]}),i}var q={storage:{},memory:!0,get:function(e){var t=void 0;try{t=window.localStorage&&window.localStorage.getItem(e)||this.storage[e]}catch(n){t=this.storage[e]}if(t)try{return JSON.parse(t)}catch(e){return}},set:function(e,t){t=JSON.stringify(t);try{window.localStorage.setItem(e,t)}catch(n){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),this.storage[e]=t}},delete:function(e){try{window.localStorage.removeItem(e)}catch(t){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),delete this.storage[e]}}},P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},W=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},B=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),D=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},j="TELEMETRY_COGNITO_CREDENTIALS",N={method:"POST",url:"https://cognito-identity.us-east-1.amazonaws.com/",headers:{"Content-type":"application/x-amz-json-1.1"}},L=18e5,M="TELEMETRY_SESSION",R="TELEMETRY_CLIENT_ID",U=function(e,t){var n={},r=n.lib={},i=function(){},o=r.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var i=0;i<e;i++)t[r+i>>>2]|=(n[i>>>2]>>>24-i%4*8&255)<<24-(r+i)%4*8;else if(n.length>65535)for(i=0;i<e;i+=4)t[r+i>>>2]=n[i>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r<t;r+=4)n.push(4294967296*e.random()|0);return new s.init(n,t)}}),a=n.enc={},c=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++){var i=t[r>>>2]>>>24-r%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++)n.push(String.fromCharCode(t[r>>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,i=n.sigBytes,o=this.blockSize,a=i/(4*o),a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0);if(t=a*o,i=e.min(4*t,i),t){for(var c=0;c<t;c+=o)this._doProcessBlock(r,c);c=r.splice(0,t),n.sigBytes-=i}return new s.init(c,i)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=h.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=U,n=t.lib,r=n.WordArray,i=n.Hasher,n=t.algo,o=[],s=[],a=function(e){return 4294967296*(e-(0|e))|0},c=2,u=0;u<64;){var l;e:{l=c;for(var h=e.sqrt(l),f=2;f<=h;f++)if(!(l%f)){l=!1;break e}l=!0}l&&(u<8&&(o[u]=a(e.pow(c,.5))),s[u]=a(e.pow(c,1/3)),u++),c++}var d=[],n=n.SHA256=i.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],a=n[3],c=n[4],u=n[5],l=n[6],h=n[7],f=0;f<64;f++){if(f<16)d[f]=0|e[t+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+s[f]+d[f],p=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=l,l=u,u=c,c=a+g|0,a=o,o=i,i=r,r=g+p|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+a|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(n),t.HmacSHA256=i._createHmacHelper(n)}(Math),function(){var e=U,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var r=e.blockSize,i=4*r;n.sigBytes>i&&(n=e.finalize(n)),n.clamp();for(var o=this._oKey=n.clone(),s=this._iKey=n.clone(),a=o.words,c=s.words,u=0;u<r;u++)a[u]^=1549556828,c[u]^=909522486;o.sigBytes=s.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}();var K={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:y,uriParserFactory:v,hasherFactory:m},F=function(){function e(t){W(this,e),this.config=w({},K,t),this.payloadSerializer=this.config.payloadSerializer||this.config.payloadSerializerFactory(),this.uriParser=this.config.uriParserFactory(),this.hasher=this.config.hasherFactory(),S(this.config.accessKeyId,"AwsSigner requires AWS AccessKeyID"),S(this.config.secretAccessKey,"AwsSigner requires AWS SecretAccessKey")}return B(e,[{key:"sign",value:function(e,t){var n={request:w({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return l(this,n),h(this,n),f(this,n),d(this,n),g(this,n),{Accept:n.request.headers.accept,Authorization:n.authorization,"Content-Type":n.request.headers["content-type"],"x-amz-date":n.request.headers["x-amz-date"],"x-amz-security-token":this.config.sessionToken||void 0}}}]),e}(),J=["size","duration","position","number","count"],Y="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",$=function(){function e(t){W(this,e),this.name="amazon",D(this,t),i().session.new&&!t.test&&this.logEvent({eventType:"_session.start"})}return B(e,[{key:"logPageView",value:function(e,t){var n=k(e,this.previousPage,t);O(n,this.userPoolID,this.app),this.previousPage=n.attributes}},{key:"logEvent",value:function(e){O(b(e),this.userPoolID,this.app)}}]),e}(),V=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};W(this,e),this.name="google",D(this,t)}return B(e,[{key:"logPageView",value:function(e,t){var n=z(e,t,this.dimensions,this.metrics);A(function(e){e.forEach(function(e){e.send(n)})})}},{key:"logEvent",value:function(e){var t=C(e,this.dimensions,this.metrics);A(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),G=function(e){if(e)return U.SHA256(e).toString(U.enc.Hex)},X=["esri.com","esriuk.com","esri.de","esri.ca","esrifrance.fr","esri.nl","esri-portugal.pt","esribulgaria.com","esri.fi","esri.kr","esrimalaysia.com.my","esri.es","esriaustralia.com.au","esri-southafrica.com","esri.cl","esrichina.com.cn","esri.co","esriturkey.com.tr","geodata.no","esriitalia.it","esri.pl"],Q=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.portal||{};return!e.disabled&&("1"!==navigator.doNotTrack&&"1"!==window.doNotTrack&&((void 0===t.eueiEnabled||!1!==t.eueiEnabled)&&(!(!t.eueiEnabled||!t.user||t.user.orgId!==t.id)||(!(!t.user||t.user.orgId||"US"!==t.ipCntryCode)||(!t.user&&"US"===t.ipCntryCode||!(Object.keys(t).length>0))))))};return function(){function e(t){W(this,e);try{if(this.trackers=[],this.workflows={},this.test=t.test,this.debug=t.debug,this.disabled=!Q(t),this.disabled&&console.log("Telemetry Disabled"),t.portal&&t.portal.user){var n=t.portal.subscriptionInfo||{};this.setUser(t.portal.user,n.type)}else t.user&&this.setUser(t.user);this.disabled||this._initTrackers(t)}catch(e){console.error("Telemetry Disabled"),console.error(e),this.disabled=!0}}return B(e,[{key:"_initTrackers",value:function(e){if(e.amazon){var t=new $(e.amazon);this.trackers.push(t)}if(e.google){var n=new V(e.google);this.trackers.push(n)}this.trackers.length||console.error(new Error("No trackers configured"))}},{key:"setUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Public";e="string"==typeof e?{username:e}:e,this.user=e,this.user.accountType=t;var n=void 0;if(e.email&&e.email.split){var r=e.email.split("@")[1];n=X.filter(function(e){return r===e}).length>0}(n||["In House","Demo and Marketing"].indexOf(t)>-1)&&(this.user.internalUser=!0)}},{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.preProcess(t);if(this.debug)console.log("Tracking page view",JSON.stringify(n));else if(this.test&&!this.disabled)return n;return!this.trackers.length||this.disabled?(this.disabled||console.error(new Error("Page view was not logged because no trackers are configured.")),!1):(this.trackers.forEach(function(t){try{t.logPageView(e,n)}catch(e){console.error(t.name+" tracker failed to log page view.",e)}}),!0)}},{key:"logEvent",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.preProcess(e);if(this.debug)console.log("Tracking event",JSON.stringify(t));else if(this.test)return t;return!this.trackers.length||this.disabled?(this.disabled||console.error(new Error("Event was not logged because no trackers are configured.")),!1):(this.trackers.forEach(function(e){try{e.logEvent(t)}catch(t){console.error(e.name+" tracker failed to log event",t)}}),!0)}},{key:"logError",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=D({eventType:"error"},e);this.logEvent(t)}},{key:"startWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={name:e,start:Date.now(),steps:[],workflowId:Math.floor(17592186044416*(1+Math.random())).toString(16)};this._saveWorkflow(n);var r=D({name:e,step:"start"},t);return this._logWorkflow(r),n}},{key:"stepWorkflow",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r="string"==typeof options?n:n.details,i=D({name:e,step:t,details:r},n);this._logWorkflow(i)}},{key:"endWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=D({name:e,step:"finish"},t);this._logWorkflow(n)}},{key:"cancelWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=D({name:e,step:"cancel"},t);this._logWorkflow(n)}},{key:"getWorkflow",value:function(e){var t=q.get("TELEMETRY-WORKFLOW:"+e);if(t){if(Date.now()-t.start<18e5)return t;this._deleteWorkflow(t)}}},{key:"_saveWorkflow",value:function(e){q.set("TELEMETRY-WORKFLOW:"+e.name,e)}},{key:"_deleteWorkflow",value:function(e){q.delete("TELEMETRY-WORKFLOW:"+e.name)}},{key:"_logWorkflow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=this.preProcess(e);var t=this.getWorkflow(e.name);t||(this.startWorkflow(e.name),t=this.getWorkflow(e.name)),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3,["cancel","finish"].indexOf(e.step)>-1?this._deleteWorkflow(t):this._saveWorkflow(t);var n=D(e,{eventType:"workflow",category:e.name,action:e.step,label:e.details,duration:t.duration,workflowId:t.workflowId});this.logEvent(n)}},{key:"preProcess",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};return this.user&&(t={user:G(this.user.username),orgId:G(this.user.orgId),lastLogin:this.user.lastLogin,userSince:this.user.created,internalUser:this.user.internalUser||!1,accountType:this.user.accountType}),D({},e,t)}}]),e}()}); | ||
define("telemetry",function(){"use strict";function e(e,t){var n=q.get(D);if(n&&Date.now()/1e3<n.Expiration)return t(n);var r={method:"POST",headers:{"Content-type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityService.GetId"},body:JSON.stringify({IdentityPoolId:e})};return fetch(j,r).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.json()}).then(function(e){var t=e.IdentityId,n={method:"POST",headers:{"Content-type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityService.GetCredentialsForIdentity"},body:JSON.stringify({IdentityId:t})};return fetch(j,n)}).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.json()}).then(function(e){var t=e.Credentials;return q.set(D,t),t})}function t(){return{session:n(),id:r()}}function n(){var e=void 0,t=q.get(K);return(!t||Date.now()>t.expiration)&&(e=!0,t=i()),t.expiration=Date.now()+B,q.set(K,t),e&&(t.new=!0),t}function r(){var e=q.get(U);return e||(e=o(),q.set(U,e)),e}function i(){return{id:Math.floor(17592186044416*(1+Math.random())).toString(16),startTimestamp:(new Date).toISOString()}}function o(){return s()+s()+"-"+s()+"-"+s()+"-"+s()+"-"+s()+s()+s()}function s(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function a(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":f(t.signDate)};t.request.method=t.request.method.toUpperCase(),t.request.body?t.payload=t.request.body:t.request.data&&e.payloadSerializer?t.payload=e.payloadSerializer(t.request.data):delete n["content-type"],t.request.headers=v(n,Object.keys(t.request.headers||{}).reduce(function(e,n){return e[n.toLowerCase()]=t.request.headers[n],e},{})),t.sortedHeaderKeys=Object.keys(t.request.headers).sort(),t.request.headers["content-type"]&&(t.request.headers["content-type"]=t.request.headers["content-type"].split(";")[0]),"object"===M(t.request.params)&&v(t.uri.queryParams,t.request.params)}function u(e,t){t.signedHeaders=t.sortedHeaderKeys.map(function(e){return e.toLowerCase()}).join(";"),t.canonicalRequest=String(t.request.method).toUpperCase()+"\n"+encodeURI(t.uri.path)+"\n"+Object.keys(t.uri.queryParams).sort().map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t.uri.queryParams[e])}).join("&")+"\n"+t.sortedHeaderKeys.map(function(e){return e.toLocaleLowerCase()+":"+t.request.headers[e]}).join("\n")+"\n\n"+t.signedHeaders+"\n"+e.hasher.hash(t.payload?t.payload:"")}function c(e,t){t.credentialScope=[f(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+f(t.signDate)+"\n"+t.credentialScope+"\n"+e.hasher.hash(t.canonicalRequest)}function l(e,t){var n=e.hasher.hmac,r=n(n(n(n("AWS4"+e.config.secretAccessKey,f(t.signDate,!0),{hexOutput:!1}),e.config.region,{hexOutput:!1,textInput:!1}),e.config.service,{hexOutput:!1,textInput:!1}),"aws4_request",{hexOutput:!1,textInput:!1});t.signature=n(r,t.stringToSign,{textInput:!1})}function h(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function f(e,t){var n=e.toISOString().replace(/[:\-]|\.\d{3}/g,"").substr(0,17);return t?n.substr(0,8):n}function d(){return function(e){return JSON.stringify(e)}}function p(){return function(e){var t=URL?new URL(e):document.createElement("a");return t.href=e,{protocol:t.protocol,host:t.host.replace(/^(.*):((80)|(443))$/,"$1"),path:("/"!==t.pathname.charAt(0)?"/":"")+t.pathname,queryParams:g(t.search)}}}function g(e){return/^\??(.*)$/.exec(e)[1].split("&").reduce(function(e,t){return t=/^(.+)=(.*)$/.exec(t),t&&(e[t[1]]=t[2]),e},{})}function y(){return{hash:function(e,t){t=v({hexOutput:!0,textInput:!0},t);var n=R.SHA256(e);return t.hexOutput?n.toString(R.enc.Hex):n},hmac:function(e,t,n){n=v({hexOutput:!0,textInput:!0},n);var r=R.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(R.enc.Hex):r}}}function v(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":M(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":M(r))?(e[n]=Array.isArray(r)?[]:{},v(e[n],r)):e[n]=r)})}),e}function m(e,t){if(void 0===e||!e)throw new Error(t)}function w(e){var t=e.telemetryData,n=e.dimensionLookup,r=void 0===n?{}:n,i=e.excludeKeys,o=void 0===i?[]:i;return Object.keys(t).filter(function(e){return!o.includes(e)}).map(function(e){return r[e]?{key:S(r,e),value:t[e]}:{key:e,value:k(t,e)}}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function k(e,t){return"json"===t?e[t]?JSON.stringify(e[t]):"null":void 0===e[t]?"null":e[t].toString()}function S(e,t){return"dimension"+e[t]}function b(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Object.keys(e).filter(function(e){return t[e]||G.includes(e)}).map(function(n){return t[n]?{key:_(t,n),value:e[n]}:{key:n,value:e[n]}}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function _(e,t){return"metric"+e[t]}function T(e){var t=e.event,n=e.session,r=n.id,i=n.startTimestamp,o=e.dimensionLookup,s=void 0===o?{}:o,a=e.metricLookup,u=void 0===a?{}:a,c=b(t,u),l=w({telemetryData:t,dimensionLookup:s,excludeKeys:["workflow"].concat(Y(Object.keys(c)),Y(Object.keys(u)))});return{eventType:t.eventType||"other",timestamp:(new Date).toISOString(),session:{id:r,startTimestamp:i},attributes:J({referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname},l),metrics:c}}function O(e){var t=e.page,n=e.session;n=void 0===n?{}:n;var r=n.id,i=n.startTimestamp,o=e.previousPage,s=void 0===o?{}:o,a=e.options,u=void 0===a?{}:a,c=e.dimensionLookup,l=void 0===c?{}:c,h=e.metricLookup,f=void 0===h?{}:h,d=b(u,f),p=w({telemetryData:u,dimensionLookup:l,excludeKeys:["workflow"].concat(Y(Object.keys(d)),Y(Object.keys(f)))}),g=document||{},y=g.referrer,v=g.title,m=window&&window.location?window.location:{},k=m.hostname,S=m.pathname;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:r,startTimestamp:i},attributes:J({referrer:y,hostname:k,path:t||S,pageUrl:t||S,pageName:v,previousPageUrl:s.pageUrl,previousPageName:s.pageName},p),metrics:d}}function x(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new V(n).sign(t)}function I(e,t){return JSON.stringify({client:{client_id:e,app_title:t.name,app_version_name:t.version||"unknown"},services:{mobile_analytics:{app_id:t.id}}})}function A(n,r,i,o){var s=t();n=Array.isArray(n)?n:[n];var a=E(n);return e(r).then(function(e){try{a.headers=x(e,a),a.headers["x-amz-Client-Context"]=I(s.id,i)}catch(e){return void console.error(e)}return fetch(X,a)}).then(function(e){if(e.ok)return{success:!0};throw new Error("Telemetry failed. "+e.status+", "+e.statusText)}).catch(function(e){console.error(e.message)})}function E(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:X,method:"POST",body:JSON.stringify({events:e})}}function P(e){var t=e.customTelemetryData,n=void 0===t?{}:t,r=e.dimensionLookup,i=void 0===r?{}:r,o=e.metricLookup,s=void 0===o?{}:o;return Object.keys(n).map(function(e){return i[e]?{key:z(i,e),value:n[e]}:s[e]?{key:L(s,e),value:n[e]}:void 0}).filter(function(e){return e}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function z(e,t){return"dimension"+e[t]}function L(e,t){return"metric"+e[t]}function C(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function H(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i={hitType:"pageview",page:e||window.location.pathname},o=P({customTelemetryData:t,dimensionLookup:n,metricLookup:r});return J({},i,o)}function W(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={hitType:"event",eventCategory:e.category||"none",eventAction:e.action,eventLabel:e.label},i=P({customTelemetryData:e,dimensionLookup:t,metricLookup:n});return J({},r,i)}var q={storage:{},memory:!0,get:function(e){var t=void 0;try{t=window.localStorage&&window.localStorage.getItem(e)||this.storage[e]}catch(n){t=this.storage[e]}if(t)try{return JSON.parse(t)}catch(e){return}},set:function(e,t){t=JSON.stringify(t);try{window.localStorage.setItem(e,t)}catch(n){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),this.storage[e]=t}},delete:function(e){try{window.localStorage.removeItem(e)}catch(t){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),delete this.storage[e]}}},D="TELEMETRY_COGNITO_CREDENTIALS",j="https://cognito-identity.us-east-1.amazonaws.com/",B=18e5,K="TELEMETRY_SESSION",U="TELEMETRY_CLIENT_ID",R=function(e,t){var n={},r=n.lib={},i=function(){},o=r.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var i=0;i<e;i++)t[r+i>>>2]|=(n[i>>>2]>>>24-i%4*8&255)<<24-(r+i)%4*8;else if(n.length>65535)for(i=0;i<e;i+=4)t[r+i>>>2]=n[i>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r<t;r+=4)n.push(4294967296*e.random()|0);return new s.init(n,t)}}),a=n.enc={},u=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++){var i=t[r>>>2]>>>24-r%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++)n.push(String.fromCharCode(t[r>>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},h=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,i=n.sigBytes,o=this.blockSize,a=i/(4*o),a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0);if(t=a*o,i=e.min(4*t,i),t){for(var u=0;u<t;u+=o)this._doProcessBlock(r,u);u=r.splice(0,t),n.sigBytes-=i}return new s.init(u,i)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=h.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=R,n=t.lib,r=n.WordArray,i=n.Hasher,n=t.algo,o=[],s=[],a=function(e){return 4294967296*(e-(0|e))|0},u=2,c=0;c<64;){var l;e:{l=u;for(var h=e.sqrt(l),f=2;f<=h;f++)if(!(l%f)){l=!1;break e}l=!0}l&&(c<8&&(o[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var d=[],n=n.SHA256=i.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],a=n[3],u=n[4],c=n[5],l=n[6],h=n[7],f=0;f<64;f++){if(f<16)d[f]=0|e[t+f];else{var p=d[f-15],g=d[f-2];d[f]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[f-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+d[f-16]}p=h+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[f]+d[f],g=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=l,l=c,c=u,u=a+p|0,a=o,o=i,i=r,r=p+g|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(n),t.HmacSHA256=i._createHmacHelper(n)}(Math),function(){var e=R,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var r=e.blockSize,i=4*r;n.sigBytes>i&&(n=e.finalize(n)),n.clamp();for(var o=this._oKey=n.clone(),s=this._iKey=n.clone(),a=o.words,u=s.words,c=0;c<r;c++)a[c]^=1549556828,u[c]^=909522486;o.sigBytes=s.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}();var M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},N=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},F=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),J=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Y=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},$={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:d,uriParserFactory:p,hasherFactory:y},V=function(){function e(t){N(this,e),this.config=v({},$,t),this.payloadSerializer=this.config.payloadSerializer||this.config.payloadSerializerFactory(),this.uriParser=this.config.uriParserFactory(),this.hasher=this.config.hasherFactory(),m(this.config.accessKeyId,"AwsSigner requires AWS AccessKeyID"),m(this.config.secretAccessKey,"AwsSigner requires AWS SecretAccessKey")}return F(e,[{key:"sign",value:function(e,t){var n={request:v({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return a(this,n),u(this,n),c(this,n),l(this,n),h(this,n),{Accept:n.request.headers.accept,Authorization:n.authorization,"Content-Type":n.request.headers["content-type"],"x-amz-date":n.request.headers["x-amz-date"],"x-amz-security-token":this.config.sessionToken||void 0}}}]),e}(),G=["size","duration","position","number","count"],X="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",Q=function(){function e(n){N(this,e),this.name="amazon",J(this,n),t().session.new&&!n.test&&this.logEvent({eventType:"_session.start"}).catch(function(e){console.error("Failed to log _session.start: "+e.message)})}return F(e,[{key:"logPageView",value:function(e,n){var r=t().session,i=O({page:e,session:r,previousPage:this.previousPage,options:n,dimensionLookup:this.dimensions,metricLookup:this.metrics});return this.previousPage=i.attributes,A(i,this.userPoolID,this.app)}},{key:"logEvent",value:function(e){return A(T({event:e,session:t().session,dimensionLookup:this.dimensions,metricLookup:this.metrics}),this.userPoolID,this.app)}}]),e}(),Z=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N(this,e),this.name="google",J(this,t)}return F(e,[{key:"logPageView",value:function(e,t){var n=H(e,t,this.dimensions,this.metrics);C(function(e){e.forEach(function(e){e.send(n)})})}},{key:"logEvent",value:function(e){var t=W(e,this.dimensions,this.metrics);C(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),ee=function(e){if(e)return R.SHA256(e).toString(R.enc.Hex)},te=["esri.com","esriuk.com","esri.de","esri.ca","esrifrance.fr","esri.nl","esri-portugal.pt","esribulgaria.com","esri.fi","esri.kr","esrimalaysia.com.my","esri.es","esriaustralia.com.au","esri-southafrica.com","esri.cl","esrichina.com.cn","esri.co","esriturkey.com.tr","geodata.no","esriitalia.it","esri.pl"],ne=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.portal||{};return!e.disabled&&("1"!==navigator.doNotTrack&&"1"!==window.doNotTrack&&((void 0===t.eueiEnabled||!1!==t.eueiEnabled)&&(!(!t.eueiEnabled||!t.user||t.user.orgId!==t.id)||(!(!t.user||t.user.orgId||"US"!==t.ipCntryCode)||(!t.user&&"US"===t.ipCntryCode||!(Object.keys(t).length>0))))))};return function(){function e(t){N(this,e);try{if(this.trackers=[],this.workflows={},this.test=t.test,this.debug=t.debug,this.disabled=!ne(t),this.disabled&&console.log("Telemetry Disabled"),t.portal&&t.portal.user){var n=t.portal.subscriptionInfo||{};this.setUser(t.portal.user,n.type)}else t.user&&this.setUser(t.user);this.disabled||this._initTrackers(t)}catch(e){console.error("Telemetry Disabled"),console.error(e),this.disabled=!0}}return F(e,[{key:"_initTrackers",value:function(e){if(e.amazon){var t=new Q(e.amazon);this.trackers.push(t)}if(e.google){var n=new Z(e.google);this.trackers.push(n)}this.trackers.length||console.error(new Error("No trackers configured"))}},{key:"setUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Public";e="string"==typeof e?{username:e}:e,this.user=e,this.user.accountType=t;var n=void 0;if(e.email&&e.email.split){var r=e.email.split("@")[1];n=te.filter(function(e){return r===e}).length>0}(n||["In House","Demo and Marketing"].indexOf(t)>-1)&&(this.user.internalUser=!0)}},{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.preProcess(t);if(this.debug&&console.log("Tracking page view",JSON.stringify(n)),this.test&&!this.disabled)return n;if(!this.trackers.length||this.disabled)return this.disabled||console.error(new Error("Page view was not logged because no trackers are configured.")),!1;var r=this.trackers.map(function(t){return t.logPageView(e,n)});return Promise.all(r).then(),!0}},{key:"logEvent",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.preProcess(e);if(this.debug&&console.log("Tracking event",JSON.stringify(t)),this.test)return t;if(!this.trackers.length||this.disabled)return this.disabled||console.error(new Error("Event was not logged because no trackers are configured.")),!1;var n=this.trackers.map(function(e){return e.logEvent(t)});return Promise.all(n).then(),!0}},{key:"logError",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=J({eventType:"error"},e);this.logEvent(t)}},{key:"startWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={name:e,start:Date.now(),steps:[],workflowId:Math.floor(17592186044416*(1+Math.random())).toString(16)};this._saveWorkflow(n);var r=J({name:e,step:"start"},t);return this._logWorkflow(r),n}},{key:"stepWorkflow",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r="string"==typeof options?n:n.details,i=J({name:e,step:t,details:r},n);this._logWorkflow(i)}},{key:"endWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=J({name:e,step:"finish"},t);this._logWorkflow(n)}},{key:"cancelWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=J({name:e,step:"cancel"},t);this._logWorkflow(n)}},{key:"getWorkflow",value:function(e){var t=q.get("TELEMETRY-WORKFLOW:"+e);if(t){if(Date.now()-t.start<18e5)return t;this._deleteWorkflow(t)}}},{key:"_saveWorkflow",value:function(e){q.set("TELEMETRY-WORKFLOW:"+e.name,e)}},{key:"_deleteWorkflow",value:function(e){q.delete("TELEMETRY-WORKFLOW:"+e.name)}},{key:"_logWorkflow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=this.preProcess(e);var t=this.getWorkflow(e.name);t||(this.startWorkflow(e.name),t=this.getWorkflow(e.name)),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3,["cancel","finish"].indexOf(e.step)>-1?this._deleteWorkflow(t):this._saveWorkflow(t);var n=J(e,{eventType:"workflow",category:e.name,action:e.step,label:e.details,duration:t.duration,workflowId:t.workflowId});this.logEvent(n)}},{key:"preProcess",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};return this.user&&(t={user:ee(this.user.username),org:ee(this.user.orgId),lastLogin:this.user.lastLogin,userSince:this.user.created,internalUser:this.user.internalUser||!1,accountType:this.user.accountType}),J({},e,t)}}]),e}()}); | ||
//# sourceMappingURL=telemetry.amd.min.js.map |
define(function () { 'use strict'; | ||
function request(options, callback) { | ||
var req = new XMLHttpRequest(); //eslint-disable-line | ||
req.addEventListener('load', function () { | ||
callback(req.responseText); | ||
}); | ||
req.open(options.method, options.url); | ||
Object.keys(options.headers).forEach(function (header) { | ||
req.setRequestHeader(header, options.headers[header]); | ||
}); | ||
req.send(options.body); | ||
} | ||
var Storage = { | ||
@@ -64,65 +49,4 @@ storage: {}, | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var COGNITO_KEY = 'TELEMETRY_COGNITO_CREDENTIALS'; | ||
var COGNITO_URL = 'https://cognito-identity.us-east-1.amazonaws.com/'; | ||
function getCredentials(IdentityPoolId, callback) { | ||
@@ -132,37 +56,41 @@ var cached = Storage.get(COGNITO_KEY); | ||
authWithCognito(IdentityPoolId, function (credentials) { | ||
Storage.set(COGNITO_KEY, credentials); | ||
callback(credentials); | ||
}); | ||
} | ||
var options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetId' | ||
}, | ||
body: JSON.stringify({ IdentityPoolId: IdentityPoolId }) | ||
}; | ||
function authWithCognito(IdentityPoolId, callback) { | ||
var options = _extends({}, defaults$$1); | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetId'; | ||
options.body = JSON.stringify({ IdentityPoolId: IdentityPoolId }); | ||
return fetch(COGNITO_URL, options).then(function (response) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
return response.json(); | ||
}).then(function (response) { | ||
var IdentityId = response.IdentityId; | ||
request(options, function (response) { | ||
requestCredentials(JSON.parse(response), callback); | ||
}); | ||
} | ||
var options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity' | ||
}, | ||
body: JSON.stringify({ IdentityId: IdentityId }) | ||
}; | ||
return fetch(COGNITO_URL, options); | ||
}).then(function (response) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
return response.json(); | ||
}).then(function (_ref) { | ||
var Credentials = _ref.Credentials; | ||
function requestCredentials(json, callback) { | ||
var options = _extends({}, defaults$$1); | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetCredentialsForIdentity'; | ||
options.body = JSON.stringify({ IdentityId: json.IdentityId }); | ||
request(options, function (response) { | ||
var json = JSON.parse(response); | ||
callback(json.Credentials); | ||
Storage.set(COGNITO_KEY, Credentials); | ||
return Credentials; | ||
}); | ||
} | ||
var defaults$$1 = { | ||
method: 'POST', | ||
url: COGNITO_URL, | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1' | ||
} | ||
}; | ||
var SESSION_LENGTH = 30 * 60 * 1000; | ||
@@ -394,2 +322,106 @@ var SESSION_KEY = 'TELEMETRY_SESSION'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// | ||
@@ -574,10 +606,3 @@ // AWS Signature v4 Implementation for Web Browsers | ||
/** | ||
* Simple URI parser factory. | ||
* Uses an `a` document element for parsing given URIs. | ||
* Therefore it most likely will only work in a web browser. | ||
*/ | ||
function SimpleUriParser() { | ||
var parser = document ? document.createElement('a') : {}; | ||
/** | ||
@@ -593,2 +618,3 @@ * Parse the given URI. | ||
return function (uri) { | ||
var parser = URL ? new URL(uri) : document.createElement('a'); | ||
parser.href = uri; | ||
@@ -602,13 +628,13 @@ return { | ||
}; | ||
} | ||
function extractQueryParams(search) { | ||
return (/^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg); | ||
if (arg) { | ||
result[arg[1]] = arg[2]; | ||
} | ||
return result; | ||
}, {}) | ||
); | ||
} | ||
function extractQueryParams(search) { | ||
return (/^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg); | ||
if (arg) { | ||
result[arg[1]] = arg[2]; | ||
} | ||
return result; | ||
}, {}) | ||
); | ||
} | ||
@@ -694,43 +720,98 @@ | ||
var METRICS = ['size', 'duration', 'position', 'number', 'count']; | ||
var DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events'; | ||
function formatTelemetryAttributes(_ref) { | ||
var telemetryData = _ref.telemetryData, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$excludeKeys = _ref.excludeKeys, | ||
excludeKeys = _ref$excludeKeys === undefined ? [] : _ref$excludeKeys; | ||
var Amazon = function () { | ||
function Amazon(options) { | ||
classCallCheck(this, Amazon); | ||
return Object.keys(telemetryData).filter(function (key) { | ||
return !excludeKeys.includes(key); | ||
}).map(function (key) { | ||
if (dimensionLookup[key]) { | ||
return { | ||
key: getCustomDimensionKey(dimensionLookup, key), | ||
value: telemetryData[key] }; | ||
} | ||
this.name = 'amazon'; | ||
_extends(this, options); | ||
var session = getUser().session; | ||
if (session.new && !options.test) this.logEvent({ eventType: '_session.start' }); | ||
return { | ||
key: key, | ||
value: getValue(telemetryData, key) | ||
}; | ||
}).reduce(function (acc, _ref2) { | ||
var key = _ref2.key, | ||
value = _ref2.value; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getValue(data, key) { | ||
if (key === 'json') { | ||
return data[key] ? JSON.stringify(data[key]) : 'null'; | ||
} | ||
createClass(Amazon, [{ | ||
key: 'logPageView', | ||
value: function logPageView(page, options) { | ||
var event = createPageView(page, this.previousPage, options); | ||
sendTelemetry(event, this.userPoolID, this.app); | ||
this.previousPage = event.attributes; | ||
return data[key] === undefined ? 'null' : data[key].toString(); | ||
} | ||
function getCustomDimensionKey(lookup, key) { | ||
return 'dimension' + lookup[key]; | ||
} | ||
var METRICS = ['size', 'duration', 'position', 'number', 'count']; | ||
function formatTelemetryMetrtics(telemetryData) { | ||
var metricLookup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return Object.keys(telemetryData).filter(function (key) { | ||
return metricLookup[key] || METRICS.includes(key); | ||
}).map(function (key) { | ||
if (metricLookup[key]) { | ||
return { | ||
key: getCustomMetricKey(metricLookup, key), | ||
value: telemetryData[key] | ||
}; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var events = createEventLog(event); | ||
sendTelemetry(events, this.userPoolID, this.app); | ||
} | ||
}]); | ||
return Amazon; | ||
}(); | ||
function createPageView(page) { | ||
var previousPage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return { | ||
key: key, | ||
value: telemetryData[key] | ||
}; | ||
}).reduce(function (acc, _ref) { | ||
var key = _ref.key, | ||
value = _ref.value; | ||
var session = getUser().session; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getCustomMetricKey(lookup, key) { | ||
return 'metric' + lookup[key]; | ||
} | ||
function createEventLog(_ref) { | ||
var event = _ref.event, | ||
_ref$session = _ref.session, | ||
id = _ref$session.id, | ||
startTimestamp = _ref$session.startTimestamp, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
var metrics = formatTelemetryMetrtics(event, metricLookup); | ||
var eventAttributes = formatTelemetryAttributes({ | ||
telemetryData: event, | ||
dimensionLookup: dimensionLookup, | ||
excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup))) | ||
}); | ||
return { | ||
eventType: 'pageView', | ||
eventType: event.eventType || 'other', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
id: id, | ||
startTimestamp: startTimestamp | ||
}, | ||
@@ -740,53 +821,104 @@ attributes: _extends({ | ||
hostname: window.location.hostname, | ||
path: page || window.location.pathname, | ||
pageUrl: page || window.location.pathname, | ||
pageName: document.title, | ||
previousPageUrl: previousPage.pageUrl, | ||
previousPageName: previousPage.pageName | ||
}, extractAttributes(options)), | ||
metrics: extractMetrics(options) | ||
path: window.location.pathname | ||
}, eventAttributes), | ||
metrics: metrics | ||
}; | ||
} | ||
function createEventLog(event) { | ||
var session = getUser().session; | ||
function createPageViewLog(_ref) { | ||
var page = _ref.page, | ||
_ref$session = _ref.session; | ||
_ref$session = _ref$session === undefined ? {} : _ref$session; | ||
var id = _ref$session.id, | ||
startTimestamp = _ref$session.startTimestamp, | ||
_ref$previousPage = _ref.previousPage, | ||
previousPage = _ref$previousPage === undefined ? {} : _ref$previousPage, | ||
_ref$options = _ref.options, | ||
options = _ref$options === undefined ? {} : _ref$options, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
var metrics = formatTelemetryMetrtics(options, metricLookup); | ||
var attributes = formatTelemetryAttributes({ | ||
telemetryData: options, | ||
dimensionLookup: dimensionLookup, | ||
excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup))) | ||
}); | ||
var _ref2 = document || {}, | ||
referrer = _ref2.referrer, | ||
title = _ref2.title; | ||
var _ref3 = window && window.location ? window.location : {}, | ||
hostname = _ref3.hostname, | ||
pathname = _ref3.pathname; | ||
return { | ||
eventType: event.eventType || 'other', | ||
eventType: 'pageView', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
id: id, | ||
startTimestamp: startTimestamp | ||
}, | ||
attributes: _extends({ | ||
referrer: document.referrer, | ||
hostname: window.location.hostname, | ||
path: window.location.pathname | ||
}, extractAttributes(event)), | ||
metrics: extractMetrics(event) | ||
referrer: referrer, | ||
hostname: hostname, | ||
path: page || pathname, | ||
pageUrl: page || pathname, | ||
pageName: title, | ||
previousPageUrl: previousPage.pageUrl, | ||
previousPageName: previousPage.pageName | ||
}, attributes), | ||
metrics: metrics | ||
}; | ||
} | ||
function extractAttributes(event) { | ||
var attributes = _extends({}, event); | ||
delete attributes.workflow; | ||
METRICS.forEach(function (metric) { | ||
return delete attributes[metric]; | ||
}); | ||
Object.keys(attributes).forEach(function (attr) { | ||
if (attr === 'json') { | ||
attributes[attr] = attributes[attr] ? JSON.stringify(attributes[attr]) : 'null'; | ||
} else { | ||
attributes[attr] = attributes[attr] !== undefined ? attributes[attr].toString() : 'null'; | ||
var DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events'; | ||
var Amazon = function () { | ||
function Amazon(options) { | ||
classCallCheck(this, Amazon); | ||
this.name = 'amazon'; | ||
_extends(this, options); | ||
var session = getUser().session; | ||
if (session.new && !options.test) { | ||
this.logEvent({ eventType: '_session.start' }).catch(function (err) { | ||
console.error('Failed to log _session.start: ' + err.message); | ||
}); | ||
} | ||
}); | ||
return attributes; | ||
} | ||
} | ||
function extractMetrics(event) { | ||
var metrics = {}; | ||
METRICS.forEach(function (metric) { | ||
if (event[metric]) metrics[metric] = event[metric]; | ||
}); | ||
return metrics; | ||
} | ||
createClass(Amazon, [{ | ||
key: 'logPageView', | ||
value: function logPageView(page, options) { | ||
var session = getUser().session; | ||
var telemetryPayload = createPageViewLog({ | ||
page: page, | ||
session: session, | ||
previousPage: this.previousPage, | ||
options: options, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}); | ||
this.previousPage = telemetryPayload.attributes; | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app); | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var session = getUser().session; | ||
var telemetryPayload = createEventLog({ | ||
event: event, | ||
session: session, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}); | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app); | ||
} | ||
}]); | ||
return Amazon; | ||
}(); | ||
@@ -825,7 +957,7 @@ function createHeaders() { | ||
function sendTelemetry(events, userPoolID, app) { | ||
function sendTelemetry(events, userPoolID, app, url) { | ||
var user = getUser(); | ||
events = Array.isArray(events) ? events : [events]; | ||
var options = createTelemetryOptions(events); | ||
getCredentials(userPoolID, function (credentials) { | ||
return getCredentials(userPoolID).then(function (credentials) { | ||
try { | ||
@@ -838,7 +970,10 @@ options.headers = createHeaders(credentials, options); | ||
} | ||
request(options, function (response) { | ||
if (response) { | ||
console.error(JSON.parse(response)); | ||
} | ||
}); | ||
return fetch(DEFAULT_ENDPOINT, options); | ||
}).then(function (response) { | ||
if (response.ok) { | ||
return { success: true }; | ||
} | ||
throw new Error('Telemetry failed. ' + response.status + ', ' + response.statusText); | ||
}).catch(function (err) { | ||
console.error(err.message); | ||
}); | ||
@@ -859,2 +994,41 @@ } | ||
function mapMetricsAndDimensions(_ref) { | ||
var _ref$customTelemetryD = _ref.customTelemetryData, | ||
customTelemetryData = _ref$customTelemetryD === undefined ? {} : _ref$customTelemetryD, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
return Object.keys(customTelemetryData).map(function (key) { | ||
if (dimensionLookup[key]) { | ||
return { | ||
key: getCustomDimensionKey$1(dimensionLookup, key), | ||
value: customTelemetryData[key] }; | ||
} | ||
if (metricLookup[key]) { | ||
return { | ||
key: getCustomMetricKey$1(metricLookup, key), | ||
value: customTelemetryData[key] | ||
}; | ||
} | ||
}).filter(function (val) { | ||
return val; | ||
}).reduce(function (acc, _ref2) { | ||
var key = _ref2.key, | ||
value = _ref2.value; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getCustomDimensionKey$1(lookup, key) { | ||
return "dimension" + lookup[key]; | ||
} | ||
function getCustomMetricKey$1(lookup, key) { | ||
return "metric" + lookup[key]; | ||
} | ||
var Google = function () { | ||
@@ -902,3 +1076,2 @@ function Google() { | ||
} | ||
function buildPageViewObject(page, options) { | ||
@@ -908,3 +1081,3 @@ var dimensions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var pageviewObject = { | ||
var standardTelemetry = { | ||
hitType: 'pageview', | ||
@@ -914,3 +1087,9 @@ page: page || window.location.pathname | ||
return mapMetricsAndDimensions(pageviewObject, options, dimensions, metrics); | ||
var mappedCustomTelemetryData = mapMetricsAndDimensions({ | ||
customTelemetryData: options, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics | ||
}); | ||
return _extends({}, standardTelemetry, mappedCustomTelemetryData); | ||
} | ||
@@ -922,27 +1101,16 @@ | ||
var eventObject = { | ||
var standardTelemetryData = { | ||
hitType: 'event', | ||
eventCategory: event.category || 'none', | ||
eventAction: event.action, | ||
eventLabel: event.label, | ||
nonInteraction: event.nonInteraction | ||
eventLabel: event.label | ||
}; | ||
return mapMetricsAndDimensions(eventObject, event, dimensions, metrics); | ||
var mappedCustomTelemetryData = mapMetricsAndDimensions({ | ||
customTelemetryData: event, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics }); | ||
return _extends({}, standardTelemetryData, mappedCustomTelemetryData); | ||
} | ||
function mapMetricsAndDimensions(inputObject, options, dimensions, metrics) { | ||
var mappedObject = inputObject; | ||
Object.keys(dimensions).forEach(function (dimension) { | ||
mappedObject['dimension' + dimensions[dimension]] = options[dimension]; | ||
}); | ||
Object.keys(metrics).forEach(function (metric) { | ||
mappedObject['metric' + metrics[metric]] = options[metric]; | ||
}); | ||
return mappedObject; | ||
} | ||
var anonymize = function (user) { | ||
@@ -1061,3 +1229,4 @@ if (!user) return undefined; | ||
var attributes = this.preProcess(options); | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes));else if (this.test && !this.disabled) return attributes; | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.test && !this.disabled) return attributes; | ||
@@ -1067,12 +1236,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false; | ||
} else { | ||
this.trackers.forEach(function (tracker) { | ||
try { | ||
tracker.logPageView(page, attributes); | ||
} catch (e) { | ||
console.error(tracker.name + ' tracker failed to log page view.', e); | ||
} | ||
}); | ||
return true; | ||
} | ||
var promises = this.trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
@@ -1086,3 +1253,4 @@ }, { | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event));else if (this.test) return event; | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event)); | ||
if (this.test) return event; | ||
@@ -1092,12 +1260,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false; | ||
} else { | ||
this.trackers.forEach(function (tracker) { | ||
try { | ||
tracker.logEvent(event); | ||
} catch (e) { | ||
console.error(tracker.name + ' tracker failed to log event', e); | ||
} | ||
}); | ||
return true; | ||
} | ||
var promises = this.trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
@@ -1225,3 +1391,3 @@ }, { | ||
user: anonymize(this.user.username), | ||
orgId: anonymize(this.user.orgId), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
@@ -1228,0 +1394,0 @@ userSince: this.user.created, |
@@ -1,2 +0,2 @@ | ||
define(function(){"use strict";function e(e,t){var n=new XMLHttpRequest;n.addEventListener("load",function(){t(n.responseText)}),n.open(e.method,e.url),Object.keys(e.headers).forEach(function(t){n.setRequestHeader(t,e.headers[t])}),n.send(e.body)}function t(e,t){var r=q.get(j);if(r&&Date.now()/1e3<r.Expiration)return t(r);n(e,function(e){q.set(j,e),t(e)})}function n(t,n){var i=D({},N);i.headers["X-Amz-Target"]="AWSCognitoIdentityService.GetId",i.body=JSON.stringify({IdentityPoolId:t}),e(i,function(e){r(JSON.parse(e),n)})}function r(t,n){var r=D({},N);r.headers["X-Amz-Target"]="AWSCognitoIdentityService.GetCredentialsForIdentity",r.body=JSON.stringify({IdentityId:t.IdentityId}),e(r,function(e){var t=JSON.parse(e);n(t.Credentials)})}function i(){return{session:o(),id:s()}}function o(){var e=void 0,t=q.get(M);return(!t||Date.now()>t.expiration)&&(e=!0,t=a()),t.expiration=Date.now()+L,q.set(M,t),e&&(t.new=!0),t}function s(){var e=q.get(R);return e||(e=c(),q.set(R,e)),e}function a(){return{id:Math.floor(17592186044416*(1+Math.random())).toString(16),startTimestamp:(new Date).toISOString()}}function c(){return u()+u()+"-"+u()+"-"+u()+"-"+u()+"-"+u()+u()+u()}function u(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function l(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":p(t.signDate)};t.request.method=t.request.method.toUpperCase(),t.request.body?t.payload=t.request.body:t.request.data&&e.payloadSerializer?t.payload=e.payloadSerializer(t.request.data):delete n["content-type"],t.request.headers=w(n,Object.keys(t.request.headers||{}).reduce(function(e,n){return e[n.toLowerCase()]=t.request.headers[n],e},{})),t.sortedHeaderKeys=Object.keys(t.request.headers).sort(),t.request.headers["content-type"]&&(t.request.headers["content-type"]=t.request.headers["content-type"].split(";")[0]),"object"===P(t.request.params)&&w(t.uri.queryParams,t.request.params)}function h(e,t){t.signedHeaders=t.sortedHeaderKeys.map(function(e){return e.toLowerCase()}).join(";"),t.canonicalRequest=String(t.request.method).toUpperCase()+"\n"+encodeURI(t.uri.path)+"\n"+Object.keys(t.uri.queryParams).sort().map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t.uri.queryParams[e])}).join("&")+"\n"+t.sortedHeaderKeys.map(function(e){return e.toLocaleLowerCase()+":"+t.request.headers[e]}).join("\n")+"\n\n"+t.signedHeaders+"\n"+e.hasher.hash(t.payload?t.payload:"")}function f(e,t){t.credentialScope=[p(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+p(t.signDate)+"\n"+t.credentialScope+"\n"+e.hasher.hash(t.canonicalRequest)}function d(e,t){var n=e.hasher.hmac,r=n(n(n(n("AWS4"+e.config.secretAccessKey,p(t.signDate,!0),{hexOutput:!1}),e.config.region,{hexOutput:!1,textInput:!1}),e.config.service,{hexOutput:!1,textInput:!1}),"aws4_request",{hexOutput:!1,textInput:!1});t.signature=n(r,t.stringToSign,{textInput:!1})}function g(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function p(e,t){var n=e.toISOString().replace(/[:\-]|\.\d{3}/g,"").substr(0,17);return t?n.substr(0,8):n}function y(){return function(e){return JSON.stringify(e)}}function v(){function e(e){return/^\??(.*)$/.exec(e)[1].split("&").reduce(function(e,t){return t=/^(.+)=(.*)$/.exec(t),t&&(e[t[1]]=t[2]),e},{})}var t=document?document.createElement("a"):{};return function(n){return t.href=n,{protocol:t.protocol,host:t.host.replace(/^(.*):((80)|(443))$/,"$1"),path:("/"!==t.pathname.charAt(0)?"/":"")+t.pathname,queryParams:e(t.search)}}}function m(){return{hash:function(e,t){t=w({hexOutput:!0,textInput:!0},t);var n=U.SHA256(e);return t.hexOutput?n.toString(U.enc.Hex):n},hmac:function(e,t,n){n=w({hexOutput:!0,textInput:!0},n);var r=U.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(U.enc.Hex):r}}}function w(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":P(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":P(r))?(e[n]=Array.isArray(r)?[]:{},w(e[n],r)):e[n]=r)})}),e}function S(e,t){if(void 0===e||!e)throw new Error(t)}function k(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=i().session;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:r.id,startTimestamp:r.startTimestamp},attributes:D({referrer:document.referrer,hostname:window.location.hostname,path:e||window.location.pathname,pageUrl:e||window.location.pathname,pageName:document.title,previousPageUrl:t.pageUrl,previousPageName:t.pageName},_(n)),metrics:E(n)}}function b(e){var t=i().session;return{eventType:e.eventType||"other",timestamp:(new Date).toISOString(),session:{id:t.id,startTimestamp:t.startTimestamp},attributes:D({referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname},_(e)),metrics:E(e)}}function _(e){var t=D({},e);return delete t.workflow,J.forEach(function(e){return delete t[e]}),Object.keys(t).forEach(function(e){t[e]="json"===e?t[e]?JSON.stringify(t[e]):"null":void 0!==t[e]?t[e].toString():"null"}),t}function E(e){var t={};return J.forEach(function(n){e[n]&&(t[n]=e[n])}),t}function T(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new F(n).sign(t)}function I(e,t){return JSON.stringify({client:{client_id:e,app_title:t.name,app_version_name:t.version||"unknown"},services:{mobile_analytics:{app_id:t.id}}})}function O(n,r,o){var s=i();n=Array.isArray(n)?n:[n];var a=x(n);t(r,function(t){try{a.headers=T(t,a),a.headers["x-amz-Client-Context"]=I(s.id,o)}catch(e){return void console.error(e)}e(a,function(e){e&&console.error(JSON.parse(e))})})}function x(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:Y,method:"POST",body:JSON.stringify({events:e})}}function A(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function z(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return H({hitType:"pageview",page:e||window.location.pathname},t,n,r)}function C(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return H({hitType:"event",eventCategory:e.category||"none",eventAction:e.action,eventLabel:e.label,nonInteraction:e.nonInteraction},e,t,n)}function H(e,t,n,r){var i=e;return Object.keys(n).forEach(function(e){i["dimension"+n[e]]=t[e]}),Object.keys(r).forEach(function(e){i["metric"+r[e]]=t[e]}),i}var q={storage:{},memory:!0,get:function(e){var t=void 0;try{t=window.localStorage&&window.localStorage.getItem(e)||this.storage[e]}catch(n){t=this.storage[e]}if(t)try{return JSON.parse(t)}catch(e){return}},set:function(e,t){t=JSON.stringify(t);try{window.localStorage.setItem(e,t)}catch(n){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),this.storage[e]=t}},delete:function(e){try{window.localStorage.removeItem(e)}catch(t){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),delete this.storage[e]}}},P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},W=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},B=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),D=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},j="TELEMETRY_COGNITO_CREDENTIALS",N={method:"POST",url:"https://cognito-identity.us-east-1.amazonaws.com/",headers:{"Content-type":"application/x-amz-json-1.1"}},L=18e5,M="TELEMETRY_SESSION",R="TELEMETRY_CLIENT_ID",U=function(e,t){var n={},r=n.lib={},i=function(){},o=r.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var i=0;i<e;i++)t[r+i>>>2]|=(n[i>>>2]>>>24-i%4*8&255)<<24-(r+i)%4*8;else if(n.length>65535)for(i=0;i<e;i+=4)t[r+i>>>2]=n[i>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r<t;r+=4)n.push(4294967296*e.random()|0);return new s.init(n,t)}}),a=n.enc={},c=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++){var i=t[r>>>2]>>>24-r%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++)n.push(String.fromCharCode(t[r>>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,i=n.sigBytes,o=this.blockSize,a=i/(4*o),a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0);if(t=a*o,i=e.min(4*t,i),t){for(var c=0;c<t;c+=o)this._doProcessBlock(r,c);c=r.splice(0,t),n.sigBytes-=i}return new s.init(c,i)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=h.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=U,n=t.lib,r=n.WordArray,i=n.Hasher,n=t.algo,o=[],s=[],a=function(e){return 4294967296*(e-(0|e))|0},c=2,u=0;u<64;){var l;e:{l=c;for(var h=e.sqrt(l),f=2;f<=h;f++)if(!(l%f)){l=!1;break e}l=!0}l&&(u<8&&(o[u]=a(e.pow(c,.5))),s[u]=a(e.pow(c,1/3)),u++),c++}var d=[],n=n.SHA256=i.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],a=n[3],c=n[4],u=n[5],l=n[6],h=n[7],f=0;f<64;f++){if(f<16)d[f]=0|e[t+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+s[f]+d[f],p=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=l,l=u,u=c,c=a+g|0,a=o,o=i,i=r,r=g+p|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+a|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(n),t.HmacSHA256=i._createHmacHelper(n)}(Math),function(){var e=U,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var r=e.blockSize,i=4*r;n.sigBytes>i&&(n=e.finalize(n)),n.clamp();for(var o=this._oKey=n.clone(),s=this._iKey=n.clone(),a=o.words,c=s.words,u=0;u<r;u++)a[u]^=1549556828,c[u]^=909522486;o.sigBytes=s.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}();var K={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:y,uriParserFactory:v,hasherFactory:m},F=function(){function e(t){W(this,e),this.config=w({},K,t),this.payloadSerializer=this.config.payloadSerializer||this.config.payloadSerializerFactory(),this.uriParser=this.config.uriParserFactory(),this.hasher=this.config.hasherFactory(),S(this.config.accessKeyId,"AwsSigner requires AWS AccessKeyID"),S(this.config.secretAccessKey,"AwsSigner requires AWS SecretAccessKey")}return B(e,[{key:"sign",value:function(e,t){var n={request:w({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return l(this,n),h(this,n),f(this,n),d(this,n),g(this,n),{Accept:n.request.headers.accept,Authorization:n.authorization,"Content-Type":n.request.headers["content-type"],"x-amz-date":n.request.headers["x-amz-date"],"x-amz-security-token":this.config.sessionToken||void 0}}}]),e}(),J=["size","duration","position","number","count"],Y="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",$=function(){function e(t){W(this,e),this.name="amazon",D(this,t),i().session.new&&!t.test&&this.logEvent({eventType:"_session.start"})}return B(e,[{key:"logPageView",value:function(e,t){var n=k(e,this.previousPage,t);O(n,this.userPoolID,this.app),this.previousPage=n.attributes}},{key:"logEvent",value:function(e){O(b(e),this.userPoolID,this.app)}}]),e}(),V=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};W(this,e),this.name="google",D(this,t)}return B(e,[{key:"logPageView",value:function(e,t){var n=z(e,t,this.dimensions,this.metrics);A(function(e){e.forEach(function(e){e.send(n)})})}},{key:"logEvent",value:function(e){var t=C(e,this.dimensions,this.metrics);A(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),G=function(e){if(e)return U.SHA256(e).toString(U.enc.Hex)},X=["esri.com","esriuk.com","esri.de","esri.ca","esrifrance.fr","esri.nl","esri-portugal.pt","esribulgaria.com","esri.fi","esri.kr","esrimalaysia.com.my","esri.es","esriaustralia.com.au","esri-southafrica.com","esri.cl","esrichina.com.cn","esri.co","esriturkey.com.tr","geodata.no","esriitalia.it","esri.pl"],Q=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.portal||{};return!e.disabled&&("1"!==navigator.doNotTrack&&"1"!==window.doNotTrack&&((void 0===t.eueiEnabled||!1!==t.eueiEnabled)&&(!(!t.eueiEnabled||!t.user||t.user.orgId!==t.id)||(!(!t.user||t.user.orgId||"US"!==t.ipCntryCode)||(!t.user&&"US"===t.ipCntryCode||!(Object.keys(t).length>0))))))};return function(){function e(t){W(this,e);try{if(this.trackers=[],this.workflows={},this.test=t.test,this.debug=t.debug,this.disabled=!Q(t),this.disabled&&console.log("Telemetry Disabled"),t.portal&&t.portal.user){var n=t.portal.subscriptionInfo||{};this.setUser(t.portal.user,n.type)}else t.user&&this.setUser(t.user);this.disabled||this._initTrackers(t)}catch(e){console.error("Telemetry Disabled"),console.error(e),this.disabled=!0}}return B(e,[{key:"_initTrackers",value:function(e){if(e.amazon){var t=new $(e.amazon);this.trackers.push(t)}if(e.google){var n=new V(e.google);this.trackers.push(n)}this.trackers.length||console.error(new Error("No trackers configured"))}},{key:"setUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Public";e="string"==typeof e?{username:e}:e,this.user=e,this.user.accountType=t;var n=void 0;if(e.email&&e.email.split){var r=e.email.split("@")[1];n=X.filter(function(e){return r===e}).length>0}(n||["In House","Demo and Marketing"].indexOf(t)>-1)&&(this.user.internalUser=!0)}},{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.preProcess(t);if(this.debug)console.log("Tracking page view",JSON.stringify(n));else if(this.test&&!this.disabled)return n;return!this.trackers.length||this.disabled?(this.disabled||console.error(new Error("Page view was not logged because no trackers are configured.")),!1):(this.trackers.forEach(function(t){try{t.logPageView(e,n)}catch(e){console.error(t.name+" tracker failed to log page view.",e)}}),!0)}},{key:"logEvent",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.preProcess(e);if(this.debug)console.log("Tracking event",JSON.stringify(t));else if(this.test)return t;return!this.trackers.length||this.disabled?(this.disabled||console.error(new Error("Event was not logged because no trackers are configured.")),!1):(this.trackers.forEach(function(e){try{e.logEvent(t)}catch(t){console.error(e.name+" tracker failed to log event",t)}}),!0)}},{key:"logError",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=D({eventType:"error"},e);this.logEvent(t)}},{key:"startWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={name:e,start:Date.now(),steps:[],workflowId:Math.floor(17592186044416*(1+Math.random())).toString(16)};this._saveWorkflow(n);var r=D({name:e,step:"start"},t);return this._logWorkflow(r),n}},{key:"stepWorkflow",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r="string"==typeof options?n:n.details,i=D({name:e,step:t,details:r},n);this._logWorkflow(i)}},{key:"endWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=D({name:e,step:"finish"},t);this._logWorkflow(n)}},{key:"cancelWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=D({name:e,step:"cancel"},t);this._logWorkflow(n)}},{key:"getWorkflow",value:function(e){var t=q.get("TELEMETRY-WORKFLOW:"+e);if(t){if(Date.now()-t.start<18e5)return t;this._deleteWorkflow(t)}}},{key:"_saveWorkflow",value:function(e){q.set("TELEMETRY-WORKFLOW:"+e.name,e)}},{key:"_deleteWorkflow",value:function(e){q.delete("TELEMETRY-WORKFLOW:"+e.name)}},{key:"_logWorkflow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=this.preProcess(e);var t=this.getWorkflow(e.name);t||(this.startWorkflow(e.name),t=this.getWorkflow(e.name)),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3,["cancel","finish"].indexOf(e.step)>-1?this._deleteWorkflow(t):this._saveWorkflow(t);var n=D(e,{eventType:"workflow",category:e.name,action:e.step,label:e.details,duration:t.duration,workflowId:t.workflowId});this.logEvent(n)}},{key:"preProcess",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};return this.user&&(t={user:G(this.user.username),orgId:G(this.user.orgId),lastLogin:this.user.lastLogin,userSince:this.user.created,internalUser:this.user.internalUser||!1,accountType:this.user.accountType}),D({},e,t)}}]),e}()}); | ||
define(function(){"use strict";function e(e,t){var n=q.get(D);if(n&&Date.now()/1e3<n.Expiration)return t(n);var r={method:"POST",headers:{"Content-type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityService.GetId"},body:JSON.stringify({IdentityPoolId:e})};return fetch(j,r).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.json()}).then(function(e){var t=e.IdentityId,n={method:"POST",headers:{"Content-type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityService.GetCredentialsForIdentity"},body:JSON.stringify({IdentityId:t})};return fetch(j,n)}).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.json()}).then(function(e){var t=e.Credentials;return q.set(D,t),t})}function t(){return{session:n(),id:r()}}function n(){var e=void 0,t=q.get(K);return(!t||Date.now()>t.expiration)&&(e=!0,t=i()),t.expiration=Date.now()+B,q.set(K,t),e&&(t.new=!0),t}function r(){var e=q.get(U);return e||(e=o(),q.set(U,e)),e}function i(){return{id:Math.floor(17592186044416*(1+Math.random())).toString(16),startTimestamp:(new Date).toISOString()}}function o(){return s()+s()+"-"+s()+"-"+s()+"-"+s()+"-"+s()+s()+s()}function s(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function a(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":f(t.signDate)};t.request.method=t.request.method.toUpperCase(),t.request.body?t.payload=t.request.body:t.request.data&&e.payloadSerializer?t.payload=e.payloadSerializer(t.request.data):delete n["content-type"],t.request.headers=v(n,Object.keys(t.request.headers||{}).reduce(function(e,n){return e[n.toLowerCase()]=t.request.headers[n],e},{})),t.sortedHeaderKeys=Object.keys(t.request.headers).sort(),t.request.headers["content-type"]&&(t.request.headers["content-type"]=t.request.headers["content-type"].split(";")[0]),"object"===M(t.request.params)&&v(t.uri.queryParams,t.request.params)}function u(e,t){t.signedHeaders=t.sortedHeaderKeys.map(function(e){return e.toLowerCase()}).join(";"),t.canonicalRequest=String(t.request.method).toUpperCase()+"\n"+encodeURI(t.uri.path)+"\n"+Object.keys(t.uri.queryParams).sort().map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t.uri.queryParams[e])}).join("&")+"\n"+t.sortedHeaderKeys.map(function(e){return e.toLocaleLowerCase()+":"+t.request.headers[e]}).join("\n")+"\n\n"+t.signedHeaders+"\n"+e.hasher.hash(t.payload?t.payload:"")}function c(e,t){t.credentialScope=[f(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+f(t.signDate)+"\n"+t.credentialScope+"\n"+e.hasher.hash(t.canonicalRequest)}function l(e,t){var n=e.hasher.hmac,r=n(n(n(n("AWS4"+e.config.secretAccessKey,f(t.signDate,!0),{hexOutput:!1}),e.config.region,{hexOutput:!1,textInput:!1}),e.config.service,{hexOutput:!1,textInput:!1}),"aws4_request",{hexOutput:!1,textInput:!1});t.signature=n(r,t.stringToSign,{textInput:!1})}function h(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function f(e,t){var n=e.toISOString().replace(/[:\-]|\.\d{3}/g,"").substr(0,17);return t?n.substr(0,8):n}function d(){return function(e){return JSON.stringify(e)}}function p(){return function(e){var t=URL?new URL(e):document.createElement("a");return t.href=e,{protocol:t.protocol,host:t.host.replace(/^(.*):((80)|(443))$/,"$1"),path:("/"!==t.pathname.charAt(0)?"/":"")+t.pathname,queryParams:g(t.search)}}}function g(e){return/^\??(.*)$/.exec(e)[1].split("&").reduce(function(e,t){return t=/^(.+)=(.*)$/.exec(t),t&&(e[t[1]]=t[2]),e},{})}function y(){return{hash:function(e,t){t=v({hexOutput:!0,textInput:!0},t);var n=R.SHA256(e);return t.hexOutput?n.toString(R.enc.Hex):n},hmac:function(e,t,n){n=v({hexOutput:!0,textInput:!0},n);var r=R.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(R.enc.Hex):r}}}function v(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":M(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":M(r))?(e[n]=Array.isArray(r)?[]:{},v(e[n],r)):e[n]=r)})}),e}function m(e,t){if(void 0===e||!e)throw new Error(t)}function w(e){var t=e.telemetryData,n=e.dimensionLookup,r=void 0===n?{}:n,i=e.excludeKeys,o=void 0===i?[]:i;return Object.keys(t).filter(function(e){return!o.includes(e)}).map(function(e){return r[e]?{key:S(r,e),value:t[e]}:{key:e,value:k(t,e)}}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function k(e,t){return"json"===t?e[t]?JSON.stringify(e[t]):"null":void 0===e[t]?"null":e[t].toString()}function S(e,t){return"dimension"+e[t]}function b(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Object.keys(e).filter(function(e){return t[e]||G.includes(e)}).map(function(n){return t[n]?{key:_(t,n),value:e[n]}:{key:n,value:e[n]}}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function _(e,t){return"metric"+e[t]}function T(e){var t=e.event,n=e.session,r=n.id,i=n.startTimestamp,o=e.dimensionLookup,s=void 0===o?{}:o,a=e.metricLookup,u=void 0===a?{}:a,c=b(t,u),l=w({telemetryData:t,dimensionLookup:s,excludeKeys:["workflow"].concat(Y(Object.keys(c)),Y(Object.keys(u)))});return{eventType:t.eventType||"other",timestamp:(new Date).toISOString(),session:{id:r,startTimestamp:i},attributes:J({referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname},l),metrics:c}}function O(e){var t=e.page,n=e.session;n=void 0===n?{}:n;var r=n.id,i=n.startTimestamp,o=e.previousPage,s=void 0===o?{}:o,a=e.options,u=void 0===a?{}:a,c=e.dimensionLookup,l=void 0===c?{}:c,h=e.metricLookup,f=void 0===h?{}:h,d=b(u,f),p=w({telemetryData:u,dimensionLookup:l,excludeKeys:["workflow"].concat(Y(Object.keys(d)),Y(Object.keys(f)))}),g=document||{},y=g.referrer,v=g.title,m=window&&window.location?window.location:{},k=m.hostname,S=m.pathname;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:r,startTimestamp:i},attributes:J({referrer:y,hostname:k,path:t||S,pageUrl:t||S,pageName:v,previousPageUrl:s.pageUrl,previousPageName:s.pageName},p),metrics:d}}function x(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new V(n).sign(t)}function I(e,t){return JSON.stringify({client:{client_id:e,app_title:t.name,app_version_name:t.version||"unknown"},services:{mobile_analytics:{app_id:t.id}}})}function A(n,r,i,o){var s=t();n=Array.isArray(n)?n:[n];var a=E(n);return e(r).then(function(e){try{a.headers=x(e,a),a.headers["x-amz-Client-Context"]=I(s.id,i)}catch(e){return void console.error(e)}return fetch(X,a)}).then(function(e){if(e.ok)return{success:!0};throw new Error("Telemetry failed. "+e.status+", "+e.statusText)}).catch(function(e){console.error(e.message)})}function E(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:X,method:"POST",body:JSON.stringify({events:e})}}function P(e){var t=e.customTelemetryData,n=void 0===t?{}:t,r=e.dimensionLookup,i=void 0===r?{}:r,o=e.metricLookup,s=void 0===o?{}:o;return Object.keys(n).map(function(e){return i[e]?{key:z(i,e),value:n[e]}:s[e]?{key:L(s,e),value:n[e]}:void 0}).filter(function(e){return e}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function z(e,t){return"dimension"+e[t]}function L(e,t){return"metric"+e[t]}function C(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function H(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i={hitType:"pageview",page:e||window.location.pathname},o=P({customTelemetryData:t,dimensionLookup:n,metricLookup:r});return J({},i,o)}function W(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={hitType:"event",eventCategory:e.category||"none",eventAction:e.action,eventLabel:e.label},i=P({customTelemetryData:e,dimensionLookup:t,metricLookup:n});return J({},r,i)}var q={storage:{},memory:!0,get:function(e){var t=void 0;try{t=window.localStorage&&window.localStorage.getItem(e)||this.storage[e]}catch(n){t=this.storage[e]}if(t)try{return JSON.parse(t)}catch(e){return}},set:function(e,t){t=JSON.stringify(t);try{window.localStorage.setItem(e,t)}catch(n){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),this.storage[e]=t}},delete:function(e){try{window.localStorage.removeItem(e)}catch(t){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),delete this.storage[e]}}},D="TELEMETRY_COGNITO_CREDENTIALS",j="https://cognito-identity.us-east-1.amazonaws.com/",B=18e5,K="TELEMETRY_SESSION",U="TELEMETRY_CLIENT_ID",R=function(e,t){var n={},r=n.lib={},i=function(){},o=r.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var i=0;i<e;i++)t[r+i>>>2]|=(n[i>>>2]>>>24-i%4*8&255)<<24-(r+i)%4*8;else if(n.length>65535)for(i=0;i<e;i+=4)t[r+i>>>2]=n[i>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r<t;r+=4)n.push(4294967296*e.random()|0);return new s.init(n,t)}}),a=n.enc={},u=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++){var i=t[r>>>2]>>>24-r%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++)n.push(String.fromCharCode(t[r>>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},h=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,i=n.sigBytes,o=this.blockSize,a=i/(4*o),a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0);if(t=a*o,i=e.min(4*t,i),t){for(var u=0;u<t;u+=o)this._doProcessBlock(r,u);u=r.splice(0,t),n.sigBytes-=i}return new s.init(u,i)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=h.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=R,n=t.lib,r=n.WordArray,i=n.Hasher,n=t.algo,o=[],s=[],a=function(e){return 4294967296*(e-(0|e))|0},u=2,c=0;c<64;){var l;e:{l=u;for(var h=e.sqrt(l),f=2;f<=h;f++)if(!(l%f)){l=!1;break e}l=!0}l&&(c<8&&(o[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var d=[],n=n.SHA256=i.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],a=n[3],u=n[4],c=n[5],l=n[6],h=n[7],f=0;f<64;f++){if(f<16)d[f]=0|e[t+f];else{var p=d[f-15],g=d[f-2];d[f]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[f-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+d[f-16]}p=h+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[f]+d[f],g=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=l,l=c,c=u,u=a+p|0,a=o,o=i,i=r,r=p+g|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(n),t.HmacSHA256=i._createHmacHelper(n)}(Math),function(){var e=R,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var r=e.blockSize,i=4*r;n.sigBytes>i&&(n=e.finalize(n)),n.clamp();for(var o=this._oKey=n.clone(),s=this._iKey=n.clone(),a=o.words,u=s.words,c=0;c<r;c++)a[c]^=1549556828,u[c]^=909522486;o.sigBytes=s.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}();var M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},N=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},F=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),J=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Y=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},$={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:d,uriParserFactory:p,hasherFactory:y},V=function(){function e(t){N(this,e),this.config=v({},$,t),this.payloadSerializer=this.config.payloadSerializer||this.config.payloadSerializerFactory(),this.uriParser=this.config.uriParserFactory(),this.hasher=this.config.hasherFactory(),m(this.config.accessKeyId,"AwsSigner requires AWS AccessKeyID"),m(this.config.secretAccessKey,"AwsSigner requires AWS SecretAccessKey")}return F(e,[{key:"sign",value:function(e,t){var n={request:v({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return a(this,n),u(this,n),c(this,n),l(this,n),h(this,n),{Accept:n.request.headers.accept,Authorization:n.authorization,"Content-Type":n.request.headers["content-type"],"x-amz-date":n.request.headers["x-amz-date"],"x-amz-security-token":this.config.sessionToken||void 0}}}]),e}(),G=["size","duration","position","number","count"],X="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",Q=function(){function e(n){N(this,e),this.name="amazon",J(this,n),t().session.new&&!n.test&&this.logEvent({eventType:"_session.start"}).catch(function(e){console.error("Failed to log _session.start: "+e.message)})}return F(e,[{key:"logPageView",value:function(e,n){var r=t().session,i=O({page:e,session:r,previousPage:this.previousPage,options:n,dimensionLookup:this.dimensions,metricLookup:this.metrics});return this.previousPage=i.attributes,A(i,this.userPoolID,this.app)}},{key:"logEvent",value:function(e){return A(T({event:e,session:t().session,dimensionLookup:this.dimensions,metricLookup:this.metrics}),this.userPoolID,this.app)}}]),e}(),Z=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N(this,e),this.name="google",J(this,t)}return F(e,[{key:"logPageView",value:function(e,t){var n=H(e,t,this.dimensions,this.metrics);C(function(e){e.forEach(function(e){e.send(n)})})}},{key:"logEvent",value:function(e){var t=W(e,this.dimensions,this.metrics);C(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),ee=function(e){if(e)return R.SHA256(e).toString(R.enc.Hex)},te=["esri.com","esriuk.com","esri.de","esri.ca","esrifrance.fr","esri.nl","esri-portugal.pt","esribulgaria.com","esri.fi","esri.kr","esrimalaysia.com.my","esri.es","esriaustralia.com.au","esri-southafrica.com","esri.cl","esrichina.com.cn","esri.co","esriturkey.com.tr","geodata.no","esriitalia.it","esri.pl"],ne=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.portal||{};return!e.disabled&&("1"!==navigator.doNotTrack&&"1"!==window.doNotTrack&&((void 0===t.eueiEnabled||!1!==t.eueiEnabled)&&(!(!t.eueiEnabled||!t.user||t.user.orgId!==t.id)||(!(!t.user||t.user.orgId||"US"!==t.ipCntryCode)||(!t.user&&"US"===t.ipCntryCode||!(Object.keys(t).length>0))))))};return function(){function e(t){N(this,e);try{if(this.trackers=[],this.workflows={},this.test=t.test,this.debug=t.debug,this.disabled=!ne(t),this.disabled&&console.log("Telemetry Disabled"),t.portal&&t.portal.user){var n=t.portal.subscriptionInfo||{};this.setUser(t.portal.user,n.type)}else t.user&&this.setUser(t.user);this.disabled||this._initTrackers(t)}catch(e){console.error("Telemetry Disabled"),console.error(e),this.disabled=!0}}return F(e,[{key:"_initTrackers",value:function(e){if(e.amazon){var t=new Q(e.amazon);this.trackers.push(t)}if(e.google){var n=new Z(e.google);this.trackers.push(n)}this.trackers.length||console.error(new Error("No trackers configured"))}},{key:"setUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Public";e="string"==typeof e?{username:e}:e,this.user=e,this.user.accountType=t;var n=void 0;if(e.email&&e.email.split){var r=e.email.split("@")[1];n=te.filter(function(e){return r===e}).length>0}(n||["In House","Demo and Marketing"].indexOf(t)>-1)&&(this.user.internalUser=!0)}},{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.preProcess(t);if(this.debug&&console.log("Tracking page view",JSON.stringify(n)),this.test&&!this.disabled)return n;if(!this.trackers.length||this.disabled)return this.disabled||console.error(new Error("Page view was not logged because no trackers are configured.")),!1;var r=this.trackers.map(function(t){return t.logPageView(e,n)});return Promise.all(r).then(),!0}},{key:"logEvent",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.preProcess(e);if(this.debug&&console.log("Tracking event",JSON.stringify(t)),this.test)return t;if(!this.trackers.length||this.disabled)return this.disabled||console.error(new Error("Event was not logged because no trackers are configured.")),!1;var n=this.trackers.map(function(e){return e.logEvent(t)});return Promise.all(n).then(),!0}},{key:"logError",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=J({eventType:"error"},e);this.logEvent(t)}},{key:"startWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={name:e,start:Date.now(),steps:[],workflowId:Math.floor(17592186044416*(1+Math.random())).toString(16)};this._saveWorkflow(n);var r=J({name:e,step:"start"},t);return this._logWorkflow(r),n}},{key:"stepWorkflow",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r="string"==typeof options?n:n.details,i=J({name:e,step:t,details:r},n);this._logWorkflow(i)}},{key:"endWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=J({name:e,step:"finish"},t);this._logWorkflow(n)}},{key:"cancelWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=J({name:e,step:"cancel"},t);this._logWorkflow(n)}},{key:"getWorkflow",value:function(e){var t=q.get("TELEMETRY-WORKFLOW:"+e);if(t){if(Date.now()-t.start<18e5)return t;this._deleteWorkflow(t)}}},{key:"_saveWorkflow",value:function(e){q.set("TELEMETRY-WORKFLOW:"+e.name,e)}},{key:"_deleteWorkflow",value:function(e){q.delete("TELEMETRY-WORKFLOW:"+e.name)}},{key:"_logWorkflow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=this.preProcess(e);var t=this.getWorkflow(e.name);t||(this.startWorkflow(e.name),t=this.getWorkflow(e.name)),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3,["cancel","finish"].indexOf(e.step)>-1?this._deleteWorkflow(t):this._saveWorkflow(t);var n=J(e,{eventType:"workflow",category:e.name,action:e.step,label:e.details,duration:t.duration,workflowId:t.workflowId});this.logEvent(n)}},{key:"preProcess",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};return this.user&&(t={user:ee(this.user.username),org:ee(this.user.orgId),lastLogin:this.user.lastLogin,userSince:this.user.created,internalUser:this.user.internalUser||!1,accountType:this.user.accountType}),J({},e,t)}}]),e}()}); | ||
//# sourceMappingURL=telemetry.dojo.min.js.map |
@@ -7,17 +7,2 @@ (function (global, factory) { | ||
function request(options, callback) { | ||
var req = new XMLHttpRequest(); //eslint-disable-line | ||
req.addEventListener('load', function () { | ||
callback(req.responseText); | ||
}); | ||
req.open(options.method, options.url); | ||
Object.keys(options.headers).forEach(function (header) { | ||
req.setRequestHeader(header, options.headers[header]); | ||
}); | ||
req.send(options.body); | ||
} | ||
var Storage = { | ||
@@ -69,65 +54,4 @@ storage: {}, | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var COGNITO_KEY = 'TELEMETRY_COGNITO_CREDENTIALS'; | ||
var COGNITO_URL = 'https://cognito-identity.us-east-1.amazonaws.com/'; | ||
function getCredentials(IdentityPoolId, callback) { | ||
@@ -137,37 +61,41 @@ var cached = Storage.get(COGNITO_KEY); | ||
authWithCognito(IdentityPoolId, function (credentials) { | ||
Storage.set(COGNITO_KEY, credentials); | ||
callback(credentials); | ||
}); | ||
} | ||
var options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetId' | ||
}, | ||
body: JSON.stringify({ IdentityPoolId: IdentityPoolId }) | ||
}; | ||
function authWithCognito(IdentityPoolId, callback) { | ||
var options = _extends({}, defaults$$1); | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetId'; | ||
options.body = JSON.stringify({ IdentityPoolId: IdentityPoolId }); | ||
return fetch(COGNITO_URL, options).then(function (response) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
return response.json(); | ||
}).then(function (response) { | ||
var IdentityId = response.IdentityId; | ||
request(options, function (response) { | ||
requestCredentials(JSON.parse(response), callback); | ||
}); | ||
} | ||
var options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity' | ||
}, | ||
body: JSON.stringify({ IdentityId: IdentityId }) | ||
}; | ||
return fetch(COGNITO_URL, options); | ||
}).then(function (response) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
return response.json(); | ||
}).then(function (_ref) { | ||
var Credentials = _ref.Credentials; | ||
function requestCredentials(json, callback) { | ||
var options = _extends({}, defaults$$1); | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetCredentialsForIdentity'; | ||
options.body = JSON.stringify({ IdentityId: json.IdentityId }); | ||
request(options, function (response) { | ||
var json = JSON.parse(response); | ||
callback(json.Credentials); | ||
Storage.set(COGNITO_KEY, Credentials); | ||
return Credentials; | ||
}); | ||
} | ||
var defaults$$1 = { | ||
method: 'POST', | ||
url: COGNITO_URL, | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1' | ||
} | ||
}; | ||
var SESSION_LENGTH = 30 * 60 * 1000; | ||
@@ -399,2 +327,106 @@ var SESSION_KEY = 'TELEMETRY_SESSION'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// | ||
@@ -579,10 +611,3 @@ // AWS Signature v4 Implementation for Web Browsers | ||
/** | ||
* Simple URI parser factory. | ||
* Uses an `a` document element for parsing given URIs. | ||
* Therefore it most likely will only work in a web browser. | ||
*/ | ||
function SimpleUriParser() { | ||
var parser = document ? document.createElement('a') : {}; | ||
/** | ||
@@ -598,2 +623,3 @@ * Parse the given URI. | ||
return function (uri) { | ||
var parser = URL ? new URL(uri) : document.createElement('a'); | ||
parser.href = uri; | ||
@@ -607,13 +633,13 @@ return { | ||
}; | ||
} | ||
function extractQueryParams(search) { | ||
return (/^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg); | ||
if (arg) { | ||
result[arg[1]] = arg[2]; | ||
} | ||
return result; | ||
}, {}) | ||
); | ||
} | ||
function extractQueryParams(search) { | ||
return (/^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg); | ||
if (arg) { | ||
result[arg[1]] = arg[2]; | ||
} | ||
return result; | ||
}, {}) | ||
); | ||
} | ||
@@ -699,43 +725,98 @@ | ||
var METRICS = ['size', 'duration', 'position', 'number', 'count']; | ||
var DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events'; | ||
function formatTelemetryAttributes(_ref) { | ||
var telemetryData = _ref.telemetryData, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$excludeKeys = _ref.excludeKeys, | ||
excludeKeys = _ref$excludeKeys === undefined ? [] : _ref$excludeKeys; | ||
var Amazon = function () { | ||
function Amazon(options) { | ||
classCallCheck(this, Amazon); | ||
return Object.keys(telemetryData).filter(function (key) { | ||
return !excludeKeys.includes(key); | ||
}).map(function (key) { | ||
if (dimensionLookup[key]) { | ||
return { | ||
key: getCustomDimensionKey(dimensionLookup, key), | ||
value: telemetryData[key] }; | ||
} | ||
this.name = 'amazon'; | ||
_extends(this, options); | ||
var session = getUser().session; | ||
if (session.new && !options.test) this.logEvent({ eventType: '_session.start' }); | ||
return { | ||
key: key, | ||
value: getValue(telemetryData, key) | ||
}; | ||
}).reduce(function (acc, _ref2) { | ||
var key = _ref2.key, | ||
value = _ref2.value; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getValue(data, key) { | ||
if (key === 'json') { | ||
return data[key] ? JSON.stringify(data[key]) : 'null'; | ||
} | ||
createClass(Amazon, [{ | ||
key: 'logPageView', | ||
value: function logPageView(page, options) { | ||
var event = createPageView(page, this.previousPage, options); | ||
sendTelemetry(event, this.userPoolID, this.app); | ||
this.previousPage = event.attributes; | ||
return data[key] === undefined ? 'null' : data[key].toString(); | ||
} | ||
function getCustomDimensionKey(lookup, key) { | ||
return 'dimension' + lookup[key]; | ||
} | ||
var METRICS = ['size', 'duration', 'position', 'number', 'count']; | ||
function formatTelemetryMetrtics(telemetryData) { | ||
var metricLookup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return Object.keys(telemetryData).filter(function (key) { | ||
return metricLookup[key] || METRICS.includes(key); | ||
}).map(function (key) { | ||
if (metricLookup[key]) { | ||
return { | ||
key: getCustomMetricKey(metricLookup, key), | ||
value: telemetryData[key] | ||
}; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var events = createEventLog(event); | ||
sendTelemetry(events, this.userPoolID, this.app); | ||
} | ||
}]); | ||
return Amazon; | ||
}(); | ||
function createPageView(page) { | ||
var previousPage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return { | ||
key: key, | ||
value: telemetryData[key] | ||
}; | ||
}).reduce(function (acc, _ref) { | ||
var key = _ref.key, | ||
value = _ref.value; | ||
var session = getUser().session; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getCustomMetricKey(lookup, key) { | ||
return 'metric' + lookup[key]; | ||
} | ||
function createEventLog(_ref) { | ||
var event = _ref.event, | ||
_ref$session = _ref.session, | ||
id = _ref$session.id, | ||
startTimestamp = _ref$session.startTimestamp, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
var metrics = formatTelemetryMetrtics(event, metricLookup); | ||
var eventAttributes = formatTelemetryAttributes({ | ||
telemetryData: event, | ||
dimensionLookup: dimensionLookup, | ||
excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup))) | ||
}); | ||
return { | ||
eventType: 'pageView', | ||
eventType: event.eventType || 'other', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
id: id, | ||
startTimestamp: startTimestamp | ||
}, | ||
@@ -745,53 +826,104 @@ attributes: _extends({ | ||
hostname: window.location.hostname, | ||
path: page || window.location.pathname, | ||
pageUrl: page || window.location.pathname, | ||
pageName: document.title, | ||
previousPageUrl: previousPage.pageUrl, | ||
previousPageName: previousPage.pageName | ||
}, extractAttributes(options)), | ||
metrics: extractMetrics(options) | ||
path: window.location.pathname | ||
}, eventAttributes), | ||
metrics: metrics | ||
}; | ||
} | ||
function createEventLog(event) { | ||
var session = getUser().session; | ||
function createPageViewLog(_ref) { | ||
var page = _ref.page, | ||
_ref$session = _ref.session; | ||
_ref$session = _ref$session === undefined ? {} : _ref$session; | ||
var id = _ref$session.id, | ||
startTimestamp = _ref$session.startTimestamp, | ||
_ref$previousPage = _ref.previousPage, | ||
previousPage = _ref$previousPage === undefined ? {} : _ref$previousPage, | ||
_ref$options = _ref.options, | ||
options = _ref$options === undefined ? {} : _ref$options, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
var metrics = formatTelemetryMetrtics(options, metricLookup); | ||
var attributes = formatTelemetryAttributes({ | ||
telemetryData: options, | ||
dimensionLookup: dimensionLookup, | ||
excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup))) | ||
}); | ||
var _ref2 = document || {}, | ||
referrer = _ref2.referrer, | ||
title = _ref2.title; | ||
var _ref3 = window && window.location ? window.location : {}, | ||
hostname = _ref3.hostname, | ||
pathname = _ref3.pathname; | ||
return { | ||
eventType: event.eventType || 'other', | ||
eventType: 'pageView', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
id: id, | ||
startTimestamp: startTimestamp | ||
}, | ||
attributes: _extends({ | ||
referrer: document.referrer, | ||
hostname: window.location.hostname, | ||
path: window.location.pathname | ||
}, extractAttributes(event)), | ||
metrics: extractMetrics(event) | ||
referrer: referrer, | ||
hostname: hostname, | ||
path: page || pathname, | ||
pageUrl: page || pathname, | ||
pageName: title, | ||
previousPageUrl: previousPage.pageUrl, | ||
previousPageName: previousPage.pageName | ||
}, attributes), | ||
metrics: metrics | ||
}; | ||
} | ||
function extractAttributes(event) { | ||
var attributes = _extends({}, event); | ||
delete attributes.workflow; | ||
METRICS.forEach(function (metric) { | ||
return delete attributes[metric]; | ||
}); | ||
Object.keys(attributes).forEach(function (attr) { | ||
if (attr === 'json') { | ||
attributes[attr] = attributes[attr] ? JSON.stringify(attributes[attr]) : 'null'; | ||
} else { | ||
attributes[attr] = attributes[attr] !== undefined ? attributes[attr].toString() : 'null'; | ||
var DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events'; | ||
var Amazon = function () { | ||
function Amazon(options) { | ||
classCallCheck(this, Amazon); | ||
this.name = 'amazon'; | ||
_extends(this, options); | ||
var session = getUser().session; | ||
if (session.new && !options.test) { | ||
this.logEvent({ eventType: '_session.start' }).catch(function (err) { | ||
console.error('Failed to log _session.start: ' + err.message); | ||
}); | ||
} | ||
}); | ||
return attributes; | ||
} | ||
} | ||
function extractMetrics(event) { | ||
var metrics = {}; | ||
METRICS.forEach(function (metric) { | ||
if (event[metric]) metrics[metric] = event[metric]; | ||
}); | ||
return metrics; | ||
} | ||
createClass(Amazon, [{ | ||
key: 'logPageView', | ||
value: function logPageView(page, options) { | ||
var session = getUser().session; | ||
var telemetryPayload = createPageViewLog({ | ||
page: page, | ||
session: session, | ||
previousPage: this.previousPage, | ||
options: options, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}); | ||
this.previousPage = telemetryPayload.attributes; | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app); | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var session = getUser().session; | ||
var telemetryPayload = createEventLog({ | ||
event: event, | ||
session: session, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}); | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app); | ||
} | ||
}]); | ||
return Amazon; | ||
}(); | ||
@@ -830,7 +962,7 @@ function createHeaders() { | ||
function sendTelemetry(events, userPoolID, app) { | ||
function sendTelemetry(events, userPoolID, app, url) { | ||
var user = getUser(); | ||
events = Array.isArray(events) ? events : [events]; | ||
var options = createTelemetryOptions(events); | ||
getCredentials(userPoolID, function (credentials) { | ||
return getCredentials(userPoolID).then(function (credentials) { | ||
try { | ||
@@ -843,7 +975,10 @@ options.headers = createHeaders(credentials, options); | ||
} | ||
request(options, function (response) { | ||
if (response) { | ||
console.error(JSON.parse(response)); | ||
} | ||
}); | ||
return fetch(DEFAULT_ENDPOINT, options); | ||
}).then(function (response) { | ||
if (response.ok) { | ||
return { success: true }; | ||
} | ||
throw new Error('Telemetry failed. ' + response.status + ', ' + response.statusText); | ||
}).catch(function (err) { | ||
console.error(err.message); | ||
}); | ||
@@ -864,2 +999,41 @@ } | ||
function mapMetricsAndDimensions(_ref) { | ||
var _ref$customTelemetryD = _ref.customTelemetryData, | ||
customTelemetryData = _ref$customTelemetryD === undefined ? {} : _ref$customTelemetryD, | ||
_ref$dimensionLookup = _ref.dimensionLookup, | ||
dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup, | ||
_ref$metricLookup = _ref.metricLookup, | ||
metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup; | ||
return Object.keys(customTelemetryData).map(function (key) { | ||
if (dimensionLookup[key]) { | ||
return { | ||
key: getCustomDimensionKey$1(dimensionLookup, key), | ||
value: customTelemetryData[key] }; | ||
} | ||
if (metricLookup[key]) { | ||
return { | ||
key: getCustomMetricKey$1(metricLookup, key), | ||
value: customTelemetryData[key] | ||
}; | ||
} | ||
}).filter(function (val) { | ||
return val; | ||
}).reduce(function (acc, _ref2) { | ||
var key = _ref2.key, | ||
value = _ref2.value; | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
} | ||
function getCustomDimensionKey$1(lookup, key) { | ||
return "dimension" + lookup[key]; | ||
} | ||
function getCustomMetricKey$1(lookup, key) { | ||
return "metric" + lookup[key]; | ||
} | ||
var Google = function () { | ||
@@ -907,3 +1081,2 @@ function Google() { | ||
} | ||
function buildPageViewObject(page, options) { | ||
@@ -913,3 +1086,3 @@ var dimensions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var pageviewObject = { | ||
var standardTelemetry = { | ||
hitType: 'pageview', | ||
@@ -919,3 +1092,9 @@ page: page || window.location.pathname | ||
return mapMetricsAndDimensions(pageviewObject, options, dimensions, metrics); | ||
var mappedCustomTelemetryData = mapMetricsAndDimensions({ | ||
customTelemetryData: options, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics | ||
}); | ||
return _extends({}, standardTelemetry, mappedCustomTelemetryData); | ||
} | ||
@@ -927,27 +1106,16 @@ | ||
var eventObject = { | ||
var standardTelemetryData = { | ||
hitType: 'event', | ||
eventCategory: event.category || 'none', | ||
eventAction: event.action, | ||
eventLabel: event.label, | ||
nonInteraction: event.nonInteraction | ||
eventLabel: event.label | ||
}; | ||
return mapMetricsAndDimensions(eventObject, event, dimensions, metrics); | ||
var mappedCustomTelemetryData = mapMetricsAndDimensions({ | ||
customTelemetryData: event, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics }); | ||
return _extends({}, standardTelemetryData, mappedCustomTelemetryData); | ||
} | ||
function mapMetricsAndDimensions(inputObject, options, dimensions, metrics) { | ||
var mappedObject = inputObject; | ||
Object.keys(dimensions).forEach(function (dimension) { | ||
mappedObject['dimension' + dimensions[dimension]] = options[dimension]; | ||
}); | ||
Object.keys(metrics).forEach(function (metric) { | ||
mappedObject['metric' + metrics[metric]] = options[metric]; | ||
}); | ||
return mappedObject; | ||
} | ||
var anonymize = function (user) { | ||
@@ -1066,3 +1234,4 @@ if (!user) return undefined; | ||
var attributes = this.preProcess(options); | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes));else if (this.test && !this.disabled) return attributes; | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (this.test && !this.disabled) return attributes; | ||
@@ -1072,12 +1241,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false; | ||
} else { | ||
this.trackers.forEach(function (tracker) { | ||
try { | ||
tracker.logPageView(page, attributes); | ||
} catch (e) { | ||
console.error(tracker.name + ' tracker failed to log page view.', e); | ||
} | ||
}); | ||
return true; | ||
} | ||
var promises = this.trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
@@ -1091,3 +1258,4 @@ }, { | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event));else if (this.test) return event; | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event)); | ||
if (this.test) return event; | ||
@@ -1097,12 +1265,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false; | ||
} else { | ||
this.trackers.forEach(function (tracker) { | ||
try { | ||
tracker.logEvent(event); | ||
} catch (e) { | ||
console.error(tracker.name + ' tracker failed to log event', e); | ||
} | ||
}); | ||
return true; | ||
} | ||
var promises = this.trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
@@ -1230,3 +1396,3 @@ }, { | ||
user: anonymize(this.user.username), | ||
orgId: anonymize(this.user.orgId), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
@@ -1233,0 +1399,0 @@ userSince: this.user.created, |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("telemetry",t):e.Telemetry=t()}(this,function(){"use strict";function e(e,t){var n=new XMLHttpRequest;n.addEventListener("load",function(){t(n.responseText)}),n.open(e.method,e.url),Object.keys(e.headers).forEach(function(t){n.setRequestHeader(t,e.headers[t])}),n.send(e.body)}function t(e,t){var r=q.get(D);if(r&&Date.now()/1e3<r.Expiration)return t(r);n(e,function(e){q.set(D,e),t(e)})}function n(t,n){var i=j({},N);i.headers["X-Amz-Target"]="AWSCognitoIdentityService.GetId",i.body=JSON.stringify({IdentityPoolId:t}),e(i,function(e){r(JSON.parse(e),n)})}function r(t,n){var r=j({},N);r.headers["X-Amz-Target"]="AWSCognitoIdentityService.GetCredentialsForIdentity",r.body=JSON.stringify({IdentityId:t.IdentityId}),e(r,function(e){var t=JSON.parse(e);n(t.Credentials)})}function i(){return{session:o(),id:s()}}function o(){var e=void 0,t=q.get(M);return(!t||Date.now()>t.expiration)&&(e=!0,t=a()),t.expiration=Date.now()+L,q.set(M,t),e&&(t.new=!0),t}function s(){var e=q.get(R);return e||(e=c(),q.set(R,e)),e}function a(){return{id:Math.floor(17592186044416*(1+Math.random())).toString(16),startTimestamp:(new Date).toISOString()}}function c(){return u()+u()+"-"+u()+"-"+u()+"-"+u()+"-"+u()+u()+u()}function u(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function l(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":p(t.signDate)};t.request.method=t.request.method.toUpperCase(),t.request.body?t.payload=t.request.body:t.request.data&&e.payloadSerializer?t.payload=e.payloadSerializer(t.request.data):delete n["content-type"],t.request.headers=w(n,Object.keys(t.request.headers||{}).reduce(function(e,n){return e[n.toLowerCase()]=t.request.headers[n],e},{})),t.sortedHeaderKeys=Object.keys(t.request.headers).sort(),t.request.headers["content-type"]&&(t.request.headers["content-type"]=t.request.headers["content-type"].split(";")[0]),"object"===P(t.request.params)&&w(t.uri.queryParams,t.request.params)}function h(e,t){t.signedHeaders=t.sortedHeaderKeys.map(function(e){return e.toLowerCase()}).join(";"),t.canonicalRequest=String(t.request.method).toUpperCase()+"\n"+encodeURI(t.uri.path)+"\n"+Object.keys(t.uri.queryParams).sort().map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t.uri.queryParams[e])}).join("&")+"\n"+t.sortedHeaderKeys.map(function(e){return e.toLocaleLowerCase()+":"+t.request.headers[e]}).join("\n")+"\n\n"+t.signedHeaders+"\n"+e.hasher.hash(t.payload?t.payload:"")}function f(e,t){t.credentialScope=[p(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+p(t.signDate)+"\n"+t.credentialScope+"\n"+e.hasher.hash(t.canonicalRequest)}function d(e,t){var n=e.hasher.hmac,r=n(n(n(n("AWS4"+e.config.secretAccessKey,p(t.signDate,!0),{hexOutput:!1}),e.config.region,{hexOutput:!1,textInput:!1}),e.config.service,{hexOutput:!1,textInput:!1}),"aws4_request",{hexOutput:!1,textInput:!1});t.signature=n(r,t.stringToSign,{textInput:!1})}function g(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function p(e,t){var n=e.toISOString().replace(/[:\-]|\.\d{3}/g,"").substr(0,17);return t?n.substr(0,8):n}function y(){return function(e){return JSON.stringify(e)}}function v(){function e(e){return/^\??(.*)$/.exec(e)[1].split("&").reduce(function(e,t){return t=/^(.+)=(.*)$/.exec(t),t&&(e[t[1]]=t[2]),e},{})}var t=document?document.createElement("a"):{};return function(n){return t.href=n,{protocol:t.protocol,host:t.host.replace(/^(.*):((80)|(443))$/,"$1"),path:("/"!==t.pathname.charAt(0)?"/":"")+t.pathname,queryParams:e(t.search)}}}function m(){return{hash:function(e,t){t=w({hexOutput:!0,textInput:!0},t);var n=U.SHA256(e);return t.hexOutput?n.toString(U.enc.Hex):n},hmac:function(e,t,n){n=w({hexOutput:!0,textInput:!0},n);var r=U.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(U.enc.Hex):r}}}function w(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":P(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":P(r))?(e[n]=Array.isArray(r)?[]:{},w(e[n],r)):e[n]=r)})}),e}function S(e,t){if(void 0===e||!e)throw new Error(t)}function k(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=i().session;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:r.id,startTimestamp:r.startTimestamp},attributes:j({referrer:document.referrer,hostname:window.location.hostname,path:e||window.location.pathname,pageUrl:e||window.location.pathname,pageName:document.title,previousPageUrl:t.pageUrl,previousPageName:t.pageName},_(n)),metrics:T(n)}}function b(e){var t=i().session;return{eventType:e.eventType||"other",timestamp:(new Date).toISOString(),session:{id:t.id,startTimestamp:t.startTimestamp},attributes:j({referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname},_(e)),metrics:T(e)}}function _(e){var t=j({},e);return delete t.workflow,J.forEach(function(e){return delete t[e]}),Object.keys(t).forEach(function(e){t[e]="json"===e?t[e]?JSON.stringify(t[e]):"null":void 0!==t[e]?t[e].toString():"null"}),t}function T(e){var t={};return J.forEach(function(n){e[n]&&(t[n]=e[n])}),t}function E(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new F(n).sign(t)}function I(e,t){return JSON.stringify({client:{client_id:e,app_title:t.name,app_version_name:t.version||"unknown"},services:{mobile_analytics:{app_id:t.id}}})}function O(n,r,o){var s=i();n=Array.isArray(n)?n:[n];var a=x(n);t(r,function(t){try{a.headers=E(t,a),a.headers["x-amz-Client-Context"]=I(s.id,o)}catch(e){return void console.error(e)}e(a,function(e){e&&console.error(JSON.parse(e))})})}function x(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:Y,method:"POST",body:JSON.stringify({events:e})}}function A(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function z(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return H({hitType:"pageview",page:e||window.location.pathname},t,n,r)}function C(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return H({hitType:"event",eventCategory:e.category||"none",eventAction:e.action,eventLabel:e.label,nonInteraction:e.nonInteraction},e,t,n)}function H(e,t,n,r){var i=e;return Object.keys(n).forEach(function(e){i["dimension"+n[e]]=t[e]}),Object.keys(r).forEach(function(e){i["metric"+r[e]]=t[e]}),i}var q={storage:{},memory:!0,get:function(e){var t=void 0;try{t=window.localStorage&&window.localStorage.getItem(e)||this.storage[e]}catch(n){t=this.storage[e]}if(t)try{return JSON.parse(t)}catch(e){return}},set:function(e,t){t=JSON.stringify(t);try{window.localStorage.setItem(e,t)}catch(n){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),this.storage[e]=t}},delete:function(e){try{window.localStorage.removeItem(e)}catch(t){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),delete this.storage[e]}}},P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},W=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},B=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),j=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},D="TELEMETRY_COGNITO_CREDENTIALS",N={method:"POST",url:"https://cognito-identity.us-east-1.amazonaws.com/",headers:{"Content-type":"application/x-amz-json-1.1"}},L=18e5,M="TELEMETRY_SESSION",R="TELEMETRY_CLIENT_ID",U=function(e,t){var n={},r=n.lib={},i=function(){},o=r.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var i=0;i<e;i++)t[r+i>>>2]|=(n[i>>>2]>>>24-i%4*8&255)<<24-(r+i)%4*8;else if(n.length>65535)for(i=0;i<e;i+=4)t[r+i>>>2]=n[i>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r<t;r+=4)n.push(4294967296*e.random()|0);return new s.init(n,t)}}),a=n.enc={},c=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++){var i=t[r>>>2]>>>24-r%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++)n.push(String.fromCharCode(t[r>>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,i=n.sigBytes,o=this.blockSize,a=i/(4*o),a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0);if(t=a*o,i=e.min(4*t,i),t){for(var c=0;c<t;c+=o)this._doProcessBlock(r,c);c=r.splice(0,t),n.sigBytes-=i}return new s.init(c,i)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=h.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=U,n=t.lib,r=n.WordArray,i=n.Hasher,n=t.algo,o=[],s=[],a=function(e){return 4294967296*(e-(0|e))|0},c=2,u=0;u<64;){var l;e:{l=c;for(var h=e.sqrt(l),f=2;f<=h;f++)if(!(l%f)){l=!1;break e}l=!0}l&&(u<8&&(o[u]=a(e.pow(c,.5))),s[u]=a(e.pow(c,1/3)),u++),c++}var d=[],n=n.SHA256=i.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],a=n[3],c=n[4],u=n[5],l=n[6],h=n[7],f=0;f<64;f++){if(f<16)d[f]=0|e[t+f];else{var g=d[f-15],p=d[f-2];d[f]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+d[f-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+d[f-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+s[f]+d[f],p=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=l,l=u,u=c,c=a+g|0,a=o,o=i,i=r,r=g+p|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+a|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(n),t.HmacSHA256=i._createHmacHelper(n)}(Math),function(){var e=U,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var r=e.blockSize,i=4*r;n.sigBytes>i&&(n=e.finalize(n)),n.clamp();for(var o=this._oKey=n.clone(),s=this._iKey=n.clone(),a=o.words,c=s.words,u=0;u<r;u++)a[u]^=1549556828,c[u]^=909522486;o.sigBytes=s.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}();var K={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:y,uriParserFactory:v,hasherFactory:m},F=function(){function e(t){W(this,e),this.config=w({},K,t),this.payloadSerializer=this.config.payloadSerializer||this.config.payloadSerializerFactory(),this.uriParser=this.config.uriParserFactory(),this.hasher=this.config.hasherFactory(),S(this.config.accessKeyId,"AwsSigner requires AWS AccessKeyID"),S(this.config.secretAccessKey,"AwsSigner requires AWS SecretAccessKey")}return B(e,[{key:"sign",value:function(e,t){var n={request:w({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return l(this,n),h(this,n),f(this,n),d(this,n),g(this,n),{Accept:n.request.headers.accept,Authorization:n.authorization,"Content-Type":n.request.headers["content-type"],"x-amz-date":n.request.headers["x-amz-date"],"x-amz-security-token":this.config.sessionToken||void 0}}}]),e}(),J=["size","duration","position","number","count"],Y="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",$=function(){function e(t){W(this,e),this.name="amazon",j(this,t),i().session.new&&!t.test&&this.logEvent({eventType:"_session.start"})}return B(e,[{key:"logPageView",value:function(e,t){var n=k(e,this.previousPage,t);O(n,this.userPoolID,this.app),this.previousPage=n.attributes}},{key:"logEvent",value:function(e){O(b(e),this.userPoolID,this.app)}}]),e}(),V=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};W(this,e),this.name="google",j(this,t)}return B(e,[{key:"logPageView",value:function(e,t){var n=z(e,t,this.dimensions,this.metrics);A(function(e){e.forEach(function(e){e.send(n)})})}},{key:"logEvent",value:function(e){var t=C(e,this.dimensions,this.metrics);A(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),G=function(e){if(e)return U.SHA256(e).toString(U.enc.Hex)},X=["esri.com","esriuk.com","esri.de","esri.ca","esrifrance.fr","esri.nl","esri-portugal.pt","esribulgaria.com","esri.fi","esri.kr","esrimalaysia.com.my","esri.es","esriaustralia.com.au","esri-southafrica.com","esri.cl","esrichina.com.cn","esri.co","esriturkey.com.tr","geodata.no","esriitalia.it","esri.pl"],Q=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.portal||{};return!e.disabled&&("1"!==navigator.doNotTrack&&"1"!==window.doNotTrack&&((void 0===t.eueiEnabled||!1!==t.eueiEnabled)&&(!(!t.eueiEnabled||!t.user||t.user.orgId!==t.id)||(!(!t.user||t.user.orgId||"US"!==t.ipCntryCode)||(!t.user&&"US"===t.ipCntryCode||!(Object.keys(t).length>0))))))};return function(){function e(t){W(this,e);try{if(this.trackers=[],this.workflows={},this.test=t.test,this.debug=t.debug,this.disabled=!Q(t),this.disabled&&console.log("Telemetry Disabled"),t.portal&&t.portal.user){var n=t.portal.subscriptionInfo||{};this.setUser(t.portal.user,n.type)}else t.user&&this.setUser(t.user);this.disabled||this._initTrackers(t)}catch(e){console.error("Telemetry Disabled"),console.error(e),this.disabled=!0}}return B(e,[{key:"_initTrackers",value:function(e){if(e.amazon){var t=new $(e.amazon);this.trackers.push(t)}if(e.google){var n=new V(e.google);this.trackers.push(n)}this.trackers.length||console.error(new Error("No trackers configured"))}},{key:"setUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Public";e="string"==typeof e?{username:e}:e,this.user=e,this.user.accountType=t;var n=void 0;if(e.email&&e.email.split){var r=e.email.split("@")[1];n=X.filter(function(e){return r===e}).length>0}(n||["In House","Demo and Marketing"].indexOf(t)>-1)&&(this.user.internalUser=!0)}},{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.preProcess(t);if(this.debug)console.log("Tracking page view",JSON.stringify(n));else if(this.test&&!this.disabled)return n;return!this.trackers.length||this.disabled?(this.disabled||console.error(new Error("Page view was not logged because no trackers are configured.")),!1):(this.trackers.forEach(function(t){try{t.logPageView(e,n)}catch(e){console.error(t.name+" tracker failed to log page view.",e)}}),!0)}},{key:"logEvent",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.preProcess(e);if(this.debug)console.log("Tracking event",JSON.stringify(t));else if(this.test)return t;return!this.trackers.length||this.disabled?(this.disabled||console.error(new Error("Event was not logged because no trackers are configured.")),!1):(this.trackers.forEach(function(e){try{e.logEvent(t)}catch(t){console.error(e.name+" tracker failed to log event",t)}}),!0)}},{key:"logError",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=j({eventType:"error"},e);this.logEvent(t)}},{key:"startWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={name:e,start:Date.now(),steps:[],workflowId:Math.floor(17592186044416*(1+Math.random())).toString(16)};this._saveWorkflow(n);var r=j({name:e,step:"start"},t);return this._logWorkflow(r),n}},{key:"stepWorkflow",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r="string"==typeof options?n:n.details,i=j({name:e,step:t,details:r},n);this._logWorkflow(i)}},{key:"endWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=j({name:e,step:"finish"},t);this._logWorkflow(n)}},{key:"cancelWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=j({name:e,step:"cancel"},t);this._logWorkflow(n)}},{key:"getWorkflow",value:function(e){var t=q.get("TELEMETRY-WORKFLOW:"+e);if(t){if(Date.now()-t.start<18e5)return t;this._deleteWorkflow(t)}}},{key:"_saveWorkflow",value:function(e){q.set("TELEMETRY-WORKFLOW:"+e.name,e)}},{key:"_deleteWorkflow",value:function(e){q.delete("TELEMETRY-WORKFLOW:"+e.name)}},{key:"_logWorkflow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=this.preProcess(e);var t=this.getWorkflow(e.name);t||(this.startWorkflow(e.name),t=this.getWorkflow(e.name)),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3,["cancel","finish"].indexOf(e.step)>-1?this._deleteWorkflow(t):this._saveWorkflow(t);var n=j(e,{eventType:"workflow",category:e.name,action:e.step,label:e.details,duration:t.duration,workflowId:t.workflowId});this.logEvent(n)}},{key:"preProcess",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};return this.user&&(t={user:G(this.user.username),orgId:G(this.user.orgId),lastLogin:this.user.lastLogin,userSince:this.user.created,internalUser:this.user.internalUser||!1,accountType:this.user.accountType}),j({},e,t)}}]),e}()}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("telemetry",t):e.Telemetry=t()}(this,function(){"use strict";function e(e,t){var n=j.get(q);if(n&&Date.now()/1e3<n.Expiration)return t(n);var r={method:"POST",headers:{"Content-type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityService.GetId"},body:JSON.stringify({IdentityPoolId:e})};return fetch(D,r).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.json()}).then(function(e){var t=e.IdentityId,n={method:"POST",headers:{"Content-type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityService.GetCredentialsForIdentity"},body:JSON.stringify({IdentityId:t})};return fetch(D,n)}).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.json()}).then(function(e){var t=e.Credentials;return j.set(q,t),t})}function t(){return{session:n(),id:r()}}function n(){var e=void 0,t=j.get(K);return(!t||Date.now()>t.expiration)&&(e=!0,t=i()),t.expiration=Date.now()+B,j.set(K,t),e&&(t.new=!0),t}function r(){var e=j.get(U);return e||(e=o(),j.set(U,e)),e}function i(){return{id:Math.floor(17592186044416*(1+Math.random())).toString(16),startTimestamp:(new Date).toISOString()}}function o(){return s()+s()+"-"+s()+"-"+s()+"-"+s()+"-"+s()+s()+s()}function s(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function a(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":f(t.signDate)};t.request.method=t.request.method.toUpperCase(),t.request.body?t.payload=t.request.body:t.request.data&&e.payloadSerializer?t.payload=e.payloadSerializer(t.request.data):delete n["content-type"],t.request.headers=v(n,Object.keys(t.request.headers||{}).reduce(function(e,n){return e[n.toLowerCase()]=t.request.headers[n],e},{})),t.sortedHeaderKeys=Object.keys(t.request.headers).sort(),t.request.headers["content-type"]&&(t.request.headers["content-type"]=t.request.headers["content-type"].split(";")[0]),"object"===M(t.request.params)&&v(t.uri.queryParams,t.request.params)}function u(e,t){t.signedHeaders=t.sortedHeaderKeys.map(function(e){return e.toLowerCase()}).join(";"),t.canonicalRequest=String(t.request.method).toUpperCase()+"\n"+encodeURI(t.uri.path)+"\n"+Object.keys(t.uri.queryParams).sort().map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t.uri.queryParams[e])}).join("&")+"\n"+t.sortedHeaderKeys.map(function(e){return e.toLocaleLowerCase()+":"+t.request.headers[e]}).join("\n")+"\n\n"+t.signedHeaders+"\n"+e.hasher.hash(t.payload?t.payload:"")}function c(e,t){t.credentialScope=[f(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+f(t.signDate)+"\n"+t.credentialScope+"\n"+e.hasher.hash(t.canonicalRequest)}function l(e,t){var n=e.hasher.hmac,r=n(n(n(n("AWS4"+e.config.secretAccessKey,f(t.signDate,!0),{hexOutput:!1}),e.config.region,{hexOutput:!1,textInput:!1}),e.config.service,{hexOutput:!1,textInput:!1}),"aws4_request",{hexOutput:!1,textInput:!1});t.signature=n(r,t.stringToSign,{textInput:!1})}function h(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function f(e,t){var n=e.toISOString().replace(/[:\-]|\.\d{3}/g,"").substr(0,17);return t?n.substr(0,8):n}function d(){return function(e){return JSON.stringify(e)}}function p(){return function(e){var t=URL?new URL(e):document.createElement("a");return t.href=e,{protocol:t.protocol,host:t.host.replace(/^(.*):((80)|(443))$/,"$1"),path:("/"!==t.pathname.charAt(0)?"/":"")+t.pathname,queryParams:g(t.search)}}}function g(e){return/^\??(.*)$/.exec(e)[1].split("&").reduce(function(e,t){return t=/^(.+)=(.*)$/.exec(t),t&&(e[t[1]]=t[2]),e},{})}function y(){return{hash:function(e,t){t=v({hexOutput:!0,textInput:!0},t);var n=R.SHA256(e);return t.hexOutput?n.toString(R.enc.Hex):n},hmac:function(e,t,n){n=v({hexOutput:!0,textInput:!0},n);var r=R.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(R.enc.Hex):r}}}function v(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":M(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":M(r))?(e[n]=Array.isArray(r)?[]:{},v(e[n],r)):e[n]=r)})}),e}function m(e,t){if(void 0===e||!e)throw new Error(t)}function w(e){var t=e.telemetryData,n=e.dimensionLookup,r=void 0===n?{}:n,i=e.excludeKeys,o=void 0===i?[]:i;return Object.keys(t).filter(function(e){return!o.includes(e)}).map(function(e){return r[e]?{key:S(r,e),value:t[e]}:{key:e,value:k(t,e)}}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function k(e,t){return"json"===t?e[t]?JSON.stringify(e[t]):"null":void 0===e[t]?"null":e[t].toString()}function S(e,t){return"dimension"+e[t]}function b(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Object.keys(e).filter(function(e){return t[e]||G.includes(e)}).map(function(n){return t[n]?{key:_(t,n),value:e[n]}:{key:n,value:e[n]}}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function _(e,t){return"metric"+e[t]}function T(e){var t=e.event,n=e.session,r=n.id,i=n.startTimestamp,o=e.dimensionLookup,s=void 0===o?{}:o,a=e.metricLookup,u=void 0===a?{}:a,c=b(t,u),l=w({telemetryData:t,dimensionLookup:s,excludeKeys:["workflow"].concat(Y(Object.keys(c)),Y(Object.keys(u)))});return{eventType:t.eventType||"other",timestamp:(new Date).toISOString(),session:{id:r,startTimestamp:i},attributes:J({referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname},l),metrics:c}}function x(e){var t=e.page,n=e.session;n=void 0===n?{}:n;var r=n.id,i=n.startTimestamp,o=e.previousPage,s=void 0===o?{}:o,a=e.options,u=void 0===a?{}:a,c=e.dimensionLookup,l=void 0===c?{}:c,h=e.metricLookup,f=void 0===h?{}:h,d=b(u,f),p=w({telemetryData:u,dimensionLookup:l,excludeKeys:["workflow"].concat(Y(Object.keys(d)),Y(Object.keys(f)))}),g=document||{},y=g.referrer,v=g.title,m=window&&window.location?window.location:{},k=m.hostname,S=m.pathname;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:r,startTimestamp:i},attributes:J({referrer:y,hostname:k,path:t||S,pageUrl:t||S,pageName:v,previousPageUrl:s.pageUrl,previousPageName:s.pageName},p),metrics:d}}function O(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new V(n).sign(t)}function I(e,t){return JSON.stringify({client:{client_id:e,app_title:t.name,app_version_name:t.version||"unknown"},services:{mobile_analytics:{app_id:t.id}}})}function A(n,r,i,o){var s=t();n=Array.isArray(n)?n:[n];var a=E(n);return e(r).then(function(e){try{a.headers=O(e,a),a.headers["x-amz-Client-Context"]=I(s.id,i)}catch(e){return void console.error(e)}return fetch(X,a)}).then(function(e){if(e.ok)return{success:!0};throw new Error("Telemetry failed. "+e.status+", "+e.statusText)}).catch(function(e){console.error(e.message)})}function E(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:X,method:"POST",body:JSON.stringify({events:e})}}function P(e){var t=e.customTelemetryData,n=void 0===t?{}:t,r=e.dimensionLookup,i=void 0===r?{}:r,o=e.metricLookup,s=void 0===o?{}:o;return Object.keys(n).map(function(e){return i[e]?{key:z(i,e),value:n[e]}:s[e]?{key:L(s,e),value:n[e]}:void 0}).filter(function(e){return e}).reduce(function(e,t){var n=t.key,r=t.value;return e[n]=r,e},{})}function z(e,t){return"dimension"+e[t]}function L(e,t){return"metric"+e[t]}function C(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function H(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i={hitType:"pageview",page:e||window.location.pathname},o=P({customTelemetryData:t,dimensionLookup:n,metricLookup:r});return J({},i,o)}function W(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r={hitType:"event",eventCategory:e.category||"none",eventAction:e.action,eventLabel:e.label},i=P({customTelemetryData:e,dimensionLookup:t,metricLookup:n});return J({},r,i)}var j={storage:{},memory:!0,get:function(e){var t=void 0;try{t=window.localStorage&&window.localStorage.getItem(e)||this.storage[e]}catch(n){t=this.storage[e]}if(t)try{return JSON.parse(t)}catch(e){return}},set:function(e,t){t=JSON.stringify(t);try{window.localStorage.setItem(e,t)}catch(n){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),this.storage[e]=t}},delete:function(e){try{window.localStorage.removeItem(e)}catch(t){this.memory||(console.error("setting local storage failed, falling back to in-memory storage"),this.memory=!0),delete this.storage[e]}}},q="TELEMETRY_COGNITO_CREDENTIALS",D="https://cognito-identity.us-east-1.amazonaws.com/",B=18e5,K="TELEMETRY_SESSION",U="TELEMETRY_CLIENT_ID",R=function(e,t){var n={},r=n.lib={},i=function(){},o=r.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var i=0;i<e;i++)t[r+i>>>2]|=(n[i>>>2]>>>24-i%4*8&255)<<24-(r+i)%4*8;else if(n.length>65535)for(i=0;i<e;i+=4)t[r+i>>>2]=n[i>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r<t;r+=4)n.push(4294967296*e.random()|0);return new s.init(n,t)}}),a=n.enc={},u=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++){var i=t[r>>>2]>>>24-r%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r<e;r++)n.push(String.fromCharCode(t[r>>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},h=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,i=n.sigBytes,o=this.blockSize,a=i/(4*o),a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0);if(t=a*o,i=e.min(4*t,i),t){for(var u=0;u<t;u+=o)this._doProcessBlock(r,u);u=r.splice(0,t),n.sigBytes-=i}return new s.init(u,i)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=h.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=R,n=t.lib,r=n.WordArray,i=n.Hasher,n=t.algo,o=[],s=[],a=function(e){return 4294967296*(e-(0|e))|0},u=2,c=0;c<64;){var l;e:{l=u;for(var h=e.sqrt(l),f=2;f<=h;f++)if(!(l%f)){l=!1;break e}l=!0}l&&(c<8&&(o[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var d=[],n=n.SHA256=i.extend({_doReset:function(){this._hash=new r.init(o.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],a=n[3],u=n[4],c=n[5],l=n[6],h=n[7],f=0;f<64;f++){if(f<16)d[f]=0|e[t+f];else{var p=d[f-15],g=d[f-2];d[f]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[f-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+d[f-16]}p=h+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[f]+d[f],g=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=l,l=c,c=u,u=a+p|0,a=o,o=i,i=r,r=p+g|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(n),t.HmacSHA256=i._createHmacHelper(n)}(Math),function(){var e=R,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var r=e.blockSize,i=4*r;n.sigBytes>i&&(n=e.finalize(n)),n.clamp();for(var o=this._oKey=n.clone(),s=this._iKey=n.clone(),a=o.words,u=s.words,c=0;c<r;c++)a[c]^=1549556828,u[c]^=909522486;o.sigBytes=s.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}();var M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},N=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},F=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),J=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Y=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},$={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:d,uriParserFactory:p,hasherFactory:y},V=function(){function e(t){N(this,e),this.config=v({},$,t),this.payloadSerializer=this.config.payloadSerializer||this.config.payloadSerializerFactory(),this.uriParser=this.config.uriParserFactory(),this.hasher=this.config.hasherFactory(),m(this.config.accessKeyId,"AwsSigner requires AWS AccessKeyID"),m(this.config.secretAccessKey,"AwsSigner requires AWS SecretAccessKey")}return F(e,[{key:"sign",value:function(e,t){var n={request:v({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return a(this,n),u(this,n),c(this,n),l(this,n),h(this,n),{Accept:n.request.headers.accept,Authorization:n.authorization,"Content-Type":n.request.headers["content-type"],"x-amz-date":n.request.headers["x-amz-date"],"x-amz-security-token":this.config.sessionToken||void 0}}}]),e}(),G=["size","duration","position","number","count"],X="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",Q=function(){function e(n){N(this,e),this.name="amazon",J(this,n),t().session.new&&!n.test&&this.logEvent({eventType:"_session.start"}).catch(function(e){console.error("Failed to log _session.start: "+e.message)})}return F(e,[{key:"logPageView",value:function(e,n){var r=t().session,i=x({page:e,session:r,previousPage:this.previousPage,options:n,dimensionLookup:this.dimensions,metricLookup:this.metrics});return this.previousPage=i.attributes,A(i,this.userPoolID,this.app)}},{key:"logEvent",value:function(e){return A(T({event:e,session:t().session,dimensionLookup:this.dimensions,metricLookup:this.metrics}),this.userPoolID,this.app)}}]),e}(),Z=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};N(this,e),this.name="google",J(this,t)}return F(e,[{key:"logPageView",value:function(e,t){var n=H(e,t,this.dimensions,this.metrics);C(function(e){e.forEach(function(e){e.send(n)})})}},{key:"logEvent",value:function(e){var t=W(e,this.dimensions,this.metrics);C(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),ee=function(e){if(e)return R.SHA256(e).toString(R.enc.Hex)},te=["esri.com","esriuk.com","esri.de","esri.ca","esrifrance.fr","esri.nl","esri-portugal.pt","esribulgaria.com","esri.fi","esri.kr","esrimalaysia.com.my","esri.es","esriaustralia.com.au","esri-southafrica.com","esri.cl","esrichina.com.cn","esri.co","esriturkey.com.tr","geodata.no","esriitalia.it","esri.pl"],ne=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.portal||{};return!e.disabled&&("1"!==navigator.doNotTrack&&"1"!==window.doNotTrack&&((void 0===t.eueiEnabled||!1!==t.eueiEnabled)&&(!(!t.eueiEnabled||!t.user||t.user.orgId!==t.id)||(!(!t.user||t.user.orgId||"US"!==t.ipCntryCode)||(!t.user&&"US"===t.ipCntryCode||!(Object.keys(t).length>0))))))};return function(){function e(t){N(this,e);try{if(this.trackers=[],this.workflows={},this.test=t.test,this.debug=t.debug,this.disabled=!ne(t),this.disabled&&console.log("Telemetry Disabled"),t.portal&&t.portal.user){var n=t.portal.subscriptionInfo||{};this.setUser(t.portal.user,n.type)}else t.user&&this.setUser(t.user);this.disabled||this._initTrackers(t)}catch(e){console.error("Telemetry Disabled"),console.error(e),this.disabled=!0}}return F(e,[{key:"_initTrackers",value:function(e){if(e.amazon){var t=new Q(e.amazon);this.trackers.push(t)}if(e.google){var n=new Z(e.google);this.trackers.push(n)}this.trackers.length||console.error(new Error("No trackers configured"))}},{key:"setUser",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Public";e="string"==typeof e?{username:e}:e,this.user=e,this.user.accountType=t;var n=void 0;if(e.email&&e.email.split){var r=e.email.split("@")[1];n=te.filter(function(e){return r===e}).length>0}(n||["In House","Demo and Marketing"].indexOf(t)>-1)&&(this.user.internalUser=!0)}},{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.preProcess(t);if(this.debug&&console.log("Tracking page view",JSON.stringify(n)),this.test&&!this.disabled)return n;if(!this.trackers.length||this.disabled)return this.disabled||console.error(new Error("Page view was not logged because no trackers are configured.")),!1;var r=this.trackers.map(function(t){return t.logPageView(e,n)});return Promise.all(r).then(),!0}},{key:"logEvent",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=this.preProcess(e);if(this.debug&&console.log("Tracking event",JSON.stringify(t)),this.test)return t;if(!this.trackers.length||this.disabled)return this.disabled||console.error(new Error("Event was not logged because no trackers are configured.")),!1;var n=this.trackers.map(function(e){return e.logEvent(t)});return Promise.all(n).then(),!0}},{key:"logError",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=J({eventType:"error"},e);this.logEvent(t)}},{key:"startWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={name:e,start:Date.now(),steps:[],workflowId:Math.floor(17592186044416*(1+Math.random())).toString(16)};this._saveWorkflow(n);var r=J({name:e,step:"start"},t);return this._logWorkflow(r),n}},{key:"stepWorkflow",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r="string"==typeof options?n:n.details,i=J({name:e,step:t,details:r},n);this._logWorkflow(i)}},{key:"endWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=J({name:e,step:"finish"},t);this._logWorkflow(n)}},{key:"cancelWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=J({name:e,step:"cancel"},t);this._logWorkflow(n)}},{key:"getWorkflow",value:function(e){var t=j.get("TELEMETRY-WORKFLOW:"+e);if(t){if(Date.now()-t.start<18e5)return t;this._deleteWorkflow(t)}}},{key:"_saveWorkflow",value:function(e){j.set("TELEMETRY-WORKFLOW:"+e.name,e)}},{key:"_deleteWorkflow",value:function(e){j.delete("TELEMETRY-WORKFLOW:"+e.name)}},{key:"_logWorkflow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=this.preProcess(e);var t=this.getWorkflow(e.name);t||(this.startWorkflow(e.name),t=this.getWorkflow(e.name)),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3,["cancel","finish"].indexOf(e.step)>-1?this._deleteWorkflow(t):this._saveWorkflow(t);var n=J(e,{eventType:"workflow",category:e.name,action:e.step,label:e.details,duration:t.duration,workflowId:t.workflowId});this.logEvent(n)}},{key:"preProcess",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};return this.user&&(t={user:ee(this.user.username),org:ee(this.user.orgId),lastLogin:this.user.lastLogin,userSince:this.user.created,internalUser:this.user.internalUser||!1,accountType:this.user.accountType}),J({},e,t)}}]),e}()}); | ||
//# sourceMappingURL=telemetry.min.js.map |
{ | ||
"name": "@esri/telemetry", | ||
"version": "1.5.0", | ||
"version": "1.5.1-beta.0", | ||
"description": "A JavaScript Implementation of the ArcGIS Telemetry Specification", | ||
@@ -9,3 +9,4 @@ "main": "dist/telemetry.js", | ||
"lint": "standard src", | ||
"test": "tape test/**/*.spec.js | tap-spec" | ||
"test": "jest \".*\\.test\\.js\" --notify", | ||
"package": "npm build && npm publish --access public" | ||
}, | ||
@@ -24,3 +25,11 @@ "repository": { | ||
], | ||
"author": "Daniel Fenton <dfenton@esri.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Rich Gwozdz", | ||
"email": "rgwozdz@esri.com" | ||
}, | ||
{ | ||
"name": "Daniel Fenton" | ||
} | ||
], | ||
"license": "Apache-2.0", | ||
@@ -37,2 +46,3 @@ "bugs": { | ||
"babel-plugin-transform-es2015-function-name": "^6.24.1", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", | ||
"babel-plugin-transform-es2015-parameters": "^6.24.1", | ||
@@ -43,3 +53,6 @@ "babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-preset-stage-1": "^6.24.1", | ||
"cross-fetch": "^3.0.6", | ||
"del": "^2.2.2", | ||
"fetch-mock": "^9.11.0", | ||
"jest": "^26.6.3", | ||
"node-localstorage": "^1.3.0", | ||
@@ -46,0 +59,0 @@ "rollup": "^0.41.6", |
@@ -1,6 +0,11 @@ | ||
import request from '../request' | ||
import Storage from '../storage' | ||
import Storage from '../helpers/storage' | ||
const COGNITO_KEY = 'TELEMETRY_COGNITO_CREDENTIALS' | ||
const COGNITO_URL = 'https://cognito-identity.us-east-1.amazonaws.com/' | ||
const defaults = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1' | ||
} | ||
} | ||
@@ -11,35 +16,40 @@ export function getCredentials (IdentityPoolId, callback) { | ||
authWithCognito(IdentityPoolId, credentials => { | ||
Storage.set(COGNITO_KEY, credentials) | ||
callback(credentials) | ||
}) | ||
} | ||
const options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetId' | ||
}, | ||
body: JSON.stringify({ IdentityPoolId }) | ||
} | ||
function authWithCognito (IdentityPoolId, callback) { | ||
const options = Object.assign({}, defaults) | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetId' | ||
options.body = JSON.stringify({ IdentityPoolId }) | ||
request(options, response => { | ||
requestCredentials(JSON.parse(response), callback) | ||
}) | ||
return fetch(COGNITO_URL, options) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(response.statusText) | ||
} | ||
return response.json() | ||
}) | ||
.then((response) => { | ||
const { IdentityId } = response | ||
const options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity' | ||
}, | ||
body: JSON.stringify({ IdentityId }) | ||
} | ||
return fetch(COGNITO_URL, options) | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(response.statusText) | ||
} | ||
return response.json() | ||
}) | ||
.then(({ Credentials }) => { | ||
Storage.set(COGNITO_KEY, Credentials) | ||
return Credentials | ||
}) | ||
} | ||
function requestCredentials (json, callback) { | ||
const options = Object.assign({}, defaults) | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetCredentialsForIdentity' | ||
options.body = JSON.stringify({ IdentityId: json.IdentityId }) | ||
request(options, response => { | ||
const json = JSON.parse(response) | ||
callback(json.Credentials) | ||
}) | ||
} | ||
const defaults = { | ||
method: 'POST', | ||
url: COGNITO_URL, | ||
headers: { | ||
'Content-type': 'application/x-amz-json-1.1' | ||
} | ||
} |
import { getCredentials } from './auth' | ||
import { getUser } from './user' | ||
import AwsSigner from './signer' | ||
import request from '../request' | ||
import createEventLog from './create-event-log' | ||
import createPageView from './create-page-view-log' | ||
const METRICS = ['size', 'duration', 'position', 'number', 'count'] | ||
const DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events' | ||
@@ -14,81 +14,36 @@ | ||
const session = getUser().session | ||
if (session.new && !options.test) this.logEvent({ eventType: '_session.start' }) | ||
if (session.new && !options.test) { | ||
this.logEvent({ eventType: '_session.start' }) | ||
.catch(err => { | ||
console.error(`Failed to log _session.start: ${err.message}`) | ||
}) | ||
} | ||
} | ||
logPageView (page, options) { | ||
const event = createPageView(page, this.previousPage, options) | ||
sendTelemetry(event, this.userPoolID, this.app) | ||
this.previousPage = event.attributes | ||
const session = getUser().session | ||
const telemetryPayload = createPageView({ | ||
page, | ||
session, | ||
previousPage: this.previousPage, | ||
options, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}) | ||
this.previousPage = telemetryPayload.attributes | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app) | ||
} | ||
logEvent (event) { | ||
const events = createEventLog(event) | ||
sendTelemetry(events, this.userPoolID, this.app) | ||
const session = getUser().session | ||
const telemetryPayload = createEventLog({ | ||
event, | ||
session, | ||
dimensionLookup: this.dimensions, | ||
metricLookup: this.metrics | ||
}) | ||
return sendTelemetry(telemetryPayload, this.userPoolID, this.app) | ||
} | ||
} | ||
function createPageView (page, previousPage = {}, options = {}) { | ||
const session = getUser().session | ||
return { | ||
eventType: 'pageView', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
}, | ||
attributes: { | ||
referrer: document.referrer, | ||
hostname: window.location.hostname, | ||
path: page || window.location.pathname, | ||
pageUrl: page || window.location.pathname, | ||
pageName: document.title, | ||
previousPageUrl: previousPage.pageUrl, | ||
previousPageName: previousPage.pageName, | ||
...extractAttributes(options) | ||
}, | ||
metrics: extractMetrics(options) | ||
} | ||
} | ||
function createEventLog (event) { | ||
const session = getUser().session | ||
return { | ||
eventType: event.eventType || 'other', | ||
timestamp: new Date().toISOString(), | ||
session: { | ||
id: session.id, | ||
startTimestamp: session.startTimestamp | ||
}, | ||
attributes: { | ||
referrer: document.referrer, | ||
hostname: window.location.hostname, | ||
path: window.location.pathname, | ||
...extractAttributes(event) | ||
}, | ||
metrics: extractMetrics(event) | ||
} | ||
} | ||
function extractAttributes (event) { | ||
const attributes = Object.assign({}, event) | ||
delete attributes.workflow | ||
METRICS.forEach(metric => delete attributes[metric]) | ||
Object.keys(attributes).forEach(attr => { | ||
if (attr === 'json') { | ||
attributes[attr] = attributes[attr] ? JSON.stringify(attributes[attr]) : 'null' | ||
} else { | ||
attributes[attr] = attributes[attr] !== undefined ? attributes[attr].toString() : 'null' | ||
} | ||
}) | ||
return attributes | ||
} | ||
function extractMetrics (event) { | ||
const metrics = {} | ||
METRICS.forEach(metric => { | ||
if (event[metric]) metrics[metric] = event[metric] | ||
}) | ||
return metrics | ||
} | ||
function createHeaders (credentials = {}, options) { | ||
@@ -123,20 +78,26 @@ const config = { | ||
function sendTelemetry (events, userPoolID, app) { | ||
function sendTelemetry (events, userPoolID, app, url) { | ||
const user = getUser() | ||
events = Array.isArray(events) ? events : [events] | ||
const options = createTelemetryOptions(events) | ||
getCredentials(userPoolID, credentials => { | ||
try { | ||
options.headers = createHeaders(credentials, options) | ||
options.headers['x-amz-Client-Context'] = createClientContext(user.id, app) | ||
} catch (e) { | ||
console.error(e) | ||
return | ||
} | ||
request(options, response => { | ||
if (response) { | ||
console.error(JSON.parse(response)) | ||
return getCredentials(userPoolID) | ||
.then(credentials => { | ||
try { | ||
options.headers = createHeaders(credentials, options) | ||
options.headers['x-amz-Client-Context'] = createClientContext(user.id, app) | ||
} catch (e) { | ||
console.error(e) | ||
return | ||
} | ||
return fetch(DEFAULT_ENDPOINT, options) | ||
}) | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
return { success: true } | ||
} | ||
throw new Error(`Telemetry failed. ${response.status}, ${response.statusText}`) | ||
}) | ||
.catch(err => { | ||
console.error(err.message) | ||
}) | ||
} | ||
@@ -143,0 +104,0 @@ |
@@ -11,3 +11,3 @@ // | ||
import CryptoJS from '../crypto' | ||
import CryptoJS from '../helpers/crypto' | ||
@@ -202,10 +202,3 @@ var defaultConfig = { | ||
/** | ||
* Simple URI parser factory. | ||
* Uses an `a` document element for parsing given URIs. | ||
* Therefore it most likely will only work in a web browser. | ||
*/ | ||
function SimpleUriParser () { | ||
var parser = document ? document.createElement('a') : {} | ||
/** | ||
@@ -221,2 +214,3 @@ * Parse the given URI. | ||
return function (uri) { | ||
const parser = URL ? new URL(uri) : document.createElement('a') | ||
parser.href = uri | ||
@@ -230,12 +224,12 @@ return { | ||
} | ||
} | ||
function extractQueryParams (search) { | ||
return /^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg) | ||
if (arg) { | ||
result[arg[1]] = arg[2] | ||
} | ||
return result | ||
}, {}) | ||
} | ||
function extractQueryParams (search) { | ||
return /^\??(.*)$/.exec(search)[1].split('&').reduce(function (result, arg) { | ||
arg = /^(.+)=(.*)$/.exec(arg) | ||
if (arg) { | ||
result[arg[1]] = arg[2] | ||
} | ||
return result | ||
}, {}) | ||
} | ||
@@ -242,0 +236,0 @@ |
@@ -1,2 +0,2 @@ | ||
import Storage from '../storage' | ||
import Storage from '../helpers/storage' | ||
@@ -3,0 +3,0 @@ const SESSION_LENGTH = 30 * 60 * 1000 |
@@ -0,1 +1,3 @@ | ||
import mapCustomMetricsAndDimensions from './map-metrics-and-dimensions' | ||
export default class Google { | ||
@@ -35,5 +37,4 @@ constructor (options = {}) { | ||
} | ||
function buildPageViewObject (page, options, dimensions = {}, metrics = {}) { | ||
const pageviewObject = { | ||
const standardTelemetry = { | ||
hitType: 'pageview', | ||
@@ -43,29 +44,24 @@ page: page || window.location.pathname | ||
return mapMetricsAndDimensions(pageviewObject, options, dimensions, metrics) | ||
const mappedCustomTelemetryData = mapCustomMetricsAndDimensions({ | ||
customTelemetryData: options, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics | ||
}) | ||
return Object.assign({}, standardTelemetry, mappedCustomTelemetryData) | ||
} | ||
function buildEventObject (event, dimensions = {}, metrics = {}) { | ||
const eventObject = { | ||
const standardTelemetryData = { | ||
hitType: 'event', | ||
eventCategory: event.category || 'none', | ||
eventAction: event.action, | ||
eventLabel: event.label, | ||
nonInteraction: event.nonInteraction | ||
eventLabel: event.label | ||
} | ||
return mapMetricsAndDimensions(eventObject, event, dimensions, metrics) | ||
const mappedCustomTelemetryData = mapCustomMetricsAndDimensions({ | ||
customTelemetryData: event, | ||
dimensionLookup: dimensions, | ||
metricLookup: metrics }) | ||
return Object.assign({}, standardTelemetryData, mappedCustomTelemetryData) | ||
} | ||
function mapMetricsAndDimensions (inputObject, options, dimensions, metrics) { | ||
let mappedObject = inputObject | ||
Object.keys(dimensions).forEach(dimension => { | ||
mappedObject[`dimension${dimensions[dimension]}`] = options[dimension] | ||
}) | ||
Object.keys(metrics).forEach(metric => { | ||
mappedObject[`metric${metrics[metric]}`] = options[metric] | ||
}) | ||
return mappedObject | ||
} |
import Amazon from './amazon' | ||
import Google from './google' | ||
import anonymize from './anonymize' | ||
import internalOrgs from './internal-orgs' | ||
import telemetryEnabled from './telemetry-enabled' | ||
import storage from './storage' | ||
import anonymize from './helpers/anonymize' | ||
import internalOrgs from './helpers/internal-orgs' | ||
import telemetryEnabled from './helpers/telemetry-enabled' | ||
import storage from './helpers/storage' | ||
@@ -71,3 +71,3 @@ export default class Telemetry { | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes)) | ||
else if (this.test && !this.disabled) return attributes | ||
if (this.test && !this.disabled) return attributes | ||
@@ -77,12 +77,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false | ||
} else { | ||
this.trackers.forEach(tracker => { | ||
try { | ||
tracker.logPageView(page, attributes) | ||
} catch (e) { | ||
console.error(`${tracker.name} tracker failed to log page view.`, e) | ||
} | ||
}) | ||
return true | ||
} | ||
const promises = this.trackers.map(tracker => { | ||
return tracker.logPageView(page, attributes) | ||
}) | ||
Promise.all(promises).then() | ||
return true | ||
} | ||
@@ -94,3 +92,3 @@ | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event)) | ||
else if (this.test) return event | ||
if (this.test) return event | ||
@@ -100,12 +98,10 @@ if (!this.trackers.length || this.disabled) { | ||
return false | ||
} else { | ||
this.trackers.forEach(tracker => { | ||
try { | ||
tracker.logEvent(event) | ||
} catch (e) { | ||
console.error(`${tracker.name} tracker failed to log event`, e) | ||
} | ||
}) | ||
return true | ||
} | ||
const promises = this.trackers.map(tracker => { | ||
return tracker.logEvent(event) | ||
}) | ||
Promise.all(promises).then() | ||
return true | ||
} | ||
@@ -209,3 +205,3 @@ | ||
user: anonymize(this.user.username), | ||
orgId: anonymize(this.user.orgId), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
@@ -212,0 +208,0 @@ userSince: this.user.created, |
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
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
723196
47
25
5871
2
22