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.0 to 1.0.1

20

dist/kochava.d.ts

@@ -1,19 +0,1 @@

import { KochavaState, IdentityLink, Callback } from "./interfaces.js";
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;
}
export {};

71

dist/kochava.js

@@ -14,6 +14,5 @@ "use strict";

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 = "2.3.0";
var SDK_VERSION = "2.5.0";
var KOCHAVA_CONTROL = "web-sdk.control.kochava.com/track/json";

@@ -58,4 +57,11 @@ var IDENTITY_LINK_ENDPOINT = "web-sdk.control.kochava.com/v1/cpi/identityLink.php";

var verifiedCustomTraits = sanitizeIdentityLink(customTraits);
if (verifiedCustomTraits) {
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 {

@@ -87,3 +93,3 @@ var requestObject = {

else
this.activity("page", { "page_name": this.kochavaState.pageName }, callback);
this.activity("page", {}, callback);
};

@@ -120,4 +126,2 @@ Kochava.prototype.activity = function (eventName, optsObject, callback) {

Kochava.prototype.installWithIdentity = function (customTraits, callback) {
if (getLocalValue("install_sent", "install_sent", this.kochavaState.useCookie) === "is_sent")
return;
this.kochavaState.identityLink = sanitizeIdentityLink(customTraits);

@@ -156,3 +160,2 @@ this.install(callback);

}());
exports.Kochava = Kochava;
;

@@ -253,16 +256,13 @@ var request = function (state, request, currRetries, callback) {

var specificData;
if (eventName === "install") {
specificData = getInstallDataPoints(state, baseData);
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;
}
else if (eventName === "page") {
if (optsObject)
specificData = getEventDataPoints(baseData, eventName, optsObject);
else
specificData = getEventDataPoints(baseData, eventName, {
page_name: state.pageName
});
}
else {
specificData = getEventDataPoints(baseData, eventName, optsObject);
}
var fullPayload = __assign(__assign({}, basePayload), { data: __assign({}, specificData) });

@@ -274,2 +274,26 @@ //if (state.logging && state.verbose) {

};
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);
}
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);
}
return getEventDataPoints(baseData, eventName, eventData);
};
var getIdentityPayload = function (state) { return ({

@@ -302,3 +326,2 @@ kochava_app_id: state.appID,

var getInstallDataPoints = function (state, baseData) {
setLocalValue("install_sent", "is_sent", state.useCookie);
return (__assign(__assign({}, baseData), { identity_link: state.identityLink }));

@@ -310,7 +333,7 @@ };

var sanitizeIdentityLink = function (idLink) {
if (idLink) {
if (idLink && typeof idLink !== "string" && Object.keys(idLink).length > 0) {
return idLink;
}
else if ((idLink instanceof String)) {
return { custom_id: idLink };
else if (typeof idLink === "string") {
return { "custom_id": idLink };
}

@@ -317,0 +340,0 @@ else {

@@ -17,3 +17,3 @@ import {

export class Kochava {
class Kochava {
readonly kochavaState: KochavaState;

@@ -28,3 +28,3 @@

) {
const SDK_VERSION = "2.3.0";
const SDK_VERSION = "2.5.0";
const KOCHAVA_CONTROL = "web-sdk.control.kochava.com/track/json";

@@ -77,5 +77,18 @@ const IDENTITY_LINK_ENDPOINT =

const verifiedCustomTraits = sanitizeIdentityLink(customTraits);
if (verifiedCustomTraits) {
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 {

@@ -116,3 +129,3 @@ const requestObject: RequestObject = {

else
this.activity("page", {"page_name": this.kochavaState.pageName}, callback);
this.activity("page", {}, callback);
}

@@ -169,3 +182,2 @@

) {
if (getLocalValue("install_sent", "install_sent", this.kochavaState.useCookie) === "is_sent") return;
this.kochavaState.identityLink = sanitizeIdentityLink(customTraits);

@@ -316,3 +328,3 @@ this.install(callback);

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
}`

@@ -351,3 +363,2 @@ );

//}
const basePayload: BasePayload = getBasePayload(state, eventName);

@@ -357,13 +368,12 @@ const baseData: BaseDataPoints = getBaseDataPoints(state);

if (eventName === "install") {
specificData = getInstallDataPoints(state, baseData);
} else if (eventName === "page") {
if (optsObject)
specificData = getEventDataPoints(baseData, eventName, optsObject);
else
specificData = getEventDataPoints(baseData, eventName, {
page_name: state.pageName
});
} else {
specificData = getEventDataPoints(baseData, eventName, optsObject);
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;
}

@@ -381,2 +391,50 @@

const setInstallData = (
state: KochavaState,
baseData: BaseDataPoints,
): InstallDataPoints => {
setLocalValue(
"kv_install_sent",
String(new Date().getTime()),
state.useCookie
);
return getInstallDataPoints(state, baseData);
};
const setPageData = (
state: KochavaState,
baseData: BaseDataPoints,
optsObject?: { [key: string]: any }
): EventDataPoints => {
let eventData = { page_name: state.pageName, };
if (optsObject && Object.keys(optsObject).length > 0) {
eventData = { ...eventData, ...optsObject };
}
return getEventDataPoints(baseData, "page", eventData);
};
const setEventData = (
state: KochavaState,
baseData: BaseDataPoints,
eventName: string,
optsObject?: { [key: string]: any },
): EventDataPoints => {
const eventTime = new Date().getTime();
const timeElapsed = eventTime - state.startTime;
const timeOnPage = Math.round(timeElapsed / 1000);
let eventData = {
page_name: state.pageName,
time_on_page: timeOnPage
};
if (optsObject && Object.keys(optsObject).length > 0) {
eventData = { ...eventData, ...optsObject };
}
return getEventDataPoints(baseData, eventName, eventData);
};
const getIdentityPayload = (

@@ -430,3 +488,2 @@ state: KochavaState,

): InstallDataPoints => {
setLocalValue("install_sent", "is_sent", state.useCookie);
return ({

@@ -445,6 +502,6 @@ ...baseData,

): IdentityLink | undefined => {
if ((idLink as IdentityLink)) {
if (idLink && typeof idLink !== "string" && Object.keys(idLink).length > 0) {
return idLink as IdentityLink;
} else if ((idLink instanceof String)) {
return { custom_id: idLink as string };
} else if (typeof idLink === "string") {
return {"custom_id": idLink as string}
} else {

@@ -451,0 +508,0 @@ return undefined;

{
"name": "kochava",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/kochava.js",

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

@@ -52,3 +52,3 @@ {

// "typeRoots": [], /* List of folders to include type definitions from. */
"types": ["dist/kochava.d.ts"], /* Type declaration files to be included in compilation. */
//"types": ["./dist/kochava.d.ts"], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */

@@ -55,0 +55,0 @@ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

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