@aicore/core-analytics-client-lib 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics.min.js +3 -3
- package/dist/analytics.min.js.map +1 -1
- package/package.json +1 -1
- package/src/analytics.js +46 -22
package/dist/analytics.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function initAnalyticsSession(e,t,n,a,o,i){let s,
|
|
2
|
-
typically means that you may be sending too many value events? .`),
|
|
3
|
-
postIntervalSeconds:${c}, granularitySec: ${f} ,URL: `+d),E&&console.warn(`Core Analytics is disabled from the server for app: ${
|
|
1
|
+
function initAnalyticsSession(e,t,n,a,o,i){let r,s,l,u,c,f,d,y,v={};const g="aicore.analytics.userID",p="aicore.analytics.sessionID",O=1e4;let m=null;var h,w,b,J="undefined"==typeof window;let C="https://analytics.core.ai",I,S,D=0,E=!1,T=!1;function U(...e){T&&console.log("analytics client: ",...e)}function A(...e){T&&console.error("analytics client: ",...e)}if(J)throw new Error("Node environment is not currently supported");function N(){return{schemaVersion:1,accountID:r,appName:s,uuid:l,sessionID:u,unixTimestampUTC:+new Date,numEventsTotal:0,events:{}}}function $(){if(!m)throw new Error("Please call initSession before using any analytics event")}function k(e){e.backoffCount=(e.backoffCount||0)+1,U(`Failed to call core analytics server. Will retry in ${30*e.backoffCount}s: `),setTimeout(()=>{L(e)},3e4*e.backoffCount)}function P(t){var e,n=JSON.stringify(t);n.length>O&&console.warn(`Analytics event generated is very large at greater than ${n.length}B. This
|
|
2
|
+
typically means that you may be sending too many value events? .`),U("Sending Analytics data of length: ",n.length,"B"),e=["Sending data:",n],T&&window.analytics.debugInfoLogsEnable&&console.info("analytics client: ",...e),window.navigator.onLine?window.fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:n}).then(e=>{200!==e.status&&(400!==e.status?k(t):console.error("Bad Request, this is most likely a problem with the library, update to latest version."))}).catch(e=>{A(e),k(t)}):k(t)}function L(e){E||(e||(e=m,D=0,R(),m=N()),0!==e.numEventsTotal&&P(e))}function R(e){I&&(clearInterval(I),I=null),e||(I=setInterval(()=>{D+=f},1e3*f))}function _(e){R(e),S&&(clearInterval(S),S=null),e||(S=setInterval(L,1e3*c))}function B(n,a,o,i=1,r=0){if(!E){var s=n,l=a,u=o,c=i,f=r;if($(),!s||!l||!u)throw new Error("missing eventType or category or subCategory");if("number"!=typeof c||c<0)throw new Error("invalid count, count should be a positive number");if("number"!=typeof f)throw new Error("invalid value, value should be a number");{s=n;l=a;u=o;let e=m.events;e[s]=e[s]||{},e[s][l]=e[s][l]||{},e[s][l][u]=e[s][l][u]||{time:[],valueCount:[]}}let t=m.events;c=t[n][a][o].time;if((0<c.length?c[c.length-1]:null)===D){f=t[n][a][o].valueCount.length-1;{var s=f,l=n,u=a,c=o,f=i,d=r;let t=m.events;var e="number"==typeof t[l][u][c].valueCount[s];if(e&&0===d)t[l][u][c].valueCount[s]+=f;else if(e&&0!==d){let e={};e[d]=f,e[0]=t[l][u][c].valueCount[s],t[l][u][c].valueCount[s]=e}else if(!e){let e=t[l][u][c].valueCount[s];e[d]=(e[d]||0)+f}m.numEventsTotal+=1}}else{if(t[n][a][o].time.push(D),0===r)t[n][a][o].valueCount.push(i);else{let e={};e[r]=i,t[n][a][o].valueCount.push(e)}m.numEventsTotal+=1}}}if(!e||!t)throw new Error("accountID and appName must exist for init");d=n?n.toString().replace(/\/$/,""):C,r=e,s=t,T=i||!1,c=a||60,f=o||3,y=d+"/ingest",l=function(){let e=localStorage.getItem(g);return e||(e=crypto.randomUUID(),localStorage.setItem(g,e)),e}(),u=function(){let e=sessionStorage.getItem(p);return e||(e=Math.random().toString(36).substr(2,10),sessionStorage.setItem(p,e)),e}(),m=N(),_(),h=a,w=o,new Promise(t=>{var e;window.navigator.onLine?(e=d+(`/getAppConfig?accountID=${r}&appName=`+s),window.fetch(e).then(e=>{switch(e.status){case 200:return void e.json().then(e=>{t(e)}).catch(e=>{A("remote response invalid. Continuing with defaults.",e),t({})});case 400:A("Bad Request, check library version compatible?",e),t({});break;default:A("Could not update from remote config. Continuing with defaults.",e),t({})}}).catch(e=>{A("Could not update from remote config. Continuing with defaults.",e),t({})})):t({})}).then(e=>{v!=={}&&(v=e,c=h||v.postIntervalSecondsInit||60,f=w||v.granularitySecInit||3,d=v.analyticsURLInit||d||C,_(E=!0===v.disabled),U(`Init analytics Config from remote. disabled: ${E}
|
|
3
|
+
postIntervalSeconds:${c}, granularitySec: ${f} ,URL: `+d),E&&console.warn(`Core Analytics is disabled from the server for app: ${r}:`+s))});for(b of analytics._initData)B(...b);analytics._initData=[],analytics._getCurrentAnalyticsEvent=function(){return $(),JSON.parse(JSON.stringify(m))},analytics._getAppConfig=function(){return{accountID:r,appName:s,disabled:E,uuid:l,sessionID:u,postIntervalSeconds:c,granularitySec:f,analyticsURL:d,serverConfig:v}},analytics.event=B}window.analytics||(window.analytics={_initData:[]}),void 0===window.crypto&&(window.crypto={}),"randomUUID"in crypto||(crypto.randomUUID=function(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))});
|
|
4
4
|
//# sourceMappingURL=analytics.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sourceRoot":"src/analytics.js","sources":["src/analytics.js"],"names":["initAnalyticsSession","accountIDInit","appNameInit","analyticsURLInit","postIntervalSecondsInit","granularitySecInit","debug","let","accountID","appName","userID","sessionID","postIntervalSeconds","granularitySec","analyticsURL","postURL","serverConfig","USERID_LOCAL_STORAGE_KEY","SESSION_ID_LOCAL_STORAGE_KEY","POST_LARGE_DATA_THRESHOLD_BYTES","currentAnalyticsEvent","eventData","IS_NODE_ENV","window","DEFAULT_BASE_URL","granularityTimer","postTimer","currentQuantisedTime","disabled","debugMode","debugLog","args","console","log","debugError","error","Error","_createAnalyticsEvent","schemaVersion","uuid","unixTimestampUTC","Date","numEventsTotal","events","_validateCurrentState","_retryPost","eventToSend","backoffCount","setTimeout","_postCurrentAnalyticsEvent","DEFAULT_RETRY_TIME_IN_SECONDS","_postEventWithRetry","textToSend","JSON","stringify","length","warn","debugInfo","analytics","debugInfoLogsEnable","info","navigator","onLine","fetch","method","headers","Content-Type","body","then","res","status","catch","_resetGranularityTimer","disable","clearInterval","setInterval","_setupTimers","event","eventType","eventCategory","subCategory","eventCount","eventValue","_validateEvent","category","count","value","_ensureAnalyticsEventExists","time","valueCount","timeArray","modificationIndex","_updateExistingAnalyticsEvent","index","newValue","storedValueIsCount","newValueCount","storedValueObject","push","replace","localUserID","localStorage","getItem","crypto","randomUUID","setItem","_getOrCreateUserID","localSessionID","sessionStorage","Math","random","
|
|
1
|
+
{"version":3,"sourceRoot":"src/analytics.js","sources":["src/analytics.js"],"names":["initAnalyticsSession","accountIDInit","appNameInit","analyticsURLInit","postIntervalSecondsInit","granularitySecInit","debug","let","accountID","appName","userID","sessionID","postIntervalSeconds","granularitySec","analyticsURL","postURL","serverConfig","USERID_LOCAL_STORAGE_KEY","SESSION_ID_LOCAL_STORAGE_KEY","POST_LARGE_DATA_THRESHOLD_BYTES","currentAnalyticsEvent","postIntervalSecondsInitial","granularitySecInitial","eventData","IS_NODE_ENV","window","DEFAULT_BASE_URL","granularityTimer","postTimer","currentQuantisedTime","disabled","debugMode","debugLog","args","console","log","debugError","error","Error","_createAnalyticsEvent","schemaVersion","uuid","unixTimestampUTC","Date","numEventsTotal","events","_validateCurrentState","_retryPost","eventToSend","backoffCount","setTimeout","_postCurrentAnalyticsEvent","DEFAULT_RETRY_TIME_IN_SECONDS","_postEventWithRetry","textToSend","JSON","stringify","length","warn","debugInfo","analytics","debugInfoLogsEnable","info","navigator","onLine","fetch","method","headers","Content-Type","body","then","res","status","catch","_resetGranularityTimer","disable","clearInterval","setInterval","_setupTimers","event","eventType","eventCategory","subCategory","eventCount","eventValue","_validateEvent","category","count","value","_ensureAnalyticsEventExists","time","valueCount","timeArray","modificationIndex","_updateExistingAnalyticsEvent","index","newValue","storedValueIsCount","newValueCount","storedValueObject","push","toString","replace","localUserID","localStorage","getItem","crypto","randomUUID","setItem","_getOrCreateUserID","localSessionID","sessionStorage","Math","random","substr","_getOrCreateSessionID","Promise","configURL","json","serverResponse","resolve","err","updatedServerConfig","_initData","_getCurrentAnalyticsEvent","parse","_getAppConfig","c","getRandomValues","Uint8Array"],"mappings":"AAwCA,SAASA,qBAAqBC,EAAeC,EAAaC,EACtDC,EAAyBC,EAAoBC,GAC7CC,IAAIC,EAAWC,EAASC,EAAQC,EAAWC,EACvCC,EAAgBC,EAAcC,EAASC,EAAa,GACxD,MAGMC,EAA2B,0BAC3BC,EAA+B,6BAC/BC,EAAkC,IACxCZ,IAAIa,EAAwB,KAC5B,IAmN+BC,EAA4BC,EAyHnDC,EA5UFC,EAAiC,oBAAXC,OAC5BlB,IAAImB,EAAmB,4BAEnBC,EACAC,EACAC,EAAuB,EACvBC,GAAW,EACXC,GAAY,EAEhB,SAASC,KAAYC,GACbF,GAGJG,QAAQC,IAAI,wBAAyBF,GASzC,SAASG,KAAcH,GACfF,GAGJG,QAAQG,MAAM,wBAAyBJ,GAI3C,GAAGT,EACC,MAAM,IAAIc,MAAM,+CAGpB,SAASC,IACL,MAAO,CACHC,cAAe,EACfhC,UAAWA,EACXC,QAASA,EACTgC,KAAM/B,EACNC,UAAWA,EACX+B,kBAAmB,IAAIC,KACvBC,eAAgB,EAChBC,OAAQ,IAIhB,SAASC,IACL,IAAI1B,EACA,MAAM,IAAIkB,MAAM,4DAiCxB,SAASS,EAAWC,GAChBA,EAAYC,cAAgBD,EAAYC,cAAgB,GAAK,EAC7DjB,yDA1FkC,GA2FEgB,EAAYC,mBAChDC,WAAW,KACPC,EAA2BH,IAC5BI,IAAuCJ,EAAYC,cAG1D,SAASI,EAAoBL,GACzBzC,IA5EkB0B,EA4EdqB,EAAaC,KAAKC,UAAUR,GAC7BM,EAAWG,OAAStC,GACnBe,QAAQwB,gEAAgE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Q,MA4CGlD,KAAKoD,IACjB1G,IAAiB,KAChBA,EAAe0G,EAEf9G,EAAsBS,GAClBL,EAAsC,yBA9NhB,GA+N1BH,EAAiBS,GAAyBN,EAAiC,oBAjOhD,EAmO3BF,EAAeE,EAA+B,kBAAKF,GAAgBY,EAEnEoD,EADAhD,GAAwC,IAA7Bd,EAAuB,UAElCgB,kDAAyDF;8BAC3ClB,sBAAwCC,WAAwBC,GAC3EgB,GACCI,QAAQwB,4DAA4DlD,KAAaC,MA0GjG,IAAQc,KAAaqC,UAAU+D,UAC3B5C,KAASxD,GAEbqC,UAAU+D,UAAY,GAGtB/D,UAAUgE,0BA7RV,WAGI,OAFA9E,IAEOS,KAAKsE,MAAMtE,KAAKC,UAAUpC,KA2RrCwC,UAAUkE,cAxIV,WACI,MAAO,CACHtH,UAAAA,EAAWC,QAAAA,EAASqB,SAAAA,EACpBW,KAAM/B,EAAQC,UAAAA,EACdC,oBAAAA,EAAqBC,eAAAA,EAAgBC,aAAAA,EAAcE,aAAAA,IAuI3D4C,UAAUmB,MAAQA,EAnYlBtD,OAAOmC,YACPnC,OAAOmC,UAAY,CACf+D,UAAW,UAIU,IAAlBlG,OAAOiF,SACdjF,OAAOiF,OAAS,IAGd,eAAgBA,SAGlBA,OAAOC,WAAa,WAChB,OACI,CAAC,MAAM,KAAK,KAAK,KAAK,MAAML,QAAQ,SAEpCyB,IAAMA,EAAIrB,OAAOsB,gBAAgB,IAAIC,WAAW,IAAI,GAAK,IAAMF,EAAI,GAAG1B,SAAS"}
|
package/package.json
CHANGED
package/src/analytics.js
CHANGED
|
@@ -10,6 +10,22 @@ if(!window.analytics){
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
if (typeof window.crypto === 'undefined'){
|
|
14
|
+
window.crypto = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!('randomUUID' in crypto)){
|
|
18
|
+
// https://stackoverflow.com/a/2117523/2800218
|
|
19
|
+
// LICENSE: https://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
20
|
+
crypto.randomUUID = function randomUUID() {
|
|
21
|
+
return (
|
|
22
|
+
[1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,
|
|
23
|
+
// eslint-disable-next-line no-bitwise
|
|
24
|
+
c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
/**
|
|
14
30
|
* Initialize the analytics session
|
|
15
31
|
* @param accountIDInit Your analytics account id as configured in the server or core.ai analytics
|
|
@@ -198,7 +214,7 @@ function initAnalyticsSession(accountIDInit, appNameInit, analyticsURLInit,
|
|
|
198
214
|
postTimer = setInterval(_postCurrentAnalyticsEvent, postIntervalSeconds*1000);
|
|
199
215
|
}
|
|
200
216
|
|
|
201
|
-
|
|
217
|
+
function _getServerConfig() {
|
|
202
218
|
return new Promise((resolve)=>{
|
|
203
219
|
if(!window.navigator.onLine){
|
|
204
220
|
resolve({});
|
|
@@ -207,11 +223,15 @@ function initAnalyticsSession(accountIDInit, appNameInit, analyticsURLInit,
|
|
|
207
223
|
return;
|
|
208
224
|
}
|
|
209
225
|
let configURL = analyticsURL + `/getAppConfig?accountID=${accountID}&appName=${appName}`;
|
|
210
|
-
window.fetch(configURL).then(
|
|
226
|
+
window.fetch(configURL).then(res=>{
|
|
211
227
|
switch (res.status) {
|
|
212
228
|
case 200:
|
|
213
|
-
|
|
214
|
-
|
|
229
|
+
res.json().then(serverResponse =>{
|
|
230
|
+
resolve(serverResponse);
|
|
231
|
+
}).catch(err => {
|
|
232
|
+
debugError("remote response invalid. Continuing with defaults.", err);
|
|
233
|
+
resolve({});
|
|
234
|
+
});
|
|
215
235
|
return;
|
|
216
236
|
case 400:
|
|
217
237
|
debugError("Bad Request, check library version compatible?", res);
|
|
@@ -240,27 +260,29 @@ function initAnalyticsSession(accountIDInit, appNameInit, analyticsURLInit,
|
|
|
240
260
|
};
|
|
241
261
|
}
|
|
242
262
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
263
|
+
function _initFromRemoteConfig(postIntervalSecondsInitial, granularitySecInitial) {
|
|
264
|
+
_getServerConfig().then(updatedServerConfig =>{
|
|
265
|
+
if(serverConfig !== {}){
|
|
266
|
+
serverConfig = updatedServerConfig;
|
|
267
|
+
// User init overrides takes precedence over server overrides
|
|
268
|
+
postIntervalSeconds = postIntervalSecondsInitial ||
|
|
269
|
+
serverConfig["postIntervalSecondsInit"] || DEFAULT_POST_INTERVAL_SECONDS;
|
|
270
|
+
granularitySec = granularitySecInitial || serverConfig["granularitySecInit"] || DEFAULT_GRANULARITY_IN_SECONDS;
|
|
271
|
+
// For URLs, the server suggested URL takes precedence over user init values
|
|
272
|
+
analyticsURL = serverConfig["analyticsURLInit"] || analyticsURL || DEFAULT_BASE_URL;
|
|
273
|
+
disabled = serverConfig["disabled"] === true;
|
|
274
|
+
_setupTimers(disabled);
|
|
275
|
+
debugLog(`Init analytics Config from remote. disabled: ${disabled}
|
|
255
276
|
postIntervalSeconds:${postIntervalSeconds}, granularitySec: ${granularitySec} ,URL: ${analyticsURL}`);
|
|
256
|
-
|
|
257
|
-
|
|
277
|
+
if(disabled){
|
|
278
|
+
console.warn(`Core Analytics is disabled from the server for app: ${accountID}:${appName}`);
|
|
279
|
+
}
|
|
258
280
|
}
|
|
259
|
-
}
|
|
281
|
+
});
|
|
260
282
|
}
|
|
261
283
|
|
|
262
284
|
function _stripTrailingSlash(url) {
|
|
263
|
-
return url.replace(/\/$/, "");
|
|
285
|
+
return url.toString().replace(/\/$/, "");
|
|
264
286
|
}
|
|
265
287
|
|
|
266
288
|
function _ensureAnalyticsEventExists(eventType, category, subCategory) {
|
|
@@ -268,8 +290,10 @@ function initAnalyticsSession(accountIDInit, appNameInit, analyticsURLInit,
|
|
|
268
290
|
events[eventType] = events[eventType] || {};
|
|
269
291
|
events[eventType][category] = events[eventType][category] || {};
|
|
270
292
|
events[eventType][category][subCategory] = events[eventType][category][subCategory] || {
|
|
271
|
-
|
|
272
|
-
|
|
293
|
+
// quantised time
|
|
294
|
+
time: [],
|
|
295
|
+
// value and count array, If a single value, then it is count, else object {"val1":count1, ...}
|
|
296
|
+
valueCount: []
|
|
273
297
|
};
|
|
274
298
|
}
|
|
275
299
|
|