Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kochava

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kochava - npm Package Compare versions

Comparing version 1.0.6 to 1.0.9

20

dist/kochava.js

@@ -17,3 +17,3 @@ "use strict";

function Kochava(app_id, verbose, use_cookie, disable_auto_install, custom_traits) {
var SDK_VERSION = "Web 2.5.0 (NPM 1.0.6)";
var SDK_VERSION = "Web 2.5.1 (NPM 1.0.9)";
var KOCHAVA_CONTROL = "web-sdk.control.kochava.com/track/json";

@@ -256,2 +256,6 @@ var IDENTITY_LINK_ENDPOINT = "web-sdk.control.kochava.com/v1/cpi/identityLink.php";

var specificData;
var conversionData;
if (state.utm) {
conversionData = { utm_source: state.utm };
}
switch (eventName) {

@@ -268,3 +272,3 @@ case "install":

}
var fullPayload = __assign(__assign({}, basePayload), { data: __assign({}, specificData) });
var fullPayload = __assign(__assign({}, basePayload), { data: __assign(__assign({}, specificData), conversionData) });
//if (state.logging && state.verbose) {

@@ -393,3 +397,3 @@ //console.log("Full payload assembled", fullPayload);

expires +
"; Secure; path=/;domain=" +
"; path=/;domain=" +
getBaseDomain();

@@ -444,3 +448,11 @@ };

};
var getBaseDomain = function () { return window.location.host; };
var getBaseDomain = function () {
try {
//@ts-ignore
return window.location.host.match(/[^\.]*\.[^.]*$/)[0];
}
catch (err) {
return window.location.host;
}
};
var getUserAgent = function () {

@@ -447,0 +459,0 @@ return (navigator) ? navigator.userAgent : "";

460

kochava.ts
import {
KochavaState,
RequestObject,
GetMAIDobject,
BasePayload,
EventPayload,
IdentityPayload,
InstallPayload,
IdentityLink,
BaseDataPoints,
InstallDataPoints,
EventDataPoints,
Callback,
KochavaState,
RequestObject,
GetMAIDobject,
BasePayload,
EventPayload,
IdentityPayload,
InstallPayload,
IdentityLink,
BaseDataPoints,
InstallDataPoints,
EventDataPoints,
Callback,
}
from "./interfaces.js";
from "./interfaces.js";

@@ -20,128 +20,80 @@ export class Kochava {

public constructor(
app_id: string,
verbose: boolean,
use_cookie: boolean,
disable_auto_install: boolean,
custom_traits?: IdentityLink
) {
const SDK_VERSION = "Web 2.5.0 (NPM 1.0.6)";
const KOCHAVA_CONTROL = "web-sdk.control.kochava.com/track/json";
const IDENTITY_LINK_ENDPOINT =
"web-sdk.control.kochava.com/v1/cpi/identityLink.php";
const RESOLVER = "identity-resolver.api.kochava.com";
const MAX_RETRIES = 10;
const MAX_RETRY_DELAY_MS = 60000;
const rawID: string = getLocalValue("kv_id", "kv_id", use_cookie);
public constructor(
app_id: string,
verbose: boolean,
use_cookie: boolean,
disable_auto_install: boolean,
custom_traits?: IdentityLink
) {
const SDK_VERSION = "Web 2.5.1 (NPM 1.0.9)";
const KOCHAVA_CONTROL = "web-sdk.control.kochava.com/track/json";
const IDENTITY_LINK_ENDPOINT =
"web-sdk.control.kochava.com/v1/cpi/identityLink.php";
const RESOLVER = "identity-resolver.api.kochava.com";
const MAX_RETRIES = 10;
const MAX_RETRY_DELAY_MS = 60000;
const rawID: string = 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()
};
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()
};
//if (this.kochavaState.verbose && this.kochavaState.logging) {
//console.log("Initialzed kochava state:", this.kochavaState);
//}
//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.");
}
if (rawID === "") {
if (!this.kochavaState.disableAutoInstall) {
this.install();
if (this.kochavaState.verbose && this.kochavaState.logging) {
console.log("Sending automatic install.");
}
}
}
}
public identify(
customTraits: IdentityLink | string,
callback?: Callback
) {
const verifiedCustomTraits = sanitizeIdentityLink(customTraits);
public identify(
customTraits: IdentityLink | string,
callback?: Callback
) {
const 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 {
const requestObject: 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);
}
}
}
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)
);
}
public page(
pageName: string,
optsObject?: { [key: string]: any },
callback?: 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);
}
public activity(
eventName: string,
optsObject?: { [key: string]: any },
callback?: Callback
) {
if (this.kochavaState.identityLink &&
Object.keys(this.kochavaState.identityLink).length > 0) {
try {
this.kochavaState.eventName = eventName;
const options: RequestObject = {
const requestObject: RequestObject = {
method: "POST",
endpoint: this.kochavaState.kochavaControl,
body: getPayloadBody(
this.kochavaState,
eventName,
optsObject
),
endpoint: this.kochavaState.identityLinkEndpoint,
body: getIdentityPayload(this.kochavaState),
contentType: "application/json",

@@ -151,77 +103,125 @@ retries: this.kochavaState.maxRetries,

};
request(
this.kochavaState,
requestObject,
this.kochavaState.maxRetries,
callback
);
if (this.kochavaState.logging && this.kochavaState.verbose) {
console.log("kochava request: ", options);
console.log("kochava.identify request: ", requestObject);
}
request(this.kochavaState, options, this.kochavaState.maxRetries, callback);
} catch (err) {
if (this.kochavaState.logging && this.kochavaState.verbose) {
console.log("kochava error: ", err.message);
console.log("kochava.identify error: ", err.message);
}
}
}
}
public conversion(
eventName: string,
optsObject?: { [key: string]: any },
callback?: Callback
) {
this.kochavaState.eventName = eventName || "";
this.activity(`conversion_${eventName}`, optsObject, callback);
}
public page(
pageName: string,
optsObject?: { [key: string]: any },
callback?: 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);
}
public install(callback?: Callback) {
this.activity("install", {}, callback);
}
public activity(
eventName: string,
optsObject?: { [key: string]: any },
callback?: Callback
) {
try {
this.kochavaState.eventName = eventName;
const options: RequestObject = {
method: "POST",
endpoint: this.kochavaState.kochavaControl,
body: getPayloadBody(
this.kochavaState,
eventName,
optsObject
),
contentType: "application/json",
retries: this.kochavaState.maxRetries,
async: true,
};
public installWithIdentity(
customTraits: IdentityLink | string,
callback?: Callback
) {
this.kochavaState.identityLink = sanitizeIdentityLink(customTraits);
this.install(callback);
}
if (this.kochavaState.logging && this.kochavaState.verbose) {
console.log("kochava request: ", options);
}
public getKochavaId(): string {
return this.kochavaState.kochavaDeviceID;
request(this.kochavaState, options, this.kochavaState.maxRetries, callback);
} catch (err) {
if (this.kochavaState.logging && this.kochavaState.verbose) {
console.log("kochava error: ", err.message);
}
}
}
public getMAID(
apikey: string,
nonce: string,
authCode: string,
async: boolean,
callback?: Callback
) {
try {
const options: GetMAIDobject = {
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,
};
public conversion(
eventName: string,
optsObject?: { [key: string]: any },
callback?: Callback
) {
this.kochavaState.eventName = eventName || "";
this.activity(`conversion_${eventName}`, optsObject, callback);
}
if (this.kochavaState.logging && this.kochavaState.verbose) {
console.log("kochava.getMAID request: ", options);
}
public install(callback?: Callback) {
this.activity("install", {}, callback);
}
request(
this.kochavaState,
options,
this.kochavaState.maxRetries,
callback
);
} catch (err) {
if (this.kochavaState.logging && this.kochavaState.verbose) {
console.log("kochava.getMAID error: ", err.message);
}
public installWithIdentity(
customTraits: IdentityLink | string,
callback?: Callback
) {
this.kochavaState.identityLink = sanitizeIdentityLink(customTraits);
this.install(callback);
}
public getKochavaId(): string {
return this.kochavaState.kochavaDeviceID;
}
public getMAID(
apikey: string,
nonce: string,
authCode: string,
async: boolean,
callback?: Callback
) {
try {
const options: GetMAIDobject = {
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);
}
}
}
};

@@ -254,3 +254,3 @@

("https:" === document.location.protocol ? "https://" : "http://") +
endpoint;
endpoint;
} else {

@@ -266,5 +266,5 @@ endpoint = "https://" + endpoint;

headers.append(
"Authorization",
request.appGuid + ", "
+ request.nonce + ", "
"Authorization",
request.appGuid + ", "
+ request.nonce + ", "
+ request.authCode

@@ -289,15 +289,15 @@ );

})
.then((response) => {
//if (state.logging && state.verbose) {
//console.log("Fetch response received:", response);
//}
return response.text();
})
.then((receivedResponse) => {
//if (state.logging && state.verbose) {
//console.log("Response converted to text:", receivedResponse);
//}
return handleRequestSuccess(state, receivedResponse, callback);
})
.catch((err) => handleRequestError(err, state, currRetries, request, callback));
.then((response) => {
//if (state.logging && state.verbose) {
//console.log("Fetch response received:", response);
//}
return response.text();
})
.then((receivedResponse) => {
//if (state.logging && state.verbose) {
//console.log("Response converted to text:", receivedResponse);
//}
return handleRequestSuccess(state, receivedResponse, callback);
})
.catch((err) => handleRequestError(err, state, currRetries, request, callback));
};

