kv-test-lib 1.0.4 → 1.0.6

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.
@@ -3,19 +3,16 @@
3
3
  Copyright (c) Kochava, Inc. All rights reserved.
4
4
  */
5
5
  export const getPackageName = () => `com.${window.location.hostname}.web`;
6
- export const getLanguage = () => (navigator) ? navigator.language : "";
7
- export const getDeviceWidth = () => (window) ? window.screen.availWidth : 0;
8
- export const getDeviceHeight = () => (window) ? window.screen.availHeight : 0;
9
- export const getDeviceOrientation = () => (window) ? window.innerWidth < window.innerHeight
10
- ? "portrait" : "landscape" : "";
6
+ export const getLanguage = () => navigator ? navigator.language : "";
7
+ export const getDeviceWidth = () => window ? window.screen.availWidth : 0;
8
+ export const getDeviceHeight = () => window ? window.screen.availHeight : 0;
9
+ export const getDeviceOrientation = () => window ? window.innerWidth < window.innerHeight ? "portrait" : "landscape" : "";
11
10
  export const getBaseDomain = () => {
12
11
  try {
13
12
  const regexResult = window.location.host.match(/[^.]*\.[^.]*$/);
14
- if (regexResult)
15
- return regexResult[0];
13
+ if (regexResult) return regexResult[0];
16
14
  return "";
17
- }
18
- catch (err) {
15
+ } catch (err) {
19
16
  return window.location.host;
20
17
  }
21
18
  };
@@ -27,14 +24,12 @@ export const getPageName = () => {
27
24
  }
28
25
  return page === "" ? "/" : page;
29
26
  };
30
- export const getUrlParameter = (name) => {
27
+ export const getUrlParameter = name => {
31
28
  if (!window.location || !window.location.search) {
32
29
  return "";
33
30
  }
34
31
  name = name.replace(/[[]/, "\\[").replace(/[\]]/, "\\]");
35
32
  const regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
36
33
  const results = regex.exec(window.location.search);
37
- return results === null
38
- ? ""
39
- : decodeURIComponent(results[1].replace(/\+/g, " "));
40
- };
34
+ return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
35
+ };
@@ -8,33 +8,22 @@ export const setCookie = (name, value) => {
8
8
  const date = new Date();
9
9
  date.setTime(date.getTime() + 3650 * 24 * 60 * 60 * 1000);
10
10
  expires = `; expires=${date.toUTCString()}`;
11
- document.cookie =
12
- name +
13
- "=" +
14
- (value || "") +
15
- expires +
16
- "; path=/;domain=" +
17
- getBaseDomain();
11
+ document.cookie = name + "=" + (value || "") + expires + "; path=/;domain=" + getBaseDomain();
18
12
  };
19
- export const getCookie = (name) => {
13
+ export const getCookie = name => {
20
14
  const nameEQ = name + "=";
21
15
  const charArray = document.cookie.split(';');
22
16
  for (let i = 0; i < charArray.length; i++) {
23
17
  let char = charArray[i];
24
- while (char.charAt(0) === " ")
25
- char = char.substring(1, char.length);
26
- if (char.indexOf(nameEQ) === 0)
27
- return char.substring(nameEQ.length, char.length);
18
+ while (char.charAt(0) === " ") char = char.substring(1, char.length);
19
+ if (char.indexOf(nameEQ) === 0) return char.substring(nameEQ.length, char.length);
28
20
  }
29
21
  return "";
30
22
  };
31
- export const deleteCookie = (name) => {
23
+ export const deleteCookie = name => {
32
24
  if (getCookie(name)) {
33
25
  const path = "/";
34
26
  const domain = getBaseDomain();
35
- document.cookie = name + "=" +
36
- ((path) ? ";path=" + path : "") +
37
- ((domain) ? ";domain=" + domain : "") +
38
- ";expires=Thu, 01 Jan 1970 00:00:01 GMT";
27
+ document.cookie = name + "=" + (path ? ";path=" + path : "") + (domain ? ";domain=" + domain : "") + ";expires=Thu, 01 Jan 1970 00:00:01 GMT";
39
28
  }
40
- };
29
+ };
@@ -23,45 +23,30 @@ export var PersistKey;
23
23
  PersistKey["OverrideDeviceId"] = "com.kochava.tracker.OverrideDeviceId";
24
24
  PersistKey["OldKvid"] = "kv_id";
25
25
  })(PersistKey || (PersistKey = {}));
26
- const storedKeys = [
27
- PersistKey.LastKvinit,
28
- PersistKey.EventQueue,
29
- PersistKey.IdLinkQueue,
30
- PersistKey.DeviceId,
31
- PersistKey.InstallId,
32
- PersistKey.FirstStartDate,
33
- PersistKey.InstallSentDate,
34
- PersistKey.KvinitSentDate,
35
- PersistKey.SessionCount,
36
- PersistKey.IdentityLinks,
37
- PersistKey.OverrideAppId,
38
- PersistKey.OverrideDeviceId,
39
- ];
26
+ const storedKeys = [PersistKey.LastKvinit, PersistKey.EventQueue, PersistKey.IdLinkQueue, PersistKey.DeviceId, PersistKey.InstallId, PersistKey.FirstStartDate, PersistKey.InstallSentDate, PersistKey.KvinitSentDate, PersistKey.SessionCount, PersistKey.IdentityLinks, PersistKey.OverrideAppId, PersistKey.OverrideDeviceId];
40
27
  export const checkInstallIdChange = (inputId, useCookies) => {
41
28
  const persistedInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, useCookies);
42
29
  // if the input is empty, we don't need to change
43
- if (!inputId)
44
- return false;
30
+ if (!inputId) return false;
45
31
  // if the persistedId is empty, we will need to change
46
32
  if (!persistedInstallId) {
47
33
  updatePersistedValue(PersistKey.InstallId, inputId, useCookies);
48
34
  return true;
49
35
  }
50
36
  // if the inputId and persistedId are the same, we dont need to change
51
- if (inputId === persistedInstallId)
52
- return false;
37
+ if (inputId === persistedInstallId) return false;
53
38
  // at this point both inputId and persistedInstallId exist and are not equal,
54
39
  // so we must need to change
55
40
  updatePersistedValue(PersistKey.InstallId, inputId, useCookies);
56
41
  return true;
57
42
  };
