@esri/telemetry
Advanced tools
Comparing version 1.1.0 to 1.1.1
64
build.js
@@ -15,3 +15,3 @@ 'use strict' | ||
ext: '.js', | ||
plugins: [], | ||
plugins: [] | ||
}, | ||
@@ -21,8 +21,20 @@ { | ||
ext: '.min.js', | ||
plugins: [uglify()], | ||
plugins: [uglify()] | ||
}, | ||
{ | ||
dojo: true, | ||
format: 'amd', | ||
ext: '.dojo.js', | ||
plugins: [] | ||
}, | ||
{ | ||
dojo: true, | ||
format: 'amd', | ||
ext: '.dojo.min.js', | ||
plugins: [uglify()] | ||
}, | ||
{ | ||
format: 'amd', | ||
ext: '.amd.js', | ||
plugins: [], | ||
plugins: [] | ||
}, | ||
@@ -32,7 +44,6 @@ { | ||
ext: '.amd.min.js', | ||
plugins: [uglify()], | ||
plugins: [uglify()] | ||
} | ||
] | ||
let promise = Promise.resolve() | ||
@@ -45,24 +56,25 @@ | ||
for (const config of bundles) { | ||
promise = promise.then(() => rollup.rollup({ | ||
entry: 'src/index.js', | ||
plugins: [ | ||
includePaths({paths: ['src/amazon', 'src/google']}), | ||
babel({ | ||
exclude: 'node_modules/**', | ||
presets: ['es2015-rollup', 'stage-1'], | ||
plugins:[ | ||
'transform-object-assign', | ||
'transform-es2015-destructuring', | ||
'transform-es2015-function-name', | ||
'transform-es2015-parameters' | ||
] | ||
promise = promise.then(() => | ||
rollup | ||
.rollup({ | ||
entry: 'src/index.js', | ||
plugins: [ | ||
includePaths({ paths: ['src/amazon', 'src/google'] }), | ||
babel({ | ||
exclude: 'node_modules/**', | ||
presets: ['es2015-rollup', 'stage-1'], | ||
plugins: ['transform-object-assign', 'transform-es2015-destructuring', 'transform-es2015-function-name', 'transform-es2015-parameters'] | ||
}) | ||
].concat(config.plugins) | ||
}) | ||
].concat(config.plugins) | ||
}).then(bundle => bundle.write({ | ||
dest: `dist/telemetry${config.ext}`, | ||
format: config.format, | ||
sourceMap: !config.minify, | ||
moduleName: 'Telemetry', | ||
moduleId: 'telemetry' | ||
}))) | ||
.then(bundle => | ||
bundle.write({ | ||
dest: `dist/telemetry${config.ext}`, | ||
format: config.format, | ||
sourceMap: !config.minify, | ||
moduleName: 'Telemetry', | ||
moduleId: config.dojo ? undefined : 'telemetry' | ||
}) | ||
) | ||
) | ||
} | ||
@@ -69,0 +81,0 @@ |
@@ -7,2 +7,18 @@ # Change Log | ||
## Unreleased | ||
### Added | ||
* Debug mode to log events to console | ||
* User will be automatically added if Telemetry is initialized with `{user: user}`. | ||
* Telemetry.user can also be set at any time | ||
* Additional attributes can be tracked along with any workflow event | ||
### Changed | ||
* Position is logged as a metric | ||
### Fixed | ||
* Log session start correctly | ||
* Workflows do not throw error if steps are logged before start | ||
* Disabled flag works | ||
* Use in-memory storage when local storage is unavailable | ||
## [1.1.0] - 06/05/2017 | ||
@@ -9,0 +25,0 @@ ### Added |
{ | ||
"name": "@esri/telemetry", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A JavaScript Implementation of the ArcGIS Telemetry Specification", | ||
@@ -5,0 +5,0 @@ "main": "dist/telemetry.js", |
@@ -18,2 +18,24 @@ define('telemetry', function () { 'use strict'; | ||
var Storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = window.localStorage.getItem(key) || this.storage[key]; | ||
if (stored) return JSON.parse(stored);else return undefined; | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
value = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, value); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
} | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
@@ -83,8 +105,7 @@ return typeof obj; | ||
function getCredentials(IdentityPoolId, callback) { | ||
var cached = window.localStorage.getItem(COGNITO_KEY); | ||
if (cached) cached = JSON.parse(cached); | ||
var cached = Storage.get(COGNITO_KEY); | ||
if (cached && Date.now() / 1000 < cached.Expiration) return callback(cached); | ||
authWithCognito(IdentityPoolId, function (credentials) { | ||
window.localStorage.setItem(COGNITO_KEY, JSON.stringify(credentials)); | ||
Storage.set(COGNITO_KEY, credentials); | ||
callback(credentials); | ||
@@ -135,10 +156,5 @@ }); | ||
function getSession() { | ||
var session = void 0; | ||
var newSession = void 0; | ||
var cached = window.localStorage.getItem(SESSION_KEY); | ||
if (cached) { | ||
cached = JSON.parse(cached); | ||
if (Date.now() < cached.expiration) session = cached; | ||
} | ||
if (!session) { | ||
var session = Storage.get(SESSION_KEY); | ||
if (!session || Date.now() > session.expiration) { | ||
newSession = true; | ||
@@ -148,3 +164,3 @@ session = generateNewSession(); | ||
session.expiration = Date.now() + SESSION_LENGTH; | ||
window.localStorage.setItem(SESSION_KEY, JSON.stringify(session)); | ||
Storage.set(SESSION_KEY, session); | ||
if (newSession) session.new = true; | ||
@@ -155,6 +171,6 @@ return session; | ||
function getClientID() { | ||
var id = window.localStorage.getItem(CLIENT_KEY); | ||
var id = Storage.get(CLIENT_KEY); | ||
if (!id) { | ||
id = generateNewClientID(); | ||
window.localStorage.setItem(CLIENT_KEY, id); | ||
Storage.set(CLIENT_KEY, id); | ||
} | ||
@@ -375,15 +391,14 @@ return id; | ||
hasherFactory: CryptoJSHasher | ||
/** | ||
* Create a new signer object with the given configuration. | ||
* Configuration must specify the AWS credentials used for the signing operation. | ||
* It must contain the following properties: | ||
* `accessKeyId`: The AWS IAM access key ID. | ||
* `secretAccessKey`: The AWS IAM secret key. | ||
* `sessionToken`: Optional session token, required for temporary credentials. | ||
* @param {object} config The configuration object. | ||
* @constructor | ||
*/ | ||
}; | ||
/** | ||
* Create a new signer object with the given configuration. | ||
* Configuration must specify the AWS credentials used for the signing operation. | ||
* It must contain the following properties: | ||
* `accessKeyId`: The AWS IAM access key ID. | ||
* `secretAccessKey`: The AWS IAM secret key. | ||
* `sessionToken`: Optional session token, required for temporary credentials. | ||
* @param {object} config The configuration object. | ||
* @constructor | ||
*/ | ||
var AwsSigner = function () { | ||
@@ -454,5 +469,4 @@ function AwsSigner(config) { | ||
'x-amz-date': amzDate(ws.signDate) | ||
}; | ||
// Payload or not? | ||
ws.request.method = ws.request.method.toUpperCase(); | ||
// Payload or not? | ||
};ws.request.method = ws.request.method.toUpperCase(); | ||
if (ws.request.body) { | ||
@@ -657,3 +671,3 @@ ws.payload = ws.request.body; | ||
var METRICS = ['size', 'duration']; | ||
var METRICS = ['size', 'duration', 'position']; | ||
var DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events'; | ||
@@ -668,3 +682,3 @@ | ||
var session = getUser().session; | ||
if (session.new) this.logEvent({ category: '_session.start' }); | ||
if (session.new) this.logEvent({ eventType: '_session.start' }); | ||
} | ||
@@ -731,3 +745,7 @@ | ||
Object.keys(attributes).forEach(function (attr) { | ||
attributes[attr] = attributes[attr] ? attributes[attr].toString() : 'null'; | ||
if (attr === 'json') { | ||
attributes[attr] = attributes[attr] ? JSON.stringify(attributes[attr]) : 'null'; | ||
} else { | ||
attributes[attr] = attributes[attr] ? attributes[attr].toString() : 'null'; | ||
} | ||
}); | ||
@@ -875,2 +893,5 @@ return attributes; | ||
this.workflows = {}; | ||
this.debug = options.debug; | ||
this.user = options.user; | ||
this.disabled = options.disabled; | ||
if (options.amazon) { | ||
@@ -895,2 +916,3 @@ var amazon = new Amazon(options.amazon); | ||
var attributes = preProcess(options); | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes)); | ||
if (!this.trackers.length || this.disabled) { | ||
@@ -912,4 +934,7 @@ if (!this.disabled) console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
key: 'logEvent', | ||
value: function logEvent(options) { | ||
value: function logEvent() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var event = preProcess(options); | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event)); | ||
if (!this.trackers.length || this.disabled) { | ||
@@ -932,3 +957,5 @@ if (!this.disabled) console.error(new Error('Event was not logged because no trackers are configured.')); | ||
value: function startWorkflow(name) { | ||
this.workflows[name] = { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflow = { | ||
name: name, | ||
@@ -938,8 +965,15 @@ start: Date.now(), | ||
}; | ||
this._logWorkflow({ name: name, step: 'start' }); | ||
this.workflows[name] = workflow; | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step, details) { | ||
this._logWorkflow({ name: name, step: step, details: details }); | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var details = typeof options === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
@@ -949,3 +983,6 @@ }, { | ||
value: function endWorkflow(name) { | ||
this._logWorkflow({ name: name, step: 'finish' }); | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
delete this.workflows[name]; | ||
@@ -956,3 +993,6 @@ } | ||
value: function cancelWorkflow(name) { | ||
this._logWorkflow({ name: name, step: 'cancel' }); | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
delete this.workflows[name]; | ||
@@ -962,3 +1002,5 @@ } | ||
key: '_logWorkflow', | ||
value: function _logWorkflow(options) { | ||
value: function _logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/* | ||
@@ -974,3 +1016,3 @@ const workflow = { | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.startWorkflow(options.name); | ||
} | ||
@@ -981,3 +1023,3 @@ | ||
var track = { | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
@@ -987,5 +1029,5 @@ category: options.name, | ||
label: options.details, | ||
user: options.user, | ||
user: options.user || this.user, | ||
duration: workflow.duration | ||
}; | ||
}); | ||
@@ -998,3 +1040,5 @@ this.logEvent(track); | ||
function preProcess(options) { | ||
function preProcess() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var attributes = _extends({}, options); | ||
@@ -1001,0 +1045,0 @@ if (attributes.user) { |
@@ -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=window.localStorage.getItem(j);if(r&&(r=JSON.parse(r)),r&&Date.now()/1e3<r.Expiration)return t(r);n(e,function(e){window.localStorage.setItem(j,JSON.stringify(e)),t(e)})}function n(t,n){var i=P({},D);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=P({},D);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=void 0,n=window.localStorage.getItem(K);return n&&(n=JSON.parse(n),Date.now()<n.expiration&&(e=n)),e||(t=!0,e=a()),e.expiration=Date.now()+W,window.localStorage.setItem(K,JSON.stringify(e)),t&&(e.new=!0),e}function s(){var e=window.localStorage.getItem(N);return e||(e=c(),window.localStorage.setItem(N,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 f(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":g(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=m(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"===q(t.request.params)&&m(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 l(e,t){t.credentialScope=[g(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+g(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,g(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 p(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function g(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 w(){return{hash:function(e,t){t=m({hexOutput:!0,textInput:!0},t);var n=M.SHA256(e);return t.hexOutput?n.toString(M.enc.Hex):n},hmac:function(e,t,n){n=m({hexOutput:!0,textInput:!0},n);var r=M.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(M.enc.Hex):r}}}function m(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":q(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":q(r))?(e[n]=Array.isArray(r)?[]:{},m(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=i().session;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:t.id,startTimestamp:t.startTimestamp},attributes:{referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname||e},metrics:{}}}function _(e){var t=i().session;return{eventType:e.eventType||"other",timestamp:(new Date).toISOString(),session:{id:t.id,startTimestamp:t.startTimestamp},attributes:P({referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname},b(e)),metrics:A(e)}}function b(e){var t=P({},e);return delete t.workflow,J.forEach(function(e){return delete t[e]}),Object.keys(t).forEach(function(e){t[e]=t[e]?t[e].toString():"null"}),t}function A(e){var t={};return J.forEach(function(n){t[n]=e[n]}),t}function I(e,t){var n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new L(n).sign(t)}function x(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=E(n);t(r,function(t){a.headers=I(t,a),a.headers["x-amz-Client-Context"]=x(s.id,o),e(a,function(e){e&&console.error(JSON.parse(e))})})}function E(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:F,method:"POST",body:JSON.stringify({events:e})}}function z(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function T(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};return Object.keys(t).forEach(function(n){r["dimension"+t[n]]=e[n]}),Object.keys(n).forEach(function(t){r["metric"+n[t]]=e[t]}),r}function H(e){var t=P({},e);return t.user&&(t.user=V(t.user)),t}var q="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},C=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}}(),P=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",D={method:"POST",url:"https://cognito-identity.us-east-1.amazonaws.com/",headers:{"Content-type":"application/x-amz-json-1.1"}},W=18e5,K="TELEMETRY_SESSION",N="TELEMETRY_CLIENT_ID",M=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)}},f=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=f.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 l.HMAC.init(e,n).finalize(t)}}});var l=n.algo={};return n}(Math);!function(e){for(var t=M,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 f;e:{f=c;for(var h=e.sqrt(f),l=2;l<=h;l++)if(!(f%l)){f=!1;break e}f=!0}f&&(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],f=n[6],h=n[7],l=0;l<64;l++){if(l<16)d[l]=0|e[t+l];else{var p=d[l-15],g=d[l-2];d[l]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[l-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+d[l-16]}p=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&f)+s[l]+d[l],g=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),h=f,f=u,u=c,c=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]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+f|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=M,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 R={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:y,uriParserFactory:v,hasherFactory:w},L=function(){function e(t){C(this,e),this.config=m({},R,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:m({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return f(this,n),h(this,n),l(this,n),d(this,n),p(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"],F="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",U=function(){function e(t){C(this,e),this.name="amazon",P(this,t),i().session.new&&this.logEvent({category:"_session.start"})}return B(e,[{key:"logPageView",value:function(e){O(k(e),this.userPoolID,this.app)}},{key:"logEvent",value:function(e){O(_(e),this.userPoolID,this.app)}}]),e}(),$=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};C(this,e),this.name="google",P(this,t)}return B(e,[{key:"logPageView",value:function(e){z(function(t){t.forEach(function(t){t.send("pageview",e||window.location.pathname)})})}},{key:"logEvent",value:function(e){var t=T(e,this.dimensions,this.metrics);z(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),V=function(e){return M.SHA256(e).toString(M.enc.Hex)};return function(){function e(t){if(C(this,e),this.trackers=[],this.workflows={},t.amazon){var n=new U(t.amazon);this.trackers.push(n)}if(t.google){var r=new $(t.google);this.trackers.push(r)}this.trackers.length||console.error(new Error("No trackers configured"))}return B(e,[{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=H(t);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(e){var t=H(e);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:"startWorkflow",value:function(e){this.workflows[e]={name:e,start:Date.now(),steps:[]},this._logWorkflow({name:e,step:"start"})}},{key:"stepWorkflow",value:function(e,t,n){this._logWorkflow({name:e,step:t,details:n})}},{key:"endWorkflow",value:function(e){this._logWorkflow({name:e,step:"finish"}),delete this.workflows[e]}},{key:"cancelWorkflow",value:function(e){this._logWorkflow({name:e,step:"cancel"}),delete this.workflows[e]}},{key:"_logWorkflow",value:function(e){e=H(e);var t=this.workflows[e.name];t||this.startWorkflow(e.name),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3;var n={eventType:"workflow",category:e.name,action:e.step,label:e.details,user:e.user,duration:t.duration};this.logEvent(n)}}]),e}()}); | ||
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(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({},W);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({},W);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(K);return(!t||Date.now()>t.expiration)&&(e=!0,t=a()),t.expiration=Date.now()+N,q.set(K,t),e&&(t.new=!0),t}function s(){var e=q.get(M);return e||(e=c(),q.set(M,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 h(e,t){var n={host:t.uri.host,"content-type":e.config.defaultContentType,accept:e.config.defaultAcceptType,"x-amz-date":g(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"===C(t.request.params)&&w(t.uri.queryParams,t.request.params)}function f(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 l(e,t){t.credentialScope=[g(t.signDate,!0),e.config.region,e.config.service,"aws4_request"].join("/"),t.stringToSign="AWS4-HMAC-SHA256\n"+g(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,g(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 p(e,t){t.authorization="AWS4-HMAC-SHA256 Credential="+e.config.accessKeyId+"/"+t.credentialScope+", SignedHeaders="+t.signedHeaders+", Signature="+t.signature}function g(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=R.SHA256(e);return t.hexOutput?n.toString(R.enc.Hex):n},hmac:function(e,t,n){n=w({hexOutput:!0,textInput:!0},n);var r=R.HmacSHA256(t,e,{asBytes:!0});return n.hexOutput?r.toString(R.enc.Hex):r}}}function w(e){return[].slice.call(arguments,1).forEach(function(t){t&&"object"===(void 0===t?"undefined":C(t))&&Object.keys(t).forEach(function(n){var r=t[n];void 0!==r&&(null!==r&&"object"===(void 0===r?"undefined":C(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=i().session;return{eventType:"pageView",timestamp:(new Date).toISOString(),session:{id:t.id,startTimestamp:t.startTimestamp},attributes:{referrer:document.referrer,hostname:window.location.hostname,path:window.location.pathname||e},metrics:{}}}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:A(e)}}function _(e){var t=j({},e);return delete t.workflow,F.forEach(function(e){return delete t[e]}),Object.keys(t).forEach(function(e){t[e]="json"===e?t[e]?JSON.stringify(t[e]):"null":t[e]?t[e].toString():"null"}),t}function A(e){var t={};return F.forEach(function(n){t[n]=e[n]}),t}function x(e,t){var n={region:"us-east-1",service:"mobileanalytics",accessKeyId:e.AccessKeyId,secretAccessKey:e.SecretKey,sessionToken:e.SessionToken};return new L(n).sign(t)}function O(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 E(n,r,o){var s=i();n=Array.isArray(n)?n:[n];var a=I(n);t(r,function(t){a.headers=x(t,a),a.headers["x-amz-Client-Context"]=O(s.id,o),e(a,function(e){e&&console.error(JSON.parse(e))})})}function I(e){return{url:arguments.length>1&&void 0!==arguments[1]?arguments[1]:U,method:"POST",body:JSON.stringify({events:e})}}function T(e){window.ga?window.ga(function(){e(window.ga.getAll())}):console.log(new Error("Google Analytics trackers not available"))}function z(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};return Object.keys(t).forEach(function(n){r["dimension"+t[n]]=e[n]}),Object.keys(n).forEach(function(t){r["metric"+n[t]]=e[t]}),r}function H(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=j({},e);return t.user&&(t.user=G(t.user)),t}var q={storage:{},memory:!0,get:function(e){var t=window.localStorage.getItem(e)||this.storage[e];return t?JSON.parse(t):void 0},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}}},C="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},B=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},P=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",W={method:"POST",url:"https://cognito-identity.us-east-1.amazonaws.com/",headers:{"Content-type":"application/x-amz-json-1.1"}},N=18e5,K="TELEMETRY_SESSION",M="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||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)}},h=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)))}},f=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.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=f.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.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 l.HMAC.init(e,n).finalize(t)}}});var l=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},c=2,u=0;u<64;){var h;e:{h=c;for(var f=e.sqrt(h),l=2;l<=f;l++)if(!(h%l)){h=!1;break e}h=!0}h&&(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],h=n[6],f=n[7],l=0;l<64;l++){if(l<16)d[l]=0|e[t+l];else{var p=d[l-15],g=d[l-2];d[l]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[l-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+d[l-16]}p=f+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&h)+s[l]+d[l],g=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&i^r&o^i&o),f=h,h=u,u=c,c=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]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+h|0,n[7]=n[7]+f|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,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 J={region:"eu-west-1",service:"execute-api",defaultContentType:"application/json",defaultAcceptType:"application/json",payloadSerializerFactory:y,uriParserFactory:v,hasherFactory:m},L=function(){function e(t){B(this,e),this.config=w({},J,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 P(e,[{key:"sign",value:function(e,t){var n={request:w({},e),signDate:t||new Date,uri:this.uriParser(e.url)};return h(this,n),f(this,n),l(this,n),d(this,n),p(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}(),F=["size","duration","position"],U="https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events",$=function(){function e(t){B(this,e),this.name="amazon",j(this,t),i().session.new&&this.logEvent({eventType:"_session.start"})}return P(e,[{key:"logPageView",value:function(e){E(k(e),this.userPoolID,this.app)}},{key:"logEvent",value:function(e){E(b(e),this.userPoolID,this.app)}}]),e}(),V=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};B(this,e),this.name="google",j(this,t)}return P(e,[{key:"logPageView",value:function(e){T(function(t){t.forEach(function(t){t.send("pageview",e||window.location.pathname)})})}},{key:"logEvent",value:function(e){var t=z(e,this.dimensions,this.metrics);T(function(e){e.forEach(function(e){e.send(t)})})}}]),e}(),G=function(e){return R.SHA256(e).toString(R.enc.Hex)};return function(){function e(t){if(B(this,e),this.trackers=[],this.workflows={},this.debug=t.debug,this.user=t.user,this.disabled=t.disabled,t.amazon){var n=new $(t.amazon);this.trackers.push(n)}if(t.google){var r=new V(t.google);this.trackers.push(r)}this.trackers.length||console.error(new Error("No trackers configured"))}return P(e,[{key:"logPageView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=H(t);return this.debug&&console.log("Tracking page view",JSON.stringify(n)),!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=H(e);return this.debug&&console.log("Tracking event",JSON.stringify(t)),!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:"startWorkflow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={name:e,start:Date.now(),steps:[]};this.workflows[e]=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),delete this.workflows[e]}},{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),delete this.workflows[e]}},{key:"_logWorkflow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=H(e);var t=this.workflows[e.name];t||(t=this.startWorkflow(e.name)),t.steps.push(e.step),t.duration=(Date.now()-t.start)/1e3;var n=j(e,{eventType:"workflow",category:e.name,action:e.step,label:e.details,user:e.user||this.user,duration:t.duration});this.logEvent(n)}}]),e}()}); | ||
//# sourceMappingURL=telemetry.amd.min.js.map |
{ | ||
"name": "@esri/telemetry", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A JavaScript Implementation of the ArcGIS Telemetry Specification", | ||
@@ -5,0 +5,0 @@ "main": "dist/telemetry.js", |
@@ -51,26 +51,27 @@ # Telemetry.js | ||
### `telemetry.startWorkflow(name)` | ||
### `telemetry.startWorkflow(name, [attributes])` | ||
```js | ||
telemetry.startWorkflow('add layer') | ||
telemetry.startWorkflow('add layer', {details: 'from search'}) | ||
``` | ||
### `telemetry.stepWorkflow(name, step, details)` | ||
### `telemetry.stepWorkflow(name, step, [attributes])` | ||
```js | ||
telemetry.stepWorkflow('add layer', 'search', 'street trees') | ||
telemetry.stepWorkflow('add layer', 'search', {details: 'street trees'}) | ||
``` | ||
### `telemetry.cancelWorkflow(name, [details])` | ||
### `telemetry.cancelWorkflow(name, [attributes])` | ||
```js | ||
telemetry.cancelWorkflow('add layer') | ||
telemetry.cancelWorkflow('search', 'back to home') | ||
telemetry.cancelWorkflow('search', {details: 'back to home'}) | ||
``` | ||
### `telemetry.endWorkflow(name, [details])` | ||
### `telemetry.endWorkflow(name, [attributes])` | ||
```js | ||
telemetry.endWorkflow('add layer') | ||
telemetry.endWorkflow('add layer', 'pasadena street trees') | ||
telemetry.endWorkflow('add layer', {details: 'pasadena street trees'}) | ||
``` | ||
@@ -114,2 +115,4 @@ | ||
- Debug mode: If `debug` is set to `true` events and page views will be logged to the console | ||
- Amazon | ||
@@ -164,7 +167,5 @@ - Request your app and user pool ID from (TBD) | ||
1. Support Workflows. | ||
- E.g. tracking the flow of finding and adding a layer to a webmap | ||
2. Support Processes | ||
1. Support Processes | ||
- E.g. time and track the process of geocoding 100 addresses | ||
3. Send events in batches | ||
2. Send events in batches | ||
- Use fewer HTTP calls and improve performance by sending near-simultaneous events in groups | ||
@@ -171,0 +172,0 @@ |
import request from '../request' | ||
import Storage from '../storage' | ||
const COGNITO_KEY = 'TELEMETRY_COGNITO_CREDENTIALS' | ||
@@ -6,8 +8,7 @@ const COGNITO_URL = 'https://cognito-identity.us-east-1.amazonaws.com/' | ||
export function getCredentials (IdentityPoolId, callback) { | ||
let cached = window.localStorage.getItem(COGNITO_KEY) | ||
if (cached) cached = JSON.parse(cached) | ||
if (cached && (Date.now() / 1000 < cached.Expiration)) return callback(cached) | ||
let cached = Storage.get(COGNITO_KEY) | ||
if (cached && Date.now() / 1000 < cached.Expiration) return callback(cached) | ||
authWithCognito(IdentityPoolId, credentials => { | ||
window.localStorage.setItem(COGNITO_KEY, JSON.stringify(credentials)) | ||
Storage.set(COGNITO_KEY, credentials) | ||
callback(credentials) | ||
@@ -27,6 +28,6 @@ }) | ||
function requestCredentials (json, callback) { | ||
function requestCredentials (json, callback) { | ||
const options = Object.assign({}, defaults) | ||
options.headers['X-Amz-Target'] = 'AWSCognitoIdentityService.GetCredentialsForIdentity' | ||
options.body = JSON.stringify({IdentityId: json.IdentityId}) | ||
options.body = JSON.stringify({ IdentityId: json.IdentityId }) | ||
@@ -33,0 +34,0 @@ request(options, response => { |
@@ -6,3 +6,3 @@ import { getCredentials } from './auth' | ||
const METRICS = ['size', 'duration'] | ||
const METRICS = ['size', 'duration', 'position'] | ||
const DEFAULT_ENDPOINT = 'https://mobileanalytics.us-east-1.amazonaws.com/2014-06-05/events' | ||
@@ -15,3 +15,3 @@ | ||
const session = getUser().session | ||
if (session.new) this.logEvent({ category: '_session.start' }) | ||
if (session.new) this.logEvent({ eventType: '_session.start' }) | ||
} | ||
@@ -72,3 +72,7 @@ | ||
Object.keys(attributes).forEach(attr => { | ||
attributes[attr] = attributes[attr] ? attributes[attr].toString() : 'null' | ||
if (attr === 'json') { | ||
attributes[attr] = attributes[attr] ? JSON.stringify(attributes[attr]) : 'null' | ||
} else { | ||
attributes[attr] = attributes[attr] ? attributes[attr].toString() : 'null' | ||
} | ||
}) | ||
@@ -75,0 +79,0 @@ return attributes |
@@ -0,1 +1,3 @@ | ||
import Storage from '../storage' | ||
const SESSION_LENGTH = 30 * 60 * 1000 | ||
@@ -13,10 +15,5 @@ const SESSION_KEY = 'TELEMETRY_SESSION' | ||
function getSession () { | ||
let session | ||
let newSession | ||
let cached = window.localStorage.getItem(SESSION_KEY) | ||
if (cached) { | ||
cached = JSON.parse(cached) | ||
if (Date.now() < cached.expiration) session = cached | ||
} | ||
if (!session) { | ||
let session = Storage.get(SESSION_KEY) | ||
if (!session || Date.now() > session.expiration) { | ||
newSession = true | ||
@@ -26,3 +23,3 @@ session = generateNewSession() | ||
session.expiration = Date.now() + SESSION_LENGTH | ||
window.localStorage.setItem(SESSION_KEY, JSON.stringify(session)) | ||
Storage.set(SESSION_KEY, session) | ||
if (newSession) session.new = true | ||
@@ -33,6 +30,6 @@ return session | ||
function getClientID () { | ||
let id = window.localStorage.getItem(CLIENT_KEY) | ||
let id = Storage.get(CLIENT_KEY) | ||
if (!id) { | ||
id = generateNewClientID() | ||
window.localStorage.setItem(CLIENT_KEY, id) | ||
Storage.set(CLIENT_KEY, id) | ||
} | ||
@@ -70,5 +67,3 @@ return id | ||
function s4 () { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1) | ||
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1) | ||
} |
@@ -9,2 +9,5 @@ import Amazon from './amazon' | ||
this.workflows = {} | ||
this.debug = options.debug | ||
this.user = options.user | ||
this.disabled = options.disabled | ||
if (options.amazon) { | ||
@@ -25,2 +28,3 @@ const amazon = new Amazon(options.amazon) | ||
const attributes = preProcess(options) | ||
if (this.debug) console.log('Tracking page view', JSON.stringify(attributes)) | ||
if (!this.trackers.length || this.disabled) { | ||
@@ -41,4 +45,5 @@ if (!this.disabled) console.error(new Error('Page view was not logged because no trackers are configured.')) | ||
logEvent (options) { | ||
logEvent (options = {}) { | ||
const event = preProcess(options) | ||
if (this.debug) console.log('Tracking event', JSON.stringify(event)) | ||
if (!this.trackers.length || this.disabled) { | ||
@@ -59,4 +64,4 @@ if (!this.disabled) console.error(new Error('Event was not logged because no trackers are configured.')) | ||
startWorkflow (name) { | ||
this.workflows[name] = { | ||
startWorkflow (name, attributes = {}) { | ||
const workflow = { | ||
name, | ||
@@ -66,20 +71,27 @@ start: Date.now(), | ||
} | ||
this._logWorkflow({ name, step: 'start' }) | ||
this.workflows[name] = workflow | ||
const workflowObj = Object.assign({ name, step: 'start' }, attributes) | ||
this._logWorkflow(workflowObj) | ||
return workflow | ||
} | ||
stepWorkflow (name, step, details) { | ||
this._logWorkflow({ name, step, details }) | ||
stepWorkflow (name, step, attributes = {}) { | ||
const details = typeof options === 'string' ? attributes : attributes.details | ||
const workflowObj = Object.assign({ name, step, details }, attributes) | ||
this._logWorkflow(workflowObj) | ||
} | ||
endWorkflow (name) { | ||
this._logWorkflow({ name, step: 'finish' }) | ||
endWorkflow (name, attributes = {}) { | ||
const workflowObj = Object.assign({ name, step: 'finish' }, attributes) | ||
this._logWorkflow(workflowObj) | ||
delete this.workflows[name] | ||
} | ||
cancelWorkflow (name) { | ||
this._logWorkflow({ name, step: 'cancel' }) | ||
cancelWorkflow (name, attributes = {}) { | ||
const workflowObj = Object.assign({ name, step: 'cancel' }, attributes) | ||
this._logWorkflow(workflowObj) | ||
delete this.workflows[name] | ||
} | ||
_logWorkflow (options) { | ||
_logWorkflow (options = {}) { | ||
/* | ||
@@ -95,3 +107,3 @@ const workflow = { | ||
if (!workflow) { | ||
this.startWorkflow(options.name) | ||
workflow = this.startWorkflow(options.name) | ||
} | ||
@@ -102,3 +114,3 @@ | ||
const track = { | ||
const track = Object.assign(options, { | ||
eventType: 'workflow', | ||
@@ -108,5 +120,5 @@ category: options.name, | ||
label: options.details, | ||
user: options.user, | ||
user: options.user || this.user, | ||
duration: workflow.duration | ||
} | ||
}) | ||
@@ -117,3 +129,3 @@ this.logEvent(track) | ||
function preProcess (options) { | ||
function preProcess (options = {}) { | ||
const attributes = Object.assign({}, options) | ||
@@ -120,0 +132,0 @@ if (attributes.user) { |
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
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
648638
37
3936
176
1