Comparing version 1.0.10 to 3.0.0
@@ -1,80 +0,117 @@ | ||
export interface RequestObject { | ||
method: string; | ||
endpoint: string; | ||
contentType: string; | ||
retries: number; | ||
async: boolean; | ||
body?: EventPayload | IdentityPayload | InstallPayload; | ||
secure?: boolean; | ||
interface DefaultConfig { | ||
readonly general: { | ||
readonly app_id_override: string; | ||
readonly device_id_override: string; | ||
}; | ||
readonly config: { | ||
readonly init_token: string; | ||
readonly refresh_minimum: number; | ||
}; | ||
readonly install: { | ||
readonly resend_id: ""; | ||
readonly updates_enabled: true; | ||
}; | ||
readonly networking: { | ||
readonly urls: { | ||
readonly init: "https://kvinit-prod.api.kochava.com/track/kvinit"; | ||
readonly install: "https://web-sdk.control.kochava.com/track/json/"; | ||
readonly event: "https://web-sdk.control.kochava.com/track/json/"; | ||
readonly identityLink: "https://web-sdk.control.kochava.com/v1/cpi/identityLink.php"; | ||
}; | ||
readonly retry_waterfall: [7, 30, 300, 1800]; | ||
}; | ||
readonly privacy: { | ||
readonly allow_custom_ids: string[]; | ||
readonly deny_datapoints: string[]; | ||
readonly deny_event_names: string[]; | ||
readonly deny_identity_links: string[]; | ||
}; | ||
} | ||
export interface GetMAIDobject extends RequestObject { | ||
appGuid: string; | ||
authCode: string; | ||
nonce: string; | ||
withCredentials: boolean; | ||
export declare const DEFAULTS: DefaultConfig; | ||
export interface KvConfig { | ||
general: { | ||
device_id_override?: string; | ||
app_id_override?: string; | ||
}; | ||
config: { | ||
init_token: string; | ||
refresh_minimum: number; | ||
}; | ||
install: { | ||
resend_id?: string; | ||
updates_enabled: boolean; | ||
}; | ||
networking: { | ||
urls: { | ||
init: string; | ||
install: string; | ||
identityLink: string; | ||
event: string; | ||
}; | ||
retry_waterfall: number[]; | ||
}; | ||
privacy: { | ||
allow_custom_ids: string[]; | ||
deny_datapoints: string[]; | ||
deny_event_names: string[]; | ||
deny_identity_links: string[]; | ||
}; | ||
} | ||
export interface BasePayload { | ||
action: string; | ||
kochava_app_id: string; | ||
kochava_device_id: string; | ||
sdk_version: string; | ||
nt_id: string; | ||
} | ||
export interface EventPayload extends BasePayload { | ||
data: EventDataPoints; | ||
} | ||
export interface InstallPayload extends BasePayload { | ||
data: InstallDataPoints; | ||
} | ||
export interface IdentityPayload { | ||
kochava_app_id: string; | ||
device_id: { | ||
kochava_device_id: string; | ||
export interface KvinitResponse { | ||
general?: { | ||
device_id_override?: string; | ||
app_id_override?: string; | ||
}; | ||
data: IdentityLink; | ||
config?: { | ||
init_token?: string; | ||
refresh_minimum?: number; | ||
}; | ||
install?: { | ||
resend_id?: string; | ||
updates_enabled?: boolean; | ||
}; | ||
networking?: { | ||
urls?: { | ||
init?: string; | ||
install?: string; | ||
identityLink?: string; | ||
event?: string; | ||
}; | ||
retry_waterfall?: number[]; | ||
}; | ||
privacy?: { | ||
allow_custom_ids?: string[]; | ||
deny_datapoints?: string[]; | ||
deny_event_names?: string[]; | ||
deny_identity_links?: string[]; | ||
}; | ||
success?: string | number | boolean; | ||
} | ||
export declare type Json = { | ||
[key: string]: any; | ||
}; | ||
export declare type IdentityLink = { | ||
[key: string]: string; | ||
}; | ||
export interface BaseDataPoints { | ||
usertime: number; | ||
user_agent: string; | ||
language: string; | ||
device_orientation: string; | ||
device_ids: { | ||
kochava_device_id?: string; | ||
}; | ||
disp_w: number; | ||
disp_h: number; | ||
export interface Urls { | ||
init: string; | ||
install: string; | ||
event: string; | ||
identityLink: string; | ||
} | ||
export interface InstallDataPoints extends BaseDataPoints { | ||
identity_link?: IdentityLink; | ||
export interface OverrideUrls { | ||
init?: string; | ||
install?: string; | ||
event?: string; | ||
identityLink?: string; | ||
} | ||
export interface EventDataPoints extends BaseDataPoints { | ||
event_name: string; | ||
event_data?: { | ||
[key: string]: any; | ||
}; | ||
export interface CustomValue { | ||
data: Json; | ||
isDeviceId: boolean; | ||
} | ||
export interface KochavaState { | ||
readonly appID: string; | ||
readonly kochavaDeviceID: string; | ||
readonly sdkVersion: string; | ||
readonly kochavaControl: string; | ||
readonly identityLinkEndpoint: string; | ||
readonly resolver: string; | ||
readonly utm: string; | ||
readonly useCookie: boolean; | ||
readonly verbose: boolean; | ||
readonly logging: boolean; | ||
readonly disableAutoInstall: boolean; | ||
readonly maxRetries: number; | ||
readonly maxRetryDelayMs: number; | ||
readonly startTime: number; | ||
identityLink?: IdentityLink; | ||
pageName: string; | ||
eventName: string; | ||
readonly session: string; | ||
readonly session_count: number; | ||
export interface WrapperVersion { | ||
name: string; | ||
version: string; | ||
build_date: string; | ||
} | ||
export declare type Callback = (err: boolean, data: any) => void; | ||
export {}; |
@@ -1,2 +0,36 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
Authored by Brett Barinaga on 11/17/21. | ||
Copyright (c) Kochava, Inc. All rights reserved. | ||
*/ | ||
export const DEFAULTS = { | ||
general: { | ||
// DO NOT DEFAULT | ||
app_id_override: "", | ||
// DO NOT DEFAULT | ||
device_id_override: "", | ||
}, | ||
config: { | ||
init_token: "", | ||
refresh_minimum: 60, | ||
}, | ||
install: { | ||
// DO NOT DEFAULT | ||
resend_id: "", | ||
updates_enabled: true, | ||
}, | ||
networking: { | ||
urls: { | ||
init: "https://kvinit-prod.api.kochava.com/track/kvinit", | ||
install: "https://web-sdk.control.kochava.com/track/json/", | ||
event: "https://web-sdk.control.kochava.com/track/json/", | ||
identityLink: "https://web-sdk.control.kochava.com/v1/cpi/identityLink.php" | ||
}, | ||
retry_waterfall: [7, 30, 300, 1800], | ||
}, | ||
privacy: { | ||
allow_custom_ids: [], | ||
deny_datapoints: [], | ||
deny_event_names: [], | ||
deny_identity_links: [], | ||
}, | ||
}; |
@@ -1,19 +0,52 @@ | ||
import { KochavaState, IdentityLink, Callback } from "./interfaces.js"; | ||
import { Json, Urls, CustomValue, KvConfig } from "./interfaces"; | ||
declare global { | ||
interface Window { | ||
kochava: Kochava; | ||
} | ||
} | ||
export interface KochavaInstance { | ||
appGuid: string; | ||
started: boolean; | ||
installStarted: boolean; | ||
kvinitDone: boolean; | ||
installDone: boolean; | ||
disableAutoPage: boolean; | ||
useCookies: boolean; | ||
sleep: boolean; | ||
version: string; | ||
buildDate: string; | ||
overrideUrls: Urls; | ||
customValues: CustomValue[]; | ||
kochavaSession: string; | ||
retryWaterfall: number[]; | ||
startTimeMS: number; | ||
utm: string; | ||
kochavaDeviceId: string; | ||
kochavaInstallId: string; | ||
kochavaInstallDate: number; | ||
kochavaSessionCount: number; | ||
kochavaConfig?: KvConfig; | ||
} | ||
export declare class Kochava { | ||
readonly kochavaState: KochavaState; | ||
constructor(app_id: string, verbose: boolean, use_cookie: boolean, disable_auto_install: boolean, custom_traits?: IdentityLink); | ||
identify(customTraits: IdentityLink | string, callback?: Callback): void; | ||
page(pageName: string, optsObject?: { | ||
[key: string]: any; | ||
}, callback?: Callback): void; | ||
activity(eventName: string, optsObject?: { | ||
[key: string]: any; | ||
}, callback?: Callback): void; | ||
conversion(eventName: string, optsObject?: { | ||
[key: string]: any; | ||
}, callback?: Callback): void; | ||
install(callback?: Callback): void; | ||
installWithIdentity(customTraits: IdentityLink | string, callback?: Callback): void; | ||
getKochavaId(): string; | ||
getMAID(apikey: string, nonce: string, authCode: string, async: boolean, callback?: Callback): void; | ||
#private; | ||
private constructor(); | ||
static create(): Kochava; | ||
static createForNode(): Kochava; | ||
static createForReact(): Kochava; | ||
static createForVue(): Kochava; | ||
static createForAngular(): Kochava; | ||
useCookies(condition?: boolean): void; | ||
disableAutoPage(condition?: boolean): void; | ||
startWithAppGuid(appGuid: string): void; | ||
shutdown(deleteData: boolean): void; | ||
setLogLevel(logLevel: string): void; | ||
executeAdvancedInstruction(key: string, valueStr: string, callback?: (input: string) => void): void; | ||
sendEvent(name: string, data?: Json | string): void; | ||
sendPageEvent(pageName?: string, additionalData?: Json): void; | ||
registerIdentityLink(name: string, identifier: string): void; | ||
registerCustomValue(name: string, value: string): void; | ||
registerCustomDeviceIdentifier(name: string, value: string): void; | ||
getStarted(): boolean; | ||
getDeviceId(): string; | ||
setSleep(sleep: boolean): void; | ||
} |
@@ -1,504 +0,474 @@ | ||
"use strict"; | ||
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); | ||
/* | ||
Authored by Brett Barinaga on 11/17/21. | ||
Copyright (c) Kochava, Inc. All rights reserved. | ||
*/ | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Kochava = void 0; | ||
var Kochava = /** @class */ (function () { | ||
function Kochava(app_id, verbose, use_cookie, disable_auto_install, custom_traits) { | ||
var SDK_VERSION = "Web 2.5.1 (NPM 1.0.9)"; | ||
var KOCHAVA_CONTROL = "web-sdk.control.kochava.com/track/json"; | ||
var IDENTITY_LINK_ENDPOINT = "web-sdk.control.kochava.com/v1/cpi/identityLink.php"; | ||
var RESOLVER = "identity-resolver.api.kochava.com"; | ||
var MAX_RETRIES = 10; | ||
var MAX_RETRY_DELAY_MS = 60000; | ||
var rawID = getLocalValue("kv_id", "kv_id", use_cookie); | ||
this.kochavaState = { | ||
appID: app_id, | ||
kochavaDeviceID: determineKvID(rawID, use_cookie), | ||
sdkVersion: SDK_VERSION, | ||
kochavaControl: KOCHAVA_CONTROL, | ||
identityLinkEndpoint: IDENTITY_LINK_ENDPOINT, | ||
resolver: RESOLVER, | ||
utm: getLocalValue("ko_click_id", app_id + "_click", use_cookie), | ||
useCookie: use_cookie || false, | ||
verbose: verbose || false, | ||
logging: (console !== null && console !== undefined), | ||
disableAutoInstall: disable_auto_install || false, | ||
maxRetries: MAX_RETRIES, | ||
maxRetryDelayMs: MAX_RETRY_DELAY_MS, | ||
startTime: new Date().getTime(), | ||
identityLink: sanitizeIdentityLink(custom_traits), | ||
pageName: getPageName(), | ||
eventName: "", | ||
session: uuidv4().substr(0, 4), | ||
session_count: readAndUpdateSessionCount(use_cookie || false) | ||
}; | ||
//if (this.kochavaState.verbose && this.kochavaState.logging) { | ||
//console.log("Initialzed kochava state:", this.kochavaState); | ||
//} | ||
if (rawID === "") { | ||
if (!this.kochavaState.disableAutoInstall) { | ||
this.install(); | ||
if (this.kochavaState.verbose && this.kochavaState.logging) { | ||
console.log("Sending automatic install."); | ||
} | ||
} | ||
} | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
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"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
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; | ||
import { Log } from "./utils/log"; | ||
import JobQueue from "./jobqueue"; | ||
import * as Kvinit from "./payloads/kvinit"; | ||
import * as Install from "./payloads/install"; | ||
import { DEFAULTS, } from "./interfaces"; | ||
import { deleteAllPersisted, readAndUpdatePersistedValue, updatePersistedValue, PersistKey, checkDuplicateIdLink, addPersistedIdLinks, checkInstallIdChange, readAndUpdateSessionCount, readAndUpdateDeviceId, readAndUpdateUTM, } from "./browser/persist"; | ||
import * as utils from "./utils/utils"; | ||
import { getPageName } from "./browser/browser"; | ||
export class Kochava { | ||
// User will use the below factories instead of directly calling | ||
// the constructor | ||
constructor() { | ||
_Kochava_instances.add(this); | ||
_Kochava_instance.set(this, void 0); | ||
_Kochava_jobQueue.set(this, void 0); | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this); | ||
__classPrivateFieldSet(this, _Kochava_jobQueue, new JobQueue(), "f"); | ||
} | ||
Kochava.prototype.identify = function (customTraits, callback) { | ||
var verifiedCustomTraits = sanitizeIdentityLink(customTraits); | ||
if (verifiedCustomTraits && Object.keys(verifiedCustomTraits).length > 0) { | ||
this.kochavaState.identityLink = verifiedCustomTraits; | ||
setLocalValue("c_trt", JSON.stringify(this.kochavaState.identityLink), this.kochavaState.useCookie); | ||
} | ||
else { | ||
this.kochavaState.identityLink = JSON.parse(getLocalValue("c_trt", "c_trt", this.kochavaState.useCookie)); | ||
} | ||
if (this.kochavaState.identityLink && | ||
Object.keys(this.kochavaState.identityLink).length > 0) { | ||
try { | ||
var requestObject = { | ||
method: "POST", | ||
endpoint: this.kochavaState.identityLinkEndpoint, | ||
body: getIdentityPayload(this.kochavaState), | ||
contentType: "application/json", | ||
retries: this.kochavaState.maxRetries, | ||
async: true, | ||
}; | ||
request(this.kochavaState, requestObject, this.kochavaState.maxRetries, callback); | ||
if (this.kochavaState.logging && this.kochavaState.verbose) { | ||
console.log("kochava.identify request: ", requestObject); | ||
} | ||
} | ||
catch (err) { | ||
if (this.kochavaState.logging && this.kochavaState.verbose) { | ||
console.log("kochava.identify error: ", err.message); | ||
} | ||
} | ||
} | ||
}; | ||
Kochava.prototype.page = function (pageName, optsObject, callback) { | ||
this.kochavaState.pageName = pageName || this.kochavaState.pageName; | ||
if (optsObject && Object.keys(optsObject).length > 0) | ||
this.activity("page", optsObject, callback); | ||
else | ||
this.activity("page", {}, callback); | ||
}; | ||
Kochava.prototype.activity = function (eventName, optsObject, callback) { | ||
try { | ||
this.kochavaState.eventName = eventName; | ||
var options = { | ||
method: "POST", | ||
endpoint: this.kochavaState.kochavaControl, | ||
body: getPayloadBody(this.kochavaState, eventName, optsObject), | ||
contentType: "application/json", | ||
retries: this.kochavaState.maxRetries, | ||
async: true, | ||
}; | ||
if (this.kochavaState.logging && this.kochavaState.verbose) { | ||
console.log("kochava request: ", options); | ||
} | ||
request(this.kochavaState, options, this.kochavaState.maxRetries, callback); | ||
} | ||
catch (err) { | ||
if (this.kochavaState.logging && this.kochavaState.verbose) { | ||
console.log("kochava error: ", err.message); | ||
} | ||
} | ||
}; | ||
Kochava.prototype.conversion = function (eventName, optsObject, callback) { | ||
this.kochavaState.eventName = eventName || ""; | ||
this.activity("conversion_" + eventName, optsObject, callback); | ||
}; | ||
Kochava.prototype.install = function (callback) { | ||
this.activity("install", {}, callback); | ||
}; | ||
Kochava.prototype.installWithIdentity = function (customTraits, callback) { | ||
this.kochavaState.identityLink = sanitizeIdentityLink(customTraits); | ||
this.install(callback); | ||
}; | ||
Kochava.prototype.getKochavaId = function () { | ||
return this.kochavaState.kochavaDeviceID; | ||
}; | ||
Kochava.prototype.getMAID = function (apikey, nonce, authCode, async, callback) { | ||
try { | ||
var options = { | ||
method: "GET", | ||
endpoint: this.kochavaState.resolver + "/maid/get", | ||
contentType: "application/json", | ||
retries: this.kochavaState.maxRetries, | ||
async: async, | ||
appGuid: apikey, | ||
authCode: authCode, | ||
nonce: nonce, | ||
withCredentials: true, | ||
secure: true, | ||
}; | ||
if (this.kochavaState.logging && this.kochavaState.verbose) { | ||
console.log("kochava.getMAID request: ", options); | ||
} | ||
request(this.kochavaState, options, this.kochavaState.maxRetries, callback); | ||
} | ||
catch (err) { | ||
if (this.kochavaState.logging && this.kochavaState.verbose) { | ||
console.log("kochava.getMAID error: ", err.message); | ||
} | ||
} | ||
}; | ||
return Kochava; | ||
}()); | ||
exports.Kochava = Kochava; | ||
; | ||
var request = function (state, request, currRetries, callback) { | ||
if (!fetch) { | ||
var err = "Fetch not supported in this browser, use a different browser or \ | ||
older version of the sdk"; | ||
console.log(err); | ||
if (callback instanceof Function) { | ||
callback(true, err); | ||
} | ||
return; | ||
// ============================= PUBLIC =============================== // | ||
static create() { | ||
return new Kochava(); | ||
} | ||
var method = request.method, endpoint = request.endpoint, body = request.body, contentType = request.contentType, secure = request.secure; | ||
method = method || "GET"; | ||
body = body || {}; | ||
contentType = contentType || "application/json"; | ||
if (document && !secure) { | ||
endpoint = | ||
("https:" === document.location.protocol ? "https://" : "http://") + | ||
endpoint; | ||
static createForNode() { | ||
const kochava = new Kochava(); | ||
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Node", version: "" })); | ||
return kochava; | ||
} | ||
else { | ||
endpoint = "https://" + endpoint; | ||
static createForReact() { | ||
const kochava = new Kochava(); | ||
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "React", version: "" })); | ||
return kochava; | ||
} | ||
var headers = new Headers(); | ||
headers.append("Content-Type", contentType); | ||
if ("appGuid" in request) { | ||
if ("authCode" in request && "nonce" in request) { | ||
headers.append("Authorization", request.appGuid + ", " | ||
+ request.nonce + ", " | ||
+ request.authCode); | ||
} | ||
else { | ||
//@ts-ignore | ||
headers.append("Authorization", request.appGuid); | ||
} | ||
static createForVue() { | ||
const kochava = new Kochava(); | ||
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Vue", version: "" })); | ||
return kochava; | ||
} | ||
//if (state.logging && state.verbose) { | ||
//console.log("Preparing to send request via fetch..."); | ||
//} | ||
fetch(endpoint, { | ||
method: method, | ||
body: JSON.stringify(body), | ||
headers: headers, | ||
}) | ||
.then(function (response) { | ||
//if (state.logging && state.verbose) { | ||
//console.log("Fetch response received:", response); | ||
//} | ||
return response.text(); | ||
}) | ||
.then(function (receivedResponse) { | ||
//if (state.logging && state.verbose) { | ||
//console.log("Response converted to text:", receivedResponse); | ||
//} | ||
return handleRequestSuccess(state, receivedResponse, callback); | ||
}) | ||
.catch(function (err) { return handleRequestError(err, state, currRetries, request, callback); }); | ||
}; | ||
var handleRequestSuccess = function (state, resp, callback) { | ||
if (state.logging && state.verbose) { | ||
console.log("event sent successfully"); | ||
static createForAngular() { | ||
const kochava = new Kochava(); | ||
kochava.executeAdvancedInstruction("wrapper", JSON.stringify({ name: "Angular", version: "1.0.0" })); | ||
return kochava; | ||
} | ||
if (callback instanceof Function) { | ||
callback(false, JSON.parse(resp)); | ||
/* | ||
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 | ||
*/ | ||
useCookies(condition = false) { | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies = condition; | ||
} | ||
}; | ||
var handleRequestError = function (err, state, retriesLeft, options, callback) { | ||
retriesLeft--; | ||
if (retriesLeft > 0) { | ||
if (state.logging && state.verbose) { | ||
console.log("Error: API call failed at the network level. Attempt: " + (state.maxRetries - retriesLeft)); | ||
/* | ||
- Set whether the sdk shouldn't automatically send a page or should. | ||
- true = no auto page | ||
- false = yes auto page | ||
- defaults to false | ||
*/ | ||
disableAutoPage(condition = false) { | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage = condition; | ||
} | ||
/* | ||
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. | ||
*/ | ||
startWithAppGuid(appGuid) { | ||
if (!appGuid) { | ||
Log.error(`Invalid appGuid ${appGuid}, start failed.`); | ||
return; | ||
} | ||
var delayFactor = state.maxRetries - retriesLeft; | ||
var delay = delayFactor * delayFactor * 500; | ||
if (delay > state.maxRetryDelayMs) { | ||
delay = state.maxRetryDelayMs; | ||
if (!__classPrivateFieldGet(this, _Kochava_instance, "f")) | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this); | ||
if (__classPrivateFieldGet(this, _Kochava_instance, "f").started) { | ||
Log.warn("Kochava SDK already started."); | ||
return; | ||
} | ||
setTimeout(function () { return request(state, options, retriesLeft, callback); }, delay); | ||
Log.diagDebug(`Host called API: Start With App Guid ${appGuid}`); | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").started = true; | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkFirstLaunchAndMigrate).call(this); | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_initInstance).call(this, appGuid); | ||
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage) | ||
this.sendPageEvent(); | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkPersistedState).call(this); | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkPersistedKvinit).call(this); | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_printStartupMsgs).call(this, appGuid); | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_beginStart).call(this); | ||
} | ||
else { | ||
if (state.logging && state.verbose) { | ||
console.log("Error: API call failed at the network level (retry limit hit).", err); | ||
/* | ||
Primary means for stopping the sdk. | ||
Will optionally delete all persisted data, and will shutdown the | ||
sdk and job queue. | ||
*/ | ||
shutdown(deleteData) { | ||
Log.diagDebug(`Host called API: Shutdown and ${deleteData ? "delete data" : "keep data"}`); | ||
if (deleteData) { | ||
Log.debug("Deleting persisted values"); | ||
deleteAllPersisted(); | ||
} | ||
if (callback instanceof Function) { | ||
callback(true, err); | ||
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").started) { | ||
Log.warn("SDK already shutdown."); | ||
} | ||
Log.info("SDK shutting down."); | ||
Kvinit.cancelRetries(); | ||
Install.cancelRetries(); | ||
__classPrivateFieldGet(this, _Kochava_jobQueue, "f").stop(); | ||
// wipe whatever was previously in the queue | ||
__classPrivateFieldSet(this, _Kochava_jobQueue, new JobQueue(), "f"); | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_resetInstance).call(this); | ||
} | ||
}; | ||
var getPayloadBody = function (state, eventName, optsObject) { | ||
//if (state.logging && state.verbose) { | ||
//console.log("Assembling request payload."); | ||
//} | ||
var basePayload = getBasePayload(state, eventName); | ||
var baseData = getBaseDataPoints(state); | ||
var specificData; | ||
var conversionData; | ||
if (state.utm) { | ||
conversionData = { utm_source: state.utm }; | ||
/* | ||
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 | ||
*/ | ||
setLogLevel(logLevel) { | ||
Log.diagDebug(`Host called API: Set Log Level ${logLevel}`); | ||
Log.setLogLevel(logLevel); | ||
} | ||
switch (eventName) { | ||
case "install": | ||
specificData = setInstallData(state, baseData); | ||
break; | ||
case "page": | ||
specificData = setPageData(state, baseData, optsObject); | ||
break; | ||
default: | ||
specificData = setEventData(state, baseData, eventName, optsObject); | ||
break; | ||
/* | ||
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 ... | ||
*/ | ||
executeAdvancedInstruction(key, valueStr, callback) { | ||
Log.diagDebug(`Host called API: Execute Advanced Instruction ${key}`); | ||
switch (key) { | ||
case "wrapper": | ||
{ | ||
const wrapperVersion = JSON.parse(valueStr); | ||
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").version) | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").version = "WebTracker 3.0.0"; | ||
switch (wrapperVersion.name) { | ||
case "Angular": | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name} ${wrapperVersion.version})`; | ||
break; | ||
default: | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").version += ` (${wrapperVersion.name})`; | ||
break; | ||
} | ||
} | ||
break; | ||
case "urls": | ||
{ | ||
const overrideUrls = JSON.parse(valueStr); | ||
if (overrideUrls.init) | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = overrideUrls.init; | ||
if (overrideUrls.event) | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = overrideUrls.event; | ||
if (overrideUrls.install) | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install = overrideUrls.install; | ||
if (overrideUrls.identityLink) | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink = overrideUrls.identityLink; | ||
} | ||
break; | ||
case "urlsRestore": | ||
{ | ||
const restoreUrls = JSON.parse(valueStr); | ||
for (const url of restoreUrls) { | ||
if (url === "init") | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.init = DEFAULTS.networking.urls.init; | ||
if (url === "event") | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.event = DEFAULTS.networking.urls.event; | ||
if (url === "install") | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.install = | ||
DEFAULTS.networking.urls.install; | ||
if (url === "identityLink") | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").overrideUrls.identityLink = | ||
DEFAULTS.networking.urls.identityLink; | ||
} | ||
} | ||
break; | ||
case "logFilter": | ||
{ | ||
const disabled = JSON.parse(valueStr); | ||
disabled.forEach((level) => Log.disableLogType(level)); | ||
} | ||
break; | ||
case "getInstance": | ||
{ | ||
const currInstance = JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f")); | ||
callback(currInstance); | ||
Log.debug(`capturing instance: ${valueStr}`); | ||
} | ||
break; | ||
case "logObjects": | ||
Log.setLogObjects(JSON.parse(valueStr)); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
var fullPayload = __assign(__assign({}, basePayload), { data: __assign(__assign({}, specificData), conversionData) }); | ||
//if (state.logging && state.verbose) { | ||
//console.log("Full payload assembled", fullPayload); | ||
//} | ||
return JSON.parse(JSON.stringify(fullPayload)); | ||
}; | ||
var setInstallData = function (state, baseData) { | ||
setLocalValue("kv_install_sent", String(new Date().getTime()), state.useCookie); | ||
return getInstallDataPoints(state, baseData); | ||
}; | ||
var setPageData = function (state, baseData, optsObject) { | ||
var eventData = { page_name: state.pageName, }; | ||
if (optsObject && Object.keys(optsObject).length > 0) { | ||
eventData = __assign(__assign({}, eventData), optsObject); | ||
/* | ||
Builds and enqueues a kochava event. Must include an event_name string, | ||
with optional event_data as either another string or object. | ||
*/ | ||
sendEvent(name, data) { | ||
Log.diagDebug(`Host called API: Send Event`); | ||
if (!name) { | ||
Log.warn("Invalid event name, ignoring call."); | ||
return; | ||
} | ||
__classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueEvent(__classPrivateFieldGet(this, _Kochava_instance, "f"), [name, data]); | ||
} | ||
return getEventDataPoints(baseData, "page", eventData); | ||
}; | ||
var setEventData = function (state, baseData, eventName, optsObject) { | ||
var eventTime = new Date().getTime(); | ||
var timeElapsed = eventTime - state.startTime; | ||
var timeOnPage = Math.round(timeElapsed / 1000); | ||
var eventData = { | ||
page_name: state.pageName, | ||
time_on_page: timeOnPage | ||
}; | ||
if (optsObject && Object.keys(optsObject).length > 0) { | ||
eventData = __assign(__assign({}, eventData), optsObject); | ||
/* | ||
Wraps the sendEvent call with predefined data specific to page events. | ||
*/ | ||
sendPageEvent(pageName, additionalData) { | ||
if (pageName) | ||
this.sendEvent("page", Object.assign({ page_name: pageName }, additionalData)); | ||
else | ||
this.sendEvent("page", Object.assign({ page_name: getPageName() }, additionalData)); | ||
} | ||
return getEventDataPoints(baseData, eventName, eventData); | ||
}; | ||
var getIdentityPayload = function (state) { return ({ | ||
kochava_app_id: state.appID, | ||
device_id: { | ||
kochava_device_id: state.kochavaDeviceID, | ||
}, | ||
data: state.identityLink, | ||
}); }; | ||
var getBasePayload = function (state, eventName) { return ({ | ||
action: getActionName(eventName), | ||
kochava_app_id: state.appID, | ||
kochava_device_id: state.kochavaDeviceID, | ||
sdk_version: state.sdkVersion, | ||
nt_id: generateNtID(state), | ||
}); }; | ||
var getBaseDataPoints = function (state) { return ({ | ||
language: getLanguage(), | ||
device_orientation: getScreenOrientation(), | ||
usertime: getCurrentUnixTime(), | ||
user_agent: getUserAgent(), | ||
device_ids: { | ||
kochava_device_id: state.kochavaDeviceID, | ||
}, | ||
disp_w: (getScreenWidth()) ? getScreenWidth() : 0, | ||
disp_h: (getScreenHeight()) ? getScreenHeight() : 0, | ||
}); }; | ||
var getEventDataPoints = function (baseData, eventName, eventData) { | ||
return (__assign(__assign({}, baseData), { event_name: eventName, event_data: eventData })); | ||
}; | ||
var getInstallDataPoints = function (state, baseData) { | ||
return (__assign(__assign({}, baseData), { identity_link: state.identityLink })); | ||
}; | ||
var determineKvID = function (rawID, use_cookie) { | ||
return (rawID === "") ? assignNewID(use_cookie) : rawID; | ||
}; | ||
var sanitizeIdentityLink = function (idLink) { | ||
if (idLink && typeof idLink !== "string" && Object.keys(idLink).length > 0) { | ||
return idLink; | ||
/* | ||
- 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. | ||
*/ | ||
registerIdentityLink(name, identifier) { | ||
Log.diagDebug(`Host called API: Register Identity Link ${name}`); | ||
if (!name || !identifier) { | ||
Log.warn("Invalid identity link, ignoring call."); | ||
return; | ||
} | ||
if (checkDuplicateIdLink(name, identifier)) { | ||
Log.debug("Duplicate Identity Link found, ignoring."); | ||
return; | ||
} | ||
const idLink = {}; | ||
idLink[name] = identifier; | ||
addPersistedIdLinks(name, identifier, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
if (__classPrivateFieldGet(this, _Kochava_instance, "f").installStarted || __classPrivateFieldGet(this, _Kochava_instance, "f").installDone) { | ||
// it will be sent standalone | ||
__classPrivateFieldGet(this, _Kochava_jobQueue, "f").enqueueIdLink(__classPrivateFieldGet(this, _Kochava_instance, "f"), idLink); | ||
} | ||
// will be sent in install | ||
} | ||
else if (typeof idLink === "string") { | ||
return { "custom_id": idLink }; | ||
// Allows the client to attach arbitrary data to certain payloads. | ||
registerCustomValue(name, value) { | ||
Log.diagDebug(`Host called API: Register Custom Value ${name}`); | ||
if (!name || !value) { | ||
Log.warn("Invalid custom value, ignoring call."); | ||
return; | ||
} | ||
const dataToAdorn = {}; | ||
dataToAdorn[name] = value; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: false }); | ||
} | ||
else { | ||
return undefined; | ||
// Allows the client to attach arbitrary identifiers to go out in the install. | ||
registerCustomDeviceIdentifier(name, value) { | ||
Log.diagDebug(`Host called API: Register Custom Device Identifier ${name}`); | ||
if (!name || !value) { | ||
Log.warn("Invalid custom device identifier, ignoring call."); | ||
return; | ||
} | ||
const dataToAdorn = {}; | ||
dataToAdorn[name] = value; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").customValues.push({ data: dataToAdorn, isDeviceId: true }); | ||
} | ||
}; | ||
var getActionName = function (eventName) { | ||
return eventName === "install" ? "install" : "event"; | ||
}; | ||
var getUrlParameter = function (name) { | ||
if (!location || !location.search) { | ||
return ""; | ||
/* | ||
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; | ||
*/ | ||
getStarted() { | ||
return __classPrivateFieldGet(this, _Kochava_instance, "f").started; | ||
} | ||
name = name.replace(/[[]/, "\\[").replace(/[\]]/, "\\]"); | ||
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); | ||
var results = regex.exec(location.search); | ||
return results === null | ||
? "" | ||
: decodeURIComponent(results[1].replace(/\+/g, " ")); | ||
}; | ||
var setLocalStorageValue = function (key, val) { | ||
if (!localStorage) { | ||
return false; | ||
/* | ||
Returns the current kochavaDeviceId, or "" if called too early. | ||
*/ | ||
getDeviceId() { | ||
Log.diagDebug(`Host called API: Get Kochava Device Id`); | ||
if (__classPrivateFieldGet(this, _Kochava_instance, "f").started) | ||
return __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId; | ||
else | ||
return ""; | ||
} | ||
try { | ||
localStorage.setItem(key, val); | ||
/* | ||
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. | ||
*/ | ||
setSleep(sleep) { | ||
Log.diagDebug(`Host called API: Sleep ${sleep ? "Stop" : "Start"}`); | ||
if (sleep && !__classPrivateFieldGet(this, _Kochava_instance, "f").sleep) { | ||
// only pause if it was running | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep; | ||
__classPrivateFieldGet(this, _Kochava_jobQueue, "f").pause(); | ||
} | ||
else if (!sleep && __classPrivateFieldGet(this, _Kochava_instance, "f").sleep) { | ||
// only resume queueing if it was paused | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").sleep = sleep; | ||
__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_beginStart).call(this); | ||
} | ||
} | ||
catch (err) { | ||
return false; | ||
} | ||
_Kochava_instance = new WeakMap(), _Kochava_jobQueue = new WeakMap(), _Kochava_instances = new WeakSet(), _Kochava_resetInstance = function _Kochava_resetInstance() { | ||
__classPrivateFieldSet(this, _Kochava_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, | ||
utm: "", | ||
kochavaDeviceId: "", | ||
kochavaInstallId: "", | ||
kochavaSessionCount: -1, | ||
kochavaInstallDate: -1, | ||
kochavaConfig: undefined, | ||
}, "f"); | ||
}, _Kochava_initInstance = function _Kochava_initInstance(appGuid) { | ||
// init instance with defaults | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").appGuid = appGuid; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage = __classPrivateFieldGet(this, _Kochava_instance, "f").disableAutoPage || false; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies = __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies || false; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").version = __classPrivateFieldGet(this, _Kochava_instance, "f").version || "WebTracker 3.0.0"; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").buildDate = "kbd: 5/16/2022, 9:51:59 AM"; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaSession = utils.uuidv4().substring(0, 5); | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").startTimeMS = utils.getCurrTimeMS(); | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").retryWaterfall = [7, 30, 300, 1800]; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig = JSON.parse(JSON.stringify(DEFAULTS)); | ||
}, _Kochava_checkFirstLaunchAndMigrate = function _Kochava_checkFirstLaunchAndMigrate() { | ||
// If this is our first launch ever, set it in persistence. | ||
if (!readAndUpdatePersistedValue(PersistKey.FirstStartDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies)) { | ||
updatePersistedValue(PersistKey.FirstStartDate, String(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
/* | ||
On a first launch of the v3 sdk, we need to migrate old persisted kv_id | ||
from v2.2, v2.3, and v2.5 | ||
*/ | ||
// perform migration | ||
const oldKvId = readAndUpdatePersistedValue(PersistKey.OldKvid, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
if (oldKvId) { | ||
updatePersistedValue(PersistKey.DeviceId, oldKvId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
updatePersistedValue(PersistKey.InstallSentDate, JSON.stringify(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
} | ||
} | ||
return true; | ||
}; | ||
var getLocalStorageValue = function (name) { | ||
if (!localStorage) { | ||
return ""; | ||
}, _Kochava_checkPersistedKvinit = function _Kochava_checkPersistedKvinit() { | ||
// check if persisted kvinit | ||
let persistedKvinit = {}; | ||
const persistedKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
if (persistedKvinitStr) { | ||
persistedKvinit = JSON.parse(persistedKvinitStr); | ||
if (persistedKvinit) { | ||
// if persisted kvinit, apply it | ||
Log.trace("Found persisted kvinit.", persistedKvinit); | ||
Kvinit.applyKvinitResp(__classPrivateFieldGet(this, _Kochava_instance, "f"), persistedKvinit); | ||
Log.trace("KochavaConfig after persistedKvinit:", JSON.parse(JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig))); | ||
} | ||
} | ||
var val = ""; | ||
try { | ||
val = localStorage.getItem(name) || ""; | ||
// check refresh minimum too | ||
const persistedKvinitDateStr = readAndUpdatePersistedValue(PersistKey.KvinitSentDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
if (persistedKvinitDateStr) { | ||
const lastKvinitDate = JSON.parse(persistedKvinitDateStr); | ||
if (lastKvinitDate) { | ||
const refreshMin = __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.config.refresh_minimum; | ||
if (utils.getCurrTimeSec() - lastKvinitDate < refreshMin) | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone = true; | ||
} | ||
} | ||
catch (err) { | ||
return ""; | ||
}, _Kochava_checkPersistedState = function _Kochava_checkPersistedState() { | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").installDone = | ||
readAndUpdatePersistedValue(PersistKey.InstallSentDate, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies).length > 0; | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaInstallId = readAndUpdatePersistedValue(PersistKey.InstallId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId = readAndUpdateDeviceId(__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaSessionCount = readAndUpdateSessionCount(__classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").utm = readAndUpdateUTM(__classPrivateFieldGet(this, _Kochava_instance, "f").appGuid, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
}, _Kochava_printStartupMsgs = function _Kochava_printStartupMsgs(appGuid) { | ||
Log.diagInfo(`Started SDK ${__classPrivateFieldGet(this, _Kochava_instance, "f").version} | ||
published ${__classPrivateFieldGet(this, _Kochava_instance, "f").buildDate}`); | ||
Log.diagInfo(`The log level is set to ${Log.getLogLevel()}`); | ||
Log.diagDebug(`This ${!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone ? "is" : "is not"} the first tracker SDK launch`); | ||
Log.diagDebug(`The kochava device id is ${__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaDeviceId}`); | ||
Log.diagDebug(`The kochava app GUID provided was ${appGuid}`); | ||
}, _Kochava_beginStart = async function _Kochava_beginStart() { | ||
// if we need to send a new kvinit, send it | ||
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone) { | ||
Log.diagDebug(`A new kvinit will be sent`); | ||
await __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_performNewKvinit).call(this); | ||
} | ||
return !(val) ? "" : val; | ||
}; | ||
var setCookie = function (name, value) { | ||
var expires = ""; | ||
var date = new Date(); | ||
date.setTime(date.getTime() + 3650 * 24 * 60 * 60 * 1000); | ||
expires = "; expires=" + date.toUTCString(); | ||
document.cookie = | ||
name + | ||
"=" + | ||
(value || "") + | ||
expires + | ||
"; path=/;domain=" + | ||
getBaseDomain(); | ||
}; | ||
var getCookie = function (name) { | ||
var nameEQ = name + "="; | ||
var carray = document.cookie.split(";"); | ||
carray.forEach(function (c) { | ||
while (c.charAt(0) == " ") | ||
c = c.substring(1, c.length); | ||
if (c.indexOf(nameEQ) == 0) | ||
return c.substring(nameEQ.length, c.length); | ||
}); | ||
return ""; | ||
}; | ||
var setLocalValue = function (key, val, useCookie) { | ||
setLocalStorageValue(key, val); | ||
if (useCookie) { | ||
setCookie(key, val); | ||
} | ||
}; | ||
var getLocalValue = function (name, storageName, useCookie) { | ||
var val = getUrlParameter(name); | ||
if (val === "") { | ||
val = getLocalStorageValue(storageName); | ||
} | ||
else { | ||
setLocalValue(storageName, val, useCookie); | ||
Log.diagDebug(`A new kvinit will not be sent`); | ||
} | ||
if (useCookie) { | ||
if (val === "") { | ||
val = getCookie(storageName); | ||
} | ||
else { | ||
setCookie(storageName, val); | ||
return val; | ||
} | ||
if (val !== "") { | ||
setLocalValue(storageName, val, useCookie); | ||
} | ||
// if the install_id changed and thus a new install must go out | ||
if (__classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_checkResendId).call(this)) | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").installDone = false; | ||
Log.diagDebug(`The install ${__classPrivateFieldGet(this, _Kochava_instance, "f").installDone ? "has already" : "has not yet"} been sent`); | ||
if (__classPrivateFieldGet(this, _Kochava_instance, "f").sleep) | ||
return; | ||
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone) { | ||
await __classPrivateFieldGet(this, _Kochava_instances, "m", _Kochava_performInstall).call(this); | ||
} | ||
return !(val) ? "" : val; | ||
}; | ||
var getPageName = function () { | ||
var page = ""; | ||
if (location) { | ||
page = location.pathname.substring(1); | ||
page = page.replace(/\/+$/, ""); | ||
if (__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone && __classPrivateFieldGet(this, _Kochava_instance, "f").installDone) { | ||
await __classPrivateFieldGet(this, _Kochava_jobQueue, "f").start(__classPrivateFieldGet(this, _Kochava_instance, "f")); | ||
} | ||
return page === "" ? "/" : page; | ||
}; | ||
var getBaseDomain = function () { | ||
try { | ||
//@ts-ignore | ||
return window.location.host.match(/[^\.]*\.[^.]*$/)[0]; | ||
}, _Kochava_performNewKvinit = async function _Kochava_performNewKvinit() { | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").kvinitDone = await Kvinit.send(__classPrivateFieldGet(this, _Kochava_instance, "f"), __classPrivateFieldGet(this, _Kochava_instance, "f").retryWaterfall); | ||
updatePersistedValue(PersistKey.KvinitSentDate, String(utils.getCurrTimeSec()), __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
// if new kvinit, apply it | ||
let newKvinit = {}; | ||
const newKvinitStr = readAndUpdatePersistedValue(PersistKey.LastKvinit, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
if (newKvinitStr) { | ||
newKvinit = JSON.parse(newKvinitStr); | ||
} | ||
catch (err) { | ||
return window.location.host; | ||
Kvinit.applyKvinitResp(__classPrivateFieldGet(this, _Kochava_instance, "f"), newKvinit); | ||
Log.trace("KochavaConfig after new Kvinit:", JSON.parse(JSON.stringify(__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig))); | ||
}, _Kochava_checkResendId = function _Kochava_checkResendId() { | ||
let resendId = ""; | ||
if (__classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.install) { | ||
resendId = __classPrivateFieldGet(this, _Kochava_instance, "f").kochavaConfig.install.resend_id; | ||
} | ||
}; | ||
var getUserAgent = function () { | ||
return (navigator) ? navigator.userAgent : ""; | ||
}; | ||
var getLanguage = function () { | ||
return (navigator) ? navigator.language : ""; | ||
}; | ||
var getScreenWidth = function () { | ||
return (window) ? window.screen.availWidth : 0; | ||
}; | ||
var getScreenHeight = function () { | ||
return (window) ? window.screen.availHeight : 0; | ||
}; | ||
var getScreenOrientation = function () { | ||
return (window) ? window.innerWidth < window.innerHeight | ||
? "portrait" | ||
: "landscape" | ||
: ""; | ||
}; | ||
var getCurrentUnixTime = function () { return Math.floor(Date.now() / 1000); }; | ||
var assignNewID = function (useCookie) { | ||
// const newId: string = uuid(); | ||
var newID = "KWE" + getCurrentUnixTime() + "T" + uuidv4(); | ||
setLocalValue("kv_id", newID, useCookie); | ||
return newID; | ||
}; | ||
var uuidv4 = function () { | ||
return (1e7 + "-" + 1e3 + "-" + 4e3 + "-" + 8e3 + "-" + 1e11).replace(/[018]/g, function (c) { | ||
return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16); | ||
}); | ||
}; | ||
var readAndUpdateSessionCount = function (useCookie) { | ||
var storedSessionCount = getLocalValue("kv_session_count", "kv_session_count", useCookie); | ||
var sessionCount = 1; | ||
if (storedSessionCount) { | ||
sessionCount = parseInt(storedSessionCount); | ||
sessionCount++; | ||
const needsNewInstall = checkInstallIdChange(resendId, __classPrivateFieldGet(this, _Kochava_instance, "f").useCookies); | ||
if (needsNewInstall) { | ||
Log.debug(`resend_id ${resendId} found, forcing new install`); | ||
} | ||
setLocalValue("kv_session_count", sessionCount.toString(), useCookie); | ||
return sessionCount; | ||
return needsNewInstall; | ||
}, _Kochava_performInstall = async function _Kochava_performInstall() { | ||
const request = Install.build(__classPrivateFieldGet(this, _Kochava_instance, "f")); | ||
__classPrivateFieldGet(this, _Kochava_instance, "f").installDone = await Install.send(__classPrivateFieldGet(this, _Kochava_instance, "f"), request); | ||
if (!__classPrivateFieldGet(this, _Kochava_instance, "f").installDone) | ||
return; | ||
// If the install succeeded, remove all idLink that were passed to it | ||
Install.onSuccess(__classPrivateFieldGet(this, _Kochava_instance, "f")); | ||
updatePersistedValue(PersistKey.IdLinkQueue, JSON.stringify(__classPrivateFieldGet(this, _Kochava_jobQueue, "f").idLinkQueue), false); | ||
}; | ||
var generateNtID = function (state) { | ||
return state.session + "-" + state.session_count + "-" + uuidv4(); | ||
}; | ||
// const uuid = (): string => { | ||
// let dt: number = new Date().getTime(); | ||
// const uuid: string = "kwxxxxxxxxxxxxx".replace(/[xy]/g, function (c) { | ||
// const r: number = (dt + Math.random() * 16) % 16 | 0; | ||
// dt = Math.floor(dt / 16); | ||
// return (c == "x" ? r : (r & 0x3) | 0x8).toString(16); | ||
// }); | ||
// return uuid; | ||
// }; | ||
// Only here for generic Web integration | ||
window.kochava = Kochava.create(); |
{ | ||
"type": "module", | ||
"name": "kochava", | ||
"version": "1.0.10", | ||
"version": "3.0.0", | ||
"main": "dist/kochava.js", | ||
"files": [ | ||
"dist/" | ||
], | ||
"description": "", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "tsc" | ||
"build": "tsc -p ../../src/tsconfig.node.json", | ||
"test": "tsc -p ." | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.5.5" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"keywords": [], | ||
"description": "" | ||
"license": "ISC" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
83413
30
1980
1
0
13
Yes
1