58
- export const addToPersistedEventQueue = (job) => {
43
+ export const addToPersistedEventQueue = job => {
59
44
  const persistedQueueStr = localStorage.getItem(PersistKey.EventQueue);
60
45
  const persistedQueue = JSON.parse(persistedQueueStr) || [];
61
46
  persistedQueue.push(job);
62
47
  localStorage.setItem(PersistKey.EventQueue, JSON.stringify(persistedQueue));
63
48
  };
64
- export const removeFromEventPersistedQueue = (job) => {
49
+ export const removeFromEventPersistedQueue = job => {
65
50
  const persistedQueueStr = localStorage.getItem(PersistKey.EventQueue);
66
51
  const persistedQueue = JSON.parse(persistedQueueStr) || [];
67
52
  const queueWithJobRemoved = persistedQueue.filter(persistedJob => {
@@ -69,7 +54,7 @@ export const removeFromEventPersistedQueue = (job) => {
69
54
  });
70
55
  localStorage.setItem(PersistKey.EventQueue, JSON.stringify(queueWithJobRemoved));
71
56
  };
72
- export const updateOrAddPersistedIdLinkQueue = (job) => {
57
+ export const updateOrAddPersistedIdLinkQueue = job => {
73
58
  const idLinkKey = Object.keys(job.idLink)[0];
74
59
  const persistedQueueStr = localStorage.getItem(PersistKey.IdLinkQueue);
75
60
  const persistedQueue = JSON.parse(persistedQueueStr) || [];
@@ -83,11 +68,10 @@ export const updateOrAddPersistedIdLinkQueue = (job) => {
83
68
  }
84
69
  }
85
70
  // if the key is new, add it
86
- if (!updated)
87
- persistedQueue.push(job);
71
+ if (!updated) persistedQueue.push(job);
88
72
  localStorage.setItem(PersistKey.IdLinkQueue, JSON.stringify(persistedQueue));
89
73
  };
90
- export const removeFromIdLinkPersistedQueue = (job) => {
74
+ export const removeFromIdLinkPersistedQueue = job => {
91
75
  const persistedQueueStr = localStorage.getItem(PersistKey.IdLinkQueue);
92
76
  const persistedQueue = JSON.parse(persistedQueueStr) || [];
93
77
  const queueWithJobRemoved = persistedQueue.filter(persistedJob => {
@@ -130,51 +114,39 @@ export const readAndUpdateUTM = (appGuid, useCookies) => {
130
114
  const urlValue = getUrlParameter("ko_click_id");
131
115
  const storageValue = localStorage.getItem(storageName);
132
116
  let cookieValue = "";
133
- if (useCookies)
134
- cookieValue = getCookie(storageName);
117
+ if (useCookies) cookieValue = getCookie(storageName);
135
118
  if (urlValue) {
136
119
  localStorage.setItem(storageName, urlValue);
137
- if (useCookies)
138
- setCookie(storageName, urlValue);
120
+ if (useCookies) setCookie(storageName, urlValue);
121
+ } else if (storageValue) {
122
+ if (useCookies) setCookie(storageName, urlValue);
139
123
  }
140
- else if (storageValue) {
141
- if (useCookies)
142
- setCookie(storageName, urlValue);
143
- }
144
- return (urlValue) ? urlValue :
145
- (storageValue) ? storageValue :
146
- (cookieValue) ? cookieValue : "";
124
+ return urlValue ? urlValue : storageValue ? storageValue : cookieValue ? cookieValue : "";
147
125
  };
148
126
  export const readAndUpdatePersistedValue = (key, useCookie) => {
149
127
  const urlValue = getUrlParameter(key);
150
128
  const storageValue = localStorage.getItem(key);
151
129
  let cookieValue = "";
152
- if (useCookie)
153
- cookieValue = getCookie(key);
130
+ if (useCookie) cookieValue = getCookie(key);
154
131
  if (urlValue) {
155
132
  updatePersistedValue(key, urlValue, useCookie);
156
- }
157
- else if (storageValue) {
133
+ } else if (storageValue) {
158
134
  updatePersistedValue(key, storageValue, useCookie);
159
- }
160
- else if (cookieValue) {
135
+ } else if (cookieValue) {
161
136
  updatePersistedValue(key, storageValue, useCookie);
162
137
  }
163
- return (urlValue) ? urlValue :
164
- (storageValue) ? storageValue :
165
- (cookieValue) ? cookieValue : "";
138
+ return urlValue ? urlValue : storageValue ? storageValue : cookieValue ? cookieValue : "";
166
139
  };
167
140
  export const updatePersistedValue = (key, value, useCookie) => {
168
141
  localStorage.setItem(key, value);
169
- if (useCookie)
170
- setCookie(key, value);
142
+ if (useCookie) setCookie(key, value);
171
143
  };
172
- export const deletePersistedValue = (item) => {
144
+ export const deletePersistedValue = item => {
173
145
  localStorage.removeItem(item);
174
146
  deleteCookie(item);
175
147
  };
176
148
  export const deleteAllPersisted = () => storedKeys.forEach(item => deletePersistedValue(item));
177
- export const readAndUpdateDeviceId = (useCookie) => {
149
+ export const readAndUpdateDeviceId = useCookie => {
178
150
  let storedDeviceId = readAndUpdatePersistedValue(PersistKey.DeviceId, useCookie);
179
151
  if (!storedDeviceId) {
180
152
  const kvId = `KB${utils.getCurrTimeSec()}T${utils.uuidv4()}`;
@@ -183,7 +155,7 @@ export const readAndUpdateDeviceId = (useCookie) => {
183
155
  updatePersistedValue(PersistKey.DeviceId, storedDeviceId, useCookie);
184
156
  return storedDeviceId;
185
157
  };
186
- export const readAndUpdateSessionCount = (useCookie) => {
158
+ export const readAndUpdateSessionCount = useCookie => {
187
159
  const storedSessionCount = readAndUpdatePersistedValue(PersistKey.SessionCount, useCookie);
188
160
  let sessionCount = 1;
189
161
  if (storedSessionCount) {
@@ -192,4 +164,4 @@ export const readAndUpdateSessionCount = (useCookie) => {
192
164
  }
193
165
  updatePersistedValue(PersistKey.SessionCount, sessionCount.toString(), useCookie);
194
166
  return sessionCount;
195
- };
167
+ };
package/dist/http.js CHANGED
@@ -12,13 +12,12 @@ export const sendRequest = async (payload, endpoint) => {
12
12
  const resp = await fetch(endpoint, {
13
13
  method: "POST",
14
14
  headers: headers,
15
- body: JSON.stringify(payload),
15
+ body: JSON.stringify(payload)
16
16
  });
17
17
  return await resp.text();
18
- }
19
- catch (e) {
18
+ } catch (e) {
20
19
  Log.error("Error in post request", e);
21
20
  return "";
22
21
  }
23
22
  };
24
- export const wasRespSuccess = (success) => success === "1" || success === 1 || success === true;
23
+ export const wasRespSuccess = success => success === "1" || success === 1 || success === true;
@@ -7,16 +7,16 @@ export const DEFAULTS = {
7
7
  // DO NOT DEFAULT
8
8
  app_id_override: "",
9
9
  // DO NOT DEFAULT
10
- device_id_override: "",
10
+ device_id_override: ""
11
11
  },
12
12
  config: {
13
13
  init_token: "",
14
- refresh_minimum: 60,
14
+ refresh_minimum: 60
15
15
  },
16
16
  install: {
17
17
  // DO NOT DEFAULT
18
18
  resend_id: "",
19
- updates_enabled: true,
19
+ updates_enabled: true
20
20
  },
21
21
  networking: {
22
22
  urls: {
@@ -25,12 +25,12 @@ export const DEFAULTS = {
25
25
  event: "https://web-sdk.control.kochava.com/track/json/",
26
26
  identityLink: "https://web-sdk.control.kochava.com/track/json/"
27
27
  },
28
- retry_waterfall: [7, 30, 300, 1800],
28
+ retry_waterfall: [7, 30, 300, 1800]
29
29
  },
30
30
  privacy: {
31
31
  allow_custom_ids: [],
32
32
  deny_datapoints: [],
33
33
  deny_event_names: [],
34
- deny_identity_links: [],
35
- },
36
- };
34
+ deny_identity_links: []
35
+ }
36
+ };
package/dist/jobqueue.js CHANGED
@@ -34,8 +34,7 @@ export default class JobQueue {
34
34
  }
35
35
  stop() {
36
36
  this.stopped = true;
37
- if (this.timeOut)
38
- clearTimeout(this.timeOut);
37
+ if (this.timeOut) clearTimeout(this.timeOut);
39
38
  this.processing = false;
40
39
  }
41
40
  pause() {
@@ -53,7 +52,7 @@ export default class JobQueue {
53
52
  preStartBody: eventPreStartBody,
54
53
  postStartBody,
55
54
  retries: 0,
56
- eventName,
55
+ eventName
57
56
  };
58
57
  this.eventQueue.push(newJob);
59
58
  addToPersistedEventQueue(newJob);
@@ -66,7 +65,7 @@ export default class JobQueue {
66
65
  preStartBody: eventPreStartBody,
67
66
  postStartBody: undefined,
68
67
  retries: 0,
69
- eventName,
68
+ eventName
70
69
  };
71
70
  this.eventQueue.push(newEventJob);
72
71
  addToPersistedEventQueue(newEventJob);
@@ -81,7 +80,7 @@ export default class JobQueue {
81
80
  preStartBody: idLinkPreStartBody,
82
81
  postStartBody,
83
82
  retries: 0,
84
- idLink,
83
+ idLink
85
84
  };
86
85
  updateOrAddPersistedIdLinkQueue(newJob);
87
86
  this.idLinkQueue.push(newJob);
@@ -94,18 +93,16 @@ export default class JobQueue {
94
93
  preStartBody: idLinkPreStartBody,
95
94
  postStartBody: undefined,
96
95
  retries: 0,
97
- idLink,
96
+ idLink
98
97
  };
99
98
  updateOrAddPersistedIdLinkQueue(newJob);
100
99
  this.idLinkQueue.push(newJob);
101
100
  }
102
101
  async dequeueJob(instance) {
103
102
  // If queue is busy, prev job not finished
104
- if (this.processing)
105
- return false;
103
+ if (this.processing) return false;
106
104
  // If the queue is paused, do not dequeue a new job
107
- if (this.paused)
108
- return false;
105
+ if (this.paused) return false;
109
106
  // If the queue is stopped do not dequeue a new job
110
107
  if (this.stopped) {
111
108
  return false;
@@ -146,8 +143,7 @@ export default class JobQueue {
146
143
  }
147
144
  }
148
145
  // If neither queue had a job, break out of recursion
149
- if (!idLinkJob && !eventJob)
150
- return false;
146
+ if (!idLinkJob && !eventJob) return false;
151
147
  return true;
152
148
  }
153
149
  async processJob(instance, job) {
@@ -158,8 +154,7 @@ export default class JobQueue {
158
154
  return true;
159
155
  }
160
156
  }
161
- }
162
- else if (jobIsIdLinkJob(job)) {
157
+ } else if (jobIsIdLinkJob(job)) {
163
158
  for (const denyIdLinkKey of instance.kochavaConfig.privacy.deny_identity_links) {
164
159
  if (denyIdLinkKey === Object.keys(job.idLink)[0]) {
165
160
  Log.debug(`Denied identity_link ${denyIdLinkKey}, dropping request.`);
@@ -180,8 +175,7 @@ export default class JobQueue {
180
175
  if (!this.stopped) {
181
176
  //retry the job
182
177
  const retryWaterfall = instance.kochavaConfig.networking.retry_waterfall;
183
- const retryIndex = (job.retries > retryWaterfall.length - 1) ?
184
- retryWaterfall.length - 1 : job.retries;
178
+ const retryIndex = job.retries > retryWaterfall.length - 1 ? retryWaterfall.length - 1 : job.retries;
185
179
  const retrySec = retryWaterfall[retryIndex];
186
180
  Log.error(`Job failed, attempting again in ${retrySec} seconds`);
187
181
  await new Promise(resolve => this.timeOut = setTimeout(resolve, retrySec * 1000));
@@ -192,11 +186,7 @@ export default class JobQueue {
192
186
  return true;
193
187
  }
194
188
  async attemptJob(instance, job) {
195
- if (job.preStartBody.action === "event")
196
- return await Event.send(instance, job.preStartBody, job.postStartBody);
197
- else if (job.preStartBody.action === "identityLink")
198
- return await IdLink.send(instance, job);
199
- else {
189
+ if (job.preStartBody.action === "event") return await Event.send(instance, job.preStartBody, job.postStartBody);else if (job.preStartBody.action === "identityLink") return await IdLink.send(instance, job);else {
200
190
  Log.warn("Invalid action in job from jobqueue, cancelling.");
201
191
  return true;
202
192
  }
@@ -217,4 +207,4 @@ export default class JobQueue {
217
207
  }
218
208
  updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.idLinkQueue), false);
219
209
  }
220
- }
210
+ }
package/dist/kochava.js CHANGED
@@ -9,8 +9,8 @@ import { Log } from "./utils/log";
9
9
  import JobQueue from "./jobqueue";
10
10
  import * as Kvinit from "./payloads/kvinit";
11
11
  import * as Install from "./payloads/install";
12
- import { DEFAULTS, } from "./interfaces";
13
- import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM, } from "./browser/persist";
12
+ import { DEFAULTS } from "./interfaces";
13
+ import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM } from "./browser/persist";
14
14
  import * as utils from "./utils/utils";
15
15
  import { getPageName } from "./browser/browser";
16
16
  // NOTE: Update this with new releases.
@@ -82,8 +82,7 @@ export class Kochava {
82
82
  Log.error(`Invalid appGuid ${appGuid}, start failed.`);
83
83
  return;
84
84
  }
85
- if (!this.instance)
86
- this.resetInstance();
85
+ if (!this.instance) this.resetInstance();
87
86
  if (this.instance.started) {
88
87
  Log.warn("Kochava SDK already started.");
89
88
  return;
@@ -92,8 +91,7 @@ export class Kochava {
92
91
  this.instance.started = true;
93
92
  this.checkFirstLaunchAndMigrate();
94
93
  this.initInstance(appGuid);
95
- if (!this.instance.disableAutoPage)
96
- this.sendPageEvent();
94
+ if (!this.instance.disableAutoPage) this.sendPageEvent();
97
95
  this.checkPersistedState();
98
96
  this.checkPersistedKvinit();
99
97
  this.printStartupMsgs(appGuid);
@@ -148,8 +146,7 @@ export class Kochava {
148
146
  case "wrapper":
149
147
  {
150
148
  const wrapperVersion = JSON.parse(valueStr);
151
- if (!this.instance.version)
152
- this.instance.version = "WebTracker " + SDK_VERSION;
149
+ if (!this.instance.version) this.instance.version = "WebTracker " + SDK_VERSION;
153
150
  switch (wrapperVersion.name) {
154
151
  case "Angular":
155
152
  this.instance.version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
@@ -163,37 +160,27 @@ export class Kochava {
163
160
  case "urls":
164
161
  {
165
162
  const overrideUrls = JSON.parse(valueStr);
166
- if (overrideUrls.init)
167
- this.instance.overrideUrls.init = overrideUrls.init;
168
- if (overrideUrls.event)
169
- this.instance.overrideUrls.event = overrideUrls.event;
170
- if (overrideUrls.install)
171
- this.instance.overrideUrls.install = overrideUrls.install;
172
- if (overrideUrls.identityLink)
173
- this.instance.overrideUrls.identityLink = overrideUrls.identityLink;
163
+ if (overrideUrls.init) this.instance.overrideUrls.init = overrideUrls.init;
164
+ if (overrideUrls.event) this.instance.overrideUrls.event = overrideUrls.event;
165
+ if (overrideUrls.install) this.instance.overrideUrls.install = overrideUrls.install;
166
+ if (overrideUrls.identityLink) this.instance.overrideUrls.identityLink = overrideUrls.identityLink;
174
167
  }
175
168
  break;
176
169
  case "urlsRestore":
177
170
  {
178
171
  const restoreUrls = JSON.parse(valueStr);
179
172
  for (const url of restoreUrls) {
180
- if (url === "init")
181
- this.instance.overrideUrls.init = DEFAULTS.networking.urls.init;
182
- if (url === "event")
183
- this.instance.overrideUrls.event = DEFAULTS.networking.urls.event;
184
- if (url === "install")
185
- this.instance.overrideUrls.install =
186
- DEFAULTS.networking.urls.install;
187
- if (url === "identityLink")
188
- this.instance.overrideUrls.identityLink =
189
- DEFAULTS.networking.urls.identityLink;
173
+ if (url === "init") this.instance.overrideUrls.init = DEFAULTS.networking.urls.init;
174
+ if (url === "event") this.instance.overrideUrls.event = DEFAULTS.networking.urls.event;
175
+ if (url === "install") this.instance.overrideUrls.install = DEFAULTS.networking.urls.install;
176
+ if (url === "identityLink") this.instance.overrideUrls.identityLink = DEFAULTS.networking.urls.identityLink;
190
177
  }
191
178
  }
192
179
  break;
193
180
  case "logFilter":
194
181
  {
195
182
  const disabled = JSON.parse(valueStr);
196
- disabled.forEach((level) => Log.disableLogType(level));
183
+ disabled.forEach(level => Log.disableLogType(level));
197
184
  }
198
185
  break;
199
186
  case "getInstance":
@@ -226,10 +213,7 @@ export class Kochava {
226
213
  Wraps the sendEvent call with predefined data specific to page events.
227
214
  */
228
215
  sendPageEvent(pageName, additionalData) {
229
- if (pageName)
230
- this.sendEvent("page", Object.assign({ page_name: pageName }, additionalData));
231
- else
232
- this.sendEvent("page", Object.assign({ page_name: getPageName() }, additionalData));
216
+ if (pageName) this.sendEvent("page", Object.assign({ page_name: pageName }, additionalData));else this.sendEvent("page", Object.assign({ page_name: getPageName() }, additionalData));
233
217
  }
234
218
  /*
235
219
  - Registers new identity links with the sdk, either to be sent out with
@@ -294,10 +278,7 @@ export class Kochava {
294
278
  */
295
279
  getDeviceId() {
296
280
  Log.diagDebug(`Host called API: Get Kochava Device Id`);
297
- if (this.instance.started)
298
- return this.instance.kochavaDeviceId;
299
- else
300
- return "";
281
+ if (this.instance.started) return this.instance.kochavaDeviceId;else return "";
301
282
  }
302
283
  /*
303
284
  Puts the sdk in a "sleep" state. This will stop the sdk from dequeuing
@@ -310,8 +291,7 @@ export class Kochava {
310
291
  // only pause if it was running
311
292
  this.instance.sleep = sleep;
312
293
  this.jobQueue.pause();
313
- }
314
- else if (!sleep && this.instance.sleep) {
294
+ } else if (!sleep && this.instance.sleep) {
315
295
  // only resume queueing if it was paused
316
296
  this.instance.sleep = sleep;
317
297
  this.beginStart();
@@ -336,7 +316,7 @@ export class Kochava {
336
316
  init: "",
337
317
  install: "",
338
318
  event: "",
339
- identityLink: "",
319
+ identityLink: ""
340
320
  },
341
321
  customValues: [],
342
322
  kochavaSession: "",
@@ -347,7 +327,7 @@ export class Kochava {
347
327
  kochavaInstallId: "",
348
328
  kochavaSessionCount: -1,
349
329
  kochavaInstallDate: -1,
350
- kochavaConfig: undefined,
330
+ kochavaConfig: undefined
351
331
  };
352
332
  }
353
333
  initInstance(appGuid) {
@@ -356,7 +336,7 @@ export class Kochava {
356
336
  this.instance.disableAutoPage = this.instance.disableAutoPage || false;
357
337
  this.instance.useCookies = this.instance.useCookies || false;
358
338
  this.instance.version = this.instance.version || "WebTracker " + SDK_VERSION;
359
- this.instance.buildDate = "kbd: 8/16/2024, 3:02:42 PM";
339
+ this.instance.buildDate = "kbd: 8/16/2024, 4:52:31 PM";
360
340
  this.instance.kochavaSession = utils.uuidv4().substring(0, 5);
361
341
  this.instance.startTimeMS = utils.getCurrTimeMS();
362
342
  this.instance.retryWaterfall = [7, 30, 300, 1800];
@@ -397,14 +377,12 @@ export class Kochava {
397
377
  const lastKvinitDate = JSON.parse(persistedKvinitDateStr);
398
378
  if (lastKvinitDate) {
399
379
  const refreshMin = this.instance.kochavaConfig.config.refresh_minimum;
400
- if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin)
401
- this.instance.kvinitDone = true;
380
+ if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin) this.instance.kvinitDone = true;
402
381
  }
403
382
  }
404
383
  }
405
384
  checkPersistedState() {
406
- this.instance.installDone =
407
- readAndUpdatePersistedValue(PersistKey.InstallSentDate, this.instance.useCookies).length > 0;
385
+ this.instance.installDone = readAndUpdatePersistedValue(PersistKey.InstallSentDate, this.instance.useCookies).length > 0;
408
386
  this.instance.kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, this.instance.useCookies);
409
387
  this.instance.kochavaDeviceId = readAndUpdateDeviceId(this.instance.useCookies);
410
388
  this.instance.kochavaSessionCount = readAndUpdateSessionCount(this.instance.useCookies);
@@ -423,16 +401,13 @@ export class Kochava {
423
401
  if (!this.instance.kvinitDone) {
424
402
  Log.diagDebug(`A new kvinit will be sent`);
425
403
  await this.performNewKvinit();
426
- }
427
- else {
404
+ } else {
428
405
  Log.diagDebug(`A new kvinit will not be sent`);
429
406
  }
430
407
  // if the install_id changed and thus a new install must go out
431
- if (this.checkResendId())
432
- this.instance.installDone = false;
408
+ if (this.checkResendId()) this.instance.installDone = false;
433
409
  Log.diagDebug(`The install ${this.instance.installDone ? "has already" : "has not yet"} been sent`);
434
- if (this.instance.sleep)
435
- return;
410
+ if (this.instance.sleep) return;
436
411
  if (!this.instance.installDone) {
437
412
  await this.performInstall();
438
413
  }
@@ -466,12 +441,11 @@ export class Kochava {
466
441
  async performInstall() {
467
442
  const request = Install.build(this.instance);
468
443
  this.instance.installDone = await Install.send(this.instance, request);
469
- if (!this.instance.installDone)
470
- return;
444
+ if (!this.instance.installDone) return;
471
445
  // If the install succeeded, remove all idLink that were passed to it
472
446
  Install.onSuccess(this.instance);
473
447
  updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.jobQueue.idLinkQueue), false);
474
448
  }
475
449
  }
476
450
  // Only here for generic Web integration
477
- window.kochava = Kochava.create();
451
+ window.kochava = Kochava.create();
@@ -17,21 +17,20 @@ export const constructPreStart = (instance, eventName, eventData) => {
17
17
  event_data: eventData,
18
18
  device_orientation: browser.getDeviceOrientation(),
19
19
  disp_w: browser.getDeviceWidth(),
20
- disp_h: browser.getDeviceHeight(),
21
- },
20
+ disp_h: browser.getDeviceHeight()
21
+ }
22
22
  };
23
- if (instance.kochavaConfig)
24
- preStart.init_token = (instance.kochavaConfig.config.init_token) || undefined;
23
+ if (instance.kochavaConfig) preStart.init_token = instance.kochavaConfig.config.init_token || undefined;
25
24
  return preStart;
26
25
  };
27
26
  export const constructPostStart = (instance, preStartBody) => {
28
27
  const postStartBody = {
29
28
  kochava_app_id: instance.appGuid,
30
29
  kochava_device_id: instance.kochavaDeviceId,
31
- nt_id: `${instance.kochavaSession}-${instance.kochavaSessionCount}-${utils.uuidv4()}`,
30
+ nt_id: `${instance.kochavaSession}-${instance.kochavaSessionCount}-${utils.uuidv4()}`
32
31
  };
33
32
  postStartBody.data = Object.assign(Object.assign({}, constructCommonData(instance)), preStartBody.data);
34
- instance.customValues.forEach((custom) => {
33
+ instance.customValues.forEach(custom => {
35
34
  if (!custom.isDeviceId) {
36
35
  const customKey = Object.keys(custom.data)[0];
37
36
  if (instance.kochavaConfig.privacy) {
@@ -41,8 +40,7 @@ export const constructPostStart = (instance, preStartBody) => {
41
40
  keyAllowed = true;
42
41
  }
43
42
  }
44
- if (keyAllowed)
45
- postStartBody.data = Object.assign(Object.assign({}, custom.data), postStartBody.data);
43
+ if (keyAllowed) postStartBody.data = Object.assign(Object.assign({}, custom.data), postStartBody.data);
46
44
  }
47
45
  }
48
46
  });
@@ -55,13 +53,11 @@ const build = (instance, preStartBody, postStartBody) => {
55
53
  instance.kochavaConfig.privacy.deny_datapoints.forEach(denyPoint => {
56
54
  for (const point in payload.data) {
57
55
  const key = point;
58
- if (key === denyPoint)
59
- delete payload.data[key];
56
+ if (key === denyPoint) delete payload.data[key];
60
57
  }
61
58
  for (const point in payload) {
62
59
  const key = point;
63
- if (key === denyPoint)
64
- delete payload[key];
60
+ if (key === denyPoint) delete payload[key];
65
61
  }
66
62
  });
67
63
  }
@@ -69,8 +65,7 @@ const build = (instance, preStartBody, postStartBody) => {
69
65
  };
70
66
  export const send = async (instance, preStartBody, postStartBody) => {
71
67
  const payload = build(instance, preStartBody, postStartBody);
72
- const respStr = await http.sendRequest(payload, (instance.overrideUrls.event) ?
73
- instance.overrideUrls.event : instance.kochavaConfig.networking.urls.event);
68
+ const respStr = await http.sendRequest(payload, instance.overrideUrls.event ? instance.overrideUrls.event : instance.kochavaConfig.networking.urls.event);
74
69
  let resp;
75
70
  let success = false;
76
71
  try {
@@ -78,8 +73,7 @@ export const send = async (instance, preStartBody, postStartBody) => {
78
73
  resp = JSON.parse(respStr);
79
74
  Log.debug("Event Response:", respStr);
80
75
  success = http.wasRespSuccess(resp.success);
81
- }
82
- catch (e) {
76
+ } catch (e) {
83
77
  Log.error("Error parsing Event Response", e);
84
78
  success = false;
85
79
  }
@@ -89,4 +83,4 @@ export const send = async (instance, preStartBody, postStartBody) => {
89
83
  }
90
84
  Log.error("Event failed!");
91
85
  return false;
92
- };
86
+ };
@@ -12,18 +12,17 @@ export const constructPreStart = (instance, idLink) => {
12
12
  sdk_version: instance.version,
13
13
  sdk_protocol: "17",
14
14
  data: {
15
- identity_link: Object.assign({}, idLink),
16
- },
15
+ identity_link: Object.assign({}, idLink)
16
+ }
17
17
  };
18
- if (instance.kochavaConfig)
19
- preStart.init_token = (instance.kochavaConfig.config.init_token) || undefined;
18
+ if (instance.kochavaConfig) preStart.init_token = instance.kochavaConfig.config.init_token || undefined;
20
19
  return preStart;
21
20
  };
22
21
  export const constructPostStart = (instance, preStartBody) => {
23
22
  const postStartBody = {
24
23
  kochava_app_id: instance.appGuid,
25
24
  kochava_device_id: instance.kochavaDeviceId,
26
- nt_id: `${instance.kochavaSession}-${instance.kochavaSessionCount}-${utils.uuidv4()}`,
25
+ nt_id: `${instance.kochavaSession}-${instance.kochavaSessionCount}-${utils.uuidv4()}`
27
26
  };
28
27
  postStartBody.data = Object.assign(Object.assign({}, preStartBody.data), constructCommonData(instance));
29
28
  return postStartBody;
@@ -36,13 +35,11 @@ const build = (instance, job) => {
36
35
  instance.kochavaConfig.privacy.deny_datapoints.forEach(denyPoint => {
37
36
  for (const point in payload.data) {
38
37
  const key = point;
39
- if (key === denyPoint)
40
- delete payload.data[key];
38
+ if (key === denyPoint) delete payload.data[key];
41
39
  }
42
40
  for (const point in payload) {
43
41
  const key = point;
44
- if (key === denyPoint)
45
- delete payload[key];
42
+ if (key === denyPoint) delete payload[key];
46
43
  }
47
44
  });
48
45
  }
@@ -50,8 +47,7 @@ const build = (instance, job) => {
50
47
  };
51
48
  export const send = async (instance, job) => {
52
49
  const payload = build(instance, job);
53
- const respStr = await http.sendRequest(payload, (instance.overrideUrls.identityLink) ?
54
- instance.overrideUrls.identityLink : instance.kochavaConfig.networking.urls.identityLink);
50
+ const respStr = await http.sendRequest(payload, instance.overrideUrls.identityLink ? instance.overrideUrls.identityLink : instance.kochavaConfig.networking.urls.identityLink);
55
51
  let resp;
56
52
  let success = false;
57
53
  try {
@@ -59,8 +55,7 @@ export const send = async (instance, job) => {
59
55
  resp = JSON.parse(respStr);
60
56
  Log.debug("IdentityLink Response:", respStr);
61
57
  success = http.wasRespSuccess(resp.success);
62
- }
63
- catch (e) {
58
+ } catch (e) {
64
59
  Log.error("Error parsing IdentityLink Response", e);
65
60
  success = false;
66
61
  }
@@ -70,4 +65,4 @@ export const send = async (instance, job) => {
70
65
  }
71
66
  Log.error("IdentityLink failed!");
72
67
  return false;
73
- };
68
+ };
@@ -10,7 +10,7 @@ import { constructPayload } from "./payload";
10
10
  import { getPersistedIdentityLinks, PersistKey, readAndUpdatePersistedValue, updatePersistedValue } from "../browser/persist";
11
11
  let timeOut;
12
12
  let canceled = false;
13
- export const build = (instance) => {
13
+ export const build = instance => {
14
14
  const payload = constructPayload("install", instance);
15
15
  instance.installStarted = true;
16
16
  payload.data = constructInstallData(instance);
@@ -19,13 +19,11 @@ export const build = (instance) => {
19
19
  instance.kochavaConfig.privacy.deny_datapoints.forEach(denyPoint => {
20
20
  for (const point in payload.data) {
21
21
  const key = point;
22
- if (key === denyPoint)
23
- delete payload.data[key];
22
+ if (key === denyPoint) delete payload.data[key];
24
23
  }
25
24
  for (const point in payload) {
26
25
  const key = point;
27
- if (key === denyPoint)
28
- delete payload[key];
26
+ if (key === denyPoint) delete payload[key];
29
27
  }
30
28
  });
31
29
  }
@@ -42,8 +40,7 @@ export const send = async (instance, payload, retries = 0) => {
42
40
  do {
43
41
  const sendTime = utils.getCurrTimeMS() - instance.startTimeMS;
44
42
  Log.diagDebug(`Sending install at ${utils.formatTime(sendTime / 1000)} seconds`);
45
- const respStr = await http.sendRequest(payload, (instance.overrideUrls.install) ?
46
- instance.overrideUrls.install : instance.kochavaConfig.networking.urls.install);
43
+ const respStr = await http.sendRequest(payload, instance.overrideUrls.install ? instance.overrideUrls.install : instance.kochavaConfig.networking.urls.install);
47
44
  const respTime = utils.getCurrTimeMS() - instance.startTimeMS;
48
45
  Log.diagDebug(`Completed install at ${new Date().toLocaleTimeString()}
49
46
  seconds with a network duration of ${utils.formatTime((respTime - sendTime) / 1000)} seconds`);
@@ -56,8 +53,7 @@ export const send = async (instance, payload, retries = 0) => {
56
53
  resp = JSON.parse(respStr);
57
54
  Log.debug("Install Response:", respStr);
58
55
  success = http.wasRespSuccess(resp.success);
59
- }
60
- catch (e) {
56
+ } catch (e) {
61
57
  Log.error("Error parsing Install Response", e);
62
58
  success = false;
63
59
  }
@@ -67,23 +63,24 @@ export const send = async (instance, payload, retries = 0) => {
67
63
  }
68
64
  if (!canceled) {
69
65
  const retryWaterfall = instance.kochavaConfig.networking.retry_waterfall;
70
- const retryIndex = (retries > retryWaterfall.length - 1) ? retryWaterfall.length - 1 : retries;
66
+ const retryIndex = retries > retryWaterfall.length - 1 ? retryWaterfall.length - 1 : retries;
71
67
  const retrySec = retryWaterfall[retryIndex];
72
68
  Log.error(`Install failed, attempting again in ${retrySec} seconds`);
73
- await new Promise(resolve => { timeOut = setTimeout(resolve, retrySec * 1000); });
69
+ await new Promise(resolve => {
70
+ timeOut = setTimeout(resolve, retrySec * 1000);
71
+ });
74
72
  retries++;
75
73
  }
76
74
  } while (!success && !canceled);
77
75
  };
78
- export const onSuccess = (instance) => {
76
+ export const onSuccess = instance => {
79
77
  instance.kochavaInstallDate = utils.getCurrTimeMS();
80
78
  updatePersistedValue(PersistKey.InstallSentDate, String(instance.kochavaInstallDate), instance.useCookies);
81
79
  };
82
- const constructInstallData = (instance) => {
80
+ const constructInstallData = instance => {
83
81
  const currTime = Math.floor(Date.now() / 1000);
84
82
  let uptime = (currTime - instance.startTimeMS) / 1000;
85
- if (uptime < 0.0)
86
- uptime = 0.0;
83
+ if (uptime < 0.0) uptime = 0.0;
87
84
  let returnObj = {
88
85
  starttime: instance.startTimeMS / 1000,
89
86
  uptime: uptime,
@@ -92,35 +89,27 @@ const constructInstallData = (instance) => {
92
89
  package: browser.getPackageName(),
93
90
  disp_w: browser.getDeviceWidth(),
94
91
  disp_h: browser.getDeviceHeight(),
95
- language: browser.getLanguage(),
92
+ language: browser.getLanguage()
96
93
  };
97
94
  if (instance.utm) {
98
95
  returnObj = Object.assign(Object.assign({}, returnObj), { conversion_data: { utm_source: instance.utm } });
99
96
  }
100
- if (instance.customValues.length > 0)
101
- returnObj.device_ids = {};
102
- instance.customValues.forEach((custom) => {
97
+ if (instance.customValues.length > 0) returnObj.device_ids = {};
98
+ instance.customValues.forEach(custom => {
103
99
  const customKey = Object.keys(custom.data)[0];
104
100
  console.log("customData: ", custom);
105
101
  if (instance.kochavaConfig.privacy) {
106
102
  let keyAllowed = false;
107
- console.log("1");
108
103
  for (const allowed of instance.kochavaConfig.privacy.allow_custom_ids) {
109
104
  if (customKey === allowed) {
110
- console.log("2");
111
105
  keyAllowed = true;
112
106
  }
113
107
  }
114
108
  if (keyAllowed) {
115
- console.log("3");
116
109
  if (custom.isDeviceId) {
117
- console.log("4");
118
110
  returnObj.device_ids = Object.assign(Object.assign({}, returnObj.device_ids), custom.data);
119
- }
120
- else {
121
- console.log("before: ", returnObj);
111
+ } else {
122
112
  returnObj = Object.assign(Object.assign({}, custom.data), returnObj);
123
- console.log("after: ", returnObj);
124
113
  }
125
114
  }
126
115
  }
@@ -137,8 +126,7 @@ const constructInstallData = (instance) => {
137
126
  includeKey = false;
138
127
  }
139
128
  }
140
- if (includeKey)
141
- returnObj.identity_link[key] = persistedIdLinks[key];
129
+ if (includeKey) returnObj.identity_link[key] = persistedIdLinks[key];
142
130
  }
143
131
  }
144
132
  return returnObj;
@@ -148,10 +136,10 @@ const determineInstallUserTime = (instance, currTime) => {
148
136
  if (firstStartStr) {
149
137
  const firstStart = JSON.parse(firstStartStr);
150
138
  // If its been 30 days since the sdk started
151
- if ((currTime - firstStart) > 2592000) {
139
+ if (currTime - firstStart > 2592000) {
152
140
  return currTime;
153
141
  }
154
142
  return firstStart;
155
143
  }
156
144
  return currTime;
157
- };
145
+ };
@@ -11,7 +11,7 @@ import { DEFAULTS } from "../interfaces";
11
11
  import { PersistKey, updatePersistedValue } from "../browser/persist";
12
12
  let timeOut;
13
13
  let canceled = false;
14
- const build = (instance) => {
14
+ const build = instance => {
15
15
  const payload = constructPayload("init", instance);
16
16
  payload.build_date = instance.buildDate;
17
17
  payload.data = constructKvinitData(instance);
@@ -31,8 +31,7 @@ export const send = async (instance, retryWaterfall, retries = 0) => {
31
31
  Log.trace("Kvinit endpoint:", instance.kochavaConfig.networking.urls.init);
32
32
  const sendTime = utils.getCurrTimeMS() - instance.startTimeMS;
33
33
  Log.diagDebug(`Sending kvinit at ${utils.formatTime(sendTime / 1000)} seconds`);
34
- const respStr = await http.sendRequest(payload, (instance.overrideUrls.init) ?
35
- instance.overrideUrls.init : instance.kochavaConfig.networking.urls.init);
34
+ const respStr = await http.sendRequest(payload, instance.overrideUrls.init ? instance.overrideUrls.init : instance.kochavaConfig.networking.urls.init);
36
35
  const respTime = utils.getCurrTimeMS() - instance.startTimeMS;
37
36
  Log.diagDebug(`Completed kvinit at ${utils.formatTime(respTime / 1000)}
38
37
  seconds with a network duration of ${utils.formatTime((respTime - sendTime) / 1000)} seconds`);
@@ -44,8 +43,7 @@ export const send = async (instance, retryWaterfall, retries = 0) => {
44
43
  resp = JSON.parse(respStr);
45
44
  Log.debug("Kvinit Response:", resp);
46
45
  success = http.wasRespSuccess(resp.success);
47
- }
48
- catch (e) {
46
+ } catch (e) {
49
47
  Log.error("Error parsing Kvinit Response", e);
50
48
  success = false;
51
49
  }
@@ -56,10 +54,12 @@ export const send = async (instance, retryWaterfall, retries = 0) => {
56
54
  }
57
55
  if (!canceled) {
58
56
  // retry kvinit
59
- const retryIndex = (retries > retryWaterfall.length - 1) ? retryWaterfall.length - 1 : retries;
57
+ const retryIndex = retries > retryWaterfall.length - 1 ? retryWaterfall.length - 1 : retries;
60
58
  const retrySec = retryWaterfall[retryIndex];
61
59
  Log.error(`Kvinit failed, attempting again in ${retrySec} seconds`);
62
- await new Promise(resolve => { timeOut = setTimeout(resolve, retrySec * 1000); });
60
+ await new Promise(resolve => {
61
+ timeOut = setTimeout(resolve, retrySec * 1000);
62
+ });
63
63
  retries++;
64
64
  }
65
65
  } while (!success && !canceled);
@@ -84,29 +84,24 @@ export const applyKvinitResp = (instance, resp) => {
84
84
  if (resp.config) {
85
85
  instance.kochavaConfig.config = {
86
86
  init_token: resp.config.init_token || DEFAULTS.config.init_token,
87
- refresh_minimum: (resp.config.refresh_minimum !== undefined &&
88
- resp.config.refresh_minimum !== null) ? resp.config.refresh_minimum :
89
- DEFAULTS.config.refresh_minimum,
87
+ refresh_minimum: resp.config.refresh_minimum !== undefined && resp.config.refresh_minimum !== null ? resp.config.refresh_minimum : DEFAULTS.config.refresh_minimum
90
88
  };
91
89
  }
92
90
  if (resp.install) {
93
91
  if (resp.install.resend_id) {
94
92
  instance.kochavaConfig.install.resend_id = resp.install.resend_id;
95
93
  }
96
- instance.kochavaConfig.install.updates_enabled =
97
- resp.install.updates_enabled || DEFAULTS.install.updates_enabled;
94
+ instance.kochavaConfig.install.updates_enabled = resp.install.updates_enabled || DEFAULTS.install.updates_enabled;
98
95
  }
99
96
  if (resp.networking) {
100
- instance.kochavaConfig.networking.retry_waterfall =
101
- resp.networking.retry_waterfall || DEFAULTS.networking.retry_waterfall;
102
- instance.retryWaterfall =
103
- instance.kochavaConfig.networking.retry_waterfall;
97
+ instance.kochavaConfig.networking.retry_waterfall = resp.networking.retry_waterfall || DEFAULTS.networking.retry_waterfall;
98
+ instance.retryWaterfall = instance.kochavaConfig.networking.retry_waterfall;
104
99
  if (resp.networking.urls) {
105
100
  instance.kochavaConfig.networking.urls = {
106
101
  init: resp.networking.urls.init || DEFAULTS.networking.urls.init,
107
102
  install: resp.networking.urls.install || DEFAULTS.networking.urls.install,
108
103
  event: resp.networking.urls.event || DEFAULTS.networking.urls.event,
109
- identityLink: resp.networking.urls.identityLink || DEFAULTS.networking.urls.identityLink,
104
+ identityLink: resp.networking.urls.identityLink || DEFAULTS.networking.urls.identityLink
110
105
  };
111
106
  }
112
107
  }
@@ -115,20 +110,19 @@ export const applyKvinitResp = (instance, resp) => {
115
110
  allow_custom_ids: resp.privacy.allow_custom_ids || DEFAULTS.privacy.allow_custom_ids,
116
111
  deny_datapoints: resp.privacy.deny_datapoints || DEFAULTS.privacy.deny_datapoints,
117
112
  deny_event_names: resp.privacy.deny_event_names || DEFAULTS.privacy.deny_event_names,
118
- deny_identity_links: resp.privacy.deny_identity_links || DEFAULTS.privacy.deny_identity_links,
113
+ deny_identity_links: resp.privacy.deny_identity_links || DEFAULTS.privacy.deny_identity_links
119
114
  };
120
115
  }
121
116
  };
122
- const constructKvinitData = (instance) => {
117
+ const constructKvinitData = instance => {
123
118
  const currTime = Math.floor(Date.now() / 1000);
124
119
  let uptime = (currTime - instance.startTimeMS) / 1000;
125
- if (uptime < 0.0)
126
- uptime = 0.0;
120
+ if (uptime < 0.0) uptime = 0.0;
127
121
  return {
128
122
  package: getPackageName(),
129
123
  platform: "web",
130
124
  starttime: instance.startTimeMS / 1000,
131
125
  uptime,
132
- usertime: currTime,
126
+ usertime: currTime
133
127
  };
134
- };
128
+ };
@@ -17,17 +17,16 @@ export const constructPayload = (action, instance, originalNtId) => {
17
17
  sdk_version: instance.version,
18
18
  sdk_protocol: "17",
19
19
  nt_id: nt_id,
20
- init_token: (instance.kochavaConfig.config.init_token) || undefined,
20
+ init_token: instance.kochavaConfig.config.init_token || undefined
21
21
  };
22
22
  };
23
- export const constructCommonData = (instance) => {
23
+ export const constructCommonData = instance => {
24
24
  const currTime = utils.getCurrTimeMS();
25
25
  let uptime = (currTime - instance.startTimeMS) / 1000;
26
- if (uptime < 0.0)
27
- uptime = 0.0;
26
+ if (uptime < 0.0) uptime = 0.0;
28
27
  return {
29
28
  starttime: instance.startTimeMS / 1000,
30
29
  uptime: uptime,
31
- usertime: currTime / 1000,
30
+ usertime: currTime / 1000
32
31
  };
33
- };
32
+ };
package/dist/utils/log.js CHANGED
@@ -14,15 +14,14 @@ var Level;
14
14
  })(Level || (Level = {}));
15
15
  class Logger {
16
16
  constructor() {
17
- if (Logger.instance)
18
- return;
17
+ if (Logger.instance) return;
19
18
  this.levelPrio = {
20
19
  Off: 0,
21
20
  Error: 1,
22
21
  Warn: 2,
23
22
  Info: 3,
24
23
  Debug: 4,
25
- Trace: 5,
24
+ Trace: 5
26
25
  };
27
26
  this.currLevel = Level.Info;
28
27
  this.logObjects = false;
@@ -33,7 +32,7 @@ class Logger {
33
32
  Info: false,
34
33
  Debug: false,
35
34
  Trace: false,
36
- Diag: false,
35
+ Diag: false
37
36
  };
38
37
  Logger.instance = this;
39
38
  }
@@ -43,8 +42,7 @@ class Logger {
43
42
  const level = Level[key];
44
43
  if (level !== undefined && level !== null) {
45
44
  this.currLevel = level;
46
- }
47
- else {
45
+ } else {
48
46
  console.log(`Invalid logLevel ${level} passed in, defaulting to info.`);
49
47
  this.currLevel = Level.Info;
50
48
  }
@@ -76,29 +74,24 @@ class Logger {
76
74
  this.print(Level.Trace, msg, ...args);
77
75
  }
78
76
  diagInfo(msg, ...args) {
79
- if (!this.logsFilteredOut.Diag)
80
- this.print(Level.Info, "Kochava Diagnostic - " + msg, ...args);
77
+ if (!this.logsFilteredOut.Diag) this.print(Level.Info, "Kochava Diagnostic - " + msg, ...args);
81
78
  }
82
79
  diagDebug(msg, ...args) {
83
- if (!this.logsFilteredOut.Diag)
84
- this.print(Level.Debug, "Kochava Diagnostic - " + msg, ...args);
80
+ if (!this.logsFilteredOut.Diag) this.print(Level.Debug, "Kochava Diagnostic - " + msg, ...args);
85
81
  }
86
82
  print(lvl, msg, ...args) {
87
- if (this.levelPrio[this.currLevel.toString()] >= this.levelPrio[lvl.toString()] &&
88
- !this.logsFilteredOut[lvl.toString()]) {
83
+ if (this.levelPrio[this.currLevel.toString()] >= this.levelPrio[lvl.toString()] && !this.logsFilteredOut[lvl.toString()]) {
89
84
  try {
90
85
  const obj = JSON.parse(args[0]);
91
86
  if (this.logObjects && obj) {
92
87
  console.log(`KVA :: ${getMsTime()} ${lvl.toString()}:`, msg, obj);
93
- }
94
- else {
88
+ } else {
95
89
  console.log(`KVA :: ${getMsTime()} ${lvl.toString()}:`, msg, ...args);
96
90
  }
97
- }
98
- catch (_a) {
91
+ } catch (_a) {
99
92
  console.log(`KVA :: ${getMsTime()} ${lvl.toString()}:`, msg, ...args);
100
93
  }
101
94
  }
102
95
  }
103
96
  }
104
- export const Log = new Logger();
97
+ export const Log = new Logger();
@@ -3,19 +3,16 @@
3
3
  Copyright (c) Kochava, Inc. All rights reserved.
4
4
  */
5
5
  export const uuidv4 = () => {
6
- return (`${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`).replace(/[018]/g, (c) => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
6
+ return `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
7
7
  };
8
8
  // returns the number of milliseconds elapsed since January 1, 1970
9
9
  export const getCurrTimeMS = () => Math.floor(Date.now());
10
10
  // returns the number of seconds elapsed since January 1, 1970
11
11
  export const getCurrTimeSec = () => Math.floor(Date.now() / 1000);
12
- export const formatTime = (num) => {
13
- if (num < 10 && num % 10 <= 9)
14
- return "0" + num.toFixed(1).toString();
15
- else
16
- return num.toFixed(1).toString();
12
+ export const formatTime = num => {
13
+ if (num < 10 && num % 10 <= 9) return "0" + num.toFixed(1).toString();else return num.toFixed(1).toString();
17
14
  };
18
15
  export const getMsTime = () => {
19
16
  const date = new Date();
20
17
  return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}:${date.getMilliseconds()}`;
21
- };
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kv-test-lib",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "dist/kochava.js",
5
5
  "files": [
6
6
  "dist/"