@@ -330,3 +330,3 @@

console.log(
`Error: API call failed at the network level. Attempt: ${state.maxRetries - retriesLeft
`Error: API call failed at the network level. Attempt: ${state.maxRetries - retriesLeft
}`

@@ -368,18 +368,23 @@ );

let specificData: EventDataPoints | InstallDataPoints;
let conversionData;
if (state.utm) {
conversionData = { utm_source: state.utm };
}
switch (eventName) {
case "install":
specificData = setInstallData(state, baseData);
break
break
case "page":
specificData = setPageData(state, baseData, optsObject);
break
break
default:
specificData = setEventData(state, baseData, eventName, optsObject);
break;
break;
}
const fullPayload: EventPayload | InstallPayload = {
...basePayload,
data: { ...specificData }
const fullPayload: EventPayload | InstallPayload = {
...basePayload,
data: { ...specificData, ...conversionData }
};

@@ -397,4 +402,4 @@ //if (state.logging && state.verbose) {

setLocalValue(
"kv_install_sent",
String(new Date().getTime()),
"kv_install_sent",
String(new Date().getTime()),
state.useCookie

@@ -420,3 +425,3 @@ );

const setEventData = (
state: KochavaState,
state: KochavaState,
baseData: BaseDataPoints,

@@ -482,3 +487,3 @@ eventName: string,

): EventDataPoints => {
return({
return ({
...baseData,

@@ -509,3 +514,3 @@ event_name: eventName,

} else if (typeof idLink === "string") {
return {"custom_id": idLink as string}
return { "custom_id": idLink as string }
} else {

@@ -517,3 +522,3 @@ return undefined;

const getActionName = (eventName: string): string =>
eventName === "install" ? "install" : "event";
eventName === "install" ? "install" : "event";

@@ -570,3 +575,3 @@ const getUrlParameter = (name: string): string => {

expires +
"; Secure; path=/;domain=" +
"; path=/;domain=" +
getBaseDomain();

@@ -628,3 +633,10 @@ };

const getBaseDomain = (): string => window.location.host;
const getBaseDomain = (): string => {
try {
//@ts-ignore
return window.location.host.match(/[^\.]*\.[^.]*$/)[0];
} catch (err) {
return window.location.host
}
}

@@ -645,7 +657,7 @@ const getUserAgent = (): string =>

(window) ? window.innerWidth < window.innerHeight
? "portrait"
: "landscape"
? "portrait"
: "landscape"
: "";
const getCurrentUnixTime = (): number => Math.floor(Date.now()/1000);
const getCurrentUnixTime = (): number => Math.floor(Date.now() / 1000);

@@ -660,5 +672,5 @@ const assignNewID = (useCookie: boolean): string => {

const uuidv4 = (): string => {
return (`${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`).replace(/[018]/g, (c: any) =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
return (`${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`).replace(/[018]/g, (c: any) =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
};

@@ -679,3 +691,3 @@

const generateNtID = (state: KochavaState): string =>
const generateNtID = (state: KochavaState): string =>
`${state.session}-${state.session_count}-${uuidv4()}`;

@@ -682,0 +694,0 @@

{
"name": "kochava",
"version": "1.0.6",
"version": "1.0.9",
"main": "dist/kochava.js",

@@ -5,0 +5,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc