web-adsmeasurement 1.8.12

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.
Files changed (41) hide show
  1. package/README.md +12 -0
  2. package/es5_dist/browser/browser.d.ts +3 -0
  3. package/es5_dist/browser/browser.js +31 -0
  4. package/es5_dist/browser/browser.js.map +1 -0
  5. package/es5_dist/browser/persist.d.ts +28 -0
  6. package/es5_dist/browser/persist.js +139 -0
  7. package/es5_dist/browser/persist.js.map +1 -0
  8. package/es5_dist/generated/buildInfo.d.ts +2 -0
  9. package/es5_dist/generated/buildInfo.js +3 -0
  10. package/es5_dist/generated/buildInfo.js.map +1 -0
  11. package/es5_dist/http.d.ts +3 -0
  12. package/es5_dist/http.js +132 -0
  13. package/es5_dist/http.js.map +1 -0
  14. package/es5_dist/interfaces.d.ts +72 -0
  15. package/es5_dist/interfaces.js +21 -0
  16. package/es5_dist/interfaces.js.map +1 -0
  17. package/es5_dist/jobqueue.d.ts +30 -0
  18. package/es5_dist/jobqueue.js +307 -0
  19. package/es5_dist/jobqueue.js.map +1 -0
  20. package/es5_dist/kochava.d.ts +80 -0
  21. package/es5_dist/kochava.js +654 -0
  22. package/es5_dist/kochava.js.map +1 -0
  23. package/es5_dist/payloads/config.d.ts +8 -0
  24. package/es5_dist/payloads/config.js +360 -0
  25. package/es5_dist/payloads/config.js.map +1 -0
  26. package/es5_dist/payloads/conversion.d.ts +5 -0
  27. package/es5_dist/payloads/conversion.js +195 -0
  28. package/es5_dist/payloads/conversion.js.map +1 -0
  29. package/es5_dist/payloads/payload.d.ts +9 -0
  30. package/es5_dist/payloads/payload.js +23 -0
  31. package/es5_dist/payloads/payload.js.map +1 -0
  32. package/es5_dist/product.d.ts +27 -0
  33. package/es5_dist/product.js +50 -0
  34. package/es5_dist/product.js.map +1 -0
  35. package/es5_dist/utils/log.d.ts +33 -0
  36. package/es5_dist/utils/log.js +151 -0
  37. package/es5_dist/utils/log.js.map +1 -0
  38. package/es5_dist/utils/utils.d.ts +10 -0
  39. package/es5_dist/utils/utils.js +81 -0
  40. package/es5_dist/utils/utils.js.map +1 -0
  41. package/package.json +19 -0
