kv-test-lib 1.0.3 → 1.0.4
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/http.d.ts +1 -0
- package/dist/http.js +1 -0
- package/dist/kochava.d.ts +16 -1
- package/dist/kochava.js +197 -195
- package/dist/payloads/install.js +11 -2
- package/package.json +1 -1
package/dist/http.d.ts
CHANGED
package/dist/http.js
CHANGED
package/dist/kochava.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import 'core-js/stable';
|
|
2
|
+
import 'regenerator-runtime/runtime';
|
|
3
|
+
import 'whatwg-fetch';
|
|
4
|
+
import JobQueue from "./jobqueue";
|
|
1
5
|
import { Json, Urls, CustomValue, KvConfig } from "./interfaces";
|
|
2
6
|
declare global {
|
|
3
7
|
interface Window {
|
|
@@ -28,7 +32,8 @@ export interface KochavaInstance {
|
|
|
28
32
|
kochavaConfig?: KvConfig;
|
|
29
33
|
}
|
|
30
34
|
export declare class Kochava {
|
|
31
|
-
|
|
35
|
+
instance: KochavaInstance;
|
|
36
|
+
jobQueue: JobQueue;
|
|
32
37
|
private constructor();
|
|
33
38
|
static create(): Kochava;
|
|
34
39
|
static createForNode(): Kochava;
|
|
@@ -49,4 +54,14 @@ export declare class Kochava {
|
|
|
49
54
|
getStarted(): boolean;
|
|
50
55
|
getDeviceId(): string;
|
|
51
56
|
setSleep(sleep: boolean): void;
|
|
57
|
+
resetInstance(): void;
|
|
58
|
+
initInstance(appGuid: string): void;
|
|
59
|
+
checkFirstLaunchAndMigrate(): void;
|
|
60
|
+
checkPersistedKvinit(): void;
|
|
61
|
+
checkPersistedState(): void;
|
|
62
|
+
printStartupMsgs(appGuid: string): void;
|
|
63
|
+
beginStart(): Promise<void>;
|
|
64
|
+
performNewKvinit(): Promise<void>;
|
|
65
|
+
checkResendId(): boolean;
|
|
66
|
+
performInstall(): Promise<void>;
|
|
52
67
|
}
|
package/dist/kochava.js
CHANGED
|
@@ -2,18 +2,9 @@
|
|
|
2
2
|
Authored by Brett Barinaga on 11/17/21.
|
|
3
3
|
Copyright (c) Kochava, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
11
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
|
-
};
|
|
16
|
-
var _Kochava_instances, _Kochava_instance, _Kochava_jobQueue, _Kochava_resetInstance, _Kochava_initInstance, _Kochava_checkFirstLaunchAndMigrate, _Kochava_checkPersistedKvinit, _Kochava_checkPersistedState, _Kochava_printStartupMsgs, _Kochava_beginStart, _Kochava_performNewKvinit, _Kochava_checkResendId, _Kochava_performInstall;
|
|
5
|
+
import 'core-js/stable';
|
|
6
|
+
import 'regenerator-runtime/runtime';
|
|
7
|
+
import 'whatwg-fetch';
|
|
17
8
|
import { Log } from "./utils/log";
|
|
18
9
|
import JobQueue from "./jobqueue";
|
|
19
10
|
import * as Kvinit from "./payloads/kvinit";
|
|
@@ -22,15 +13,14 @@ import { DEFAULTS, } from "./interfaces";
|
|
|
22
13
|
import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM, } from "./browser/persist";
|
|
23
14
|
import * as utils from "./utils/utils";
|
|
24
15
|
import { getPageName } from "./browser/browser";
|
|
16
|
+
// NOTE: Update this with new releases.
|
|
17
|
+
const SDK_VERSION = "3.1.0";
|
|
25
18
|
export class Kochava {
|
|
26
19
|
// User will use the below factories instead of directly calling
|
|
27
20
|
// the constructor
|
|
28
21
|
constructor() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
_Kochava_jobQueue.set(this, void 0);
|
|
32
|
-
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this);
|
|
33
|
-
__classPrivateFieldSet(this, _Kochava_jobQueue, new JobQueue(), "f");
|
|
22
|
+
this.resetInstance();
|
|
23
|
+
this.jobQueue = new JobQueue();
|
|
34
24
|
}
|
|
35
25
|
// ============================= PUBLIC =============================== //
|
|
36
26
|
static create() {
|
|
@@ -65,7 +55,7 @@ export class Kochava {
|
|
|
65
55
|
- defaults to false
|
|
66
56
|
*/
|
|
67
57
|
useCookies(condition = false) {
|
|
68
|
-
|
|
58
|
+
this.instance.useCookies = condition;
|
|
69
59
|
}
|
|
70
60
|
/*
|
|
71
61
|
- Set whether the sdk shouldn't automatically send a page or should.
|
|
@@ -74,7 +64,7 @@ export class Kochava {
|
|
|
74
64
|
- defaults to false
|
|
75
65
|
*/
|
|
76
66
|
disableAutoPage(condition = false) {
|
|
77
|
-
|
|
67
|
+
this.instance.disableAutoPage = condition;
|
|
78
68
|
}
|
|
79
69
|
/*
|
|
80
70
|
The primary means for starting the sdk.
|
|
@@ -92,22 +82,22 @@ export class Kochava {
|
|
|
92
82
|
Log.error(`Invalid appGuid ${appGuid}, start failed.`);
|
|
93
83
|
return;
|
|
94
84
|
}
|
|
95
|
-
if (!
|
|
96
|
-
|
|
97
|
-
if (
|
|
85
|
+
if (!this.instance)
|
|
86
|
+
this.resetInstance();
|
|
87
|
+
if (this.instance.started) {
|
|
98
88
|
Log.warn("Kochava SDK already started.");
|
|
99
89
|
return;
|
|
100
90
|
}
|
|
101
91
|
Log.diagDebug(`Host called API: Start With App Guid ${appGuid}`);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (!
|
|
92
|
+
this.instance.started = true;
|
|
93
|
+
this.checkFirstLaunchAndMigrate();
|
|
94
|
+
this.initInstance(appGuid);
|
|
95
|
+
if (!this.instance.disableAutoPage)
|
|
106
96
|
this.sendPageEvent();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
this.checkPersistedState();
|
|
98
|
+
this.checkPersistedKvinit();
|
|
99
|
+
this.printStartupMsgs(appGuid);
|
|
100
|
+
this.beginStart();
|
|
111
101
|
}
|
|
112
102
|
/*
|
|
113
103
|
Primary means for stopping the sdk.
|
|
@@ -120,16 +110,16 @@ export class Kochava {
|
|
|
120
110
|
Log.debug("Deleting persisted values");
|
|
121
111
|
deleteAllPersisted();
|
|
122
112
|
}
|
|
123
|
-
if (!
|
|
113
|
+
if (!this.instance.started) {
|
|
124
114
|
Log.warn("SDK already shutdown.");
|
|
125
115
|
}
|
|
126
116
|
Log.info("SDK shutting down.");
|
|
127
117
|
Kvinit.cancelRetries();
|
|
128
118
|
Install.cancelRetries();
|
|
129
|
-
|
|
119
|
+
this.jobQueue.stop();
|
|
130
120
|
// wipe whatever was previously in the queue
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
this.jobQueue = new JobQueue();
|
|
122
|
+
this.resetInstance();
|
|
133
123
|
}
|
|
134
124
|
/*
|
|
135
125
|
Changes the current logLevel.
|
|
@@ -158,14 +148,14 @@ export class Kochava {
|
|
|
158
148
|
case "wrapper":
|
|
159
149
|
{
|
|
160
150
|
const wrapperVersion = JSON.parse(valueStr);
|
|
161
|
-
if (!
|
|
162
|
-
|
|
151
|
+
if (!this.instance.version)
|
|
152
|
+
this.instance.version = "WebTracker " + SDK_VERSION;
|
|
163
153
|
switch (wrapperVersion.name) {
|
|
164
154
|
case "Angular":
|
|
165
|
-
|
|
155
|
+
this.instance.version += ` (${wrapperVersion.name} ${wrapperVersion.version})`;
|
|
166
156
|
break;
|
|
167
157
|
default:
|
|
168
|
-
|
|
158
|
+
this.instance.version += ` (${wrapperVersion.name})`;
|
|
169
159
|
break;
|
|
170
160
|
}
|
|
171
161
|
}
|
|
@@ -174,13 +164,13 @@ export class Kochava {
|
|
|
174
164
|
{
|
|
175
165
|
const overrideUrls = JSON.parse(valueStr);
|
|
176
166
|
if (overrideUrls.init)
|
|
177
|
-
|
|
167
|
+
this.instance.overrideUrls.init = overrideUrls.init;
|
|
178
168
|
if (overrideUrls.event)
|
|
179
|
-
|
|
169
|
+
this.instance.overrideUrls.event = overrideUrls.event;
|
|
180
170
|
if (overrideUrls.install)
|
|
181
|
-
|
|
171
|
+
this.instance.overrideUrls.install = overrideUrls.install;
|
|
182
172
|
if (overrideUrls.identityLink)
|
|
183
|
-
|
|
173
|
+
this.instance.overrideUrls.identityLink = overrideUrls.identityLink;
|
|
184
174
|
}
|
|
185
175
|
break;
|
|
186
176
|
case "urlsRestore":
|
|
@@ -188,14 +178,14 @@ export class Kochava {
|
|
|
188
178
|
const restoreUrls = JSON.parse(valueStr);
|
|
189
179
|
for (const url of restoreUrls) {
|
|
190
180
|
if (url === "init")
|
|
191
|
-
|
|
181
|
+
this.instance.overrideUrls.init = DEFAULTS.networking.urls.init;
|
|
192
182
|
if (url === "event")
|
|
193
|
-
|
|
183
|
+
this.instance.overrideUrls.event = DEFAULTS.networking.urls.event;
|
|
194
184
|
if (url === "install")
|
|
195
|
-
|
|
185
|
+
this.instance.overrideUrls.install =
|
|
196
186
|
DEFAULTS.networking.urls.install;
|
|
197
187
|
if (url === "identityLink")
|
|
198
|
-
|
|
188
|
+
this.instance.overrideUrls.identityLink =
|
|
199
189
|
DEFAULTS.networking.urls.identityLink;
|
|
200
190
|
}
|
|
201
191
|
}
|
|
@@ -208,7 +198,7 @@ export class Kochava {
|
|
|
208
198
|
break;
|
|
209
199
|
case "getInstance":
|
|
210
200
|
{
|
|
211
|
-
const currInstance = JSON.stringify(
|
|
201
|
+
const currInstance = JSON.stringify(this.instance);
|
|
212
202
|
callback(currInstance);
|
|
213
203
|
Log.debug(`capturing instance: ${valueStr}`);
|
|
214
204
|
}
|
|
@@ -230,7 +220,7 @@ export class Kochava {
|
|
|
230
220
|
Log.warn("Invalid event name, ignoring call.");
|
|
231
221
|
return;
|
|
232
222
|
}
|
|
233
|
-
|
|
223
|
+
this.jobQueue.enqueueEvent(this.instance, [name, data]);
|
|
234
224
|
}
|
|
235
225
|
/*
|
|
236
226
|
Wraps the sendEvent call with predefined data specific to page events.
|
|
@@ -260,11 +250,11 @@ export class Kochava {
|
|
|
260
250
|
}
|
|
261
251
|
const idLink = {};
|
|
262
252
|
idLink[name] = identifier;
|
|
263
|
-
addPersistedIdLinks(name, identifier,
|
|
264
|
-
// if (this
|
|
253
|
+
addPersistedIdLinks(name, identifier, this.instance.useCookies);
|
|
254
|
+
// if (this.instance.installStarted || this.instance.installDone) {
|
|
265
255
|
if (localStorage.getItem("com.kochava.tracker.InstallSentDate")) {
|
|
266
256
|
// it will be sent standalone
|
|
267
|
-
|
|
257
|
+
this.jobQueue.enqueueIdLink(this.instance, idLink);
|
|
268
258
|
}
|
|
269
259
|
// will be sent in install
|
|
270
260
|
}
|
|
@@ -277,7 +267,7 @@ export class Kochava {
|
|
|
277
267
|
}
|
|
278
268
|
const dataToAdorn = {};
|
|
279
269
|
dataToAdorn[name] = value;
|
|
280
|
-
|
|
270
|
+
this.instance.customValues.push({ data: dataToAdorn, isDeviceId: false });
|
|
281
271
|
}
|
|
282
272
|
// Allows the client to attach arbitrary identifiers to go out in the install.
|
|
283
273
|
registerCustomDeviceIdentifier(name, value) {
|
|
@@ -288,7 +278,7 @@ export class Kochava {
|
|
|
288
278
|
}
|
|
289
279
|
const dataToAdorn = {};
|
|
290
280
|
dataToAdorn[name] = value;
|
|
291
|
-
|
|
281
|
+
this.instance.customValues.push({ data: dataToAdorn, isDeviceId: true });
|
|
292
282
|
}
|
|
293
283
|
/*
|
|
294
284
|
Returns whether or not the sdk is in a "started" state.
|
|
@@ -297,15 +287,15 @@ export class Kochava {
|
|
|
297
287
|
Likewise, shutdown will set "started" to false;
|
|
298
288
|
*/
|
|
299
289
|
getStarted() {
|
|
300
|
-
return
|
|
290
|
+
return this.instance.started;
|
|
301
291
|
}
|
|
302
292
|
/*
|
|
303
293
|
Returns the current kochavaDeviceId, or "" if called too early.
|
|
304
294
|
*/
|
|
305
295
|
getDeviceId() {
|
|
306
296
|
Log.diagDebug(`Host called API: Get Kochava Device Id`);
|
|
307
|
-
if (
|
|
308
|
-
return
|
|
297
|
+
if (this.instance.started)
|
|
298
|
+
return this.instance.kochavaDeviceId;
|
|
309
299
|
else
|
|
310
300
|
return "";
|
|
311
301
|
}
|
|
@@ -316,160 +306,172 @@ export class Kochava {
|
|
|
316
306
|
*/
|
|
317
307
|
setSleep(sleep) {
|
|
318
308
|
Log.diagDebug(`Host called API: Sleep ${sleep ? "Stop" : "Start"}`);
|
|
319
|
-
if (sleep && !
|
|
309
|
+
if (sleep && !this.instance.sleep) {
|
|
320
310
|
// only pause if it was running
|
|
321
|
-
|
|
322
|
-
|
|
311
|
+
this.instance.sleep = sleep;
|
|
312
|
+
this.jobQueue.pause();
|
|
323
313
|
}
|
|
324
|
-
else if (!sleep &&
|
|
314
|
+
else if (!sleep && this.instance.sleep) {
|
|
325
315
|
// only resume queueing if it was paused
|
|
326
|
-
|
|
327
|
-
|
|
316
|
+
this.instance.sleep = sleep;
|
|
317
|
+
this.beginStart();
|
|
328
318
|
}
|
|
329
319
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").appGuid = appGuid;
|
|
363
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage = __classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage || false;
|
|
364
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies = __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies || false;
|
|
365
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").version = __classPrivateFieldGet(this, _Kochava_instance, "f").version || "WebTracker 3.0.0";
|
|
366
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").buildDate = "kbd: 7/12/2022, 9:10:58 AM";
|
|
367
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaSession = utils.uuidv4().substring(0, 5);
|
|
368
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").startTimeMS = utils.getCurrTimeMS();
|
|
369
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").retryWaterfall = [7, 30, 300, 1800];
|
|
370
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
|
|
371
|
-
}, _Kochava_checkFirstLaunchAndMigrate = function _Kochava_checkFirstLaunchAndMigrate() {
|
|
372
|
-
// If this is our first launch ever, set it in persistence.
|
|
373
|
-
if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies)) {
|
|
374
|
-
updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
375
|
-
/*
|
|
376
|
-
On a first launch of the v3 sdk, we need to migrate old persisted kv_id
|
|
377
|
-
from v2.2, v2.3, and v2.5
|
|
378
|
-
*/
|
|
379
|
-
// perform migration
|
|
380
|
-
const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
381
|
-
if (oldKvId) {
|
|
382
|
-
updatePersistedValue(PersistKey.DeviceId, oldKvId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
383
|
-
updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies);
|
|
384
|
-
}
|
|
320
|
+
// ============================= =============================== //
|
|
321
|
+
// Unintialized/invalid state.
|
|
322
|
+
// start must be called before these values will be correct.
|
|
323
|
+
resetInstance() {
|
|
324
|
+
this.instance = {
|
|
325
|
+
appGuid: "",
|
|
326
|
+
started: false,
|
|
327
|
+
installStarted: false,
|
|
328
|
+
kvinitDone: false,
|
|
329
|
+
installDone: false,
|
|
330
|
+
disableAutoPage: false,
|
|
331
|
+
useCookies: false,
|
|
332
|
+
sleep: false,
|
|
333
|
+
version: "",
|
|
334
|
+
buildDate: "",
|
|
335
|
+
overrideUrls: {
|
|
336
|
+
init: "",
|
|
337
|
+
install: "",
|
|
338
|
+
event: "",
|
|
339
|
+
identityLink: "",
|
|
340
|
+
},
|
|
341
|
+
customValues: [],
|
|
342
|
+
kochavaSession: "",
|
|
343
|
+
retryWaterfall: [],
|
|
344
|
+
startTimeMS: 0,
|
|
345
|
+
utm: "",
|
|
346
|
+
kochavaDeviceId: "",
|
|
347
|
+
kochavaInstallId: "",
|
|
348
|
+
kochavaSessionCount: -1,
|
|
349
|
+
kochavaInstallDate: -1,
|
|
350
|
+
kochavaConfig: undefined,
|
|
351
|
+
};
|
|
385
352
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
353
|
+
initInstance(appGuid) {
|
|
354
|
+
// init instance with defaults
|
|
355
|
+
this.instance.appGuid = appGuid;
|
|
356
|
+
this.instance.disableAutoPage = this.instance.disableAutoPage || false;
|
|
357
|
+
this.instance.useCookies = this.instance.useCookies || false;
|
|
358
|
+
this.instance.version = this.instance.version || "WebTracker " + SDK_VERSION;
|
|
359
|
+
this.instance.buildDate = "kbd: 8/16/2024, 3:02:42 PM";
|
|
360
|
+
this.instance.kochavaSession = utils.uuidv4().substring(0, 5);
|
|
361
|
+
this.instance.startTimeMS = utils.getCurrTimeMS();
|
|
362
|
+
this.instance.retryWaterfall = [7, 30, 300, 1800];
|
|
363
|
+
this.instance.kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
|
|
398
364
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
365
|
+
checkFirstLaunchAndMigrate() {
|
|
366
|
+
// If this is our first launch ever, set it in persistence.
|
|
367
|
+
if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, this.instance.useCookies)) {
|
|
368
|
+
updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
|
|
369
|
+
/*
|
|
370
|
+
On a first launch of the v3 sdk, we need to migrate old persisted kv_id
|
|
371
|
+
from v2.2, v2.3, and v2.5
|
|
372
|
+
*/
|
|
373
|
+
// perform migration
|
|
374
|
+
const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, this.instance.useCookies);
|
|
375
|
+
if (oldKvId) {
|
|
376
|
+
updatePersistedValue(PersistKey.DeviceId, oldKvId, this.instance.useCookies);
|
|
377
|
+
updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), this.instance.useCookies);
|
|
378
|
+
}
|
|
407
379
|
}
|
|
408
380
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
381
|
+
checkPersistedKvinit() {
|
|
382
|
+
// check if persisted kvinit
|
|
383
|
+
let persistedKvinit = {};
|
|
384
|
+
const persistedKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
|
|
385
|
+
if (persistedKvinitStr) {
|
|
386
|
+
persistedKvinit = JSON.parse(persistedKvinitStr);
|
|
387
|
+
if (persistedKvinit) {
|
|
388
|
+
// if persisted kvinit, apply it
|
|
389
|
+
Log.trace("Found persisted kvinit.", persistedKvinit);
|
|
390
|
+
Kvinit.applyKvinitResp(this.instance, persistedKvinit);
|
|
391
|
+
Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
// check refresh minimum too
|
|
395
|
+
const persistedKvinitDateStr = readAndUpdatePersistedValue(PersistKey.KvinitSentDate, this.instance.useCookies);
|
|
396
|
+
if (persistedKvinitDateStr) {
|
|
397
|
+
const lastKvinitDate = JSON.parse(persistedKvinitDateStr);
|
|
398
|
+
if (lastKvinitDate) {
|
|
399
|
+
const refreshMin = this.instance.kochavaConfig.config.refresh_minimum;
|
|
400
|
+
if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin)
|
|
401
|
+
this.instance.kvinitDone = true;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
428
404
|
}
|
|
429
|
-
|
|
430
|
-
|
|
405
|
+
checkPersistedState() {
|
|
406
|
+
this.instance.installDone =
|
|
407
|
+
readAndUpdatePersistedValue(PersistKey.InstallSentDate, this.instance.useCookies).length > 0;
|
|
408
|
+
this.instance.kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, this.instance.useCookies);
|
|
409
|
+
this.instance.kochavaDeviceId = readAndUpdateDeviceId(this.instance.useCookies);
|
|
410
|
+
this.instance.kochavaSessionCount = readAndUpdateSessionCount(this.instance.useCookies);
|
|
411
|
+
this.instance.utm = readAndUpdateUTM(this.instance.appGuid, this.instance.useCookies);
|
|
431
412
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
await __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_performInstall).call(this);
|
|
413
|
+
printStartupMsgs(appGuid) {
|
|
414
|
+
Log.diagInfo(`Started SDK ${this.instance.version}
|
|
415
|
+
published ${this.instance.buildDate}`);
|
|
416
|
+
Log.diagInfo(`The log level is set to ${Log.getLogLevel()}`);
|
|
417
|
+
Log.diagDebug(`This ${!this.instance.installDone ? "is" : "is not"} the first tracker SDK launch`);
|
|
418
|
+
Log.diagDebug(`The kochava device id is ${this.instance.kochavaDeviceId}`);
|
|
419
|
+
Log.diagDebug(`The kochava app GUID provided was ${appGuid}`);
|
|
440
420
|
}
|
|
441
|
-
|
|
442
|
-
|
|
421
|
+
async beginStart() {
|
|
422
|
+
// if we need to send a new kvinit, send it
|
|
423
|
+
if (!this.instance.kvinitDone) {
|
|
424
|
+
Log.diagDebug(`A new kvinit will be sent`);
|
|
425
|
+
await this.performNewKvinit();
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
Log.diagDebug(`A new kvinit will not be sent`);
|
|
429
|
+
}
|
|
430
|
+
// if the install_id changed and thus a new install must go out
|
|
431
|
+
if (this.checkResendId())
|
|
432
|
+
this.instance.installDone = false;
|
|
433
|
+
Log.diagDebug(`The install ${this.instance.installDone ? "has already" : "has not yet"} been sent`);
|
|
434
|
+
if (this.instance.sleep)
|
|
435
|
+
return;
|
|
436
|
+
if (!this.instance.installDone) {
|
|
437
|
+
await this.performInstall();
|
|
438
|
+
}
|
|
439
|
+
if (this.instance.kvinitDone && this.instance.installDone) {
|
|
440
|
+
await this.jobQueue.start(this.instance);
|
|
441
|
+
}
|
|
443
442
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
443
|
+
async performNewKvinit() {
|
|
444
|
+
this.instance.kvinitDone = await Kvinit.send(this.instance, this.instance.retryWaterfall);
|
|
445
|
+
updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), this.instance.useCookies);
|
|
446
|
+
// if new kvinit, apply it
|
|
447
|
+
let newKvinit = {};
|
|
448
|
+
const newKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, this.instance.useCookies);
|
|
449
|
+
if (newKvinitStr) {
|
|
450
|
+
newKvinit = JSON.parse(newKvinitStr);
|
|
451
|
+
}
|
|
452
|
+
Kvinit.applyKvinitResp(this.instance, newKvinit);
|
|
453
|
+
Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(this.instance.kochavaConfig)));
|
|
452
454
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
455
|
+
checkResendId() {
|
|
456
|
+
let resendId = "";
|
|
457
|
+
if (this.instance.kochavaConfig.install) {
|
|
458
|
+
resendId = this.instance.kochavaConfig.install.resend_id;
|
|
459
|
+
}
|
|
460
|
+
const needsNewInstall = checkInstallIdChange(resendId, this.instance.useCookies);
|
|
461
|
+
if (needsNewInstall) {
|
|
462
|
+
Log.debug(`resend_id ${resendId} found, forcing new install`);
|
|
463
|
+
}
|
|
464
|
+
return needsNewInstall;
|
|
459
465
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
466
|
+
async performInstall() {
|
|
467
|
+
const request = Install.build(this.instance);
|
|
468
|
+
this.instance.installDone = await Install.send(this.instance, request);
|
|
469
|
+
if (!this.instance.installDone)
|
|
470
|
+
return;
|
|
471
|
+
// If the install succeeded, remove all idLink that were passed to it
|
|
472
|
+
Install.onSuccess(this.instance);
|
|
473
|
+
updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(this.jobQueue.idLinkQueue), false);
|
|
463
474
|
}
|
|
464
|
-
|
|
465
|
-
}, _Kochava_performInstall = async function _Kochava_performInstall() {
|
|
466
|
-
const request = Install.build(__classPrivateFieldGet(this, _Kochava_instance, "f"));
|
|
467
|
-
__classPrivateFieldGet(this, _Kochava_instance, "f").installDone = await Install.send(__classPrivateFieldGet(this, _Kochava_instance, "f"), request);
|
|
468
|
-
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone)
|
|
469
|
-
return;
|
|
470
|
-
// If the install succeeded, remove all idLink that were passed to it
|
|
471
|
-
Install.onSuccess(__classPrivateFieldGet(this, _Kochava_instance, "f"));
|
|
472
|
-
updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(__classPrivateFieldGet(this, _Kochava_jobQueue, "f").idLinkQueue), false);
|
|
473
|
-
};
|
|
475
|
+
}
|
|
474
476
|
// Only here for generic Web integration
|
|
475
477
|
window.kochava = Kochava.create();
|
package/dist/payloads/install.js
CHANGED
|
@@ -101,18 +101,27 @@ const constructInstallData = (instance) => {
|
|
|
101
101
|
returnObj.device_ids = {};
|
|
102
102
|
instance.customValues.forEach((custom) => {
|
|
103
103
|
const customKey = Object.keys(custom.data)[0];
|
|
104
|
+
console.log("customData: ", custom);
|
|
104
105
|
if (instance.kochavaConfig.privacy) {
|
|
105
106
|
let keyAllowed = false;
|
|
107
|
+
console.log("1");
|
|
106
108
|
for (const allowed of instance.kochavaConfig.privacy.allow_custom_ids) {
|
|
107
109
|
if (customKey === allowed) {
|
|
110
|
+
console.log("2");
|
|
108
111
|
keyAllowed = true;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
if (keyAllowed) {
|
|
112
|
-
|
|
115
|
+
console.log("3");
|
|
116
|
+
if (custom.isDeviceId) {
|
|
117
|
+
console.log("4");
|
|
113
118
|
returnObj.device_ids = Object.assign(Object.assign({}, returnObj.device_ids), custom.data);
|
|
114
|
-
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.log("before: ", returnObj);
|
|
115
122
|
returnObj = Object.assign(Object.assign({}, custom.data), returnObj);
|
|
123
|
+
console.log("after: ", returnObj);
|
|
124
|
+
}
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
127
|
});
|