UNPKG

react-native-kochava-measurement

Version:

A lightweight and easy to integrate SDK, providing first-class integration with Kochava’s installation attribution and analytics platform.

255 lines (254 loc) 11.1 kB
"use strict"; import { Log } from "./utils/log.js"; export var KochavaMeasurementEventType; (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"; })(KochavaMeasurementEventType || (KochavaMeasurementEventType = {})); var KochavaMeasurementEvent = /** @class */function () { function KochavaMeasurementEvent(kochava, eventName) { this._eventData = {}; this._durationMeasurementEnabled = false; this._durationStart = 0; this._eventName = eventName; this.kochava = kochava; this._durationStart = Date.now(); } KochavaMeasurementEvent.prototype.send = function () { var duration = this._eventData.hasOwnProperty('duration') ? this._eventData['duration'] : undefined; if (this._durationMeasurementEnabled) { if (duration === undefined || duration === null) { duration = (Date.now() - this._durationStart) / 1000; this.setDuration(duration); } } if (this._bucketConfig && this._bucketConfig.length > 0 && duration !== undefined) { var bucketLabel = this._calculateBucket(duration); this.setCustomStringValue('duration_bucket', bucketLabel); } this.kochava.sendEvent(this._eventName, this._eventData); }; KochavaMeasurementEvent.prototype._calculateBucket = function (duration) { var bucketLabel = ''; if (this._bucketConfig) { for (var i = 0; i < this._bucketConfig.length; i++) { if (duration < this._bucketConfig[i]) { bucketLabel = i === 0 ? "[0s-".concat(this._bucketConfig[i], "s)") : "[".concat(this._bucketConfig[i - 1], "s-").concat(this._bucketConfig[i], "s)"); break; } } if (!bucketLabel && this._bucketConfig.length > 0) { bucketLabel = "[".concat(this._bucketConfig[this._bucketConfig.length - 1], "s-inf)"); } } return bucketLabel; }; KochavaMeasurementEvent.prototype.enableDurationMeasurement = function (enable) { if (enable === void 0) { enable = true; } this._durationMeasurementEnabled = enable; }; KochavaMeasurementEvent.prototype.registerDurationBuckets = function (bucketConfig) { for (var i = 0; i < bucketConfig.length; i++) { if (bucketConfig[i] <= 0) { Log.warn('Bucket values contain non-positive values.'); break; } if (i > 0 && bucketConfig[i] <= bucketConfig[i - 1]) { Log.warn('Bucket values are not in ascending order.'); break; } } this._bucketConfig = bucketConfig; }; KochavaMeasurementEvent.prototype.setCustomStringValue = function (key, value) { if (key && value && typeof value === "string") { this._eventData[key] = value; } }; KochavaMeasurementEvent.prototype.setCustomBoolValue = function (key, value) { if (key && value != null && typeof value === "boolean") { this._eventData[key] = value; } }; KochavaMeasurementEvent.prototype.setCustomNumberValue = function (key, value) { if (key && value != null && typeof value === "number") { this._eventData[key] = value; } }; KochavaMeasurementEvent.prototype._setCustomDictionaryValue = function (key, value) { if (key && value != null && typeof value === 'object') { this._eventData[key] = value; } }; KochavaMeasurementEvent.prototype.buildEventWithEventType = function (eventType) { return new KochavaMeasurementEvent(this.kochava, eventType); }; //Standard Event Parameters KochavaMeasurementEvent.prototype.setAction = function (value) { return this.setCustomStringValue('action', value); }; KochavaMeasurementEvent.prototype.setBackground = function (value) { return this.setCustomBoolValue('background', value); }; KochavaMeasurementEvent.prototype.setCheckoutAsGuest = function (value) { return this.setCustomStringValue('checkout_as_guest', value); }; KochavaMeasurementEvent.prototype.setCompleted = function (value) { return this.setCustomBoolValue('completed', value); }; KochavaMeasurementEvent.prototype.setContentId = function (value) { return this.setCustomStringValue('content_id', value); }; KochavaMeasurementEvent.prototype.setContentType = function (value) { return this.setCustomStringValue('content_type', value); }; KochavaMeasurementEvent.prototype.setCurrency = function (value) { return this.setCustomStringValue('currency', value); }; KochavaMeasurementEvent.prototype.setDate = function (value) { return this.setCustomStringValue('date', value); }; KochavaMeasurementEvent.prototype.setDescription = function (value) { return this.setCustomStringValue('description', value); }; KochavaMeasurementEvent.prototype.setDestination = function (value) { return this.setCustomStringValue('destination', value); }; KochavaMeasurementEvent.prototype.setDuration = function (value) { return this.setCustomNumberValue('duration', value); }; KochavaMeasurementEvent.prototype.setEndDate = function (value) { return this.setCustomStringValue('end_date', value); }; KochavaMeasurementEvent.prototype.setItemAddedFrom = function (value) { return this.setCustomStringValue('item_added_from', value); }; KochavaMeasurementEvent.prototype.setLevel = function (value) { return this.setCustomStringValue('level', value); }; KochavaMeasurementEvent.prototype.setMaxRatingValue = function (value) { return this.setCustomNumberValue('max_rating_value', value); }; KochavaMeasurementEvent.prototype.setName = function (value) { return this.setCustomStringValue('name', value); }; KochavaMeasurementEvent.prototype.setOrderId = function (value) { return this.setCustomStringValue('order_id', value); }; KochavaMeasurementEvent.prototype.setOrigin = function (value) { return this.setCustomStringValue('origin', value); }; KochavaMeasurementEvent.prototype.setPayload = function (value) { return this._setCustomDictionaryValue('payload', value); }; KochavaMeasurementEvent.prototype.setPrice = function (value) { return this.setCustomNumberValue('price', value); }; KochavaMeasurementEvent.prototype.setQuantity = function (value) { return this.setCustomNumberValue('quantity', value); }; KochavaMeasurementEvent.prototype.setRatingValue = function (value) { return this.setCustomNumberValue('rating_value', value); }; KochavaMeasurementEvent.prototype.setReceiptId = function (value) { return this.setCustomStringValue('receipt_id', value); }; KochavaMeasurementEvent.prototype.setReferralFrom = function (value) { return this.setCustomStringValue('referral_from', value); }; KochavaMeasurementEvent.prototype.setRegistrationMethod = function (value) { return this.setCustomStringValue('registration_method', value); }; KochavaMeasurementEvent.prototype.setResults = function (value) { return this.setCustomStringValue('results', value); }; KochavaMeasurementEvent.prototype.setScore = function (value) { return this.setCustomStringValue('score', value); }; KochavaMeasurementEvent.prototype.setSearchTerm = function (value) { return this.setCustomStringValue('search_term', value); }; KochavaMeasurementEvent.prototype.setSource = function (value) { return this.setCustomStringValue('source', value); }; KochavaMeasurementEvent.prototype.setSpatialX = function (value) { return this.setCustomNumberValue('spatial_x', value); }; KochavaMeasurementEvent.prototype.setSpatialY = function (value) { return this.setCustomNumberValue('spatial_y', value); }; KochavaMeasurementEvent.prototype.setSpatialZ = function (value) { return this.setCustomNumberValue('spatial_z', value); }; KochavaMeasurementEvent.prototype.setStartDate = function (value) { return this.setCustomStringValue('start_date', value); }; KochavaMeasurementEvent.prototype.setSuccess = function (value) { return this.setCustomStringValue('success', value); }; KochavaMeasurementEvent.prototype.setUri = function (value) { return this.setCustomStringValue('uri', value); }; KochavaMeasurementEvent.prototype.setUserId = function (value) { return this.setCustomStringValue('user_id', value); }; KochavaMeasurementEvent.prototype.setUserName = function (value) { return this.setCustomStringValue('user_name', value); }; KochavaMeasurementEvent.prototype.setValidated = function (value) { return this.setCustomStringValue('validated', value); }; //LTV Values KochavaMeasurementEvent.prototype.setAdCampaignId = function (value) { this.setCustomStringValue("ad_campaign_id", value); }; KochavaMeasurementEvent.prototype.setAdCampaignName = function (value) { this.setCustomStringValue("ad_campaign_name", value); }; KochavaMeasurementEvent.prototype.setAdDeviceType = function (value) { this.setCustomStringValue("device_type", value); }; KochavaMeasurementEvent.prototype.setAdGroupId = function (value) { this.setCustomStringValue("ad_group_id", value); }; KochavaMeasurementEvent.prototype.setAdGroupName = function (value) { this.setCustomStringValue("ad_group_name", value); }; KochavaMeasurementEvent.prototype.setAdMediationName = function (value) { this.setCustomStringValue("ad_mediation_name", value); }; KochavaMeasurementEvent.prototype.setAdNetworkName = function (value) { this.setCustomStringValue("ad_network_name", value); }; KochavaMeasurementEvent.prototype.setAdPlacement = function (value) { this.setCustomStringValue("placement", value); }; KochavaMeasurementEvent.prototype.setAdSize = function (value) { this.setCustomStringValue("ad_size", value); }; KochavaMeasurementEvent.prototype.setAdType = function (value) { this.setCustomStringValue("ad_type", value); }; return KochavaMeasurementEvent; }(); export { KochavaMeasurementEvent }; //# sourceMappingURL=measurementEvent.js.map