react-native-kochava-measurement
Version:
A lightweight and easy to integrate SDK, providing first-class integration with Kochava’s installation attribution and analytics platform.
633 lines (560 loc) • 19.3 kB
JavaScript
"use strict";
//
// KochavaMeasurement (ReactNative)
//
// Copyright (c) 2018 - 2025 Kochava, Inc. All rights reserved.
//
// Imports
import { KochavaMeasurementImpl } from './KochavaMeasurementImpl';
//
// Log Levels
//
// Defaults to Info
//
export let KochavaMeasurementLogLevel = /*#__PURE__*/function (KochavaMeasurementLogLevel) {
KochavaMeasurementLogLevel["None"] = "none";
KochavaMeasurementLogLevel["Error"] = "error";
KochavaMeasurementLogLevel["Warn"] = "warn";
KochavaMeasurementLogLevel["Info"] = "info";
KochavaMeasurementLogLevel["Debug"] = "debug";
KochavaMeasurementLogLevel["Trace"] = "trace";
return KochavaMeasurementLogLevel;
}({});
//
// Standard Event Types
//
// For samples and expected usage see: https://support.kochava.com/reference-information/post-install-event-examples/
//
export let KochavaMeasurementEventType = /*#__PURE__*/function (KochavaMeasurementEventType) {
KochavaMeasurementEventType["Achievement"] = "Achievement";
KochavaMeasurementEventType["AddToCart"] = "Add to Cart";
KochavaMeasurementEventType["AddToWishList"] = "Add to Wish List";
KochavaMeasurementEventType["CheckoutStart"] = "Checkout Start";
KochavaMeasurementEventType["LevelComplete"] = "Level Complete";
KochavaMeasurementEventType["Purchase"] = "Purchase";
KochavaMeasurementEventType["Rating"] = "Rating";
KochavaMeasurementEventType["RegistrationComplete"] = "Registration Complete";
KochavaMeasurementEventType["Search"] = "Search";
KochavaMeasurementEventType["TutorialComplete"] = "Tutorial Complete";
KochavaMeasurementEventType["View"] = "View";
KochavaMeasurementEventType["AdView"] = "Ad View";
KochavaMeasurementEventType["PushReceived"] = "Push Received";
KochavaMeasurementEventType["PushOpened"] = "Push Opened";
KochavaMeasurementEventType["ConsentGranted"] = "Consent Granted";
KochavaMeasurementEventType["Deeplink"] = "_Deeplink";
KochavaMeasurementEventType["AdClick"] = "Ad Click";
KochavaMeasurementEventType["StartTrial"] = "Start Trial";
KochavaMeasurementEventType["Subscribe"] = "Subscribe";
return KochavaMeasurementEventType;
}({});
//
// Kochava Measurement Event
//
export class KochavaMeasurementEvent {
_eventData = {};
_appleAppStoreReceiptBase64String = null;
_androidGooglePlayReceiptData = null;
_androidGooglePlayReceiptSignature = null;
// Constructor
constructor(eventName) {
this._eventName = eventName;
}
// Send the event.
send() {
KochavaMeasurement.instance.sendEventWithEvent(this);
}
// Set a custom key/value on the event where the type of the value is a string.
setCustomStringValue(key, value) {
if (key && value && typeof value === "string") {
this._eventData[key] = value;
}
}
// Set a custom key/value on the event where the type of the value is a boolean.
setCustomBoolValue(key, value) {
if (key && value != null && typeof value === "boolean") {
this._eventData[key] = value;
}
}
// Set a custom key/value on the event where the type of the value is a number.
setCustomNumberValue(key, value) {
if (key && value != null && typeof value === "number") {
this._eventData[key] = value;
}
}
// (Internal) Set a custom key/value on the event where the type of the value is a dictionary.
_setCustomDictionaryValue(key, value) {
if (key && value != null && typeof value === "object") {
this._eventData[key] = value;
}
}
// (Android Only) Set the receipt from the Android Google Play Store.
setAndroidGooglePlayReceipt(data, signature) {
if (data && typeof data === "string" && signature && typeof signature === "string") {
this._androidGooglePlayReceiptData = data;
this._androidGooglePlayReceiptSignature = signature;
}
}
// (Apple Only) Set the receipt from the iOS Apple App Store.
// Deprecated: Use setAppleAppStoreReceipt instead.
setiOSAppStoreReceipt(base64String) {
this.setAppleAppStoreReceipt(base64String);
}
// (Apple Only) Set the receipt from the iOS Apple App Store.
setAppleAppStoreReceipt(base64String) {
if (base64String && typeof base64String === "string") {
this._appleAppStoreReceiptBase64String = base64String;
}
}
//
// Standard Event Parameters.
//
setAction(value) {
this.setCustomStringValue("action", value);
}
setBackground(value) {
this.setCustomBoolValue("background", value);
}
setCheckoutAsGuest(value) {
this.setCustomStringValue("checkout_as_guest", value);
}
setCompleted(value) {
this.setCustomBoolValue("completed", value);
}
setContentId(value) {
this.setCustomStringValue("content_id", value);
}
setContentType(value) {
this.setCustomStringValue("content_type", value);
}
setCurrency(value) {
this.setCustomStringValue("currency", value);
}
setDate(value) {
this.setCustomStringValue("date", value);
}
setDescription(value) {
this.setCustomStringValue("description", value);
}
setDestination(value) {
this.setCustomStringValue("destination", value);
}
setDuration(value) {
this.setCustomNumberValue("duration", value);
}
setEndDate(value) {
this.setCustomStringValue("end_date", value);
}
setItemAddedFrom(value) {
this.setCustomStringValue("item_added_from", value);
}
setLevel(value) {
this.setCustomStringValue("level", value);
}
setMaxRatingValue(value) {
this.setCustomNumberValue("max_rating_value", value);
}
setName(value) {
this.setCustomStringValue("name", value);
}
setOrderId(value) {
this.setCustomStringValue("order_id", value);
}
setOrigin(value) {
this.setCustomStringValue("origin", value);
}
setPayload(value) {
this._setCustomDictionaryValue("payload", value);
}
setPrice(value) {
this.setCustomNumberValue("price", value);
}
setQuantity(value) {
this.setCustomNumberValue("quantity", value);
}
setRatingValue(value) {
this.setCustomNumberValue("rating_value", value);
}
setReceiptId(value) {
this.setCustomStringValue("receipt_id", value);
}
setReferralFrom(value) {
this.setCustomStringValue("referral_from", value);
}
setRegistrationMethod(value) {
this.setCustomStringValue("registration_method", value);
}
setResults(value) {
this.setCustomStringValue("results", value);
}
setScore(value) {
this.setCustomStringValue("score", value);
}
setSearchTerm(value) {
this.setCustomStringValue("search_term", value);
}
setSource(value) {
this.setCustomStringValue("source", value);
}
setSpatialX(value) {
this.setCustomNumberValue("spatial_x", value);
}
setSpatialY(value) {
this.setCustomNumberValue("spatial_y", value);
}
setSpatialZ(value) {
this.setCustomNumberValue("spatial_z", value);
}
setStartDate(value) {
this.setCustomStringValue("start_date", value);
}
setSuccess(value) {
this.setCustomStringValue("success", value);
}
setUri(value) {
this.setCustomStringValue("uri", value);
}
setUserId(value) {
this.setCustomStringValue("user_id", value);
}
setUserName(value) {
this.setCustomStringValue("user_name", value);
}
setValidated(value) {
this.setCustomStringValue("validated", value);
}
//
// Ad LTV Event Parameters
//
setAdCampaignId(value) {
this.setCustomStringValue("ad_campaign_id", value);
}
setAdCampaignName(value) {
this.setCustomStringValue("ad_campaign_name", value);
}
setAdDeviceType(value) {
this.setCustomStringValue("device_type", value);
}
setAdGroupId(value) {
this.setCustomStringValue("ad_group_id", value);
}
setAdGroupName(value) {
this.setCustomStringValue("ad_group_name", value);
}
setAdMediationName(value) {
this.setCustomStringValue("ad_mediation_name", value);
}
setAdNetworkName(value) {
this.setCustomStringValue("ad_network_name", value);
}
setAdPlacement(value) {
this.setCustomStringValue("placement", value);
}
setAdSize(value) {
this.setCustomStringValue("ad_size", value);
}
setAdType(value) {
this.setCustomStringValue("ad_type", value);
}
// Return all the event info in the form to pass down to the native layer.
getData() {
return {
"eventName": this._eventName,
"eventData": this._eventData,
"appleAppStoreReceiptBase64String": this._appleAppStoreReceiptBase64String,
"androidGooglePlayReceiptData": this._androidGooglePlayReceiptData,
"androidGooglePlayReceiptSignature": this._androidGooglePlayReceiptSignature
};
}
}
//
// Kochava Measurement Install Attribution Result
//
export class KochavaMeasurementInstallAttribution {
// Constructor
constructor(data) {
if (data == null) {
this.retrieved = false;
this.raw = {};
this.attributed = false;
this.firstInstall = false;
} else {
this.retrieved = data["retrieved"] ?? false;
this.raw = data["raw"] ?? {};
this.attributed = data["attributed"] ?? false;
this.firstInstall = data["firstInstall"] ?? false;
}
}
}
//
// Kochava Measurement Deeplink Result
//
export class KochavaMeasurementDeeplink {
// Constructor
constructor(data) {
if (data == null) {
this.destination = "";
this.raw = {};
} else {
this.destination = data["destination"] ?? "";
this.raw = data["raw"] ?? {};
}
}
}
//
// Kochava Measurement Init Result
// Deprecated: Use KochavaMeasurementConfig instead.
//
export class KochavaMeasurementInit {
// Constructor
constructor(config) {
this.consentGdprApplies = config.consentGdprApplies;
}
}
//
// Kochava Measurement Config Result
//
export class KochavaMeasurementConfig {
// Constructor
constructor(data) {
if (data == null) {
this.consentGdprApplies = false;
} else {
this.consentGdprApplies = data["consentGdprApplies"] ?? false;
}
}
}
//
// Kochava Measurement Init Completed
// Deprecated: Use KochavaMeasurementConfigCompletedListener instead.
//
//
// Kochava Measurement Config Completed
//
//
// Kochava Measurement SDK
//
// A lightweight and easy to integrate SDK, providing first-class integration with Kochava’s installation attribution and analytics platform.
// Getting Started: https://support.kochava.com/articles/sdk-integration/48867-reactnative-sdk/
//
export class KochavaMeasurement {
// Singleton Instance
static instance = new KochavaMeasurement();
// Internal State
_api = new KochavaMeasurementImpl();
_startParameters = {};
// Reserved function, only use if directed to by your Client Success Manager.
executeAdvancedInstruction(name, value) {
this._api.executeAdvancedInstruction(name, value);
}
// Set the log level. This should be set prior to starting the SDK.
setLogLevel(logLevel) {
this._api.setLogLevel(logLevel);
}
// Set the sleep state.
setSleep(enabled) {
this._api.setSleep(enabled);
}
// Set if app level advertising tracking should be limited.
setAppLimitAdTracking(enabled) {
this._api.setAppLimitAdTracking(enabled);
}
// Register a custom device identifier for install attribution.
registerCustomDeviceIdentifier(name, value) {
this._api.registerCustomDeviceIdentifier(name, value);
}
// Register a custom value to be included in SDK payloads.
registerCustomStringValue(name, value) {
this._api.registerCustomStringValue(name, value);
}
// Register a custom value to be included in SDK payloads.
registerCustomBoolValue(name, value) {
this._api.registerCustomBoolValue(name, value);
}
// Register a custom value to be included in SDK payloads.
registerCustomNumberValue(name, value) {
this._api.registerCustomNumberValue(name, value);
}
// Register an Identity Link that allows linking different identities together in the form of key and value pairs.
registerIdentityLink(name, value) {
this._api.registerIdentityLink(name, value);
}
// (Apple Only) Enable App Clips by setting the Container App Group Identifier for App Clips data migration.
// Deprecated: Use enableAppleAppClips instead.
enableiOSAppClips(identifier) {
this._api.enableAppleAppClips(identifier);
}
// (Apple Only) Enable App Clips by setting the Container App Group Identifier for App Clips data migration.
enableAppleAppClips(identifier) {
this._api.enableAppleAppClips(identifier);
}
// (Apple Only) Enable App Tracking Transparency.
// Deprecated: Use enableAppleAtt instead.
enableiOSAtt() {
this.enableAppleAtt();
}
// (Apple Only) Enable App Tracking Transparency.
enableAppleAtt() {
this._api.enableAppleAtt();
}
// (Apple Only) Set the amount of time in seconds to wait for App Tracking Transparency Authorization. Default 30 seconds.
// Deprecated: Use setAppleAttAuthorizationWaitTime instead.
setiOSAttAuthorizationWaitTime(timeInterval) {
this.setAppleAttAuthorizationWaitTime(timeInterval);
}
// (Apple Only) Set the amount of time in seconds to wait for App Tracking Transparency Authorization. Default 30 seconds.
setAppleAttAuthorizationWaitTime(timeInterval) {
this._api.setAppleAttAuthorizationWaitTime(timeInterval);
}
// (Apple Only) Set if the SDK should automatically request App Tracking Transparency Authorization on start. Default true.
// Deprecated: Use setAppleAttAuthorizationAutoRequest instead.
setiOSAttAuthorizationAutoRequest(enabled) {
this.setAppleAttAuthorizationAutoRequest(enabled);
}
// (Apple Only) Set if the SDK should automatically request App Tracking Transparency Authorization on start. Default true.
setAppleAttAuthorizationAutoRequest(enabled) {
this._api.setAppleAttAuthorizationAutoRequest(enabled);
}
// (Apple Only) Set if the app is handling the ATT prompt on their own. Default false.
setAppleAttAuthorizationCustomPrompt(enabled) {
this._api.setAppleAttAuthorizationCustomPrompt(enabled);
}
// (Apple Only) Call to indicate that the custom prompt prompt was answered to allow the SDK to move forward.
appleAttAuthorizationCustomPromptDidComplete() {
this._api.appleAttAuthorizationCustomPromptDidComplete();
}
// Register a privacy profile, creating or overwriting an existing pofile.
registerPrivacyProfile(name, keys) {
this._api.registerPrivacyProfile(name, keys);
}
// Enable or disable an existing privacy profile.
setPrivacyProfileEnabled(name, enabled) {
this._api.setPrivacyProfileEnabled(name, enabled);
}
// Set the init completed callback listener.
// Deprecated: Use setConfigCompletedListener instead.
setInitCompletedListener(initCompletedListener) {
if (initCompletedListener == null) {
this._api.setConfigCompletedListener(null);
} else {
this._api.setConfigCompletedListener(config => {
initCompletedListener(new KochavaMeasurementInit(config));
});
}
}
// Set the config completed callback listener.
setConfigCompletedListener(configCompletedListener) {
this._api.setConfigCompletedListener(configCompletedListener);
}
// Set if consent has been explicitly opted in or out by the user.
setIntelligentConsentGranted(granted) {
this._api.setIntelligentConsentGranted(granted);
}
// Return if the SDK is currently started.
getStarted() {
return this._api.getStarted();
}
// Register the Android App GUID. Do this prior to calling Start.
registerAndroidAppGuid(androidAppGuid) {
this._startParameters["androidAppGuid"] = androidAppGuid;
}
// Register the iOS App GUID. Do this prior to calling Start.
// Deprecated: Use registerAppleAppGuid instead.
registerIosAppGuid(appleAppGuid) {
this.registerAppleAppGuid(appleAppGuid);
}
// Register the Apple App GUID. Do this prior to calling Start.
registerAppleAppGuid(appleAppGuid) {
this._startParameters["appleAppGuid"] = appleAppGuid;
}
// Register the Vega App GUID. Do this prior to calling Start.
registerVegaAppGuid(vegaAppGuid) {
this._startParameters["vegaAppGuid"] = vegaAppGuid;
}
// Register the Web App GUID. Do this prior to calling Start.
// registerWebAppGuid(webAppGuid: string): void {
// this._startParameters["webAppGuid"] = webAppGuid;
// }
// Register your Partner Name. Do this prior to calling Start.
//
// NOTE: Only use this method if directed to by your Client Success Manager.
registerPartnerName(partnerName) {
this._startParameters["partnerName"] = partnerName;
}
// Start the SDK with the previously registered App GUID or Partner Name.
start() {
let wrapper = {
name: "ReactNative",
version: "4.0.0",
build_date: "2025-12-18T23:44:59Z"
};
this.executeAdvancedInstruction("wrapper", JSON.stringify(wrapper));
this._api.start(this._startParameters);
}
// Shut down the SDK and optionally delete all local SDK data.
//
// NOTE: Care should be taken when using this method as deleting the SDK data will make it reset back to a first install state.
shutdown(deleteData) {
this._startParameters = {};
this._api.shutdown(deleteData);
}
// Return the Kochava Device ID.
retrieveInstallId() {
return this._api.retrieveInstallId();
}
// Retrieve install attribution data from the server.
retrieveInstallAttribution() {
return this._api.retrieveInstallAttribution();
}
// Process a launch deeplink using the default 10 second timeout.
processDeeplink(path) {
return this._api.processDeeplink(path);
}
// Process a launch deeplink using a custom timeout in seconds.
processDeeplinkWithOverrideTimeout(path, timeout) {
return this._api.processDeeplinkWithOverrideTimeout(path, timeout);
}
registerDeeplinkWrapperDomain(domain) {
this._api.registerDeeplinkWrapperDomain(domain);
}
// Registers a default parameter on every event.
registerDefaultEventStringParameter(name, value) {
this._api.registerDefaultEventStringParameter(name, value);
}
// Registers a default parameter on every event.
registerDefaultEventBoolParameter(name, value) {
this._api.registerDefaultEventBoolParameter(name, value);
}
// Registers a default parameter on every event.
registerDefaultEventNumberParameter(name, value) {
this._api.registerDefaultEventNumberParameter(name, value);
}
// Registers a default user_id value on every event.
registerDefaultEventUserId(value) {
this._api.registerDefaultEventUserId(value);
}
// Send an event.
sendEvent(name) {
this._api.sendEvent(name);
}
// Send an event with string data.
sendEventWithString(name, data) {
this._api.sendEventWithString(name, data);
}
// Send an event with dictionary data.
sendEventWithDictionary(name, data) {
this._api.sendEventWithDictionary(name, data);
}
// (Internal) Send an event object (Called via Event.send()).
sendEventWithEvent(event) {
this._api.sendEventWithEvent(event);
}
// Build and return an event using a Standard Event Type.
buildEventWithEventType(type) {
return new KochavaMeasurementEvent(type);
}
// Build and return an event using a custom name.
buildEventWithEventName(name) {
return new KochavaMeasurementEvent(name);
}
}
//# sourceMappingURL=index.js.map