@@ -0,0 +1,654 @@
1
+ /*
2
+ Authored by Jacob Bechler on 6/13/23.
3
+ Copyright (c) Kochava, Inc. All rights reserved.
4
+ */
5
+ var __assign = this && this.__assign || function () {
6
+ __assign = Object.assign || function (t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
10
+ }
11
+ return t;
12
+ };
13
+ return __assign.apply(this, arguments);
14
+ };
15
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
16
+ function adopt(value) {
17
+ return value instanceof P ? value : new P(function (resolve) {
18
+ resolve(value);
19
+ });
20
+ }
21
+ return new (P || (P = Promise))(function (resolve, reject) {
22
+ function fulfilled(value) {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ }
29
+ function rejected(value) {
30
+ try {
31
+ step(generator["throw"](value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ }
36
+ function step(result) {
37
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
38
+ }
39
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
40
+ });
41
+ };
42
+ var __generator = this && this.__generator || function (thisArg, body) {
43
+ var _ = { label: 0, sent: function () {
44
+ if (t[0] & 1) throw t[1];return t[1];
45
+ }, trys: [], ops: [] },
46
+ f,
47
+ y,
48
+ t,
49
+ g;
50
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
51
+ return this;
52
+ }), g;
53
+ function verb(n) {
54
+ return function (v) {
55
+ return step([n, v]);
56
+ };
57
+ }
58
+ function step(op) {
59
+ if (f) throw new TypeError("Generator is already executing.");
60
+ while (_) try {
61
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
62
+ if (y = 0, t) op = [op[0] & 2, t.value];
63
+ switch (op[0]) {
64
+ case 0:case 1:
65
+ t = op;break;
66
+ case 4:
67
+ _.label++;return { value: op[1], done: false };
68
+ case 5:
69
+ _.label++;y = op[1];op = [0];continue;
70
+ case 7:
71
+ op = _.ops.pop();_.trys.pop();continue;
72
+ default:
73
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
74
+ _ = 0;continue;
75
+ }
76
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
77
+ _.label = op[1];break;
78
+ }
79
+ if (op[0] === 6 && _.label < t[1]) {
80
+ _.label = t[1];t = op;break;
81
+ }
82
+ if (t && _.label < t[2]) {
83
+ _.label = t[2];_.ops.push(op);break;
84
+ }
85
+ if (t[2]) _.ops.pop();
86
+ _.trys.pop();continue;
87
+ }
88
+ op = body.call(thisArg, _);
89
+ } catch (e) {
90
+ op = [6, e];y = 0;
91
+ } finally {
92
+ f = t = 0;
93
+ }
94
+ if (op[0] & 5) throw op[1];return { value: op[0] ? op[1] : void 0, done: true };
95
+ }
96
+ };
97
+ var __rest = this && this.__rest || function (s, e) {
98
+ var t = {};
99
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
100
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
101
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
102
+ }
103
+ return t;
104
+ };
105
+ import { Log } from "./utils/log";
106
+ import JobQueue from "./jobqueue";
107
+ import * as Config from "./payloads/config";
108
+ import { DEFAULTS } from "./interfaces";
109
+ import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, readPersistedConfig, readAndUpdateInstallId, readPersistedCustomDeviceIdentifiers } from "./browser/persist";
110
+ import * as utils from "./utils/utils";
111
+ import { Product } from "./product";
112
+ // Re-export Product so framework harnesses (React, Vue, Angular, ReactNative)
113
+ // can import both PubSuite and Product from a single module reference, matching
114
+ // K4A's pattern. Parity with K4A's src/kochava.ts which re-exports Product.
115
+ export { Product } from "./product";
116
+ var PubSuite = /** @class */function () {
117
+ // User will use the below factories instead of directly calling
118
+ // the constructor
119
+ function PubSuite() {
120
+ this.product = Product.adsmeasurement;
121
+ this.resetInstance();
122
+ this.jobQueue = new JobQueue();
123
+ }
124
+ // ============================= PUBLIC =============================== //
125
+ PubSuite.create = function () {
126
+ return new PubSuite();
127
+ };
128
+ // Framework-specific factories. Parity with K4A's PubSuite/Kochava factory
129
+ // pattern so the framework harnesses (and any framework integrations) can
130
+ // instantiate via a per-framework entry point. For now each delegates to
131
+ // create(); per-framework configuration can park here later.
132
+ PubSuite.createForReact = function () {
133
+ return PubSuite.create();
134
+ };
135
+ PubSuite.createForVue = function () {
136
+ return PubSuite.create();
137
+ };
138
+ PubSuite.createForAngular = function () {
139
+ return PubSuite.create();
140
+ };
141
+ PubSuite.createForReactNative = function () {
142
+ return PubSuite.create();
143
+ };
144
+ PubSuite.prototype.startWithConfig = function (config) {
145
+ var _a, _b, _c, _d;
146
+ Log.diagInfo("Host called API: Start With Config");
147
+ var event_metadata = config.event_metadata,
148
+ rest = __rest(config, ["event_metadata"]);
149
+ this.instance.HostConfig = __assign({ conversion_metadata: event_metadata }, rest);
150
+ this.start((_b = (_a = this.instance.HostConfig.general) === null || _a === void 0 ? void 0 : _a.product_id) !== null && _b !== void 0 ? _b : "", (_d = (_c = this.instance.HostConfig.general) === null || _c === void 0 ? void 0 : _c.access_token) !== null && _d !== void 0 ? _d : "");
151
+ };
152
+ PubSuite.prototype.startWithProductId = function (product_id, access_token) {
153
+ Log.diagInfo("Host called API: Start With Product ID");
154
+ this.start(product_id, access_token);
155
+ };
156
+ /*
157
+ The primary means for starting the sdk.
158
+ Responsibilites:
159
+ - Creates the sdk instance.
160
+ - Checks for persisted state.
161
+ - Determines and applies config.
162
+ - Starts the job queue.
163
+ */
164
+ PubSuite.prototype.start = function (product_id, access_token) {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ return __generator(this, function (_a) {
167
+ switch (_a.label) {
168
+ case 0:
169
+ if (!product_id) {
170
+ Log.error("Invalid product_id: ".concat(product_id, ", start failed."));
171
+ return [2 /*return*/];
172
+ }
173
+ if (!access_token) {
174
+ Log.error("Invalid access_token: ".concat(access_token, ", start failed."));
175
+ return [2 /*return*/];
176
+ }
177
+ if (!this.instance) this.resetInstance();
178
+ if (this.instance.started) {
179
+ Log.warn("SDK already started.");
180
+ return [2 /*return*/];
181
+ }
182
+ this.instance.started = true;
183
+ this.checkFirstLaunch();
184
+ this.initInstance(product_id, access_token);
185
+ if (!!this.instance.configDone) return [3 /*break*/, 2];
186
+ return [4 /*yield*/, this.performNewConfig()];
187
+ case 1:
188
+ _a.sent();
189
+ _a.label = 2;
190
+ case 2:
191
+ this.checkPersistedState();
192
+ this.printStartupMsgs(product_id);
193
+ this.enableElementTracking();
194
+ this.beginStart();
195
+ return [2 /*return*/];
196
+ }
197
+ });
198
+ });
199
+ };
200
+ /*
201
+ Builds and enqueues a conversion. Must include a conversion_name string,
202
+ with optional conversion_data as either another string or object.
203
+ */
204
+ PubSuite.prototype.sendConversion = function (name, data, override_access_token, override_product_id) {
205
+ Log.diagInfo("Host called API: Send Conversion");
206
+ if (!name) {
207
+ Log.warn("Invalid Conversion name, ignoring call.");
208
+ return;
209
+ }
210
+ if (this.instance.sessionConfig.enabled) {
211
+ this.updateSessionState();
212
+ }
213
+ this.jobQueue.enqueueConversion(this.instance, [name, data, override_access_token, override_product_id]);
214
+ };
215
+ /*
216
+ Returns whether or not the sdk is in a "started" state.
217
+ This basically amounts to if start has been called,
218
+ not if config is done or the queue is started.
219
+ Likewise, shutdown will set "started" to false;
220
+ */
221
+ PubSuite.prototype.getStarted = function () {
222
+ return this.instance.started;
223
+ };
224
+ PubSuite.prototype.registerCustomDeviceIdentifier = function (name, value) {
225
+ Log.diagInfo("Host called API: Register Custom Device Identifier ".concat(value ? 'setting' : 'clearing', " ").concat(name));
226
+ if (!name) {
227
+ Log.warn("Invalid custom device identifier, ignoring call.");
228
+ return;
229
+ }
230
+ var persistedCustomDeviceIds = readPersistedCustomDeviceIdentifiers(this.instance.useCookies);
231
+ if (persistedCustomDeviceIds) {
232
+ this.instance.customDeviceIds = JSON.parse(persistedCustomDeviceIds);
233
+ }
234
+ this.instance.customDeviceIds = this.instance.customDeviceIds.filter(function (id) {
235
+ return id.name !== name;
236
+ });
237
+ if (value) {
238
+ var newCustomDeviceId = {
239
+ name: name.substring(0, 256),
240
+ value: value.substring(0, 256)
241
+ };
242
+ this.instance.customDeviceIds.push(newCustomDeviceId);
243
+ if (this.instance.customDeviceIds.length > 100) {
244
+ this.instance.customDeviceIds = this.instance.customDeviceIds.slice(-100);
245
+ }
246
+ }
247
+ updatePersistedValue(PersistKey.CustomDeviceIdentifiers, JSON.stringify(this.instance.customDeviceIds), this.instance.useCookies);
248
+ };
249
+ /*
250
+ Puts the sdk in a "sleep" state. This will stop the sdk from dequeuing
251
+ new jobs and retrying failed jobs. Different than shutdown, because the
252
+ current state is not destroyed.
253
+ */
254
+ PubSuite.prototype.setSleep = function (sleep) {
255
+ Log.diagInfo("Host called API: Sleep ".concat(sleep ? "Stop" : "Start"));
256
+ if (sleep && !this.instance.sleep) {
257
+ // only pause if it was running
258
+ this.instance.sleep = sleep;
259
+ this.jobQueue.pause();
260
+ } else if (!sleep && this.instance.sleep) {
261
+ // only resume queueing if it was paused
262
+ this.instance.sleep = sleep;
263
+ this.beginStart();
264
+ }
265
+ };
266
+ /*
267
+ Primary means for stopping the sdk.
268
+ Will optionally delete all persisted data, and will shutdown the
269
+ sdk and job queue.
270
+ */
271
+ PubSuite.prototype.shutdown = function (deleteData) {
272
+ Log.diagInfo("Host called API: Shutdown and ".concat(deleteData ? "delete data" : "keep data"));
273
+ if (deleteData) {
274
+ Log.debug("Deleting persisted values");
275
+ deleteAllPersisted();
276
+ }
277
+ if (!this.instance.started) {
278
+ Log.warn("SDK already shutdown.");
279
+ }
280
+ Log.info("SDK shutting down.");
281
+ Config.cancelRetries();
282
+ this.jobQueue.stop();
283
+ // wipe whatever was previously in the queue
284
+ this.jobQueue = new JobQueue();
285
+ this.resetInstance();
286
+ };
287
+ /*
288
+ Changes the current logLevel.
289
+ Options include:
290
+ - Off :: No logging whatsoever
291
+ - Error :: Only critical errors
292
+ - Warn :: Only critical errors and non-critical warnings
293
+ - Info :: High-level sdk behavior logs (default)
294
+ - Debug :: More in-depth sdk behavior logs and payload logs
295
+ - Trace :: Everything, granular detail
296
+ */
297
+ PubSuite.prototype.setLogLevel = function (logLevel) {
298
+ Log.diagInfo("Host called API: Set Log Level ".concat(logLevel));
299
+ Log.setLogLevel(logLevel);
300
+ };
301
+ /*
302
+ Used internally, for special SDK behavior not utilized by a client.
303
+ Examples include:
304
+ - urls :: purposefully changing an endpoint for testing
305
+ - wrapper :: overwriting the version of a wrapper
306
+ several more ...
307
+ */
308
+ PubSuite.prototype.executeAdvancedInstruction = function (key, valueStr, callback) {
309
+ Log.diagInfo("Host called API: Execute Advanced Instruction ".concat(key));
310
+ switch (key) {
311
+ case "wrapper":
312
+ {
313
+ var wrapperVersion = JSON.parse(valueStr);
314
+ Product.adsmeasurement.wrapperProduct = new Product("Product.wrapper", wrapperVersion.name, wrapperVersion.name, wrapperVersion.version, "");
315
+ this.instance.version = Product.adsmeasurement.standardVersionInfoString;
316
+ }
317
+ break;
318
+ case "urls":
319
+ {
320
+ var overrideUrls = JSON.parse(valueStr);
321
+ if (overrideUrls.config) this.instance.overrideUrls.serverConfig = overrideUrls.config;
322
+ if (overrideUrls.conversion) this.instance.overrideUrls.conversion = overrideUrls.conversion;
323
+ }
324
+ break;
325
+ case "urlsRestore":
326
+ {
327
+ var restoreUrls = JSON.parse(valueStr);
328
+ for (var _i = 0, restoreUrls_1 = restoreUrls; _i < restoreUrls_1.length; _i++) {
329
+ var url = restoreUrls_1[_i];
330
+ if (url === "config") this.instance.overrideUrls.hostServerConfig = DEFAULTS.networking.urls.serverConfig;
331
+ if (url === "conversion") this.instance.overrideUrls.conversion = DEFAULTS.networking.urls.conversion;
332
+ }
333
+ }
334
+ break;
335
+ case "logFilter":
336
+ {
337
+ var disabled = JSON.parse(valueStr);
338
+ disabled.forEach(function (level) {
339
+ return Log.disableLogType(level);
340
+ });
341
+ }
342
+ break;
343
+ case "getInstance":
344
+ {
345
+ var currInstance = JSON.stringify(this.instance);
346
+ if (callback) callback(currInstance);
347
+ Log.debug("capturing instance: ".concat(valueStr));
348
+ }
349
+ break;
350
+ case "logObjects":
351
+ Log.setLogObjects(JSON.parse(valueStr));
352
+ break;
353
+ case "pInstance":
354
+ return JSON.stringify(this.instance);
355
+ break;
356
+ default:
357
+ break;
358
+ }
359
+ };
360
+ PubSuite.prototype.enableElementTracking = function (condition) {
361
+ if (condition === void 0) {
362
+ condition = true;
363
+ }
364
+ if (this.boundClickHandler) {
365
+ document.removeEventListener('click', this.boundClickHandler);
366
+ }
367
+ if (condition) {
368
+ this.boundClickHandler = this.ClickHandler.bind(this);
369
+ if (this.boundClickHandler) {
370
+ document.addEventListener('click', this.boundClickHandler);
371
+ }
372
+ } else {
373
+ this.boundClickHandler = null;
374
+ }
375
+ };
376
+ // Unintialized/invalid state.
377
+ // start must be called before these values will be correct.
378
+ PubSuite.prototype.resetInstance = function () {
379
+ // Log.diagDebug("RESETTING INSTANCE.")
380
+ this.instance = {
381
+ product_id: "",
382
+ access_token: "",
383
+ started: false,
384
+ configDone: false,
385
+ HostConfig: {
386
+ general: {},
387
+ config: {
388
+ refresh_minimum: 60
389
+ },
390
+ networking: {
391
+ urls: {
392
+ config: "",
393
+ conversion: ""
394
+ },
395
+ retry_waterfall: [7, 30, 300, 1800]
396
+ },
397
+ sessions: {
398
+ enabled: false,
399
+ timeout: 1800
400
+ }
401
+ },
402
+ customDataAttribute: 'data-ps-conversion',
403
+ element_conversions: [],
404
+ button_conversions: [],
405
+ useCookies: false,
406
+ collectReferrer: false,
407
+ collectUrl: false,
408
+ sleep: false,
409
+ version: Product.adsmeasurement.standardVersionInfoString,
410
+ buildDate: Product.adsmeasurement.sdkBuildDate,
411
+ collect_ga: false,
412
+ overrideUrls: {
413
+ serverConfig: "",
414
+ hostServerConfig: "",
415
+ conversion: ""
416
+ },
417
+ customDeviceIds: [],
418
+ conversion_metadata: {},
419
+ pubSuiteSession: "",
420
+ retryWaterfall: [],
421
+ startTimeMS: 0,
422
+ sdk_disabled: false,
423
+ instance_id: '',
424
+ installIdEnabled: false,
425
+ pubSuiteSessionCount: -1,
426
+ pubSuiteConfig: undefined,
427
+ pubSuiteInstallId: '',
428
+ sessionConfig: {
429
+ enabled: false,
430
+ timeout: 1800
431
+ },
432
+ sessionState: {
433
+ last_activity_time: 0,
434
+ session_time: 0,
435
+ count: 0
436
+ }
437
+ };
438
+ };
439
+ PubSuite.prototype.initInstance = function (product_id, access_token) {
440
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
441
+ // init instance with defaults
442
+ this.instance.product_id = product_id;
443
+ this.instance.access_token = access_token;
444
+ this.instance.version = Product.adsmeasurement.standardVersionInfoString;
445
+ this.instance.buildDate = Product.adsmeasurement.sdkBuildDate;
446
+ this.instance.pubSuiteSession = utils.uuidv4().substring(0, 5);
447
+ this.instance.startTimeMS = utils.getCurrTimeMS();
448
+ this.instance.retryWaterfall = [7, 30, 300, 1800];
449
+ this.instance.instance_id = utils.uuidv4().substring(0, 5);
450
+ this.instance.installIdEnabled = (_b = (_a = this.instance.HostConfig.general) === null || _a === void 0 ? void 0 : _a.install_id_enabled) !== null && _b !== void 0 ? _b : false;
451
+ this.instance.useCookies = (_e = ((_c = this.instance.HostConfig.general) === null || _c === void 0 ? void 0 : _c.cookies_enabled) || ((_d = this.instance.HostConfig.general) === null || _d === void 0 ? void 0 : _d.pers_tr)) !== null && _e !== void 0 ? _e : false;
452
+ this.instance.sessionConfig.enabled = (_g = (_f = this.instance.HostConfig.sessions) === null || _f === void 0 ? void 0 : _f.enabled) !== null && _g !== void 0 ? _g : false;
453
+ this.instance.sessionConfig.timeout = (_j = (_h = this.instance.HostConfig.sessions) === null || _h === void 0 ? void 0 : _h.timeout) !== null && _j !== void 0 ? _j : 1800;
454
+ this.instance.collectReferrer = (_l = (_k = this.instance.HostConfig.general) === null || _k === void 0 ? void 0 : _k.collect_page_info) !== null && _l !== void 0 ? _l : false;
455
+ this.instance.collectUrl = (_o = (_m = this.instance.HostConfig.general) === null || _m === void 0 ? void 0 : _m.collect_page_info) !== null && _o !== void 0 ? _o : false;
456
+ this.instance.pubSuiteConfig = JSON.parse(JSON.stringify(DEFAULTS));
457
+ };
458
+ PubSuite.prototype.checkFirstLaunch = function () {
459
+ // If this is our first launch ever, set it in persistence.
460
+ if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate)) {
461
+ updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()));
462
+ }
463
+ };
464
+ PubSuite.prototype.checkPersistedState = function () {
465
+ // this.instance.pubSuiteSessionCount = readAndUpdateSessionCount();
466
+ if (this.instance.installIdEnabled) this.instance.pubSuiteInstallId = readAndUpdateInstallId(this.instance.useCookies);
467
+ if (this.instance.sessionConfig.enabled) {
468
+ var persistedSessionTime = parseInt(readAndUpdatePersistedValue(PersistKey.SessionTime));
469
+ this.instance.sessionState.session_time = isNaN(persistedSessionTime) ? 0 : persistedSessionTime;
470
+ var persistedLastActivityTime = parseInt(readAndUpdatePersistedValue(PersistKey.LastActivityTime));
471
+ this.instance.sessionState.last_activity_time = isNaN(persistedLastActivityTime) ? 0 : persistedLastActivityTime;
472
+ var persistedSessionCount = parseInt(readAndUpdatePersistedValue(PersistKey.SessionCount));
473
+ this.instance.sessionState.count = isNaN(persistedSessionCount) ? 0 : persistedSessionCount;
474
+ }
475
+ var persistedCustomDeviceIds = readPersistedCustomDeviceIdentifiers(this.instance.useCookies);
476
+ if (persistedCustomDeviceIds) {
477
+ var restoredCustomDeviceIds = JSON.parse(persistedCustomDeviceIds);
478
+ this.instance.customDeviceIds = restoredCustomDeviceIds;
479
+ }
480
+ };
481
+ PubSuite.prototype.printStartupMsgs = function (product_id) {
482
+ var adsmeasurementProduct = Product.adsmeasurement;
483
+ Log.diagInfo("Started SDK ".concat(adsmeasurementProduct.standardVersionInfoString, "\n published ").concat(adsmeasurementProduct.sdkBuildDate));
484
+ Log.diagInfo("The log level is set to ".concat(Log.getLogLevel()));
485
+ Log.diagDebug("The product ID provided was '".concat(product_id, "'"));
486
+ };
487
+ PubSuite.prototype.beginStart = function () {
488
+ return __awaiter(this, void 0, void 0, function () {
489
+ return __generator(this, function (_a) {
490
+ switch (_a.label) {
491
+ case 0:
492
+ if (this.instance.sleep) return [2 /*return*/];
493
+ if (this.instance.sessionConfig.enabled) this.updateSessionState();
494
+ return [4 /*yield*/, this.jobQueue.start(this.instance)];
495
+ case 1:
496
+ _a.sent();
497
+ return [2 /*return*/];
498
+ }
499
+ });
500
+ });
501
+ };
502
+ PubSuite.prototype.performNewConfig = function () {
503
+ var _a, _b, _c, _d;
504
+ return __awaiter(this, void 0, void 0, function () {
505
+ var config, serverConfig, hostServerConfig;
506
+ return __generator(this, function (_e) {
507
+ switch (_e.label) {
508
+ case 0:
509
+ if (this.instance.HostConfig) config = Config.mergeConfig((_a = this.instance.pubSuiteConfig) !== null && _a !== void 0 ? _a : {}, this.instance.HostConfig);
510
+ if (!Config.ConfigExpired(this.instance)) return [3 /*break*/, 2];
511
+ return [4 /*yield*/, Config.getServerConfig(this.instance, this.instance.retryWaterfall)];
512
+ case 1:
513
+ _e.sent();
514
+ _e.label = 2;
515
+ case 2:
516
+ serverConfig = readPersistedConfig(PersistKey.LastServerConfig);
517
+ if (!!((_b = serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.general) === null || _b === void 0 ? void 0 : _b.sdk_disabled)) return [3 /*break*/, 4];
518
+ if (!(((_d = (_c = config.networking) === null || _c === void 0 ? void 0 : _c.urls) === null || _d === void 0 ? void 0 : _d.config) && Config.ConfigExpired(this.instance))) return [3 /*break*/, 4];
519
+ return [4 /*yield*/, Config.getHostServerConfig(this.instance, this.instance.retryWaterfall)];
520
+ case 3:
521
+ _e.sent();
522
+ hostServerConfig = readPersistedConfig(PersistKey.LastHostServerConfig);
523
+ _e.label = 4;
524
+ case 4:
525
+ if (hostServerConfig) config = Config.mergeConfig(config, hostServerConfig);
526
+ config = Config.mergeConfig(config, serverConfig !== null && serverConfig !== void 0 ? serverConfig : {});
527
+ Config.applyConfigResp(this.instance, config);
528
+ updatePersistedValue(PersistKey.LastConfigDate, String(utils.getCurrTimeSec()));
529
+ this.instance.configDone = true;
530
+ return [2 /*return*/];
531
+ }
532
+ });
533
+ });
534
+ };
535
+ PubSuite.prototype.updateSessionState = function () {
536
+ var currTime = utils.getCurrTimeSec();
537
+ var activityDiff = currTime - this.instance.sessionState.last_activity_time;
538
+ this.instance.sessionState.last_activity_time = currTime;
539
+ updatePersistedValue(PersistKey.LastActivityTime, String(this.instance.sessionState.last_activity_time), this.instance.useCookies);
540
+ if (activityDiff > this.instance.sessionConfig.timeout) {
541
+ this.instance.sessionState.count++;
542
+ this.instance.sessionState.session_time = currTime;
543
+ this.sendConversion("session_start");
544
+ }
545
+ updatePersistedValue(PersistKey.SessionTime, this.instance.sessionState.session_time.toString(), this.instance.useCookies);
546
+ updatePersistedValue(PersistKey.SessionCount, String(this.instance.sessionState.count), this.instance.useCookies);
547
+ };
548
+ PubSuite.prototype.reportUserActivity = function () {
549
+ this.updateSessionState();
550
+ };
551
+ PubSuite.prototype.ClickHandler = function (event) {
552
+ var _a;
553
+ var targetElement = event.target;
554
+ var targetTag = targetElement.tagName;
555
+ var conversion_name = null;
556
+ if (this.instance.button_conversions && (targetTag === "INPUT" || targetTag === "BUTTON")) {
557
+ var buttonText = targetTag === "INPUT" ? targetElement.value : targetElement.textContent;
558
+ if (this.instance.button_conversions[buttonText]) {
559
+ conversion_name = this.instance.button_conversions[buttonText];
560
+ }
561
+ }
562
+ if (targetElement.hasAttribute(this.instance.customDataAttribute)) {
563
+ conversion_name = targetElement.getAttribute(this.instance.customDataAttribute);
564
+ }
565
+ if (this.instance.element_conversions[targetElement.id]) {
566
+ conversion_name = this.instance.element_conversions[targetElement.id];
567
+ }
568
+ if (conversion_name) {
569
+ this.sendConversion(conversion_name, (_a = this.instance.conversion_metadata) !== null && _a !== void 0 ? _a : {});
570
+ return;
571
+ }
572
+ if (Object.keys(this.instance.button_conversions).length && Object.keys(this.instance.element_conversions).length) {
573
+ Log.trace('Element conversions and button conversions are configured, but neither the ID of this element nor the button text match any in the element_conversions or button_text list provided in the config on startup.');
574
+ } else if (Object.keys(this.instance.element_conversions).length) {
575
+ Log.trace('Element conversions are configured, but the ID of this element does not match any in the element_conversions list provided in the config on startup');
576
+ } else if (Object.keys(this.instance.button_conversions).length) {
577
+ Log.trace('Button conversions are configured, but the text of this element does not match any in the button_conversions list provided in the config on startup');
578
+ }
579
+ };
580
+ PubSuite.prototype.Impressions = function () {
581
+ window.addEventListener("load", function () {
582
+ // Executes when visible for more than a second
583
+ function visibleForOneSecond(element) {
584
+ window.pubSuite.sendConversion(element.id);
585
+ }
586
+ // Observer Callback
587
+ function intersectionCallback(entries, observer) {
588
+ entries.forEach(function (entry) {
589
+ if (entry.isIntersecting) {
590
+ var target_1 = entry.target;
591
+ var timerId = setTimeout(function () {
592
+ var rect = entry.target.getBoundingClientRect();
593
+ if (fourCornersVisible(target_1)) {
594
+ visibleForOneSecond(target_1);
595
+ observer.unobserve(target_1);
596
+ }
597
+ }, 1000);
598
+ target_1._visibilityTimer = timerId;
599
+ } else {
600
+ clearTimeout(entry.target._visibilityTimer);
601
+ }
602
+ });
603
+ }
604
+ // Create the intersection observer
605
+ var observer = new IntersectionObserver(intersectionCallback, {
606
+ threshold: 1.0 // Trigger when 100% of the element is visible
607
+ });
608
+ // Observe elements with the specified class name (e.g. '.watched-element')
609
+ var elementsToWatch = document.querySelectorAll('[data-pubSuiteTrack]');
610
+ elementsToWatch.forEach(function (element) {
611
+ return observer.observe(element);
612
+ });
613
+ function fourCornersVisible(target) {
614
+ var rect = target.getBoundingClientRect();
615
+ var topLeftVisible = pointIsVisible(target, rect.left, rect.top);
616
+ var topRightVisible = pointIsVisible(target, rect.right - 1, rect.top + 1);
617
+ var botLeftVisible = pointIsVisible(target, rect.left + 1, rect.bottom - 1);
618
+ var botRightVisible = pointIsVisible(target, rect.right - 1, rect.bottom - 1);
619
+ return topLeftVisible && topRightVisible && botLeftVisible && botRightVisible;
620
+ }
621
+ function pointIsVisible(target, x, y) {
622
+ var topElement = document.elementFromPoint(x, y);
623
+ return target === topElement || target.contains(topElement);
624
+ }
625
+ }, false);
626
+ };
627
+ return PubSuite;
628
+ }();
629
+ export { PubSuite };
630
+ var sdk_instance = PubSuite.create();
631
+ window.pubSuite = sdk_instance;
632
+ function initSDK(currentScript, sdkInstance) {
633
+ if (!currentScript) return;
634
+ var sdkName = currentScript.getAttribute('data-sdk-name') || 'pubSuite';
635
+ var sdkTag = currentScript.getAttribute('data-sdk-tag');
636
+ var sdkNameRegex = /^[A-Za-z_][A-Za-z0-9_]*$/;
637
+ var sdkTagRegex = /^[A-Z]{2}$/;
638
+ if (!sdkNameRegex.test(sdkName)) {
639
+ Log.warn('Invalid SDK Name provided. SDK Name must start with a letter or underscore, and contain only letters, numbers, and underscores.');
640
+ return;
641
+ }
642
+ if (!sdkTag) {
643
+ Log.initLog(sdkName);
644
+ } else {
645
+ if (sdkTagRegex.test(sdkTag)) {
646
+ Log.initLog(sdkName, sdkTag);
647
+ } else {
648
+ Log.warn('Invalid SDK Tag provided. SDK Tag must be exactly two uppercase letters.');
649
+ }
650
+ }
651
+ window[sdkName] = sdkInstance;
652
+ }
653
+ initSDK(document.currentScript, sdk_instance);
654
+ //# sourceMappingURL=kochava.js.map