react-native-kochava-measurement
Version:
A lightweight and easy to integrate SDK, providing first-class integration with Kochava’s installation attribution and analytics platform.
751 lines (750 loc) • 35.4 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
/*
Authored by Jacob Bechler on 06/09/25.
Copyright (c) Kochava, Inc. All rights reserved.
*/
import './polyfills/rn.js';
import 'whatwg-fetch';
import { Log } from "./utils/log";
import JobQueue from "./jobqueue";
import * as Kvinit from "./payloads/kvinit";
import * as Install from "./payloads/install";
import { KochavaMeasurementEvent } from "./measurementEvent";
export { KochavaMeasurementEventType } from "./measurementEvent";
import { DEFAULTS, } from "./interfaces";
import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM, getItem, configureStorage } from "./browser/persist";
import * as utils from "./utils/utils";
import { getPageName } from "./browser/browser";
import adapter from './adapters/adapter.rn.js';
// NOTE: Update this with new releases.
var SDK_VERSION = "3.2.0";
configureStorage(adapter);
var Kochava = /** @class */ (function () {
// User will use the below factories instead of directly calling
// the constructor
function Kochava() {
this._resetInstance();
this._jobQueue = new JobQueue();
}
// ============================= PUBLIC =============================== //
Kochava.create = function () {
return new Kochava();
};
Kochava.createForReactNative = function () {
var kochava = new Kochava();
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "ReactNative", version: "" }));
return kochava;
};
Kochava.createForNode = function () {
var kochava = new Kochava();
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Node", version: "" }));
return kochava;
};
Kochava.createForReact = function () {
var kochava = new Kochava();
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "React", version: "" }));
return kochava;
};
Kochava.createForVue = function () {
var kochava = new Kochava();
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Vue", version: "" }));
return kochava;
};
Kochava.createForAngular = function () {
var kochava = new Kochava();
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Angular", version: "1.0.0" }));
return kochava;
};
/*
Set if the SDK should also store persisted values in cookie storage.
- Not all values can be persisted in cookies, such as event/idlink queues
due to size constraints.
- true = yes use cookies
- no = no don't use cookies
- defaults to false
*/
Kochava.prototype.useCookies = function (condition) {
if (condition === void 0) { condition = false; }
this._instance.useCookies = condition;
};
/*
- Set whether the sdk shouldn't automatically send a page or should.
- true = no auto page
- false = yes auto page
- defaults to false
*/
Kochava.prototype.disableAutoPage = function (condition) {
if (condition === void 0) { condition = false; }
this._instance.disableAutoPage = condition;
};
Kochava.prototype.buildEventWithEventType = function (type) {
if (!type) {
Log.warn("Invalid event type, ignoring call.");
return;
}
return new KochavaMeasurementEvent(this, type);
};
Kochava.prototype.buildEventWithEventName = function (eventName) {
if (!eventName) {
Log.warn("Invalid event name, ignoring call.");
return;
}
return new KochavaMeasurementEvent(this, eventName);
};
/*
The primary means for starting the sdk.
Responsibilites:
- Checks for migrations.
- Creates the sdk instance.
- Checks for persisted state.
- Determines and sends kvinit.
- Determines and sends install.
- Optionally enqueues an auto_page.
- Starts the job queue.
*/
Kochava.prototype.startWithAppGuid = function (appGuid) {
this._startWithAppGuid(appGuid);
};
Kochava.prototype._startWithAppGuid = function (appGuid) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!appGuid) {
Log.error("Invalid appGuid ".concat(appGuid, ", start failed."));
return [2 /*return*/];
}
if (!this._instance)
this._resetInstance();
if (this._instance.started) {
Log.warn("Kochava SDK already started.");
return [2 /*return*/];
}
Log.diagDebug("Host called API: Start With App Guid ".concat(appGuid));
this._instance.started = true;
return [4 /*yield*/, this._checkFirstLaunchAndMigrate()];
case 1:
_a.sent();
this._initInstance(appGuid);
if (!this._instance.disableAutoPage)
this.sendPageEvent();
return [4 /*yield*/, this._checkPersistedState()];
case 2:
_a.sent();
return [4 /*yield*/, this._checkPersistedKvinit()];
case 3:
_a.sent();
this._printStartupMsgs(appGuid);
return [4 /*yield*/, this._beginStart()];
case 4:
_a.sent();
return [2 /*return*/];
}
});
});
};
/*
Primary means for stopping the sdk.
Will optionally delete all persisted data, and will shutdown the
sdk and job queue.
*/
Kochava.prototype.shutdown = function (deleteData) {
this._shutdown(deleteData);
};
Kochava.prototype._shutdown = function (deleteData) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Log.diagDebug("Host called API: Shutdown and ".concat(deleteData ? "delete data" : "keep data"));
if (!deleteData) return [3 /*break*/, 2];
Log.debug("Deleting persisted values");
return [4 /*yield*/, deleteAllPersisted()];
case 1:
_a.sent();
_a.label = 2;
case 2:
if (!this._instance.started) {
Log.warn("SDK already shutdown.");
}
Log.info("SDK shutting down.");
Kvinit.cancelRetries();
Install.cancelRetries();
this._jobQueue.stop();
// wipe whatever was previously in the queue
this._jobQueue = new JobQueue();
this._resetInstance();
return [2 /*return*/];
}
});
});
};
/*
Changes the current logLevel.
Options include:
- Off :: No logging whatsoever
- Error :: Only critical errors
- Warn :: Only critical errors and non-critical warnings
- Info :: High-level sdk behavior logs (default)
- Debug :: More in-depth sdk behavior logs and payload logs
- Trace :: Everything, granular detail
*/
Kochava.prototype.setLogLevel = function (logLevel) {
Log.diagDebug("Host called API: Set Log Level ".concat(logLevel));
Log.setLogLevel(logLevel);
};
/*
Used internally, for special SDK behavior not utilized by a client.
Examples include:
- urls :: purposefully changing an endpoint for testing
- wrapper :: overwriting the version of a wrapper
several more ...
*/
Kochava.prototype.executeAdvancedInstruction = function (key, valueStr, callback) {
Log.diagDebug("Host called API: Execute Advanced Instruction ".concat(key));
switch (key) {
case "wrapper":
{
var wrapperVersion = JSON.parse(valueStr);
if (!this._instance.version)
this._instance.version = "WebTracker " + SDK_VERSION;
switch (wrapperVersion.name) {
case "Angular":
this._instance.version += " (".concat(wrapperVersion.name, " ").concat(wrapperVersion.version, ")");
break;
default:
this._instance.version += " (".concat(wrapperVersion.name, ")");
break;
}
}
break;
case "urls":
{
var overrideUrls = JSON.parse(valueStr);
if (overrideUrls.init)
this._instance.overrideUrls.init = overrideUrls.init;
if (overrideUrls.event)
this._instance.overrideUrls.event = overrideUrls.event;
if (overrideUrls.install)
this._instance.overrideUrls.install = overrideUrls.install;
if (overrideUrls.identityLink)
this._instance.overrideUrls.identityLink = overrideUrls.identityLink;
}
break;
case "urlsRestore":
{
var restoreUrls = JSON.parse(valueStr);
for (var _i = 0, restoreUrls_1 = restoreUrls; _i < restoreUrls_1.length; _i++) {
var url = restoreUrls_1[_i];
if (url === "init")
this._instance.overrideUrls.init = DEFAULTS.networking.urls.init;
if (url === "event")
this._instance.overrideUrls.event = DEFAULTS.networking.urls.event;
if (url === "install")
this._instance.overrideUrls.install =
DEFAULTS.networking.urls.install;
if (url === "identityLink")
this._instance.overrideUrls.identityLink =
DEFAULTS.networking.urls.identityLink;
}
}
break;
case "logFilter":
{
var disabled = JSON.parse(valueStr);
disabled.forEach(function (level) { return Log.disableLogType(level); });
}
break;
case "getInstance":
{
var currInstance = JSON.stringify(this._instance);
callback(currInstance);
Log.debug("capturing instance: ".concat(valueStr));
}
break;
case "logObjects":
Log.setLogObjects(JSON.parse(valueStr));
break;
default:
break;
}
};
/*
Builds and enqueues a kochava event. Must include an event_name string,
with optional event_data as either another string or object.
*/
Kochava.prototype.sendEvent = function (name, data) {
this._sendEvent(name, data);
};
Kochava.prototype._sendEvent = function (name, data) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Log.diagDebug("Host called API: Send Event");
if (!name) {
Log.warn("Invalid event name, ignoring call.");
return [2 /*return*/];
}
return [4 /*yield*/, this._jobQueue.enqueueEvent(this._instance, [name, data])];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
/*
Wraps the sendEvent call with predefined data specific to page events.
*/
Kochava.prototype.sendPageEvent = function (pageName, additionalData) {
if (pageName)
this.sendEvent("page", __assign({ page_name: pageName }, additionalData));
else
this.sendEvent("page", __assign({ page_name: getPageName() }, additionalData));
};
/*
- Registers new identity links with the sdk, either to be sent out with
the install, or standalone.
- Will update an identity link if its key already exists in storage.
- A max of 10 identity links are currently allowed to be stored
at any one time.
*/
Kochava.prototype.registerIdentityLink = function (name, identifier) {
this._registerIdentityLink(name, identifier);
};
Kochava.prototype._registerIdentityLink = function (name, identifier) {
return __awaiter(this, void 0, void 0, function () {
var idLink;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Log.diagDebug("Host called API: Register Identity Link ".concat(name));
if (!name || !identifier) {
Log.warn("Invalid identity link, ignoring call.");
return [2 /*return*/];
}
return [4 /*yield*/, checkDuplicateIdLink(name, identifier)];
case 1:
if (_a.sent()) {
Log.debug("Duplicate Identity Link found, ignoring.");
return [2 /*return*/];
}
idLink = {};
idLink[name] = identifier;
return [4 /*yield*/, addPersistedIdLinks(name, identifier, this._instance.useCookies)];
case 2:
_a.sent();
return [4 /*yield*/, getItem("com.kochava.tracker.InstallSentDate")];
case 3:
if (!_a.sent()) return [3 /*break*/, 5];
// it will be sent standalone
return [4 /*yield*/, this._jobQueue.enqueueIdLink(this._instance, idLink)];
case 4:
// it will be sent standalone
_a.sent();
_a.label = 5;
case 5: return [2 /*return*/];
}
});
});
};
// Allows the client to attach arbitrary data to certain payloads.
Kochava.prototype.registerCustomValue = function (name, value) {
Log.diagDebug("Host called API: Register Custom Value ".concat(value ? 'setting' : 'clearing', " ").concat(name));
if (!name) {
Log.warn("Invalid custom value, ignoring call.");
return;
}
if (!value) {
this._instance.customValues = this._instance.customValues.filter(function (cv) { return !cv.data.hasOwnProperty(name); });
return;
}
var dataToAdorn = {};
dataToAdorn[name] = value;
this._instance.customValues.push({ data: dataToAdorn, isDeviceId: false });
};
// Allows the client to attach arbitrary identifiers to go out in the install.
Kochava.prototype.registerCustomDeviceIdentifier = function (name, value) {
Log.diagDebug("Host called API: Register Custom Device Identifier ".concat(value ? 'setting' : 'clearing', " ").concat(name));
if (!name) {
Log.warn("Invalid custom device identifier, ignoring call.");
return;
}
if (!value) {
this._instance.customValues = this._instance.customValues.filter(function (cv) { return !cv.data.hasOwnProperty(name) || !cv.isDeviceId; });
return;
}
var dataToAdorn = {};
dataToAdorn[name] = value;
this._instance.customValues.push({ data: dataToAdorn, isDeviceId: true });
};
/*
Returns whether or not the sdk is in a "started" state.
This basically amounts to if start has been called,
not if kvinit is done or the queue is started.
Likewise, shutdown will set "started" to false;
*/
Kochava.prototype.getStarted = function () {
return this._instance.started;
};
/*
Returns the current kochavaDeviceId, or "" if called too early.
*/
Kochava.prototype.getDeviceId = function () {
Log.diagDebug("Host called API: Get Kochava Device Id");
if (this._instance.started)
return this._instance.kochavaDeviceId;
else
return "";
};
/*
Puts the sdk in a "sleep" state. This will stop the sdk from dequeuing
new jobs and retrying failed jobs. Different than shutdown, because the
current state is not destroyed.
*/
Kochava.prototype.setSleep = function (sleep) {
return this._setSleep(sleep);
};
Kochava.prototype._setSleep = function (sleep) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Log.diagDebug("Host called API: Sleep ".concat(sleep ? "Stop" : "Start"));
if (!(sleep && !this._instance.sleep)) return [3 /*break*/, 1];
// only pause if it was running
this._instance.sleep = sleep;
this._jobQueue.pause();
return [3 /*break*/, 3];
case 1:
if (!(!sleep && this._instance.sleep)) return [3 /*break*/, 3];
// only resume queueing if it was paused
this._instance.sleep = sleep;
return [4 /*yield*/, this._beginStart()];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
};
// ============================= =============================== //
// Unintialized/invalid state.
// start must be called before these values will be correct.
Kochava.prototype._resetInstance = function () {
this._instance = {
appGuid: "",
started: false,
installStarted: false,
kvinitDone: false,
installDone: false,
disableAutoPage: false,
useCookies: false,
sleep: false,
version: "",
buildDate: "",
overrideUrls: {
init: "",
install: "",
event: "",
identityLink: "",
},
customValues: [],
kochavaSession: "",
retryWaterfall: [],
startTimeMS: 0,
sdkDisabled: false,
utm: "",
installCount: 0,
kochavaDeviceId: "",
kochavaInstallId: "",
kochavaSessionCount: -1,
kochavaInstallDate: -1,
kochavaConfig: undefined,
};
};
Kochava.prototype._initInstance = function (appGuid) {
// init instance with defaults
this._instance.appGuid = appGuid;
this._instance.disableAutoPage = this._instance.disableAutoPage || false;
this._instance.useCookies = this._instance.useCookies || false;
this._instance.version = this._instance.version || "WebTracker " + SDK_VERSION;
this._instance.buildDate = "kbd: 12/17/2025, 2:58:17 PM";
this._instance.kochavaSession = utils.uuidv4().substring(0, 5);
this._instance.startTimeMS = utils.getCurrTimeMS();
this._instance.retryWaterfall = [7, 30, 300, 1800];
this._instance.kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS));
};
Kochava.prototype._checkFirstLaunchAndMigrate = function () {
return __awaiter(this, void 0, void 0, function () {
var firstLaunchDate, oldKvId;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.FirstStartDate, this._instance.useCookies)];
case 1:
firstLaunchDate = _a.sent();
if (!!firstLaunchDate) return [3 /*break*/, 6];
return [4 /*yield*/, updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), this._instance.useCookies)];
case 2:
_a.sent();
return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.OldKvid, this._instance.useCookies)];
case 3:
oldKvId = _a.sent();
if (!oldKvId) return [3 /*break*/, 6];
return [4 /*yield*/, updatePersistedValue(PersistKey.DeviceId, oldKvId, this._instance.useCookies)];
case 4:
_a.sent();
return [4 /*yield*/, updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), this._instance.useCookies)];
case 5:
_a.sent();
_a.label = 6;
case 6: return [2 /*return*/];
}
});
});
};
Kochava.prototype._checkPersistedKvinit = function () {
return __awaiter(this, void 0, void 0, function () {
var persistedKvinit, persistedKvinitStr, persistedKvinitDateStr, lastKvinitDate, refreshMin;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
persistedKvinit = {};
return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.LastKvinit, this._instance.useCookies)];
case 1:
persistedKvinitStr = _a.sent();
if (!persistedKvinitStr) return [3 /*break*/, 3];
persistedKvinit = JSON.parse(persistedKvinitStr);
if (!persistedKvinit) return [3 /*break*/, 3];
// if persisted kvinit, apply it
Log.trace("Found persisted kvinit.", persistedKvinit);
return [4 /*yield*/, Kvinit.applyKvinitResp(this._instance, persistedKvinit)];
case 2:
_a.sent();
Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(this._instance.kochavaConfig)));
_a.label = 3;
case 3: return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.KvinitSentDate, this._instance.useCookies)];
case 4:
persistedKvinitDateStr = _a.sent();
if (persistedKvinitDateStr) {
lastKvinitDate = JSON.parse(persistedKvinitDateStr);
if (lastKvinitDate) {
refreshMin = this._instance.kochavaConfig.config.refresh_minimum;
if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin)
this._instance.kvinitDone = true;
}
}
return [2 /*return*/];
}
});
});
};
Kochava.prototype._checkPersistedState = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c, _d, _e, installCountStr, parsedInstallCount;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
_a = this._instance;
return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.InstallSentDate, this._instance.useCookies)];
case 1:
_a.installDone =
(_f.sent()).length > 0;
_b = this._instance;
return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.InstallId, this._instance.useCookies)];
case 2:
_b.kochavaInstallId = _f.sent();
_c = this._instance;
return [4 /*yield*/, readAndUpdateDeviceId(this._instance.useCookies)];
case 3:
_c.kochavaDeviceId = _f.sent();
_d = this._instance;
return [4 /*yield*/, readAndUpdateSessionCount(this._instance.useCookies)];
case 4:
_d.kochavaSessionCount = _f.sent();
_e = this._instance;
return [4 /*yield*/, readAndUpdateUTM(this._instance.appGuid, this._instance.useCookies)];
case 5:
_e.utm = _f.sent();
return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.InstallCount, this._instance.useCookies)];
case 6:
installCountStr = _f.sent();
parsedInstallCount = parseInt(installCountStr, 10);
this._instance.installCount = isNaN(parsedInstallCount) ? 0 : parsedInstallCount;
return [2 /*return*/];
}
});
});
};
Kochava.prototype._printStartupMsgs = function (appGuid) {
Log.diagInfo("Started SDK ".concat(this._instance.version, "\n published ").concat(this._instance.buildDate));
Log.diagInfo("The log level is set to ".concat(Log.getLogLevel()));
Log.diagDebug("This ".concat(!this._instance.installDone ? "is" : "is not", " the first tracker SDK launch"));
Log.diagDebug("The kochava device id is ".concat(this._instance.kochavaDeviceId));
Log.diagDebug("The kochava app GUID provided was ".concat(appGuid));
};
Kochava.prototype._beginStart = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this._instance.kvinitDone) return [3 /*break*/, 2];
Log.diagDebug("A new kvinit will be sent");
return [4 /*yield*/, this.performNewKvinit()];
case 1:
_a.sent();
return [3 /*break*/, 3];
case 2:
Log.diagDebug("A new kvinit will not be sent");
_a.label = 3;
case 3: return [4 /*yield*/, this.checkResendId()];
case 4:
// if the install_id changed and thus a new install must go out
if (_a.sent())
this._instance.installDone = false;
Log.diagDebug("The install ".concat(this._instance.installDone ? "has already" : "has not yet", " been sent"));
if (this._instance.sleep)
return [2 /*return*/];
if (!!this._instance.installDone) return [3 /*break*/, 6];
return [4 /*yield*/, this.performInstall()];
case 5:
_a.sent();
_a.label = 6;
case 6:
if (!(this._instance.kvinitDone && this._instance.installDone)) return [3 /*break*/, 8];
return [4 /*yield*/, this._jobQueue.start(this._instance)];
case 7:
_a.sent();
_a.label = 8;
case 8: return [2 /*return*/];
}
});
});
};
Kochava.prototype.performNewKvinit = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, newKvinit, newKvinitStr;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this._instance;
return [4 /*yield*/, Kvinit.send(this._instance, this._instance.retryWaterfall)];
case 1:
_a.kvinitDone = _b.sent();
return [4 /*yield*/, updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), this._instance.useCookies)];
case 2:
_b.sent();
newKvinit = {};
return [4 /*yield*/, readAndUpdatePersistedValue(PersistKey.LastKvinit, this._instance.useCookies)];
case 3:
newKvinitStr = _b.sent();
if (newKvinitStr) {
newKvinit = JSON.parse(newKvinitStr);
}
return [4 /*yield*/, Kvinit.applyKvinitResp(this._instance, newKvinit)];
case 4:
_b.sent();
Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(this._instance.kochavaConfig)));
return [2 /*return*/];
}
});
});
};
Kochava.prototype.checkResendId = function () {
return __awaiter(this, void 0, void 0, function () {
var resendId, needsNewInstall;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
resendId = "";
if (this._instance.kochavaConfig.install) {
resendId = this._instance.kochavaConfig.install.resend_id;
}
return [4 /*yield*/, checkInstallIdChange(resendId, this._instance.useCookies)];
case 1:
needsNewInstall = _a.sent();
if (needsNewInstall) {
Log.debug("resend_id ".concat(resendId, " found, forcing new install"));
}
return [2 /*return*/, needsNewInstall];
}
});
});
};
Kochava.prototype.performInstall = function () {
return __awaiter(this, void 0, void 0, function () {
var request, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, Install.build(this._instance)];
case 1:
request = _b.sent();
_a = this._instance;
return [4 /*yield*/, Install.send(this._instance, request)];
case 2:
_a.installDone = _b.sent();
if (!this._instance.installDone)
return [2 /*return*/];
// If the install succeeded, remove all idLink that were passed to it
Install.onSuccess(this._instance);
return [4 /*yield*/, this._jobQueue.persistIdLinkQueue()];
case 3:
_b.sent();
return [2 /*return*/];
}
});
});
};
return Kochava;
}());
export { Kochava };
// Only here for generic Web integration
window.kochava = Kochava.create();