UNPKG

@smartface/plugin-firebase

Version:

Smartface Firebase Plugin for Smartface Native Framework

117 lines 4.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // @ts-ignore var NativeFirebaseAnalytics = requireClass('com.google.firebase.analytics.FirebaseAnalytics'); // @ts-ignore var NativeBundle = requireClass('android.os.Bundle'); var androidconfig_1 = __importDefault(require("@smartface/native/util/Android/androidconfig")); var events_1 = __importDefault(require("./events")); var params_1 = __importDefault(require("./params")); var Analytics = /** @class */ (function () { function Analytics() { } /** * Logs an app event. The event can have up to 25 parameters. Events with the same name must have the same parameters. Up to 500 event names are supported. * Using predefined events and/or parameters is recommended for optimal reporting. * * @android * @ios * @since 0.1 */ Analytics.logEvent = function (name, customAttributes) { if (!androidconfig_1.default.isEmulator) { var bundle = new NativeBundle(); if (customAttributes instanceof Array) { for (var i = 0; i < customAttributes.length; i++) { var value = customAttributes[i].value; if (typeof value === 'string') { bundle.putString(customAttributes[i].key, value); } else if (typeof value === 'number') { if (Number.isInteger(value)) bundle.putInt(customAttributes[i].key, value); else bundle.putDouble(customAttributes[i].key, value); } } } // @ts-ignore Analytics.nativeObject().logEvent(name, bundle); } }; /** * Sets a user property to a given value. Up to 25 user property names are supported. * Once set, user property values persist throughout the app lifecycle and across sessions. * * @android * @ios * @since 0.1 */ Analytics.setUserProperty = function (name, value) { if (!androidconfig_1.default.isEmulator) { // @ts-ignore Analytics.nativeObject().setUserProperty(name, value); } }; /** * Sets the user ID property. This feature must be used in accordance with Google’s Privacy Policy. * * @android * @ios * @since 0.1 */ Analytics.setUserId = function (id) { if (!androidconfig_1.default.isEmulator) { // @ts-ignore Analytics.nativeObject().setUserId(id); } }; /** * Sets the current screen name, which specifies the current visual context in your app. * This helps identify the areas in your app where users spend their time and how they interact with your app. * Must be called on the main thread. * * @android * @ios * @since 0.1 */ Analytics.setCurrentScreen = function (screenName, screenClassOverride) { if (!androidconfig_1.default.isEmulator) { var screenNameAttribute = new Analytics.CustomAttribute(NativeFirebaseAnalytics.Param.SCREEN_NAME, screenName); // @ts-ignore var screenClassAttribute = new Analytics.CustomAttribute(NativeFirebaseAnalytics.Param.SCREEN_CLASS, screenClassOverride); this.logEvent(NativeFirebaseAnalytics.Event.SCREEN_VIEW, [screenNameAttribute, screenClassAttribute]); } }; Analytics.ios = {}; Analytics.nativeObject = !androidconfig_1.default.isEmulator ? function () { return NativeFirebaseAnalytics.getInstance(androidconfig_1.default.activity); } : undefined; Analytics.Event = events_1.default; Analytics.Param = params_1.default; /** * CustomAttribute for logCustom. * * @example * const Answers = require('sf-plugin-fabric/answers'); * var attribute1 = new Answers.CustomAttribute("key","value"); * var attribute2 = new Answers.CustomAttribute("key",12); * * @android * @ios * @static * @since 1.0 */ Analytics.CustomAttribute = /** @class */ (function () { function class_1(key, value) { this.key = key; this.value = value; } return class_1; }()); return Analytics; }()); exports.default = Analytics; module.exports = Analytics; //# sourceMappingURL=analytics-Android.js.map