From 6d402418f11ade91114541d8ac6f1e4bd997410d Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 10:54:33 +0100 Subject: [PATCH 01/49] refactor(analytics): move to TypeScript --- packages/analytics/lib/index.ts | 701 ++++++++++++++++++++++ packages/analytics/lib/namespaced.ts | 855 +++++++++++++++++++++++++++ 2 files changed, 1556 insertions(+) create mode 100644 packages/analytics/lib/index.ts create mode 100644 packages/analytics/lib/namespaced.ts diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts new file mode 100644 index 0000000000..ce0568ec0e --- /dev/null +++ b/packages/analytics/lib/index.ts @@ -0,0 +1,701 @@ +// @ts-ignore - JavaScript module without types +import { MODULAR_DEPRECATION_ARG } from '../../app/lib/common/index'; +import { getApp } from '@react-native-firebase/app'; +import { Platform } from 'react-native'; +import type { ReactNativeFirebase } from '@react-native-firebase/app'; +import type { FirebaseAnalyticsTypes } from '../'; + +/** + * Returns an Analytics instance for the given app. + */ +export function getAnalytics(app?: ReactNativeFirebase.FirebaseApp): FirebaseAnalyticsTypes.Module { + if (app) { + return getApp(app.name).analytics(); + } + return getApp().analytics(); +} + +/** + * Returns an Analytics instance for the given app. + */ +export function initializeAnalytics( + app: ReactNativeFirebase.FirebaseApp, + _options?: FirebaseAnalyticsTypes.AnalyticsSettings, +): FirebaseAnalyticsTypes.Module { + return getApp(app.name).analytics(); +} + +/** + * Retrieves a unique Google Analytics identifier for the web client. + */ +export async function getGoogleAnalyticsClientId( + analytics: FirebaseAnalyticsTypes.Module, +): Promise { + if (Platform.OS === 'android' || Platform.OS === 'ios') { + throw new Error('getGoogleAnalyticsClientId is web-only.'); + } else { + const instanceId = await getAppInstanceId(analytics); + return instanceId || ''; + } +} + +/** + * Log a custom event with optional params. + */ +export function logEvent( + analytics: FirebaseAnalyticsTypes.Module, + name: string, + params: { [key: string]: any } = {}, + options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.logEvent.call(analytics, name, params, options, MODULAR_DEPRECATION_ARG); +} + +/** + * If true, allows the device to collect analytical data and send it to Firebase. Useful for GDPR. + */ +export function setAnalyticsCollectionEnabled( + analytics: FirebaseAnalyticsTypes.Module, + enabled: boolean, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setAnalyticsCollectionEnabled.call(analytics, enabled, MODULAR_DEPRECATION_ARG); +} + +/** + * Sets the duration of inactivity that terminates the current session. + */ +export function setSessionTimeoutDuration( + analytics: FirebaseAnalyticsTypes.Module, + milliseconds: number = 1800000, +): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setSessionTimeoutDuration.call(analytics, milliseconds, MODULAR_DEPRECATION_ARG); +} + +/** + * Retrieve the app instance id of the application. + */ +export function getAppInstanceId(analytics: FirebaseAnalyticsTypes.Module): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.getAppInstanceId.call(analytics, MODULAR_DEPRECATION_ARG); +} + +/** + * Retrieves the session id from the client. + * On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details. + */ +export function getSessionId(analytics: FirebaseAnalyticsTypes.Module): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.getSessionId.call(analytics, MODULAR_DEPRECATION_ARG); +} + +/** + * Gives a user a unique identification. + */ +export function setUserId( + analytics: FirebaseAnalyticsTypes.Module, + id: string | null, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setUserId.call(analytics, id, MODULAR_DEPRECATION_ARG); +} + +/** + * Sets a key/value pair of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. + */ +export function setUserProperty( + analytics: FirebaseAnalyticsTypes.Module, + name: string, + value: string | null, +): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setUserProperty.call(analytics, name, value, MODULAR_DEPRECATION_ARG); +} + +/** + * Sets multiple key/value pairs of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. + */ +export function setUserProperties( + analytics: FirebaseAnalyticsTypes.Module, + properties: { [key: string]: string | null }, + options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setUserProperties.call(analytics, properties, options, MODULAR_DEPRECATION_ARG); +} + +/** + * Clears all analytics data for this instance from the device and resets the app instance ID. + */ +export function resetAnalyticsData(analytics: FirebaseAnalyticsTypes.Module): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.resetAnalyticsData.call(analytics, MODULAR_DEPRECATION_ARG); +} + +/** + * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported automatically for Google Play-based apps. + */ +export function logAddPaymentInfo( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.AddPaymentInfoEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddPaymentInfo(params); +} + +/** + * Sets or clears the screen name and class the user is currently viewing. + */ +export function logScreenView( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.ScreenViewParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logScreenView(params); +} + +/** + * Add Payment Info event. This event signifies that a user has submitted their payment information to your app. + */ +export function logAddShippingInfo( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.AddShippingInfoParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddShippingInfo(params); +} + +/** + * E-Commerce Add To Cart event. + */ +export function logAddToCart( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.AddToCartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddToCart(params); +} + +/** + * E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. + */ +export function logAddToWishlist( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.AddToWishlistEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddToWishlist(params); +} + +/** + * App Open event. By logging this event when an App is moved to the foreground, developers can understand how often users leave and return during the course of a Session. + */ +export function logAppOpen(analytics: FirebaseAnalyticsTypes.Module): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAppOpen(); +} + +/** + * E-Commerce Begin Checkout event. This event signifies that a user has begun the process of checking out. + */ +export function logBeginCheckout( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.BeginCheckoutEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logBeginCheckout(params); +} + +/** + * Log this event to supply the referral details of a re-engagement campaign. + */ +export function logCampaignDetails( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.CampaignDetailsEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logCampaignDetails(params); +} + +/** + * Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app. + */ +export function logEarnVirtualCurrency( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.EarnVirtualCurrencyEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logEarnVirtualCurrency(params); +} + +/** + * Generate Lead event. Log this event when a lead has been generated in the app. + */ +export function logGenerateLead( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.GenerateLeadEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logGenerateLead(params); +} + +/** + * Join Group event. Log this event when a user joins a group such as a guild, team or family. + */ +export function logJoinGroup( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.JoinGroupEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logJoinGroup(params); +} + +/** + * Level End event. + */ +export function logLevelEnd( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.LevelEndEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLevelEnd(params); +} + +/** + * Level Start event. + */ +export function logLevelStart( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.LevelStartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLevelStart(params); +} + +/** + * Level Up event. This event signifies that a player has leveled up in your gaming app. + */ +export function logLevelUp( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.LevelUpEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLevelUp(params); +} + +/** + * Login event. Apps with a login feature can report this event to signify that a user has logged in. + */ +export function logLogin( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.LoginEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLogin(params); +} + +/** + * Post Score event. Log this event when the user posts a score in your gaming app. + */ +export function logPostScore( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.PostScoreEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logPostScore(params); +} + +/** + * Select Content event. This general purpose event signifies that a user has selected some content of a certain type in an app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SelectContentEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSelectContent( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.SelectContentEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSelectContent(params); +} + +/** + * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {PurchaseEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logPurchase( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.PurchaseEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logPurchase(params); +} + +/** + * E-Commerce Refund event. This event signifies that a refund was issued. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {RefundEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logRefund( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.RefundEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logRefund(params); +} + +/** + * Remove from cart event. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {RemoveFromCartEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logRemoveFromCart( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.RemoveFromCartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logRemoveFromCart(params); +} + +/** + * Search event. Apps that support search features can use this event to contextualize search operations by supplying the appropriate, corresponding parameters. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SearchEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSearch( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.SearchEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSearch(params); +} + +/** + * Select Item event. This event signifies that an item was selected by a user from a list. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SelectItemEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSelectItem( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.SelectItemEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSelectItem(params); +} + +/** + * Set checkout option event. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SetCheckoutOptionEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSetCheckoutOption( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.SetCheckoutOptionEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSetCheckoutOption(params); +} + +/** + * Select promotion event. This event signifies that a user has selected a promotion offer. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SelectPromotionEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSelectPromotion( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.SelectPromotionEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSelectPromotion(params); +} + +/** + * Share event. Apps with social features can log the Share event to identify the most viral content. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ShareEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logShare( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.ShareEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logShare(params); +} + +/** + * Sign Up event. This event indicates that a user has signed up for an account in your app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SignUpEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSignUp( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.SignUpEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSignUp(params); +} + +/** + * Spend Virtual Currency event. This event tracks the sale of virtual goods in your app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SpendVirtualCurrencyEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSpendVirtualCurrency( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.SpendVirtualCurrencyEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSpendVirtualCurrency(params); +} + +/** + * Tutorial Begin event. This event signifies the start of the on-boarding process in your app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @returns {Promise} + */ +export function logTutorialBegin(analytics: FirebaseAnalyticsTypes.Module): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logTutorialBegin(); +} + +/** + * Tutorial End event. Use this event to signify the user's completion of your app's on-boarding process. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @returns {Promise} + */ +export function logTutorialComplete(analytics: FirebaseAnalyticsTypes.Module): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logTutorialComplete(); +} + +/** + * Unlock Achievement event. Log this event when the user has unlocked an achievement in your game. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {UnlockAchievementEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logUnlockAchievement( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.UnlockAchievementEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logUnlockAchievement(params); +} + +/** + * E-commerce View Cart event. This event signifies that a user has viewed their cart. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewCartEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewCart( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.ViewCartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewCart(params); +} + +/** + * View Item event. This event signifies that some content was shown to the user. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewItemEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewItem( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.ViewItemEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewItem(params); +} + +/** + * View Item List event. Log this event when the user has been presented with a list of items of a certain category. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewItemListEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewItemList( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.ViewItemListEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewItemList(params); +} + +/** + * View Promotion event. This event signifies that a promotion was shown to a user. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewPromotionEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewPromotion( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.ViewPromotionEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewPromotion(params); +} + +/** + * View Search Results event. Log this event when the user has been presented with the results of a search. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewSearchResultsParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewSearchResults( + analytics: FirebaseAnalyticsTypes.Module, + params: FirebaseAnalyticsTypes.ViewSearchResultsParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewSearchResults(params); +} + +/** + * Adds parameters that will be set on every event logged from the SDK, including automatic ones. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {object} [params={}] - Parameters to be added to the map of parameters added to every event. + * @returns {Promise} + */ +export function setDefaultEventParameters( + analytics: FirebaseAnalyticsTypes.Module, + params: { [key: string]: any } = {}, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setDefaultEventParameters.call(analytics, params, MODULAR_DEPRECATION_ARG); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {string} emailAddress - Email address, properly formatted complete with domain name e.g, 'user@example.com'. + * @returns {Promise} + */ +export function initiateOnDeviceConversionMeasurementWithEmailAddress( + analytics: FirebaseAnalyticsTypes.Module, + emailAddress: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithEmailAddress.call( + analytics, + emailAddress, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile + * + * @param analytics Analytics instance. + * @param hashedEmailAddress sha256-hashed of normalized email address, properly formatted complete with domain name e.g, 'user@example.com' + * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials + */ +export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( + analytics: FirebaseAnalyticsTypes.Module, + hashedEmailAddress: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress.call( + analytics, + hashedEmailAddress, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {string} phoneNumber - Phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. + * @returns {Promise} + */ +export function initiateOnDeviceConversionMeasurementWithPhoneNumber( + analytics: FirebaseAnalyticsTypes.Module, + phoneNumber: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber.call( + analytics, + phoneNumber, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile + * + * @param analytics Analytics instance. + * @param hashedPhoneNumber sha256-hashed of normalized phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. + * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials + */ +export function initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( + analytics: FirebaseAnalyticsTypes.Module, + hashedPhoneNumber: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber.call( + analytics, + hashedPhoneNumber, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * Checks four different things. + * 1. Checks if it's not a browser extension environment. + * 2. Checks if cookies are enabled in current browser. + * 3. Checks if IndexedDB is supported by the browser environment. + * 4. Checks if the current browser context is valid for using IndexedDB.open(). + * @returns {Promise} + */ +export function isSupported(): Promise { + return Promise.resolve(true); +} + +/** + * Sets the applicable end user consent state for this app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ConsentSettings} consentSettings - See ConsentSettings. + * @returns {Promise} + */ +export function setConsent( + analytics: FirebaseAnalyticsTypes.Module, + consentSettings: FirebaseAnalyticsTypes.ConsentSettings, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setConsent.call(analytics, consentSettings, MODULAR_DEPRECATION_ARG); +} + +/** + * Configures Firebase Analytics to use custom gtag or dataLayer names. + * Intended to be used if gtag.js script has been installed on this page independently of Firebase Analytics, and is using non-default names for either the gtag function or for dataLayer. Must be called before calling `getAnalytics()` or it won't have any effect. Web only. + * @param {SettingsOptions} options - See SettingsOptions. + * @returns {void} + */ +export function settings(_options: FirebaseAnalyticsTypes.SettingsOptions): void { + // Returns nothing until Web implemented. +} diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts new file mode 100644 index 0000000000..df03b859b3 --- /dev/null +++ b/packages/analytics/lib/namespaced.ts @@ -0,0 +1,855 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { + isAlphaNumericUnderscore, + isE164PhoneNumber, + isIOS, + isNull, + isNumber, + isObject, + isOneOf, + isString, + isUndefined, +} from '@react-native-firebase/app/lib/common'; + +import { + createModuleNamespace, + FirebaseModule, + getFirebaseRoot, +} from '@react-native-firebase/app/lib/internal'; +import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule'; +import { isBoolean } from '@react-native-firebase/app/lib/common'; + +import { validateStruct, validateCompound } from './struct'; +import fallBackModule from './web/RNFBAnalyticsModule'; +import version from './version'; +import * as structs from './structs'; + +// Import types from the index file +import type { FirebaseAnalyticsTypes } from '../'; + +const ReservedEventNames: readonly string[] = [ + 'ad_activeview', + 'ad_click', + 'ad_exposure', + // 'ad_impression', // manual ad_impression logging is allowed, See #6307 + 'ad_query', + 'ad_reward', + 'adunit_exposure', + 'app_background', + 'app_clear_data', + // 'app_exception', + 'app_remove', + 'app_store_refund', + 'app_store_subscription_cancel', + 'app_store_subscription_convert', + 'app_store_subscription_renew', + 'app_update', + 'app_upgrade', + 'dynamic_link_app_open', + 'dynamic_link_app_update', + 'dynamic_link_first_open', + 'error', + 'first_open', + 'first_visit', + 'in_app_purchase', + 'notification_dismiss', + 'notification_foreground', + 'notification_open', + 'notification_receive', + 'os_update', + 'session_start', + 'session_start_with_rollout', + 'user_engagement', +] as const; + +const statics: FirebaseAnalyticsTypes.Statics = {}; + +const namespace = 'analytics'; + +const nativeModuleName = 'RNFBAnalyticsModule'; + +class FirebaseAnalyticsModule extends FirebaseModule { + logEvent( + name: string, + params: { [key: string]: any } = {}, + options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, + ): Promise { + if (!isString(name)) { + throw new Error("firebase.analytics().logEvent(*) 'name' expected a string value."); + } + + if (!isUndefined(params) && !isObject(params)) { + throw new Error("firebase.analytics().logEvent(_, *) 'params' expected an object value."); + } + + // check name is not a reserved event name + if (isOneOf(name, ReservedEventNames as any[])) { + throw new Error( + `firebase.analytics().logEvent(*) 'name' the event name '${name}' is reserved and can not be used.`, + ); + } + + // name format validation + if (!isAlphaNumericUnderscore(name) || name.length > 40) { + throw new Error( + `firebase.analytics().logEvent(*) 'name' invalid event name '${name}'. Names should contain 1 to 40 alphanumeric characters or underscores.`, + ); + } + + if (!isUndefined(options)) { + if (!isObject(options)) { + throw new Error( + "firebase.analytics().logEvent(_, _, *) 'options' expected an object value.", + ); + } + + if (!isUndefined(options.global) && !isBoolean(options.global)) { + throw new Error("'options.global' property expected a boolean."); + } + } + + return this.native.logEvent(name, params); + } + + setAnalyticsCollectionEnabled(enabled: boolean): Promise { + if (!isBoolean(enabled)) { + throw new Error( + "firebase.analytics().setAnalyticsCollectionEnabled(*) 'enabled' expected a boolean value.", + ); + } + + return this.native.setAnalyticsCollectionEnabled(enabled); + } + + setSessionTimeoutDuration(milliseconds: number = 1800000): Promise { + if (!isNumber(milliseconds)) { + throw new Error( + "firebase.analytics().setSessionTimeoutDuration(*) 'milliseconds' expected a number value.", + ); + } + + if (milliseconds < 0) { + throw new Error( + "firebase.analytics().setSessionTimeoutDuration(*) 'milliseconds' expected a positive number value.", + ); + } + + return this.native.setSessionTimeoutDuration(milliseconds); + } + + getAppInstanceId(): Promise { + return this.native.getAppInstanceId(); + } + + getSessionId(): Promise { + return this.native.getSessionId(); + } + + setUserId(id: string | null): Promise { + if (!isNull(id) && !isString(id)) { + throw new Error("firebase.analytics().setUserId(*) 'id' expected a string value."); + } + + return this.native.setUserId(id); + } + + setUserProperty(name: string, value: string | null): Promise { + if (!isString(name)) { + throw new Error("firebase.analytics().setUserProperty(*) 'name' expected a string value."); + } + + if (value !== null && !isString(value)) { + throw new Error( + "firebase.analytics().setUserProperty(_, *) 'value' expected a string value.", + ); + } + + return this.native.setUserProperty(name, value); + } + + setUserProperties( + properties: { [key: string]: string | null }, + options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, + ): Promise { + if (!isObject(properties)) { + throw new Error( + "firebase.analytics().setUserProperties(*) 'properties' expected an object of key/value pairs.", + ); + } + + if (!isUndefined(options)) { + if (!isObject(options)) { + throw new Error( + "firebase.analytics().logEvent(_, _, *) 'options' expected an object value.", + ); + } + + if (!isUndefined(options.global) && !isBoolean(options.global)) { + throw new Error("'options.global' property expected a boolean."); + } + } + + const entries = Object.entries(properties); + for (let i = 0; i < entries.length; i++) { + const [key, value] = entries[i]; + if (!isNull(value) && !isString(value)) { + throw new Error( + `firebase.analytics().setUserProperties(*) 'properties' value for parameter '${key}' is invalid, expected a string.`, + ); + } + } + + return this.native.setUserProperties(properties); + } + + resetAnalyticsData(): Promise { + return this.native.resetAnalyticsData(); + } + + setConsent(consentSettings: FirebaseAnalyticsTypes.ConsentSettings): Promise { + if (!isObject(consentSettings)) { + throw new Error( + 'firebase.analytics().setConsent(*): The supplied arg must be an object of key/values.', + ); + } + + const entries = Object.entries(consentSettings); + for (let i = 0; i < entries.length; i++) { + const [key, value] = entries[i]; + if (!isBoolean(value)) { + throw new Error( + `firebase.analytics().setConsent(*) 'consentSettings' value for parameter '${key}' is invalid, expected a boolean.`, + ); + } + } + + return this.native.setConsent(consentSettings); + } + + /** ------------------- + * EVENTS + * -------------------- */ + logAddPaymentInfo( + object: FirebaseAnalyticsTypes.AddPaymentInfoEventParameters = {}, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logAddPaymentInfo(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddPaymentInfo(*):'); + + return this.logEvent( + 'add_payment_info', + validateStruct(object, structs.AddPaymentInfo, 'firebase.analytics().logAddPaymentInfo(*):'), + ); + } + + logScreenView(object: FirebaseAnalyticsTypes.ScreenViewParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logScreenView(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'screen_view', + validateStruct(object, structs.ScreenView, 'firebase.analytics().logScreenView(*):'), + ); + } + + logAddShippingInfo(object: FirebaseAnalyticsTypes.AddShippingInfoParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logAddShippingInfo(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddShippingInfo(*):'); + + return this.logEvent( + 'add_shipping_info', + validateStruct( + object, + structs.AddShippingInfo, + 'firebase.analytics().logAddShippingInfo(*):', + ), + ); + } + + logAddToCart(object: FirebaseAnalyticsTypes.AddToCartEventParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logAddToCart(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddToCart(*):'); + + return this.logEvent( + 'add_to_cart', + validateStruct(object, structs.AddToCart, 'firebase.analytics().logAddToCart(*):'), + ); + } + + logAddToWishlist( + object: FirebaseAnalyticsTypes.AddToWishlistEventParameters = {}, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logAddToWishlist(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddToWishlist(*):'); + + return this.logEvent( + 'add_to_wishlist', + validateStruct(object, structs.AddToWishlist, 'firebase.analytics().logAddToWishlist(*):'), + ); + } + + logAppOpen(): Promise { + return this.logEvent('app_open'); + } + + logBeginCheckout( + object: FirebaseAnalyticsTypes.BeginCheckoutEventParameters = {}, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logBeginCheckout(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logBeginCheckout(*):'); + + return this.logEvent( + 'begin_checkout', + validateStruct(object, structs.BeginCheckout, 'firebase.analytics().logBeginCheckout(*):'), + ); + } + + logCampaignDetails(object: FirebaseAnalyticsTypes.CampaignDetailsEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logCampaignDetails(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'campaign_details', + validateStruct( + object, + structs.CampaignDetails, + 'firebase.analytics().logCampaignDetails(*):', + ), + ); + } + + logEarnVirtualCurrency( + object: FirebaseAnalyticsTypes.EarnVirtualCurrencyEventParameters, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logEarnVirtualCurrency(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'earn_virtual_currency', + validateStruct( + object, + structs.EarnVirtualCurrency, + 'firebase.analytics().logEarnVirtualCurrency(*):', + ), + ); + } + + logGenerateLead(object: FirebaseAnalyticsTypes.GenerateLeadEventParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logGenerateLead(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logGenerateLead(*):'); + + return this.logEvent( + 'generate_lead', + validateStruct(object, structs.GenerateLead, 'firebase.analytics().logGenerateLead(*):'), + ); + } + + logJoinGroup(object: FirebaseAnalyticsTypes.JoinGroupEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logJoinGroup(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'join_group', + validateStruct(object, structs.JoinGroup, 'firebase.analytics().logJoinGroup(*):'), + ); + } + + logLevelEnd(object: FirebaseAnalyticsTypes.LevelEndEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logLevelEnd(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'level_end', + validateStruct(object, structs.LevelEnd, 'firebase.analytics().logLevelEnd(*):'), + ); + } + + logLevelStart(object: FirebaseAnalyticsTypes.LevelStartEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logLevelStart(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'level_start', + validateStruct(object, structs.LevelStart, 'firebase.analytics().logLevelStart(*):'), + ); + } + + logLevelUp(object: FirebaseAnalyticsTypes.LevelUpEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logLevelUp(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'level_up', + validateStruct(object, structs.LevelUp, 'firebase.analytics().logLevelUp(*):'), + ); + } + + logLogin(object: FirebaseAnalyticsTypes.LoginEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logLogin(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'login', + validateStruct(object, structs.Login, 'firebase.analytics().logLogin(*):'), + ); + } + + logPostScore(object: FirebaseAnalyticsTypes.PostScoreEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logPostScore(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'post_score', + validateStruct(object, structs.PostScore, 'firebase.analytics().logPostScore(*):'), + ); + } + + logSelectContent(object: FirebaseAnalyticsTypes.SelectContentEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logSelectContent(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'select_content', + validateStruct(object, structs.SelectContent, 'firebase.analytics().logSelectContent(*):'), + ); + } + + logPurchase(object: FirebaseAnalyticsTypes.PurchaseEventParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logPurchase(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logPurchase(*):'); + + return this.logEvent( + 'purchase', + validateStruct(object, structs.Purchase, 'firebase.analytics().logPurchaseEvent(*):'), + ); + } + + logRefund(object: FirebaseAnalyticsTypes.RefundEventParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logRefund(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logRefund(*):'); + + return this.logEvent( + 'refund', + validateStruct(object, structs.Refund, 'firebase.analytics().logRefund(*):'), + ); + } + + logRemoveFromCart( + object: FirebaseAnalyticsTypes.RemoveFromCartEventParameters = {}, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logRemoveFromCart(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logRemoveFromCart(*):'); + + return this.logEvent( + 'remove_from_cart', + validateStruct(object, structs.RemoveFromCart, 'firebase.analytics().logRemoveFromCart(*):'), + ); + } + + logSearch(object: FirebaseAnalyticsTypes.SearchEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logSearch(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'search', + validateStruct(object, structs.Search, 'firebase.analytics().logSearch(*):'), + ); + } + + logSelectItem(object: FirebaseAnalyticsTypes.SelectItemEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logSelectItem(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'select_item', + validateStruct(object, structs.SelectItem, 'firebase.analytics().logSelectItem(*):'), + ); + } + + logSetCheckoutOption( + object: FirebaseAnalyticsTypes.SetCheckoutOptionEventParameters, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logSetCheckoutOption(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'set_checkout_option', + validateStruct( + object, + structs.SetCheckoutOption, + 'firebase.analytics().logSetCheckoutOption(*):', + ), + ); + } + + logSelectPromotion(object: FirebaseAnalyticsTypes.SelectPromotionEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logSelectPromotion(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'select_promotion', + validateStruct( + object, + structs.SelectPromotion, + 'firebase.analytics().logSelectPromotion(*):', + ), + ); + } + + logShare(object: FirebaseAnalyticsTypes.ShareEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logShare(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'share', + validateStruct(object, structs.Share, 'firebase.analytics().logShare(*):'), + ); + } + + logSignUp(object: FirebaseAnalyticsTypes.SignUpEventParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logSignUp(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'sign_up', + validateStruct(object, structs.SignUp, 'firebase.analytics().logSignUp(*):'), + ); + } + + logSpendVirtualCurrency( + object: FirebaseAnalyticsTypes.SpendVirtualCurrencyEventParameters, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logSpendVirtualCurrency(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'spend_virtual_currency', + validateStruct( + object, + structs.SpendVirtualCurrency, + 'firebase.analytics().logSpendVirtualCurrency(*):', + ), + ); + } + + logTutorialBegin(): Promise { + return this.logEvent('tutorial_begin'); + } + + logTutorialComplete(): Promise { + return this.logEvent('tutorial_complete'); + } + + logUnlockAchievement( + object: FirebaseAnalyticsTypes.UnlockAchievementEventParameters, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logUnlockAchievement(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'unlock_achievement', + validateStruct( + object, + structs.UnlockAchievement, + 'firebase.analytics().logUnlockAchievement(*):', + ), + ); + } + + logViewCart(object: FirebaseAnalyticsTypes.ViewCartEventParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logViewCart(*): The supplied arg must be an object of key/values.', + ); + } + + validateCompound(object, 'value', 'currency', 'firebase.analytics().logViewCart(*):'); + + return this.logEvent( + 'view_cart', + validateStruct(object, structs.ViewCart, 'firebase.analytics().logViewCart(*):'), + ); + } + + logViewItem(object: FirebaseAnalyticsTypes.ViewItemEventParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logViewItem(*): The supplied arg must be an object of key/values.', + ); + } + validateCompound(object, 'value', 'currency', 'firebase.analytics().logViewItem(*):'); + + return this.logEvent( + 'view_item', + validateStruct(object, structs.ViewItem, 'firebase.analytics().logViewItem(*):'), + ); + } + + logViewItemList(object: FirebaseAnalyticsTypes.ViewItemListEventParameters = {}): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logViewItemList(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'view_item_list', + validateStruct(object, structs.ViewItemList, 'firebase.analytics().logViewItemList(*):'), + ); + } + + logViewPromotion( + object: FirebaseAnalyticsTypes.ViewPromotionEventParameters = {}, + ): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logViewPromotion(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'view_promotion', + validateStruct(object, structs.ViewPromotion, 'firebase.analytics().logViewPromotion(*):'), + ); + } + /** + * Unsupported in "Enhanced Ecommerce reports": + * https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-view_search_results + */ + logViewSearchResults(object: FirebaseAnalyticsTypes.ViewSearchResultsParameters): Promise { + if (!isObject(object)) { + throw new Error( + 'firebase.analytics().logViewSearchResults(*): The supplied arg must be an object of key/values.', + ); + } + + return this.logEvent( + 'view_search_results', + validateStruct( + object, + structs.ViewSearchResults, + 'firebase.analytics().logViewSearchResults(*):', + ), + ); + } + + setDefaultEventParameters(params?: { [key: string]: any }): Promise { + if (!isObject(params) && !isNull(params) && !isUndefined(params)) { + throw new Error( + "firebase.analytics().setDefaultEventParameters(*) 'params' expected an object value when it is defined.", + ); + } + + return this.native.setDefaultEventParameters(params); + } + + initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress: string): Promise { + if (!isString(emailAddress)) { + throw new Error( + "firebase.analytics().initiateOnDeviceConversionMeasurementWithEmailAddress(*) 'emailAddress' expected a string value.", + ); + } + + if (!isIOS) { + return Promise.resolve(); + } + + return this.native.initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress); + } + + initiateOnDeviceConversionMeasurementWithHashedEmailAddress( + hashedEmailAddress: string, + ): Promise { + if (!isString(hashedEmailAddress)) { + throw new Error( + "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedEmailAddress(*) 'hashedEmailAddress' expected a string value.", + ); + } + + if (!isIOS) { + return Promise.resolve(); + } + + return this.native.initiateOnDeviceConversionMeasurementWithHashedEmailAddress( + hashedEmailAddress, + ); + } + + initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber: string): Promise { + if (!isE164PhoneNumber(phoneNumber)) { + throw new Error( + "firebase.analytics().initiateOnDeviceConversionMeasurementWithPhoneNumber(*) 'phoneNumber' expected a string value in E.164 format.", + ); + } + + if (!isIOS) { + return Promise.resolve(); + } + + return this.native.initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber); + } + + initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( + hashedPhoneNumber: string, + ): Promise { + if (isE164PhoneNumber(hashedPhoneNumber)) { + throw new Error( + "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(*) 'hashedPhoneNumber' expected a sha256-hashed value of a phone number in E.164 format.", + ); + } + + if (!isString(hashedPhoneNumber)) { + throw new Error( + "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(*) 'hashedPhoneNumber' expected a string value.", + ); + } + + if (!isIOS) { + return Promise.resolve(); + } + + return this.native.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( + hashedPhoneNumber, + ); + } +} + +// import { SDK_VERSION } from '@react-native-firebase/analytics'; +export const SDK_VERSION: string = version; + +// import analytics from '@react-native-firebase/analytics'; +// analytics().logEvent(...); +export default createModuleNamespace({ + statics, + version, + namespace, + nativeModuleName, + nativeEvents: false, + hasMultiAppSupport: false, + hasCustomUrlOrRegionSupport: false, + ModuleClass: FirebaseAnalyticsModule, +}); + +export * from './modular/index'; + +// import analytics, { firebase } from '@react-native-firebase/analytics'; +// analytics().logEvent(...); +// firebase.analytics().logEvent(...); +export const firebase = getFirebaseRoot(); + +// Register the interop module for non-native platforms. +setReactNativeModule(nativeModuleName, fallBackModule); From c358bcb2c861ace91f92dc761224babdc7cb5b10 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 10:56:14 +0100 Subject: [PATCH 02/49] chore: make index.ts modular and reexport namespaced from there --- packages/analytics/lib/index.ts | 2 ++ packages/analytics/lib/namespaced.ts | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index ce0568ec0e..38ec760e96 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -699,3 +699,5 @@ export function setConsent( export function settings(_options: FirebaseAnalyticsTypes.SettingsOptions): void { // Returns nothing until Web implemented. } + +export * from './namespaced'; diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index df03b859b3..ea99918f39 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -844,8 +844,6 @@ export default createModuleNamespace({ ModuleClass: FirebaseAnalyticsModule, }); -export * from './modular/index'; - // import analytics, { firebase } from '@react-native-firebase/analytics'; // analytics().logEvent(...); // firebase.analytics().logEvent(...); From 135363f9920b2ccf27d9265282e8001ecc49bef0 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 11:03:44 +0100 Subject: [PATCH 03/49] chore: remove modular folder --- packages/analytics/lib/modular/index.d.ts | 1267 --------------------- packages/analytics/lib/modular/index.js | 673 ----------- 2 files changed, 1940 deletions(-) delete mode 100644 packages/analytics/lib/modular/index.d.ts delete mode 100644 packages/analytics/lib/modular/index.js diff --git a/packages/analytics/lib/modular/index.d.ts b/packages/analytics/lib/modular/index.d.ts deleted file mode 100644 index 83a66da8fb..0000000000 --- a/packages/analytics/lib/modular/index.d.ts +++ /dev/null @@ -1,1267 +0,0 @@ -import { ReactNativeFirebase } from '@react-native-firebase/app'; -import { FirebaseAnalyticsTypes } from '..'; -import Analytics = FirebaseAnalyticsTypes.Module; -import AnalyticsCallOptions = FirebaseAnalyticsTypes.AnalyticsCallOptions; -import EventParams = FirebaseAnalyticsTypes.EventParams; -import FirebaseApp = ReactNativeFirebase.FirebaseApp; - -/** - * Returns an Analytics instance for the given app. - * - * @param app - FirebaseApp. Optional. - */ -export declare function getAnalytics(app?: FirebaseApp): Analytics; - -/** - * Returns an Analytics instance for the given app. - * - * @param app - FirebaseApp. - * @param options - `AnalyticsSettings`. Web only. - */ -export declare function initializeAnalytics( - app: FirebaseApp, - options?: FirebaseAnalyticsTypes.AnalyticsSettings, -): Analytics; - -/** - * Retrieves a unique Google Analytics identifier for the web client. - * - * @param analyticsInstance - Instance of analytics (web - only) - * - */ -export declare function getGoogleAnalyticsClientId(analyticsInstance: Analytics): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'add_payment_info', - params?: { - coupon?: EventParams['coupon']; - currency?: EventParams['currency']; - items?: EventParams['items']; - payment_type?: EventParams['payment_type']; - value?: EventParams['value']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'purchase' | 'refund', - params?: { - value?: EventParams['value']; - currency?: EventParams['currency']; - transaction_id: EventParams['transaction_id']; - tax?: EventParams['tax']; - shipping?: EventParams['shipping']; - items?: EventParams['items']; - coupon?: EventParams['coupon']; - affiliation?: EventParams['affiliation']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'screen_view', - params?: { - firebase_screen: EventParams['firebase_screen']; - firebase_screen_class: EventParams['firebase_screen_class']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'search' | 'view_search_results', - params?: { - search_term?: EventParams['search_term']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'select_content', - params?: { - content_type?: EventParams['content_type']; - item_id?: EventParams['item_id']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'select_item', - params?: { - items?: EventParams['items']; - item_list_name?: EventParams['item_list_name']; - item_list_id?: EventParams['item_list_id']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'select_promotion' | 'view_promotion', - params?: { - items?: EventParams['items']; - promotion_id?: EventParams['promotion_id']; - promotion_name?: EventParams['promotion_name']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'set_checkout_option', - params?: { - checkout_step?: EventParams['checkout_step']; - checkout_option?: EventParams['checkout_option']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'share', - params?: { - method?: EventParams['method']; - content_type?: EventParams['content_type']; - item_id?: EventParams['item_id']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'sign_up', - params?: { - method?: EventParams['method']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'timing_complete', - params?: { - name: string; - value: number; - event_category?: string; - event_label?: string; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'add_shipping_info', - params?: { - coupon?: EventParams['coupon']; - currency?: EventParams['currency']; - items?: EventParams['items']; - shipping_tier?: EventParams['shipping_tier']; - value?: EventParams['value']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'view_cart' | 'view_item', - params?: { - currency?: EventParams['currency']; - items?: EventParams['items']; - value?: EventParams['value']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'view_item_list', - params?: { - items?: EventParams['items']; - item_list_name?: EventParams['item_list_name']; - item_list_id?: EventParams['item_list_id']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: FirebaseAnalyticsTypes.CustomEventName, - params?: { - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'add_to_cart' | 'add_to_wishlist' | 'remove_from_cart', - params?: { - currency?: EventParams['currency']; - value?: EventParams['value']; - items?: EventParams['items']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'begin_checkout', - params?: { - currency?: EventParams['currency']; - coupon?: EventParams['coupon']; - value?: EventParams['value']; - items?: EventParams['items']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'checkout_progress', - params?: { - currency?: EventParams['currency']; - coupon?: EventParams['coupon']; - value?: EventParams['value']; - items?: EventParams['items']; - checkout_step?: EventParams['checkout_step']; - checkout_option?: EventParams['checkout_option']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'exception', - params?: { - description?: EventParams['description']; - fatal?: EventParams['fatal']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'generate_lead', - params?: { - value?: EventParams['value']; - currency?: EventParams['currency']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'login', - params?: { - method?: EventParams['method']; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * @param analytics Analytics instance. - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ -export declare function logEvent( - analytics: Analytics, - name: 'page_view', - params?: { - page_title?: string; - page_location?: string; - page_path?: string; - [key: string]: any; - }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * If true, allows the device to collect analytical data and send it to - * Firebase. Useful for GDPR. - */ -export declare function setAnalyticsCollectionEnabled( - analyticsInstance: Analytics, - enabled: boolean, -): Promise; - -/** - * Sets the duration of inactivity that terminates the current session. - * - * @param analytics Analytics instance. - * @param milliseconds The default value is 1800000 (30 minutes). - */ -export declare function setSessionTimeoutDuration( - analytics: Analytics, - milliseconds: number, -): Promise; - -/** - * Retrieve the app instance id of the application. - * - * @param analytics Analytics instance. - * @returns Returns the app instance id or null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. - */ -export function getAppInstanceId(analytics: Analytics): Promise; - -/** - * Gives a user a unique identification. - * - * @param analytics Analytics instance. - * @param id Set to null to remove a previously assigned ID from analytics events - * @param options Additional options that can be passed to Analytics method calls such as logEvent, etc. - */ -export function setUserId( - analytics: Analytics, - id: string | null, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Sets a key/value pair of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - * - * @param analytics Analytics instance. - * @param name A user property identifier. - * @param value Set to null to remove a previously assigned ID from analytics events. - */ -export function setUserProperty( - analytics: Analytics, - name: string, - value: string | null, -): Promise; - -/** - * Sets multiple key/value pairs of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - * - * > When you set user properties, be sure to never include personally identifiable information such as names, social security numbers, or email addresses, even in hashed form. - * - * @param analytics Analytics instance. - * @param properties Set a property value to null to remove it. - * @param options `AnalyticsCallOptions`. Additional options that can be passed. Web only. - */ -export function setUserProperties( - analytics: Analytics, - properties: { [key: string]: any }, - options?: AnalyticsCallOptions, -): Promise; - -/** - * Clears all analytics data for this instance from the device and resets the app instance ID. - * - * @param analytics Analytics instance. - */ -export function resetAnalyticsData(analytics: Analytics): Promise; - -/** - * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported - * automatically for Google Play-based apps. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `purchase` - * - * @param analytics Analytics instance. - * @param object See {@link analytics.AddPaymentInfoEventParameters}. - */ -export function logAddPaymentInfo( - analytics: Analytics, - object: FirebaseAnalyticsTypes.AddPaymentInfoEventParameters, -): Promise; - -/** - * Sets or clears the screen name and class the user is currently viewing - * - * @param analytics Analytics instance. - * @param params See {@link analytics.ScreenViewParameters}. - */ -export function logScreenView( - analytics: Analytics, - params: FirebaseAnalyticsTypes.ScreenViewParameters, -): Promise; - -/** - * Add Payment Info event. This event signifies that a user has submitted their payment information to your app. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `add_payment_info` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.AddShippingInfoParameters}. - */ -export function logAddShippingInfo( - analytics: Analytics, - params: FirebaseAnalyticsTypes.AddShippingInfoParameters, -): Promise; - -/** - * E-Commerce Add To Cart event. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `add_to_cart` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.AddToCartEventParameters}. - */ -export function logAddToCart( - analytics: Analytics, - params: FirebaseAnalyticsTypes.AddToCartEventParameters, -): Promise; - -/** - * E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. - * Use this event to identify popular gift items in your app. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `add_to_wishlist - * - * @param analytics Analytics instance. - * @param params See {@link analytics.AddToWishlistEventParameters}. - */ -export function logAddToWishlist( - analytics, - params: FirebaseAnalyticsTypes.AddToWishlistEventParameters, -): Promise; - -/** - * App Open event. By logging this event when an App is moved to the foreground, developers can - * understand how often users leave and return during the course of a Session. Although Sessions - * are automatically reported, this event can provide further clarification around the continuous - * engagement of app-users. - * - * @param analytics Analytics instance. - */ -export function logAppOpen(analytics: Analytics): Promise; - -/** - * E-Commerce Begin Checkout event. This event signifies that a user has begun the process of - * checking out. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `begin_checkout` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.BeginCheckoutEventParameters}. - */ -export function logBeginCheckout( - analytics: Analytics, - params: FirebaseAnalyticsTypes.BeginCheckoutEventParameters, -): Promise; - -/** - * Log this event to supply the referral details of a re-engagement campaign. - * - * Logged event name: `campaign_details` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.CampaignDetailsEventParameters}. - */ -export function logCampaignDetails( - analytics: Analytics, - params: FirebaseAnalyticsTypes.CampaignDetailsEventParameters, -): Promise; - -/** - * Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app. Log this along with - * {@link analytics.logSpendVirtualCurrency} to better understand your virtual economy. - * - * Logged event name: `earn_virtual_currency` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.EarnVirtualCurrencyEventParameters}. - */ -export function logEarnVirtualCurrency( - analytics: Analytics, - params: FirebaseAnalyticsTypes.EarnVirtualCurrencyEventParameters, -): Promise; - -/** - * Generate Lead event. Log this event when a lead has been generated in the app to understand - * the efficacy of your install and re-engagement campaigns. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `generate_lead` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.GenerateLeadEventParameters}. - */ -export function logGenerateLead( - analytics: Analytics, - params: FirebaseAnalyticsTypes.GenerateLeadEventParameters, -): Promise; - -/** - * Join Group event. Log this event when a user joins a group such as a guild, team or family. - * Use this event to analyze how popular certain groups or social features are in your app - * - * Logged event name: `join_group` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.JoinGroupEventParameters}. - */ -export function logJoinGroup( - analytics: Analytics, - params: FirebaseAnalyticsTypes.JoinGroupEventParameters, -): Promise; - -/** - * Level End event. - * - * Logged event name: `level_end` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.LevelEndEventParameters}. - */ -export function logLevelEnd( - analytics: Analytics, - params: FirebaseAnalyticsTypes.LevelEndEventParameters, -): Promise; - -/** - * Level Start event. - * - * Logged event name: `level_start` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.LevelStartEventParameters}. - */ -export function logLevelStart( - analytics: Analytics, - params: FirebaseAnalyticsTypes.LevelStartEventParameters, -): Promise; - -/** - * Level Up event. This event signifies that a player has leveled up in your gaming app. - * It can help you gauge the level distribution of your userbase and help you identify certain levels that are difficult to pass. - * - * Logged event name: `level_up` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.LevelUpEventParameters}. - */ -export function logLevelUp( - analytics: Analytics, - params: FirebaseAnalyticsTypes.LevelUpEventParameters, -): Promise; - -/** - * Login event. Apps with a login feature can report this event to signify that a user has logged in. - * - * Logged event name: `login` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.LoginEventParameters}. - */ -export function logLogin( - analytics: Analytics, - params: FirebaseAnalyticsTypes.LoginEventParameters, -): Promise; - -/** - * Post Score event. Log this event when the user posts a score in your gaming app. This event can - * help you understand how users are actually performing in your game and it can help you correlate - * high scores with certain audiences or behaviors. - * - * Logged event name: `post_score` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.PostScoreEventParameters}. - */ -export function logPostScore( - analytics: Analytics, - params: FirebaseAnalyticsTypes.PostScoreEventParameters, -): Promise; - -/** - * Select Content event. This general purpose event signifies that a user has selected some - * content of a certain type in an app. The content can be any object in your app. This event - * can help you identify popular content and categories of content in your app. - * - * Logged event name: `select_content` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.SelectContentEventParameters}. - */ -export function logSelectContent( - analytics: Analytics, - params: FirebaseAnalyticsTypes.SelectContentEventParameters, -): Promise; - -/** - * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported - * automatically for Google Play-based apps. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `purchase` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.PurchaseEventParameters}. - */ -export function logPurchase( - analytics: Analytics, - params: FirebaseAnalyticsTypes.PurchaseEventParameters, -): Promise; - -/** - * E-Commerce Refund event. This event signifies that a refund was issued. - * - * Logged event name: `remove_from_cart` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.RefundEventParameters}. - */ -export function logRefund( - analytics: Analytics, - params: FirebaseAnalyticsTypes.RefundEventParameters, -): Promise; - -/** - * Remove from cart event. - * - * Logged event name: `remove_from_cart` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.RemoveFromCartEventParameters}. - */ -export function logRemoveFromCart( - analytics: Analytics, - params: FirebaseAnalyticsTypes.RemoveFromCartEventParameters, -): Promise; - -/** - * Search event. Apps that support search features can use this event to contextualize search - * operations by supplying the appropriate, corresponding parameters. This event can help you - * identify the most popular content in your app. - * - * Logged event name: `search` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.SearchEventParameters}. - */ -export function logSearch( - analytics: Analytics, - params: FirebaseAnalyticsTypes.SearchEventParameters, -): Promise; - -/** - * Select Item event. This event signifies that an item was selected by a user from a list. - * Use the appropriate parameters to contextualize the event. - * Use this event to discover the most popular items selected. - * - * Logged event name: `select_item` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.SelectItemEventParameters}. - */ -export function logSelectItem( - analytics: Analytics, - params: FirebaseAnalyticsTypes.SelectItemEventParameters, -): Promise; - -/** - * Set checkout option event. - * - * Logged event name: `set_checkout_option` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.SetCheckoutOptionEventParameters}. - */ -export function logSetCheckoutOption( - analytics: Analytics, - params: FirebaseAnalyticsTypes.SetCheckoutOptionEventParameters, -): Promise; - -/** - * Select promotion event. This event signifies that a user has selected a promotion offer. Use the - * appropriate parameters to contextualize the event, such as the item(s) for which the promotion applies. - * - * Logged event name: `select_promotion` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.SelectPromotionEventParameters}. - */ -export function logSelectPromotion( - analytics: Analytics, - params: FirebaseAnalyticsTypes.SelectPromotionEventParameters, -): Promise; - -/** - * Share event. Apps with social features can log the Share event to identify the most viral content. - * - * Logged event name: `share` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.ShareEventParameters}. - */ -export function logShare( - analytics: Analytics, - params: FirebaseAnalyticsTypes.ShareEventParameters, -): Promise; - -/** - * Sign Up event. This event indicates that a user has signed up for an account in your app. - * The parameter signifies the method by which the user signed up. Use this event to understand - * the different behaviors between logged in and logged out users. - * - * Logged event name: `sign_up` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.SignUpEventParameters}. - */ -export function logSignUp( - analytics: Analytics, - params: FirebaseAnalyticsTypes.SignUpEventParameters, -): Promise; - -/** - * Spend Virtual Currency event. This event tracks the sale of virtual goods in your app and can - * help you identify which virtual goods are the most popular objects of purchase. - * - * Logged event name: `spend_virtual_currency` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.SpendVirtualCurrencyEventParameters}. - */ -export function logSpendVirtualCurrency( - analytics: Analytics, - params: FirebaseAnalyticsTypes.SpendVirtualCurrencyEventParameters, -): Promise; - -/** - * Tutorial Begin event. This event signifies the start of the on-boarding process in your app. - * Use this in a funnel with {@link analytics#logTutorialComplete} to understand how many users - * complete this process and move on to the full app experience. - * - * Logged event name: `tutorial_begin` - * - * @param analytics Analytics instance. - */ -export function logTutorialBegin(analytics: Analytics): Promise; - -/** - * Tutorial End event. Use this event to signify the user's completion of your app's on-boarding process. - * Add this to a funnel with {@link analytics#logTutorialBegin} to understand how many users - * complete this process and move on to the full app experience. - * - * Logged event name: `tutorial_complete` - * - * @param analytics Analytics instance. - */ -export function logTutorialComplete(analytics: Analytics): Promise; - -/** - * Unlock Achievement event. Log this event when the user has unlocked an achievement in your game. - * Since achievements generally represent the breadth of a gaming experience, this event can help - * you understand how many users are experiencing all that your game has to offer. - * - * Logged event name: `unlock_achievement` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.UnlockAchievementEventParameters}. - */ -export function logUnlockAchievement( - analytics: Analytics, - params: FirebaseAnalyticsTypes.UnlockAchievementEventParameters, -): Promise; - -/** - * E-commerce View Cart event. This event signifies that a user has viewed their cart. Use this to analyze your purchase funnel. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `view_cart` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.ViewCartEventParameters}. - */ -export function logViewCart( - analytics: Analytics, - params: FirebaseAnalyticsTypes.ViewCartEventParameters, -): Promise; - -/** - * View Item event. This event signifies that some content was shown to the user. This content - * may be a product, a screen or just a simple image or text. Use the appropriate parameters - * to contextualize the event. Use this event to discover the most popular items viewed in your app. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `view_item` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.ViewItemEventParameters}. - */ -export function logViewItem( - analytics: Analytics, - params: FirebaseAnalyticsTypes.ViewItemEventParameters, -): Promise; - -/** - * View Item List event. Log this event when the user has been presented with a list of items of a certain category. - * - * Logged event name: `view_item_list` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.ViewItemListEventParameters}. - */ -export function logViewItemList( - analytics: Analytics, - params: FirebaseAnalyticsTypes.ViewItemListEventParameters, -): Promise; - -/** - * View Promotion event. This event signifies that a promotion was shown to a user. - * - * Logged event name: `view_promotion` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.ViewPromotionEventParameters}. - */ -export function logViewPromotion( - analytics: Analytics, - params: FirebaseAnalyticsTypes.ViewPromotionEventParameters, -): Promise; - -/** - * View Search Results event. Log this event when the user has been presented with the results of a search. - * - * Logged event name: `view_search_results` - * - * @param analytics Analytics instance. - * @param params See {@link analytics.ViewSearchResultsParameters}. - */ -export function logViewSearchResults( - analytics: Analytics, - params: FirebaseAnalyticsTypes.ViewSearchResultsParameters, -): Promise; - -/** - * Adds parameters that will be set on every event logged from the SDK, including automatic ones. - * - * They will be added to the map of default event parameters, replacing any existing - * parameter with the same name. Valid parameter values are String, long, and double. - * Setting a key's value to null will clear that parameter. Passing in a null bundle - * will clear all parameters. - * For Web, the values passed persist on the current page and are passed with all - * subsequent events. - * - * @platform ios - * @param analytics Analytics instance. - * @param params Parameters to be added to the map of parameters added to every event. - */ -export function setDefaultEventParameters( - analytics: Analytics, - params: { [p: string]: any }, -): Promise; - -/** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * - * @platform ios - * @param analytics Analytics instance. - * @param emailAddress email address, properly formatted complete with domain name e.g, 'user@example.com' - */ -export function initiateOnDeviceConversionMeasurementWithEmailAddress( - analytics: Analytics, - emailAddress: string, -): Promise; - -/** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * You need to pass the sha256-hashed of normalized email address to this function. See [this link](https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials) for more information. - * - * @platform ios - * @param analytics Analytics instance. - * @param hashedEmailAddress sha256-hashed of normalized email address, properly formatted complete with domain name e.g, 'user@example.com' - */ -export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( - analytics: Analytics, - hashedEmailAddress: string, -): Promise; - -/** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * - * @platform ios - * @param analytics Analytics instance. - * @param phoneNumber phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - */ -export function initiateOnDeviceConversionMeasurementWithPhoneNumber( - analytics: Analytics, - phoneNumber: string, -): Promise; - -/** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * You need to pass the sha256-hashed of phone number in E.164 format. See [this link](https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials) for more information. - * - * @platform ios - * @param analytics Analytics instance. - * @param hashedPhoneNumber sha256-hashed of normalized phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - */ -export function initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( - analytics: Analytics, - hashedPhoneNumber: string, -): Promise; - -/** - * Checks four different things. - * 1. Checks if it's not a browser extension environment. - * 2. Checks if cookies are enabled in current browser. - * 3. Checks if IndexedDB is supported by the browser environment. - * 4. Checks if the current browser context is valid for using IndexedDB.open(). - * - * @returns {Promise} - */ -export function isSupported(): Promise; - -/** - * Sets the applicable end user consent state for this app. - * references once Firebase Analytics is initialized. - * @param analytics Analytics instance. - * @param consentSettings See {@link analytics.ConsentSettings}. - * @returns {Promise} - */ -export function setConsent( - analytics: Analytics, - consentSettings: FirebaseAnalyticsTypes.ConsentSettings, -): Promise; - -/** - * Configures Firebase Analytics to use custom gtag or dataLayer names. - * Intended to be used if gtag.js script has been installed on this page - * independently of Firebase Analytics, and is using non-default names for - * either the gtag function or for dataLayer. Must be called before calling - * `getAnalytics()` or it won't have any effect. Web only. - * @param options See {@link analytics.SettingsOptions}. - * @returns {void} - */ -export function settings(options: FirebaseAnalyticsTypes.SettingsOptions): void; - -/** - * Retrieves the session id from the client. - * On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details. - * - * Returns the session id or null if session is expired, null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. - * @param {Analytics} instance. - * @returns {Promise} - */ -export function getSessionId(analytics: Analytics): Promise; diff --git a/packages/analytics/lib/modular/index.js b/packages/analytics/lib/modular/index.js deleted file mode 100644 index 90e0138551..0000000000 --- a/packages/analytics/lib/modular/index.js +++ /dev/null @@ -1,673 +0,0 @@ -import { MODULAR_DEPRECATION_ARG } from '../../../app/lib/common'; -import { getApp } from '@react-native-firebase/app'; -import { Platform } from 'react-native'; - -/** - * @typedef {import('@firebase/app').FirebaseApp} FirebaseApp - * @typedef {import("..").FirebaseAnalyticsTypes.Module} FirebaseAnalytics - * @typedef {import("..").FirebaseAnalyticsTypes.AnalyticsCallOptions} AnalyticsCallOptions - * @typedef {import("..").FirebaseAnalyticsTypes.EventParams} EventParams - * @typedef {import("..").FirebaseAnalyticsTypes.AddPaymentInfoEventParameters} AddPaymentInfoEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ScreenViewParameters} ScreenViewParameters - * @typedef {import("..").FirebaseAnalyticsTypes.AddShippingInfoParameters} AddShippingInfoParameters - * @typedef {import("..").FirebaseAnalyticsTypes.AddToCartEventParameters} AddToCartEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.AddToWishlistEventParameters} AddToWishlistEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.BeginCheckoutEventParameters} BeginCheckoutEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.CampaignDetailsEventParameters} CampaignDetailsEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.EarnVirtualCurrencyEventParameters} EarnVirtualCurrencyEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.GenerateLeadEventParameters} GenerateLeadEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.JoinGroupEventParameters} JoinGroupEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.LevelEndEventParameters} LevelEndEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.LevelStartEventParameters} LevelStartEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.LevelUpEventParameters} LevelUpEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.LoginEventParameters} LoginEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.PostScoreEventParameters} PostScoreEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.SelectContentEventParameters} SelectContentEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.PurchaseEventParameters} PurchaseEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.RefundEventParameters} RefundEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.RemoveFromCartEventParameters} RemoveFromCartEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.SearchEventParameters} SearchEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.SelectItemEventParameters} SelectItemEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.SetCheckoutOptionEventParameters} SetCheckoutOptionEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.SelectPromotionEventParameters} SelectPromotionEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ShareEventParameters} ShareEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.SignUpEventParameters} SignUpEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.SpendVirtualCurrencyEventParameters} SpendVirtualCurrencyEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.UnlockAchievementEventParameters} UnlockAchievementEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ViewCartEventParameters} ViewCartEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ViewItemEventParameters} ViewItemEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ViewItemListEventParameters} ViewItemListEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ViewPromotionEventParameters} ViewPromotionEventParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ViewSearchResultsParameters} ViewSearchResultsParameters - * @typedef {import("..").FirebaseAnalyticsTypes.ConsentSettings} ConsentSettings - * @typedef {import("..").FirebaseAnalyticsTypes.SettingsOptions} SettingsOptions - */ - -/** - * Returns an Analytics instance for the given app. - * @param {FirebaseApp} [app] - FirebaseApp. Optional. - * @returns {FirebaseAnalytics} - */ -export function getAnalytics(app) { - if (app) { - return getApp(app.name).analytics(); - } - return getApp().analytics(); -} - -/** - * Returns an Analytics instance for the given app. - * @param {FirebaseApp} app - FirebaseApp. - * @param {object} [options] - AnalyticsSettings. Web only. - * @returns {FirebaseAnalytics} - */ -// eslint-disable-next-line -export function initializeAnalytics(app, options) { - return getApp(app.name).analytics(); -} - -/** - * Retrieves a unique Google Analytics identifier for the web client. - * - * @param {FirebaseAnalytics} analytics - Instance of analytics (web - only) - * @returns {Promise} - */ -export async function getGoogleAnalyticsClientId(analytics) { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - throw new Error('getGoogleAnalyticsClientId is web-only.'); - } else { - return getAppInstanceId(analytics); - } -} - -/** - * Log a custom event with optional params. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {string} name - Event name must not conflict with any Reserved Events. - * @param {object} [params={}] - Parameters to be sent and displayed with the event. - * @param {AnalyticsCallOptions} [options={}] - Additional options that can be passed. Web only. - * @returns {Promise} - */ -export function logEvent(analytics, name, params = {}, options = {}) { - return analytics.logEvent.call(analytics, name, params, options, MODULAR_DEPRECATION_ARG); -} - -/** - * If true, allows the device to collect analytical data and send it to Firebase. Useful for GDPR. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {boolean} enabled - A boolean value representing whether Analytics collection is enabled or disabled. - * @returns {Promise} - */ -export function setAnalyticsCollectionEnabled(analytics, enabled) { - return analytics.setAnalyticsCollectionEnabled.call(analytics, enabled, MODULAR_DEPRECATION_ARG); -} - -/** - * Sets the duration of inactivity that terminates the current session. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {number} [milliseconds=1800000] - The default value is 1800000 (30 minutes). - * @returns {Promise} - */ -export function setSessionTimeoutDuration(analytics, milliseconds = 1800000) { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - return analytics.setSessionTimeoutDuration.call(analytics, milliseconds, MODULAR_DEPRECATION_ARG); -} - -/** - * Retrieve the app instance id of the application. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} Returns the app instance id or null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. - */ -export function getAppInstanceId(analytics) { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - return analytics.getAppInstanceId.call(analytics, MODULAR_DEPRECATION_ARG); -} - -/** - * Retrieves the session id from the client. - * On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} Returns the session id or null if session is expired, null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. - */ -export function getSessionId(analytics) { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - return analytics.getSessionId.call(analytics, MODULAR_DEPRECATION_ARG); -} - -/** - * Gives a user a unique identification. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {string|null} id - Set to null to remove a previously assigned ID from analytics events. - * @returns {Promise} - */ -export function setUserId(analytics, id) { - return analytics.setUserId.call(analytics, id, MODULAR_DEPRECATION_ARG); -} - -/** - * Sets a key/value pair of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {string} name - A user property identifier. - * @param {string|null} value - Set to null to remove a previously assigned ID from analytics events. - * @returns {Promise} - */ -export function setUserProperty(analytics, name, value) { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - return analytics.setUserProperty.call(analytics, name, value, MODULAR_DEPRECATION_ARG); -} - -/** - * Sets multiple key/value pairs of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {object} properties - Set a property value to null to remove it. - * @param {AnalyticsCallOptions} [options={}] - Additional options that can be passed. Web only. - * @returns {Promise} - */ -export function setUserProperties(analytics, properties, options = {}) { - return analytics.setUserProperties.call(analytics, properties, options, MODULAR_DEPRECATION_ARG); -} - -/** - * Clears all analytics data for this instance from the device and resets the app instance ID. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} - */ -export function resetAnalyticsData(analytics) { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - return analytics.resetAnalyticsData.call(analytics, MODULAR_DEPRECATION_ARG); -} - -/** - * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported automatically for Google Play-based apps. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {AddPaymentInfoEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logAddPaymentInfo(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logAddPaymentInfo(params); -} - -/** - * Sets or clears the screen name and class the user is currently viewing. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ScreenViewParameters} params - Event parameters. - * @returns {Promise} - */ -export function logScreenView(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logScreenView(params); -} - -/** - * Add Payment Info event. This event signifies that a user has submitted their payment information to your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {AddShippingInfoParameters} params - Event parameters. - * @returns {Promise} - */ -export function logAddShippingInfo(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logAddShippingInfo(params); -} - -/** - * E-Commerce Add To Cart event. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {AddToCartEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logAddToCart(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logAddToCart(params); -} - -/** - * E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {AddToWishlistEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logAddToWishlist(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logAddToWishlist(params); -} - -/** - * App Open event. By logging this event when an App is moved to the foreground, developers can understand how often users leave and return during the course of a Session. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} - */ -export function logAppOpen(analytics) { - // This is deprecated for both namespaced and modular. - return analytics.logAppOpen(); -} - -/** - * E-Commerce Begin Checkout event. This event signifies that a user has begun the process of checking out. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {BeginCheckoutEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logBeginCheckout(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logBeginCheckout(params); -} - -/** - * Log this event to supply the referral details of a re-engagement campaign. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {CampaignDetailsEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logCampaignDetails(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logCampaignDetails(params); -} - -/** - * Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {EarnVirtualCurrencyEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logEarnVirtualCurrency(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logEarnVirtualCurrency(params); -} - -/** - * Generate Lead event. Log this event when a lead has been generated in the app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {GenerateLeadEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logGenerateLead(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logGenerateLead(params); -} - -/** - * Join Group event. Log this event when a user joins a group such as a guild, team or family. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {JoinGroupEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logJoinGroup(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logJoinGroup(params); -} - -/** - * Level End event. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {LevelEndEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logLevelEnd(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logLevelEnd(params); -} - -/** - * Level Start event. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {LevelStartEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logLevelStart(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logLevelStart(params); -} - -/** - * Level Up event. This event signifies that a player has leveled up in your gaming app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {LevelUpEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logLevelUp(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logLevelUp(params); -} - -/** - * Login event. Apps with a login feature can report this event to signify that a user has logged in. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {LoginEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logLogin(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logLogin(params); -} - -/** - * Post Score event. Log this event when the user posts a score in your gaming app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {PostScoreEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logPostScore(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logPostScore(params); -} - -/** - * Select Content event. This general purpose event signifies that a user has selected some content of a certain type in an app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SelectContentEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSelectContent(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logSelectContent(params); -} - -/** - * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {PurchaseEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logPurchase(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logPurchase(params); -} - -/** - * E-Commerce Refund event. This event signifies that a refund was issued. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {RefundEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logRefund(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logRefund(params); -} - -/** - * Remove from cart event. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {RemoveFromCartEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logRemoveFromCart(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logRemoveFromCart(params); -} - -/** - * Search event. Apps that support search features can use this event to contextualize search operations by supplying the appropriate, corresponding parameters. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SearchEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSearch(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logSearch(params); -} - -/** - * Select Item event. This event signifies that an item was selected by a user from a list. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SelectItemEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSelectItem(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logSelectItem(params); -} - -/** - * Set checkout option event. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SetCheckoutOptionEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSetCheckoutOption(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logSetCheckoutOption(params); -} - -/** - * Select promotion event. This event signifies that a user has selected a promotion offer. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SelectPromotionEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSelectPromotion(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logSelectPromotion(params); -} - -/** - * Share event. Apps with social features can log the Share event to identify the most viral content. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ShareEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logShare(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logShare(params); -} - -/** - * Sign Up event. This event indicates that a user has signed up for an account in your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SignUpEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSignUp(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logSignUp(params); -} - -/** - * Spend Virtual Currency event. This event tracks the sale of virtual goods in your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SpendVirtualCurrencyEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSpendVirtualCurrency(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logSpendVirtualCurrency(params); -} - -/** - * Tutorial Begin event. This event signifies the start of the on-boarding process in your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} - */ -export function logTutorialBegin(analytics) { - // This is deprecated for both namespaced and modular. - return analytics.logTutorialBegin(); -} - -/** - * Tutorial End event. Use this event to signify the user's completion of your app's on-boarding process. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} - */ -export function logTutorialComplete(analytics) { - // This is deprecated for both namespaced and modular. - return analytics.logTutorialComplete(); -} - -/** - * Unlock Achievement event. Log this event when the user has unlocked an achievement in your game. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {UnlockAchievementEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logUnlockAchievement(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logUnlockAchievement(params); -} - -/** - * E-commerce View Cart event. This event signifies that a user has viewed their cart. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewCartEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewCart(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logViewCart(params); -} - -/** - * View Item event. This event signifies that some content was shown to the user. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewItemEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewItem(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logViewItem(params); -} - -/** - * View Item List event. Log this event when the user has been presented with a list of items of a certain category. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewItemListEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewItemList(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logViewItemList(params); -} - -/** - * View Promotion event. This event signifies that a promotion was shown to a user. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewPromotionEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewPromotion(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logViewPromotion(params); -} - -/** - * View Search Results event. Log this event when the user has been presented with the results of a search. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewSearchResultsParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewSearchResults(analytics, params) { - // This is deprecated for both namespaced and modular. - return analytics.logViewSearchResults(params); -} - -/** - * Adds parameters that will be set on every event logged from the SDK, including automatic ones. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {object} [params={}] - Parameters to be added to the map of parameters added to every event. - * @returns {Promise} - */ -export function setDefaultEventParameters(analytics, params = {}) { - return analytics.setDefaultEventParameters.call(analytics, params, MODULAR_DEPRECATION_ARG); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {string} emailAddress - Email address, properly formatted complete with domain name e.g, 'user@example.com'. - * @returns {Promise} - */ -export function initiateOnDeviceConversionMeasurementWithEmailAddress(analytics, emailAddress) { - return analytics.initiateOnDeviceConversionMeasurementWithEmailAddress.call( - analytics, - emailAddress, - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile - * - * @param analytics Analytics instance. - * @param hashedEmailAddress sha256-hashed of normalized email address, properly formatted complete with domain name e.g, 'user@example.com' - * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials - */ -export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( - analytics, - hashedEmailAddress, -) { - return analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress.call( - analytics, - hashedEmailAddress, - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {string} phoneNumber - Phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - * @returns {Promise} - */ -export function initiateOnDeviceConversionMeasurementWithPhoneNumber(analytics, phoneNumber) { - return analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber.call( - analytics, - phoneNumber, - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile - * - * @param analytics Analytics instance. - * @param hashedPhoneNumber sha256-hashed of normalized phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials - */ -export function initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( - analytics, - hashedPhoneNumber, -) { - return analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber.call( - analytics, - hashedPhoneNumber, - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * Checks four different things. - * 1. Checks if it's not a browser extension environment. - * 2. Checks if cookies are enabled in current browser. - * 3. Checks if IndexedDB is supported by the browser environment. - * 4. Checks if the current browser context is valid for using IndexedDB.open(). - * @returns {Promise} - */ -export function isSupported() { - return Promise.resolve(true); -} - -/** - * Sets the applicable end user consent state for this app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ConsentSettings} consentSettings - See ConsentSettings. - * @returns {Promise} - */ -export function setConsent(analytics, consentSettings) { - return analytics.setConsent.call(analytics, consentSettings, MODULAR_DEPRECATION_ARG); -} - -/** - * Configures Firebase Analytics to use custom gtag or dataLayer names. - * Intended to be used if gtag.js script has been installed on this page independently of Firebase Analytics, and is using non-default names for either the gtag function or for dataLayer. Must be called before calling `getAnalytics()` or it won't have any effect. Web only. - * @param {SettingsOptions} options - See SettingsOptions. - * @returns {void} - */ -// eslint-disable-next-line -export function settings(options) { - // Returns nothing until Web implemented. -} From 5a58a79a8efdefd2370da419bb864cd1566e6489 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 11:10:04 +0100 Subject: [PATCH 04/49] chore: RN bob builder setup + package.json updates --- packages/analytics/package.json | 59 +++++++++++++++++++++++++++++--- packages/analytics/tsconfig.json | 27 +++++++++++++++ 2 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 packages/analytics/tsconfig.json diff --git a/packages/analytics/package.json b/packages/analytics/package.json index 04b4b9b71b..5a218a7295 100644 --- a/packages/analytics/package.json +++ b/packages/analytics/package.json @@ -3,12 +3,14 @@ "version": "23.0.0", "author": "Invertase (http://invertase.io)", "description": "React Native Firebase - The analytics module provides out of the box support with Google Analytics for Firebase. Integration with the Android & iOS allows for in-depth analytical insight reporting, such as device information, location, user actions and more.", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "./dist/commonjs/index.js", + "module": "./dist/module/index.js", + "types": "./dist/typescript/commonjs/lib/index.d.ts", "scripts": { - "build": "genversion --semi lib/version.js", + "build": "genversion --esm --semi lib/version.ts", "build:clean": "rimraf android/build && rimraf ios/build", - "prepare": "yarn run build" + "compile": "bob build", + "prepare": "yarn run build && yarn compile" }, "repository": { "type": "git", @@ -30,5 +32,52 @@ }, "dependencies": { "superstruct": "^2.0.2" - } + }, + "devDependencies": { + "react-native-builder-bob": "^0.40.13" + }, + "exports": { + ".": { + "source": "./lib/index.js", + "import": { + "types": "./dist/typescript/module/lib/index.d.ts", + "default": "./dist/module/index.js" + }, + "require": { + "types": "./dist/typescript/commonjs/lib/index.d.ts", + "default": "./dist/commonjs/index.js" + } + }, + "./package.json": "./package.json" + }, + "files": [ + "lib", + "dist", + "!**/__tests__", + "!**/__fixtures__", + "!**/__mocks__" + ], + "react-native-builder-bob": { + "source": "lib", + "output": "dist", + "targets": [ + [ + "module", + { + "esm": true + } + ], + [ + "commonjs", + { + "esm": true + } + ], + "typescript" + ] + }, + "eslintIgnore": [ + "node_modules/", + "dist/" + ] } diff --git a/packages/analytics/tsconfig.json b/packages/analytics/tsconfig.json new file mode 100644 index 0000000000..b89df98d6a --- /dev/null +++ b/packages/analytics/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "rootDir": ".", + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react-jsx", + "lib": [ + "ESNext" + ], + "module": "ESNext", + "moduleResolution": "bundler", + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noImplicitUseStrict": false, + "noStrictGenericChecks": false, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "ESNext", + "verbatimModuleSyntax": true + } +} From c081c7a54a1408c54a62ead65d2ff087eb39d1d9 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 11:10:46 +0100 Subject: [PATCH 05/49] tsconfig.json update to find app package --- packages/analytics/tsconfig.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/analytics/tsconfig.json b/packages/analytics/tsconfig.json index b89df98d6a..84dca50702 100644 --- a/packages/analytics/tsconfig.json +++ b/packages/analytics/tsconfig.json @@ -22,6 +22,10 @@ "skipLibCheck": true, "strict": true, "target": "ESNext", - "verbatimModuleSyntax": true + "verbatimModuleSyntax": true, + "baseUrl": ".", + "paths": { + "@react-native-firebase/app": ["../app/lib"] + } } } From d0a837cea3c27cfaa8ef1f487e6ae5ff843604af Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 12:07:03 +0100 Subject: [PATCH 06/49] chore(app): validate.d.ts --- packages/app/lib/common/validate.d.ts | 110 ++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 packages/app/lib/common/validate.d.ts diff --git a/packages/app/lib/common/validate.d.ts b/packages/app/lib/common/validate.d.ts new file mode 100644 index 0000000000..1d1131c48a --- /dev/null +++ b/packages/app/lib/common/validate.d.ts @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * Validates that all key-value pairs in an object are strings. + */ +export function objectKeyValuesAreStrings(object: any): boolean; + +/** + * Simple is null check. + */ +export function isNull(value: any): value is null; + +/** + * Simple is object check. + */ +export function isObject(value: any): value is Record; + +/** + * Simple is date check + */ +export function isDate(value: any): value is Date; + +/** + * Simple is function check + */ +export function isFunction(value: any): value is (...args: any[]) => any; + +/** + * Simple is string check + */ +export function isString(value: any): value is string; + +/** + * Simple is number check + */ +export function isNumber(value: any): value is number; + +/** + * Simple is phone number check for E.164 format + */ +export function isE164PhoneNumber(value: any): boolean; + +/** + * Simple finite check + */ +export function isFinite(value: any): boolean; + +/** + * Simple integer check + */ +export function isInteger(value: any): boolean; + +/** + * Simple is boolean check + */ +export function isBoolean(value: any): value is boolean; + +/** + * Array check + */ +export function isArray(value: any): value is Array; + +/** + * Undefined check + */ +export function isUndefined(value: any): value is undefined; + +/** + * Alphanumeric underscore pattern check (/^[a-zA-Z0-9_]+$/) + */ +export function isAlphaNumericUnderscore(value: any): boolean; + +/** + * URL validation test + */ +export function isValidUrl(url: any): boolean; + +/** + * Array includes check + */ +export function isOneOf(value: any, oneOf?: any[]): boolean; + +/** + * No-operation function + */ +export function noop(): void; + +/** + * Validates that an optional native dependency exists + */ +export function validateOptionalNativeDependencyExists( + firebaseJsonKey: string, + apiName: string, + nativeFnExists: boolean, +): void; From 068b59f081a40439c6dae962597844b6279da2c3 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 13:33:12 +0100 Subject: [PATCH 07/49] refactor: convert codebase to TypeScript --- packages/analytics/index.d.ts | 1 + packages/analytics/lib/index.js | 823 ------------------ packages/analytics/lib/namespaced.ts | 12 +- .../analytics/lib/{struct.js => struct.ts} | 27 +- .../analytics/lib/{structs.js => structs.ts} | 0 ...roid.js => RNFBAnalyticsModule.android.ts} | 0 ...dule.ios.js => RNFBAnalyticsModule.ios.ts} | 0 ...lyticsModule.js => RNFBAnalyticsModule.ts} | 50 +- packages/analytics/lib/web/api.d.ts | 32 + packages/analytics/lib/web/{api.js => api.ts} | 102 ++- packages/analytics/tsconfig.json | 1 + packages/analytics/types/index.d.ts | 68 ++ packages/analytics/types/index.ts | 58 ++ packages/app/lib/index.d.ts | 15 + packages/app/lib/internal.d.ts | 49 ++ .../app/lib/internal/web/firebaseApp.d.ts | 21 + packages/app/lib/internal/web/utils.d.ts | 22 + 17 files changed, 396 insertions(+), 885 deletions(-) create mode 100644 packages/analytics/index.d.ts delete mode 100644 packages/analytics/lib/index.js rename packages/analytics/lib/{struct.js => struct.ts} (61%) rename packages/analytics/lib/{structs.js => structs.ts} (100%) rename packages/analytics/lib/web/{RNFBAnalyticsModule.android.js => RNFBAnalyticsModule.android.ts} (100%) rename packages/analytics/lib/web/{RNFBAnalyticsModule.ios.js => RNFBAnalyticsModule.ios.ts} (100%) rename packages/analytics/lib/web/{RNFBAnalyticsModule.js => RNFBAnalyticsModule.ts} (63%) create mode 100644 packages/analytics/lib/web/api.d.ts rename packages/analytics/lib/web/{api.js => api.ts} (78%) create mode 100644 packages/analytics/types/index.d.ts create mode 100644 packages/analytics/types/index.ts create mode 100644 packages/app/lib/internal.d.ts create mode 100644 packages/app/lib/internal/web/firebaseApp.d.ts create mode 100644 packages/app/lib/internal/web/utils.d.ts diff --git a/packages/analytics/index.d.ts b/packages/analytics/index.d.ts new file mode 100644 index 0000000000..11aece60c4 --- /dev/null +++ b/packages/analytics/index.d.ts @@ -0,0 +1 @@ +export * from './lib/index'; diff --git a/packages/analytics/lib/index.js b/packages/analytics/lib/index.js deleted file mode 100644 index 581af582f3..0000000000 --- a/packages/analytics/lib/index.js +++ /dev/null @@ -1,823 +0,0 @@ -/* - * Copyright (c) 2016-present Invertase Limited & Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this library except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -import { - isAlphaNumericUnderscore, - isE164PhoneNumber, - isIOS, - isNull, - isNumber, - isObject, - isOneOf, - isString, - isUndefined, -} from '@react-native-firebase/app/lib/common'; - -import { - createModuleNamespace, - FirebaseModule, - getFirebaseRoot, -} from '@react-native-firebase/app/lib/internal'; -import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule'; -import { isBoolean } from '@react-native-firebase/app/lib/common'; - -import { validateStruct, validateCompound } from './struct'; -import fallBackModule from './web/RNFBAnalyticsModule'; -import version from './version'; -import * as structs from './structs'; - -const ReservedEventNames = [ - 'ad_activeview', - 'ad_click', - 'ad_exposure', - // 'ad_impression', // manual ad_impression logging is allowed, See #6307 - 'ad_query', - 'ad_reward', - 'adunit_exposure', - 'app_background', - 'app_clear_data', - // 'app_exception', - 'app_remove', - 'app_store_refund', - 'app_store_subscription_cancel', - 'app_store_subscription_convert', - 'app_store_subscription_renew', - 'app_update', - 'app_upgrade', - 'dynamic_link_app_open', - 'dynamic_link_app_update', - 'dynamic_link_first_open', - 'error', - 'first_open', - 'first_visit', - 'in_app_purchase', - 'notification_dismiss', - 'notification_foreground', - 'notification_open', - 'notification_receive', - 'os_update', - 'session_start', - 'session_start_with_rollout', - 'user_engagement', -]; - -const statics = {}; - -const namespace = 'analytics'; - -const nativeModuleName = 'RNFBAnalyticsModule'; - -class FirebaseAnalyticsModule extends FirebaseModule { - logEvent(name, params = {}, options = {}) { - if (!isString(name)) { - throw new Error("firebase.analytics().logEvent(*) 'name' expected a string value."); - } - - if (!isUndefined(params) && !isObject(params)) { - throw new Error("firebase.analytics().logEvent(_, *) 'params' expected an object value."); - } - - // check name is not a reserved event name - if (isOneOf(name, ReservedEventNames)) { - throw new Error( - `firebase.analytics().logEvent(*) 'name' the event name '${name}' is reserved and can not be used.`, - ); - } - - // name format validation - if (!isAlphaNumericUnderscore(name) || name.length > 40) { - throw new Error( - `firebase.analytics().logEvent(*) 'name' invalid event name '${name}'. Names should contain 1 to 40 alphanumeric characters or underscores.`, - ); - } - - if (!isUndefined(options)) { - if (!isObject(options)) { - throw new Error( - "firebase.analytics().logEvent(_, _, *) 'options' expected an object value.", - ); - } - - if (!isUndefined(options.global) && !isBoolean(options.global)) { - throw new Error("'options.global' property expected a boolean."); - } - } - - return this.native.logEvent(name, params); - } - - setAnalyticsCollectionEnabled(enabled) { - if (!isBoolean(enabled)) { - throw new Error( - "firebase.analytics().setAnalyticsCollectionEnabled(*) 'enabled' expected a boolean value.", - ); - } - - return this.native.setAnalyticsCollectionEnabled(enabled); - } - - setSessionTimeoutDuration(milliseconds = 1800000) { - if (!isNumber(milliseconds)) { - throw new Error( - "firebase.analytics().setSessionTimeoutDuration(*) 'milliseconds' expected a number value.", - ); - } - - if (milliseconds < 0) { - throw new Error( - "firebase.analytics().setSessionTimeoutDuration(*) 'milliseconds' expected a positive number value.", - ); - } - - return this.native.setSessionTimeoutDuration(milliseconds); - } - - getAppInstanceId() { - return this.native.getAppInstanceId(); - } - - getSessionId() { - return this.native.getSessionId(); - } - - setUserId(id) { - if (!isNull(id) && !isString(id)) { - throw new Error("firebase.analytics().setUserId(*) 'id' expected a string value."); - } - - return this.native.setUserId(id); - } - - setUserProperty(name, value) { - if (!isString(name)) { - throw new Error("firebase.analytics().setUserProperty(*) 'name' expected a string value."); - } - - if (value !== null && !isString(value)) { - throw new Error( - "firebase.analytics().setUserProperty(_, *) 'value' expected a string value.", - ); - } - - return this.native.setUserProperty(name, value); - } - - setUserProperties(properties, options = {}) { - if (!isObject(properties)) { - throw new Error( - "firebase.analytics().setUserProperties(*) 'properties' expected an object of key/value pairs.", - ); - } - - if (!isUndefined(options)) { - if (!isObject(options)) { - throw new Error( - "firebase.analytics().logEvent(_, _, *) 'options' expected an object value.", - ); - } - - if (!isUndefined(options.global) && !isBoolean(options.global)) { - throw new Error("'options.global' property expected a boolean."); - } - } - - const entries = Object.entries(properties); - for (let i = 0; i < entries.length; i++) { - const [key, value] = entries[i]; - if (!isNull(value) && !isString(value)) { - throw new Error( - `firebase.analytics().setUserProperties(*) 'properties' value for parameter '${key}' is invalid, expected a string.`, - ); - } - } - - return this.native.setUserProperties(properties); - } - - resetAnalyticsData() { - return this.native.resetAnalyticsData(); - } - - setConsent(consentSettings) { - if (!isObject(consentSettings)) { - throw new Error( - 'firebase.analytics().setConsent(*): The supplied arg must be an object of key/values.', - ); - } - - const entries = Object.entries(consentSettings); - for (let i = 0; i < entries.length; i++) { - const [key, value] = entries[i]; - if (!isBoolean(value)) { - throw new Error( - `firebase.analytics().setConsent(*) 'consentSettings' value for parameter '${key}' is invalid, expected a boolean.`, - ); - } - } - - return this.native.setConsent(consentSettings); - } - - /** ------------------- - * EVENTS - * -------------------- */ - logAddPaymentInfo(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logAddPaymentInfo(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddPaymentInfo(*):'); - - return this.logEvent( - 'add_payment_info', - validateStruct(object, structs.AddPaymentInfo, 'firebase.analytics().logAddPaymentInfo(*):'), - ); - } - - logScreenView(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logScreenView(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'screen_view', - validateStruct(object, structs.ScreenView, 'firebase.analytics().logScreenView(*):'), - ); - } - - logAddShippingInfo(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logAddShippingInfo(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddShippingInfo(*):'); - - return this.logEvent( - 'add_shipping_info', - validateStruct( - object, - structs.AddShippingInfo, - 'firebase.analytics().logAddShippingInfo(*):', - ), - ); - } - - logAddToCart(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logAddToCart(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddToCart(*):'); - - return this.logEvent( - 'add_to_cart', - validateStruct(object, structs.AddToCart, 'firebase.analytics().logAddToCart(*):'), - ); - } - - logAddToWishlist(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logAddToWishlist(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddToWishlist(*):'); - - return this.logEvent( - 'add_to_wishlist', - validateStruct(object, structs.AddToWishlist, 'firebase.analytics().logAddToWishlist(*):'), - ); - } - - logAppOpen() { - return this.logEvent('app_open'); - } - - logBeginCheckout(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logBeginCheckout(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logBeginCheckout(*):'); - - return this.logEvent( - 'begin_checkout', - validateStruct(object, structs.BeginCheckout, 'firebase.analytics().logBeginCheckout(*):'), - ); - } - - logCampaignDetails(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logCampaignDetails(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'campaign_details', - validateStruct( - object, - structs.CampaignDetails, - 'firebase.analytics().logCampaignDetails(*):', - ), - ); - } - - logEarnVirtualCurrency(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logEarnVirtualCurrency(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'earn_virtual_currency', - validateStruct( - object, - structs.EarnVirtualCurrency, - 'firebase.analytics().logEarnVirtualCurrency(*):', - ), - ); - } - - logGenerateLead(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logGenerateLead(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logGenerateLead(*):'); - - return this.logEvent( - 'generate_lead', - validateStruct(object, structs.GenerateLead, 'firebase.analytics().logGenerateLead(*):'), - ); - } - - logJoinGroup(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logJoinGroup(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'join_group', - validateStruct(object, structs.JoinGroup, 'firebase.analytics().logJoinGroup(*):'), - ); - } - - logLevelEnd(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logLevelEnd(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'level_end', - validateStruct(object, structs.LevelEnd, 'firebase.analytics().logLevelEnd(*):'), - ); - } - - logLevelStart(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logLevelStart(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'level_start', - validateStruct(object, structs.LevelStart, 'firebase.analytics().logLevelStart(*):'), - ); - } - - logLevelUp(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logLevelUp(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'level_up', - validateStruct(object, structs.LevelUp, 'firebase.analytics().logLevelUp(*):'), - ); - } - - logLogin(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logLogin(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'login', - validateStruct(object, structs.Login, 'firebase.analytics().logLogin(*):'), - ); - } - - logPostScore(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logPostScore(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'post_score', - validateStruct(object, structs.PostScore, 'firebase.analytics().logPostScore(*):'), - ); - } - - logSelectContent(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logSelectContent(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'select_content', - validateStruct(object, structs.SelectContent, 'firebase.analytics().logSelectContent(*):'), - ); - } - - logPurchase(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logPurchase(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logPurchase(*):'); - - return this.logEvent( - 'purchase', - validateStruct(object, structs.Purchase, 'firebase.analytics().logPurchaseEvent(*):'), - ); - } - - logRefund(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logRefund(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logRefund(*):'); - - return this.logEvent( - 'refund', - validateStruct(object, structs.Refund, 'firebase.analytics().logRefund(*):'), - ); - } - - logRemoveFromCart(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logRemoveFromCart(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logRemoveFromCart(*):'); - - return this.logEvent( - 'remove_from_cart', - validateStruct(object, structs.RemoveFromCart, 'firebase.analytics().logRemoveFromCart(*):'), - ); - } - - logSearch(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logSearch(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'search', - validateStruct(object, structs.Search, 'firebase.analytics().logSearch(*):'), - ); - } - - logSelectItem(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logSelectItem(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'select_item', - validateStruct(object, structs.SelectItem, 'firebase.analytics().logSelectItem(*):'), - ); - } - - logSetCheckoutOption(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logSetCheckoutOption(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'set_checkout_option', - validateStruct( - object, - structs.SetCheckoutOption, - 'firebase.analytics().logSetCheckoutOption(*):', - ), - ); - } - - logSelectPromotion(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logSelectPromotion(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'select_promotion', - validateStruct( - object, - structs.SelectPromotion, - 'firebase.analytics().logSelectPromotion(*):', - ), - ); - } - - logShare(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logShare(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'share', - validateStruct(object, structs.Share, 'firebase.analytics().logShare(*):'), - ); - } - - logSignUp(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logSignUp(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'sign_up', - validateStruct(object, structs.SignUp, 'firebase.analytics().logSignUp(*):'), - ); - } - - logSpendVirtualCurrency(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logSpendVirtualCurrency(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'spend_virtual_currency', - validateStruct( - object, - structs.SpendVirtualCurrency, - 'firebase.analytics().logSpendVirtualCurrency(*):', - ), - ); - } - - logTutorialBegin() { - return this.logEvent('tutorial_begin'); - } - - logTutorialComplete() { - return this.logEvent('tutorial_complete'); - } - - logUnlockAchievement(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logUnlockAchievement(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'unlock_achievement', - validateStruct( - object, - structs.UnlockAchievement, - 'firebase.analytics().logUnlockAchievement(*):', - ), - ); - } - - logViewCart(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logViewCart(*): The supplied arg must be an object of key/values.', - ); - } - - validateCompound(object, 'value', 'currency', 'firebase.analytics().logViewCart(*):'); - - return this.logEvent( - 'view_cart', - validateStruct(object, structs.ViewCart, 'firebase.analytics().logViewCart(*):'), - ); - } - - logViewItem(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logViewItem(*): The supplied arg must be an object of key/values.', - ); - } - validateCompound(object, 'value', 'currency', 'firebase.analytics().logViewItem(*):'); - - return this.logEvent( - 'view_item', - validateStruct(object, structs.ViewItem, 'firebase.analytics().logViewItem(*):'), - ); - } - - logViewItemList(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logViewItemList(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'view_item_list', - validateStruct(object, structs.ViewItemList, 'firebase.analytics().logViewItemList(*):'), - ); - } - - logViewPromotion(object = {}) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logViewPromotion(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'view_promotion', - validateStruct(object, structs.ViewPromotion, 'firebase.analytics().logViewPromotion(*):'), - ); - } - /** - * Unsupported in "Enhanced Ecommerce reports": - * https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-view_search_results - */ - logViewSearchResults(object) { - if (!isObject(object)) { - throw new Error( - 'firebase.analytics().logViewSearchResults(*): The supplied arg must be an object of key/values.', - ); - } - - return this.logEvent( - 'view_search_results', - validateStruct( - object, - structs.ViewSearchResults, - 'firebase.analytics().logViewSearchResults(*):', - ), - ); - } - - setDefaultEventParameters(params) { - if (!isObject(params) && !isNull(params) && !isUndefined(params)) { - throw new Error( - "firebase.analytics().setDefaultEventParameters(*) 'params' expected an object value when it is defined.", - ); - } - - return this.native.setDefaultEventParameters(params); - } - - initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress) { - if (!isString(emailAddress)) { - throw new Error( - "firebase.analytics().initiateOnDeviceConversionMeasurementWithEmailAddress(*) 'emailAddress' expected a string value.", - ); - } - - if (!isIOS) { - return; - } - - return this.native.initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress); - } - - initiateOnDeviceConversionMeasurementWithHashedEmailAddress(hashedEmailAddress) { - if (!isString(hashedEmailAddress)) { - throw new Error( - "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedEmailAddress(*) 'hashedEmailAddress' expected a string value.", - ); - } - - if (!isIOS) { - return; - } - - return this.native.initiateOnDeviceConversionMeasurementWithHashedEmailAddress( - hashedEmailAddress, - ); - } - - initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber) { - if (!isE164PhoneNumber(phoneNumber)) { - throw new Error( - "firebase.analytics().initiateOnDeviceConversionMeasurementWithPhoneNumber(*) 'phoneNumber' expected a string value in E.164 format.", - ); - } - - if (!isIOS) { - return; - } - - return this.native.initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber); - } - - initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(hashedPhoneNumber) { - if (isE164PhoneNumber(hashedPhoneNumber)) { - throw new Error( - "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(*) 'hashedPhoneNumber' expected a sha256-hashed value of a phone number in E.164 format.", - ); - } - - if (!isString(hashedPhoneNumber)) { - throw new Error( - "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(*) 'hashedPhoneNumber' expected a string value.", - ); - } - - if (!isIOS) { - return; - } - - return this.native.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( - hashedPhoneNumber, - ); - } -} - -// import { SDK_VERSION } from '@react-native-firebase/analytics'; -export const SDK_VERSION = version; - -// import analytics from '@react-native-firebase/analytics'; -// analytics().logEvent(...); -export default createModuleNamespace({ - statics, - version, - namespace, - nativeModuleName, - nativeEvents: false, - hasMultiAppSupport: false, - hasCustomUrlOrRegionSupport: false, - ModuleClass: FirebaseAnalyticsModule, -}); - -export * from './modular/index'; - -// import analytics, { firebase } from '@react-native-firebase/analytics'; -// analytics().logEvent(...); -// firebase.analytics().logEvent(...); -export const firebase = getFirebaseRoot(); - -// Register the interop module for non-native platforms. -setReactNativeModule(nativeModuleName, fallBackModule); diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index ea99918f39..03a0a8f3b5 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -32,6 +32,8 @@ import { FirebaseModule, getFirebaseRoot, } from '@react-native-firebase/app/lib/internal'; + +// Internal types are now available through module declarations in app package import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule'; import { isBoolean } from '@react-native-firebase/app/lib/common'; @@ -85,6 +87,8 @@ const namespace = 'analytics'; const nativeModuleName = 'RNFBAnalyticsModule'; class FirebaseAnalyticsModule extends FirebaseModule { + // Explicitly declare native property from parent class + declare native: any; logEvent( name: string, params: { [key: string]: any } = {}, @@ -207,7 +211,9 @@ class FirebaseAnalyticsModule extends FirebaseModule { const entries = Object.entries(properties); for (let i = 0; i < entries.length; i++) { - const [key, value] = entries[i]; + const entry = entries[i]; + if (!entry) continue; + const [key, value] = entry; if (!isNull(value) && !isString(value)) { throw new Error( `firebase.analytics().setUserProperties(*) 'properties' value for parameter '${key}' is invalid, expected a string.`, @@ -231,7 +237,9 @@ class FirebaseAnalyticsModule extends FirebaseModule { const entries = Object.entries(consentSettings); for (let i = 0; i < entries.length; i++) { - const [key, value] = entries[i]; + const entry = entries[i]; + if (!entry) continue; + const [key, value] = entry; if (!isBoolean(value)) { throw new Error( `firebase.analytics().setConsent(*) 'consentSettings' value for parameter '${key}' is invalid, expected a boolean.`, diff --git a/packages/analytics/lib/struct.js b/packages/analytics/lib/struct.ts similarity index 61% rename from packages/analytics/lib/struct.js rename to packages/analytics/lib/struct.ts index 0d820e0705..0e4b04c713 100644 --- a/packages/analytics/lib/struct.js +++ b/packages/analytics/lib/struct.ts @@ -15,29 +15,40 @@ */ import { isUndefined } from '@react-native-firebase/app/lib/common/validate'; -import { create } from 'superstruct'; +import { create, Struct, StructError } from 'superstruct'; -export const validateStruct = (value = {}, struct, prefix = '') => { +export const validateStruct = ( + value: Record = {}, + struct: Struct, + prefix = '', +): Record => { try { - return create(value, struct); + return create(value, struct) as Record; } catch (e) { - const { path, message } = e; + const { path, message } = e as StructError; const key = path[0]; if (message === undefined) { throw new Error(`${prefix} unknown property '${key}'.`); } - e.message = `${prefix} ${e.message}`; + (e as StructError).message = `${prefix} ${message}`; throw e; } }; -export const validateCompound = (source = {}, a, b, prefix = '') => { +export const validateCompound = ( + source: Record = {}, + a: string, + b: string, + prefix = '', +): void => { + const sourceA = source[a]; + const sourceB = source[b]; if ( - (isUndefined(source[a]) && !isUndefined(source[b])) || - (!isUndefined(source[a]) && isUndefined(source[b])) + (isUndefined(sourceA) && !isUndefined(sourceB)) || + (!isUndefined(sourceA) && isUndefined(sourceB)) ) { throw new Error( `${prefix} if you supply the '${a}' parameter, you must also supply the '${b}' parameter.`, diff --git a/packages/analytics/lib/structs.js b/packages/analytics/lib/structs.ts similarity index 100% rename from packages/analytics/lib/structs.js rename to packages/analytics/lib/structs.ts diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.android.js b/packages/analytics/lib/web/RNFBAnalyticsModule.android.ts similarity index 100% rename from packages/analytics/lib/web/RNFBAnalyticsModule.android.js rename to packages/analytics/lib/web/RNFBAnalyticsModule.android.ts diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.ios.js b/packages/analytics/lib/web/RNFBAnalyticsModule.ios.ts similarity index 100% rename from packages/analytics/lib/web/RNFBAnalyticsModule.ios.js rename to packages/analytics/lib/web/RNFBAnalyticsModule.ios.ts diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.js b/packages/analytics/lib/web/RNFBAnalyticsModule.ts similarity index 63% rename from packages/analytics/lib/web/RNFBAnalyticsModule.js rename to packages/analytics/lib/web/RNFBAnalyticsModule.ts index fa183142cd..29ac9339b8 100644 --- a/packages/analytics/lib/web/RNFBAnalyticsModule.js +++ b/packages/analytics/lib/web/RNFBAnalyticsModule.ts @@ -2,10 +2,20 @@ import { getApp } from '@react-native-firebase/app/lib/internal/web/firebaseApp' import { guard } from '@react-native-firebase/app/lib/internal/web/utils'; import { AnalyticsApi } from './api'; +import type { + AnalyticsEventParameters, + AnalyticsUserProperties, + AnalyticsConsent, + RNFBAnalyticsModule, +} from '../../types'; -let analyticsInstances = {}; +interface AnalyticsInstances { + [measurementId: string]: AnalyticsApi; +} + +let analyticsInstances: AnalyticsInstances = {}; -function getAnalyticsApi(appName) { +function getAnalyticsApi(appName: string): AnalyticsApi { const app = getApp(appName); const measurementId = app.options.measurementId; if (!measurementId) { @@ -13,10 +23,16 @@ function getAnalyticsApi(appName) { console.warn( 'No measurement id (`FirebaseOptions.measurementId`) found for Firebase Analytics. Analytics will be unavailable.', ); + // Return a default instance with empty measurementId for cases where it's not configured + const defaultKey = 'default'; + if (!analyticsInstances[defaultKey]) { + analyticsInstances[defaultKey] = new AnalyticsApi('[DEFAULT]', ''); + } + return analyticsInstances[defaultKey]; } if (!analyticsInstances[measurementId]) { analyticsInstances[measurementId] = new AnalyticsApi('[DEFAULT]', measurementId); - if (globalThis.RNFBDebug) { + if ((globalThis as any).RNFBDebug) { analyticsInstances[measurementId].setDebug(true); } } @@ -29,8 +45,8 @@ function getAnalyticsApi(appName) { * the native android/ios modules e.g. `@ReactMethod` annotated * java methods on Android. */ -export default { - logEvent(name, params) { +const RNFBAnalyticsModule: RNFBAnalyticsModule = { + logEvent(name: string, params?: AnalyticsEventParameters): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); api.logEvent(name, params); @@ -38,7 +54,7 @@ export default { }); }, - setUserId(userId) { + setUserId(userId: string | null): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); api.setUserId(userId); @@ -46,7 +62,7 @@ export default { }); }, - setUserProperty(key, value) { + setUserProperty(key: string, value: string | null): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); api.setUserProperty(key, value); @@ -54,7 +70,7 @@ export default { }); }, - setUserProperties(properties) { + setUserProperties(properties: AnalyticsUserProperties): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); api.setUserProperties(properties); @@ -62,7 +78,7 @@ export default { }); }, - setDefaultEventParameters(params) { + setDefaultEventParameters(params: AnalyticsEventParameters | null): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); api.setDefaultEventParameters(params); @@ -70,18 +86,18 @@ export default { }); }, - setConsent(consent) { + setConsent(consent: AnalyticsConsent): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); // TODO currently we only support ad_personalization - if (consent && consent.ad_personalization) { + if (consent && consent.ad_personalization !== undefined) { api.setConsent({ ad_personalization: consent.ad_personalization }); } return null; }); }, - setAnalyticsCollectionEnabled(enabled) { + setAnalyticsCollectionEnabled(enabled: boolean): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); api.setAnalyticsCollectionEnabled(enabled); @@ -89,31 +105,33 @@ export default { }); }, - resetAnalyticsData() { + resetAnalyticsData(): Promise { // Unsupported for web. return guard(async () => { return null; }); }, - setSessionTimeoutDuration() { + setSessionTimeoutDuration(): Promise { // Unsupported for web. return guard(async () => { return null; }); }, - getAppInstanceId() { + getAppInstanceId(): Promise { return guard(async () => { const api = getAnalyticsApi('[DEFAULT]'); return api._getCid(); }); }, - getSessionId() { + getSessionId(): Promise { // Unsupported for web. return guard(async () => { return null; }); }, }; + +export default RNFBAnalyticsModule; diff --git a/packages/analytics/lib/web/api.d.ts b/packages/analytics/lib/web/api.d.ts new file mode 100644 index 0000000000..0368a2e912 --- /dev/null +++ b/packages/analytics/lib/web/api.d.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import type { AnalyticsApi as IAnalyticsApi } from '../../types'; + +export declare class AnalyticsApi implements IAnalyticsApi { + constructor(appName: string, measurementId: string); + logEvent(name: string, params?: any): void; + setUserId(userId: string | null): void; + setUserProperty(key: string, value: string | null): void; + setUserProperties(properties: any): void; + setDefaultEventParameters(params: any): void; + setConsent(consent: any): void; + setAnalyticsCollectionEnabled(enabled: boolean): void; + setDebug(enabled: boolean): void; + setCurrentScreen(screenName: string | null): void; + _getCid(): Promise; +} diff --git a/packages/analytics/lib/web/api.js b/packages/analytics/lib/web/api.ts similarity index 78% rename from packages/analytics/lib/web/api.js rename to packages/analytics/lib/web/api.ts index d1a3f2ed91..394b10772d 100644 --- a/packages/analytics/lib/web/api.js +++ b/packages/analytics/lib/web/api.ts @@ -13,12 +13,18 @@ import { } from '@react-native-firebase/app/lib/internal/asyncStorage'; import { isNumber } from '@react-native-firebase/app/lib/common'; +import type { + AnalyticsEventParameters, + AnalyticsUserProperties, + AnalyticsConsent, + AnalyticsApi as IAnalyticsApi, +} from '../../types'; /** * Generates a Google Analytics client ID. * @returns {string} The generated client ID. */ -function generateGAClientId() { +function generateGAClientId(): string { const randomNumber = Math.round(Math.random() * 2147483647); // TODO: Don't seem to need this for now. // var hash = 1; @@ -36,8 +42,30 @@ function generateGAClientId() { return randomPart + '.' + timestamp; } -class AnalyticsApi { - constructor(appName, measurementId) { +interface AnalyticsEvent { + name: string; + params: AnalyticsEventParameters; +} + +class AnalyticsApi implements IAnalyticsApi { + public readonly appName: string; + public readonly measurementId: string; + private eventQueue: AnalyticsEvent[]; + private queueTimer: NodeJS.Timeout | null; + private readonly queueInterval: number; + private defaultEventParameters: AnalyticsEventParameters; + private userId: string | null; + private userProperties: AnalyticsUserProperties; + private consent: AnalyticsConsent; + private analyticsCollectionEnabled: boolean; + private started: boolean; + private installationId: string | null; + private debug: boolean; + private currentScreen: string | null; + private sessionId?: number; + private cid?: string; + + constructor(appName: string, measurementId: string) { this.appName = appName; this.measurementId = measurementId; this.eventQueue = []; @@ -54,7 +82,7 @@ class AnalyticsApi { this.currentScreen = null; this._getInstallationId().catch(error => { - if (globalThis.RNFBDebug) { + if ((globalThis as any).RNFBDebug) { console.debug('[RNFB->Analytics][🔴] Error getting Firebase Installation Id:', error); } else { // No-op. This is a non-critical error. @@ -62,7 +90,7 @@ class AnalyticsApi { }); } - setDefaultEventParameters(params) { + setDefaultEventParameters(params: AnalyticsEventParameters | null): void { if (params === null || params === undefined) { this.defaultEventParameters = {}; } else { @@ -75,36 +103,36 @@ class AnalyticsApi { } } - setDebug(enabled) { + setDebug(enabled: boolean): void { this.debug = enabled; } - setUserId(userId) { + setUserId(userId: string | null): void { this.userId = userId; } - setCurrentScreen(screenName) { + setCurrentScreen(screenName: string | null): void { this.currentScreen = screenName; } - setUserProperty(key, value) { + setUserProperty(key: string, value: string | null): void { this.userProperties[key] = value; if (value === null) { delete this.userProperties[key]; } } - setUserProperties(properties) { + setUserProperties(properties: AnalyticsUserProperties): void { for (const [key, value] of Object.entries(properties)) { - this.setUserProperty(key, value); + this.setUserProperty(key, value as string | null); } } - setConsent(consentSettings) { + setConsent(consentSettings: AnalyticsConsent): void { this.consent = { ...this.consent, ...consentSettings }; } - setAnalyticsCollectionEnabled(enabled) { + setAnalyticsCollectionEnabled(enabled: boolean): void { this.analyticsCollectionEnabled = enabled; if (!enabled) { this._stopQueueProcessing(); @@ -113,7 +141,7 @@ class AnalyticsApi { } } - logEvent(eventName, eventParams = {}) { + logEvent(eventName: string, eventParams: AnalyticsEventParameters = {}): void { if (!this.analyticsCollectionEnabled) return; this.eventQueue.push({ name: eventName, @@ -122,22 +150,22 @@ class AnalyticsApi { this._startQueueProcessing(); } - async _getInstallationId() { - navigator.onLine = true; + private async _getInstallationId(): Promise { + (navigator as any).onLine = true; makeIDBAvailable(); const app = getApp(this.appName); const installations = getInstallations(app); const id = await getId(installations); - if (globalThis.RNFBDebug) { + if ((globalThis as any).RNFBDebug) { console.debug('[RNFB->Analytics][📊] Firebase Installation Id:', id); } this.installationId = id; - onIdChange(installations, newId => { + onIdChange(installations, (newId: string) => { this.installationId = newId; }); } - _startQueueProcessing() { + private _startQueueProcessing(): void { if (this.started) return; this.sessionId = Math.floor(Date.now() / 1000); this.started = true; @@ -147,13 +175,15 @@ class AnalyticsApi { ); } - _stopQueueProcessing() { + private _stopQueueProcessing(): void { if (!this.started) return; this.started = false; - clearInterval(this.queueTimer); + if (this.queueTimer) { + clearInterval(this.queueTimer); + } } - async _processQueue() { + private async _processQueue(): Promise { if (this.eventQueue.length === 0) return; const events = this.eventQueue.splice(0, 5); await this._sendEvents(events); @@ -162,7 +192,7 @@ class AnalyticsApi { } } - async _getCid() { + async _getCid(): Promise { this.cid = await getItem('analytics:cid'); if (this.cid) { return this.cid; @@ -192,7 +222,7 @@ class AnalyticsApi { return this.cid; } - async _sendEvents(events) { + private async _sendEvents(events: AnalyticsEvent[]): Promise { const cid = this.cid || (await this._getCid()); for (const event of events) { const queryParams = new URLSearchParams({ @@ -201,18 +231,18 @@ class AnalyticsApi { en: event.name, cid, pscdl: 'noapi', - sid: this.sessionId, + sid: String(this.sessionId), 'ep.origin': 'firebase', _z: 'fetch', _p: '' + Date.now(), - _s: 1, - _ee: 1, - dma: 0, - tfd: Math.round(performance.now()), - are: 1, - sct: 2, - seg: 1, - frm: 0, + _s: '1', + _ee: '1', + dma: '0', + tfd: String(Math.round(performance.now())), + are: '1', + sct: '2', + seg: '1', + frm: '0', }); if (this.debug) { @@ -297,7 +327,7 @@ class AnalyticsApi { try { const url = `https://www.google-analytics.com/g/collect?${queryParams.toString()}`; - if (globalThis.RNFBDebug) { + if ((globalThis as any).RNFBDebug) { console.debug(`[RNFB-->Fetch][📊] Sending analytics call: ${url}`); } const response = await fetch(url, { @@ -317,11 +347,11 @@ class AnalyticsApi { 'user-agent': 'react-native-firebase', }, }); - if (globalThis.RNFBDebug) { + if ((globalThis as any).RNFBDebug) { console.debug(`[RNFB<--Fetch][📊] Response: ${response.status}`); } } catch (error) { - if (globalThis.RNFBDebug) { + if ((globalThis as any).RNFBDebug) { console.debug('[RNFB<--Fetch][🔴] Error sending Analytics event:', error); } } diff --git a/packages/analytics/tsconfig.json b/packages/analytics/tsconfig.json index 84dca50702..6274ec760b 100644 --- a/packages/analytics/tsconfig.json +++ b/packages/analytics/tsconfig.json @@ -24,6 +24,7 @@ "target": "ESNext", "verbatimModuleSyntax": true, "baseUrl": ".", + "typeRoots": ["./types", "./node_modules/@types"], "paths": { "@react-native-firebase/app": ["../app/lib"] } diff --git a/packages/analytics/types/index.d.ts b/packages/analytics/types/index.d.ts new file mode 100644 index 0000000000..e20cfd287b --- /dev/null +++ b/packages/analytics/types/index.d.ts @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// Module declarations for analytics package internal dependencies + +declare module './struct' { + export function validateStruct(object: any, struct: any, prefix: string): any; + export function validateCompound(object: any, key1: string, key2: string, prefix: string): void; +} + +declare module './version' { + const version: string; + export default version; +} + +declare module './structs' { + export const AddPaymentInfo: any; + export const ScreenView: any; + export const AddShippingInfo: any; + export const AddToCart: any; + export const AddToWishlist: any; + export const BeginCheckout: any; + export const CampaignDetails: any; + export const EarnVirtualCurrency: any; + export const GenerateLead: any; + export const JoinGroup: any; + export const LevelEnd: any; + export const LevelStart: any; + export const LevelUp: any; + export const Login: any; + export const PostScore: any; + export const SelectContent: any; + export const Purchase: any; + export const Refund: any; + export const RemoveFromCart: any; + export const Search: any; + export const SelectItem: any; + export const SetCheckoutOption: any; + export const SelectPromotion: any; + export const Share: any; + export const SignUp: any; + export const SpendVirtualCurrency: any; + export const UnlockAchievement: any; + export const ViewCart: any; + export const ViewItem: any; + export const ViewItemList: any; + export const ViewPromotion: any; + export const ViewSearchResults: any; +} + +declare module './web/RNFBAnalyticsModule' { + const fallBackModule: any; + export default fallBackModule; +} diff --git a/packages/analytics/types/index.ts b/packages/analytics/types/index.ts new file mode 100644 index 0000000000..75c28cb597 --- /dev/null +++ b/packages/analytics/types/index.ts @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { ReactNativeFirebase } from '@react-native-firebase/app'; + +export interface AnalyticsEventParameters { + [key: string]: string | number | boolean | undefined | null; +} + +export interface AnalyticsUserProperties { + [key: string]: string | number | boolean | undefined | null; +} + +export interface AnalyticsConsent { + ad_personalization?: boolean; + [key: string]: boolean | undefined; +} + +export interface AnalyticsApi { + logEvent(name: string, params?: AnalyticsEventParameters): void; + setUserId(userId: string | null): void; + setUserProperty(key: string, value: string | null): void; + setUserProperties(properties: AnalyticsUserProperties): void; + setDefaultEventParameters(params: AnalyticsEventParameters | null): void; + setConsent(consent: AnalyticsConsent): void; + setAnalyticsCollectionEnabled(enabled: boolean): void; + setDebug(enabled: boolean): void; + setCurrentScreen(screenName: string | null): void; + _getCid(): Promise; +} + +export interface RNFBAnalyticsModule { + logEvent(name: string, params?: AnalyticsEventParameters): Promise; + setUserId(userId: string | null): Promise; + setUserProperty(key: string, value: string | null): Promise; + setUserProperties(properties: AnalyticsUserProperties): Promise; + setDefaultEventParameters(params: AnalyticsEventParameters | null): Promise; + setConsent(consent: AnalyticsConsent): Promise; + setAnalyticsCollectionEnabled(enabled: boolean): Promise; + resetAnalyticsData(): Promise; + setSessionTimeoutDuration(): Promise; + getAppInstanceId(): Promise; + getSessionId(): Promise; +} diff --git a/packages/app/lib/index.d.ts b/packages/app/lib/index.d.ts index 02374120a4..31545f8532 100644 --- a/packages/app/lib/index.d.ts +++ b/packages/app/lib/index.d.ts @@ -612,5 +612,20 @@ export const utils: ReactNativeFirebase.FirebaseModuleWithStatics(fn: () => Promise): Promise; +export function getWebError(error: Error): ReactNativeFirebase.NativeFirebaseError; +export function emitEvent(eventName: string, event: any): void; From f241c1757081ab3dd194cb41b58ec57ef4f80621 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 14:30:07 +0100 Subject: [PATCH 08/49] chore: resolve index.d.ts issue --- packages/analytics/lib/index.ts | 5 +- packages/analytics/lib/namespaced.ts | 8 ++-- packages/analytics/lib/types.ts | 19 ++++++++ packages/analytics/types/index.d.ts | 68 ---------------------------- 4 files changed, 24 insertions(+), 76 deletions(-) create mode 100644 packages/analytics/lib/types.ts delete mode 100644 packages/analytics/types/index.d.ts diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index 38ec760e96..9605817464 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -1,9 +1,8 @@ -// @ts-ignore - JavaScript module without types -import { MODULAR_DEPRECATION_ARG } from '../../app/lib/common/index'; +import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; import { getApp } from '@react-native-firebase/app'; import { Platform } from 'react-native'; import type { ReactNativeFirebase } from '@react-native-firebase/app'; -import type { FirebaseAnalyticsTypes } from '../'; +import type { FirebaseAnalyticsTypes } from './types'; /** * Returns an Analytics instance for the given app. diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 03a0a8f3b5..dcdee9f052 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -39,11 +39,11 @@ import { isBoolean } from '@react-native-firebase/app/lib/common'; import { validateStruct, validateCompound } from './struct'; import fallBackModule from './web/RNFBAnalyticsModule'; -import version from './version'; +import { version } from './version'; import * as structs from './structs'; // Import types from the index file -import type { FirebaseAnalyticsTypes } from '../'; +import type { FirebaseAnalyticsTypes } from './types'; const ReservedEventNames: readonly string[] = [ 'ad_activeview', @@ -253,9 +253,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { /** ------------------- * EVENTS * -------------------- */ - logAddPaymentInfo( - object: FirebaseAnalyticsTypes.AddPaymentInfoEventParameters = {}, - ): Promise { + logAddPaymentInfo(object: FirebaseAnalyticsTypes.AddPaymentInfoEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logAddPaymentInfo(*): The supplied arg must be an object of key/values.', diff --git a/packages/analytics/lib/types.ts b/packages/analytics/lib/types.ts new file mode 100644 index 0000000000..25a84e1daa --- /dev/null +++ b/packages/analytics/lib/types.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// Re-export the FirebaseAnalyticsTypes namespace from the .d.ts file +export type { FirebaseAnalyticsTypes } from './index.d'; diff --git a/packages/analytics/types/index.d.ts b/packages/analytics/types/index.d.ts deleted file mode 100644 index e20cfd287b..0000000000 --- a/packages/analytics/types/index.d.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2016-present Invertase Limited & Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this library except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// Module declarations for analytics package internal dependencies - -declare module './struct' { - export function validateStruct(object: any, struct: any, prefix: string): any; - export function validateCompound(object: any, key1: string, key2: string, prefix: string): void; -} - -declare module './version' { - const version: string; - export default version; -} - -declare module './structs' { - export const AddPaymentInfo: any; - export const ScreenView: any; - export const AddShippingInfo: any; - export const AddToCart: any; - export const AddToWishlist: any; - export const BeginCheckout: any; - export const CampaignDetails: any; - export const EarnVirtualCurrency: any; - export const GenerateLead: any; - export const JoinGroup: any; - export const LevelEnd: any; - export const LevelStart: any; - export const LevelUp: any; - export const Login: any; - export const PostScore: any; - export const SelectContent: any; - export const Purchase: any; - export const Refund: any; - export const RemoveFromCart: any; - export const Search: any; - export const SelectItem: any; - export const SetCheckoutOption: any; - export const SelectPromotion: any; - export const Share: any; - export const SignUp: any; - export const SpendVirtualCurrency: any; - export const UnlockAchievement: any; - export const ViewCart: any; - export const ViewItem: any; - export const ViewItemList: any; - export const ViewPromotion: any; - export const ViewSearchResults: any; -} - -declare module './web/RNFBAnalyticsModule' { - const fallBackModule: any; - export default fallBackModule; -} From aa2a0401ec3ae4958b216987fc48499f26668235 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 14:39:58 +0100 Subject: [PATCH 09/49] chore(analytics): fix types for index.ts --- packages/app/lib/common/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/app/lib/common/index.d.ts diff --git a/packages/app/lib/common/index.d.ts b/packages/app/lib/common/index.d.ts new file mode 100644 index 0000000000..2d2775a10e --- /dev/null +++ b/packages/app/lib/common/index.d.ts @@ -0,0 +1,5 @@ +declare module '@react-native-firebase/app/lib/common' { + export const MODULAR_DEPRECATION_ARG: string; + export const isAndroid: boolean; + export const isNumber: (value: any) => value is number; +} From ffa235b342fb6fb9d5f9733ac3a5aedd1972d646 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 14:48:40 +0100 Subject: [PATCH 10/49] fix(analytics): RNFBAnalyticsModule make it modular export --- packages/analytics/lib/namespaced.ts | 4 ++-- packages/analytics/lib/web/RNFBAnalyticsModule.android.ts | 3 ++- packages/analytics/lib/web/RNFBAnalyticsModule.ios.ts | 3 ++- packages/analytics/lib/web/RNFBAnalyticsModule.ts | 2 +- packages/analytics/tsconfig.json | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index dcdee9f052..07526c95e2 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -38,7 +38,7 @@ import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/na import { isBoolean } from '@react-native-firebase/app/lib/common'; import { validateStruct, validateCompound } from './struct'; -import fallBackModule from './web/RNFBAnalyticsModule'; +import { RNFBAnalyticsModule } from './web/RNFBAnalyticsModule'; import { version } from './version'; import * as structs from './structs'; @@ -856,4 +856,4 @@ export default createModuleNamespace({ export const firebase = getFirebaseRoot(); // Register the interop module for non-native platforms. -setReactNativeModule(nativeModuleName, fallBackModule); +setReactNativeModule(nativeModuleName, RNFBAnalyticsModule); diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.android.ts b/packages/analytics/lib/web/RNFBAnalyticsModule.android.ts index af77c859b1..dd5a6be890 100644 --- a/packages/analytics/lib/web/RNFBAnalyticsModule.android.ts +++ b/packages/analytics/lib/web/RNFBAnalyticsModule.android.ts @@ -1,2 +1,3 @@ // No-op for android. -export default {}; +const RNFBAnalyticsModule = {}; +export { RNFBAnalyticsModule }; diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.ios.ts b/packages/analytics/lib/web/RNFBAnalyticsModule.ios.ts index a3429ada0e..8d87cbca08 100644 --- a/packages/analytics/lib/web/RNFBAnalyticsModule.ios.ts +++ b/packages/analytics/lib/web/RNFBAnalyticsModule.ios.ts @@ -1,2 +1,3 @@ // No-op for ios. -export default {}; +const RNFBAnalyticsModule = {}; +export { RNFBAnalyticsModule }; diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.ts b/packages/analytics/lib/web/RNFBAnalyticsModule.ts index 29ac9339b8..15b9605186 100644 --- a/packages/analytics/lib/web/RNFBAnalyticsModule.ts +++ b/packages/analytics/lib/web/RNFBAnalyticsModule.ts @@ -134,4 +134,4 @@ const RNFBAnalyticsModule: RNFBAnalyticsModule = { }, }; -export default RNFBAnalyticsModule; +export { RNFBAnalyticsModule }; diff --git a/packages/analytics/tsconfig.json b/packages/analytics/tsconfig.json index 6274ec760b..cce2f9edcd 100644 --- a/packages/analytics/tsconfig.json +++ b/packages/analytics/tsconfig.json @@ -22,7 +22,7 @@ "skipLibCheck": true, "strict": true, "target": "ESNext", - "verbatimModuleSyntax": true, + "verbatimModuleSyntax": false, "baseUrl": ".", "typeRoots": ["./types", "./node_modules/@types"], "paths": { From 067d3338378731c2a7e1610d7e3a8026918ebf22 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 14:59:49 +0100 Subject: [PATCH 11/49] fix: analytics with structs --- packages/analytics/lib/index.d.ts | 33 +++++++++++++++++++++++++++++++ packages/analytics/lib/struct.ts | 8 ++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/analytics/lib/index.d.ts b/packages/analytics/lib/index.d.ts index 2267bd9813..4f2071ed96 100644 --- a/packages/analytics/lib/index.d.ts +++ b/packages/analytics/lib/index.d.ts @@ -50,6 +50,39 @@ import { ReactNativeFirebase } from '@react-native-firebase/app'; export namespace FirebaseAnalyticsTypes { import FirebaseModule = ReactNativeFirebase.FirebaseModule; + /** + * A currency amount. + */ + export type Currency = number; + + /** + * Consent status string values. + */ + export type ConsentStatusString = 'granted' | 'denied'; + + /** + * Promotion object for analytics events. + */ + export interface Promotion { + /** + * The name of a creative used in a promotional spot + */ + creative_name?: string; + /** + * The name of a creative slot + */ + creative_slot?: string; + /** + * The ID of a product promotion + */ + promotion_id?: string; + /** + * The name of a product promotion + */ + promotion_name?: string; + [key: string]: any; + } + export interface Item { /** * The item's brand. diff --git a/packages/analytics/lib/struct.ts b/packages/analytics/lib/struct.ts index 0e4b04c713..f484e61456 100644 --- a/packages/analytics/lib/struct.ts +++ b/packages/analytics/lib/struct.ts @@ -18,12 +18,12 @@ import { isUndefined } from '@react-native-firebase/app/lib/common/validate'; import { create, Struct, StructError } from 'superstruct'; export const validateStruct = ( - value: Record = {}, + value: Record = {}, struct: Struct, prefix = '', -): Record => { +): Record => { try { - return create(value, struct) as Record; + return create(value, struct) as Record; } catch (e) { const { path, message } = e as StructError; @@ -39,7 +39,7 @@ export const validateStruct = ( }; export const validateCompound = ( - source: Record = {}, + source: Record = {}, a: string, b: string, prefix = '', From bddd22028ee6cbe0aa434723e0326a2fd8dd133f Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 15:03:03 +0100 Subject: [PATCH 12/49] chore: remove import --- packages/analytics/lib/struct.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/analytics/lib/struct.ts b/packages/analytics/lib/struct.ts index f484e61456..84af57db36 100644 --- a/packages/analytics/lib/struct.ts +++ b/packages/analytics/lib/struct.ts @@ -15,11 +15,11 @@ */ import { isUndefined } from '@react-native-firebase/app/lib/common/validate'; -import { create, Struct, StructError } from 'superstruct'; +import { create, StructError } from 'superstruct'; export const validateStruct = ( value: Record = {}, - struct: Struct, + struct: any, prefix = '', ): Record => { try { From e609f762da3b5befd4fc7dc8f0722fe31c0d830f Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 15:13:25 +0100 Subject: [PATCH 13/49] chore: rename to web types --- packages/analytics/lib/web/RNFBAnalyticsModule.ts | 2 +- packages/analytics/lib/web/api.ts | 2 +- packages/analytics/types/{index.ts => web.ts} | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) rename packages/analytics/types/{index.ts => web.ts} (97%) diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.ts b/packages/analytics/lib/web/RNFBAnalyticsModule.ts index 15b9605186..c8fa9e43dd 100644 --- a/packages/analytics/lib/web/RNFBAnalyticsModule.ts +++ b/packages/analytics/lib/web/RNFBAnalyticsModule.ts @@ -7,7 +7,7 @@ import type { AnalyticsUserProperties, AnalyticsConsent, RNFBAnalyticsModule, -} from '../../types'; +} from '../../types/web'; interface AnalyticsInstances { [measurementId: string]: AnalyticsApi; diff --git a/packages/analytics/lib/web/api.ts b/packages/analytics/lib/web/api.ts index 394b10772d..dc6fbf2bc6 100644 --- a/packages/analytics/lib/web/api.ts +++ b/packages/analytics/lib/web/api.ts @@ -18,7 +18,7 @@ import type { AnalyticsUserProperties, AnalyticsConsent, AnalyticsApi as IAnalyticsApi, -} from '../../types'; +} from '../../types/web'; /** * Generates a Google Analytics client ID. diff --git a/packages/analytics/types/index.ts b/packages/analytics/types/web.ts similarity index 97% rename from packages/analytics/types/index.ts rename to packages/analytics/types/web.ts index 75c28cb597..a94ec55659 100644 --- a/packages/analytics/types/index.ts +++ b/packages/analytics/types/web.ts @@ -15,8 +15,6 @@ * */ -import { ReactNativeFirebase } from '@react-native-firebase/app'; - export interface AnalyticsEventParameters { [key: string]: string | number | boolean | undefined | null; } From 081fb4e2cb516d4fb7a8204e809628a1636cae9a Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 15:45:34 +0100 Subject: [PATCH 14/49] fix: analytics types --- packages/analytics/lib/namespaced.ts | 15 +- packages/analytics/types/analytics.ts | 871 ++++++++++++++++++++++++++ 2 files changed, 885 insertions(+), 1 deletion(-) create mode 100644 packages/analytics/types/analytics.ts diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 07526c95e2..868f04c6eb 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -14,7 +14,7 @@ * limitations under the License. * */ - +import { ReactNativeFirebase } from '@react-native-firebase/app'; import { isAlphaNumericUnderscore, isE164PhoneNumber, @@ -41,10 +41,23 @@ import { validateStruct, validateCompound } from './struct'; import { RNFBAnalyticsModule } from './web/RNFBAnalyticsModule'; import { version } from './version'; import * as structs from './structs'; +import { Statics } from '../types/analytics'; // Import types from the index file import type { FirebaseAnalyticsTypes } from './types'; +export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< + FirebaseAnalyticsModule, + Statics +>; + +// export declare firebase: FirebaseAnalyticsModule & { +// analytics: typeof defaultExport; +// app( +// name?: string, +// ): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsTypes.Module }; +// }; + const ReservedEventNames: readonly string[] = [ 'ad_activeview', 'ad_click', diff --git a/packages/analytics/types/analytics.ts b/packages/analytics/types/analytics.ts new file mode 100644 index 0000000000..e94fe38564 --- /dev/null +++ b/packages/analytics/types/analytics.ts @@ -0,0 +1,871 @@ +/** + * A currency amount. + */ +export type Currency = number; + +/** + * Consent status string values. + */ +export type ConsentStatusString = 'granted' | 'denied'; + +/** + * Promotion object for analytics events. + */ +export interface Promotion { + /** + * The name of a creative used in a promotional spot + */ + creative_name?: string; + /** + * The name of a creative slot + */ + creative_slot?: string; + /** + * The ID of a product promotion + */ + promotion_id?: string; + /** + * The name of a product promotion + */ + promotion_name?: string; + [key: string]: any; +} + +export interface Item { + /** + * The item's brand. + */ + item_brand?: string; + /** + * An item ID. + */ + item_id?: string; + /** + * An item name. + */ + item_name?: string; + /** + * First class item category. + */ + item_category?: string; + /** + * Second class item category. + */ + item_category2?: string; + /** + * Third class item category. + */ + item_category3?: string; + /** + * Fourth class item category. + */ + item_category4?: string; + /** + * Fifth class item category. + */ + item_category5?: string; + /** + * The ID of the list in which the item was presented to the user. + */ + item_list_id?: string; + /** + * The name of the list in which the item was presented to the user. + */ + item_list_name?: string; + /** + * The Google [Place ID](https://developers.google.com/places/place-id) that corresponds to the associated item (String). Alternatively, you can supply your own custom Location ID. + */ + location_id?: string; + /** + * The Item variant. + */ + item_variant?: string; + /** + * The Item quantity. + */ + quantity?: number; + /** + * The Item price. + * Note that firebase analytics will display this as an integer with trailing zeros, due to some firebase-internal conversion. + * See https://github.com/invertase/react-native-firebase/issues/4578#issuecomment-771703420 for more information + */ + price?: number; + /** + * The affiliation of the item. + */ + affiliation?: string; + /** + * The coupon associated with the item. + */ + coupon?: string; + /** + * The creative name associated with the item. + */ + creative_name?: string; + /** + * The creative slot associated with the item. + */ + creative_slot?: string; + /** + * The discount applied to the item. + */ + discount?: Currency; + /** + * The index of the item. + */ + index?: number; + /** + * The promotion ID associated with the item. + */ + promotion_id?: string; + /** + * The promotion name associated with the item. + */ + promotion_name?: string; + /** + * Custom event parameters. The parameter names can be up to 40 characters long and must start with an alphabetic character and contain only alphanumeric characters and underscores. String parameter values can be up to 100 characters long. + * The "firebase_", "google_" and "ga_" prefixes are reserved and should not be used for parameter names. + */ + [key: string]: string | number | undefined; +} + +export interface AddPaymentInfoEventParameters { + items?: Item[]; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + value?: number; + /** + * Coupon code for a purchasable item. + */ + coupon?: string; + /** + * The chosen method of payment + */ + payment_type?: string; +} + +export interface AddShippingInfoEventParameters { + items?: Item[]; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + value?: number; + /** + * Coupon code for a purchasable item. + */ + coupon?: string; + /** + * The shipping tier (e.g. Ground, Air, Next-day) selected for delivery of the purchased item + */ + shipping_tier?: string; +} + +export interface AddToCartEventParameters { + items?: Item[]; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + /** + * value of item + */ + value?: number; +} + +export interface AddToWishlistEventParameters { + items?: Item[]; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + value?: number; +} + +export interface BeginCheckoutEventParameters { + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + //TODO if value is a param, so must currency: https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-add_to_wishlist + currency?: string; + value?: number; + /** + * Coupon code for a purchasable item. + */ + coupon?: string; + + items?: Item[]; + /** + * Custom event parameters. + */ + [key: string]: any; +} + +export interface CampaignDetailsEventParameters { + /** + * Used to identify a search engine, newsletter, or other source. + */ + source: string; + /** + * Used to identify a medium such as email or cost-per-click (cpc). + */ + medium: string; + /** + * Used for keyword analysis to identify a specific product promotion or strategic campaign. + */ + campaign: string; + /** + * Used with paid search to supply the keywords for ads. + */ + term?: string; + /** + * Used for A/B testing and content-targeted ads to differentiate ads or links that point to the same URL. + */ + content?: string; + /** + * A campaign detail click ID. + */ + aclid?: string; + cp1?: string; +} + +// +// Unsupported in "Enhanced Ecommerce reports": +// https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-checkout_progress +// +// export interface CheckoutProgressEventParameters { +// checkout_step: string; +// checkout_options: string; +// } + +export interface EarnVirtualCurrencyEventParameters { + /** + * Name of virtual currency type. E.g. `gems`. + */ + virtual_currency_name: string; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. + */ + value: number; +} + +export interface GenerateLeadEventParameters { + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value?: number; +} + +export interface JoinGroupEventParameters { + /** + * Group/clan/guild id. + */ + group_id: string; +} + +export interface LevelEndEventParameters { + /** + * Level in game. + */ + level: number; + /** + * The result of an operation. + */ + success?: string; +} + +export interface LevelStartEventParameters { + /** + * Level in game. + */ + level: number; +} + +export interface LevelUpEventParameters { + /** + * Level in game. + */ + level: number; + /** + * Character used in game. + */ + character?: string; +} + +export interface LoginEventParameters { + /** + * The login method. E.g. `facebook.com`. + */ + method: string; +} + +export interface PostScoreEventParameters { + /** + * Score in game. + */ + score: number; + /** + * Level in game. + */ + level?: number; + /** + * Character used in game. + */ + character?: string; +} + +export interface PurchaseEventParameters { + /** + * A product affiliation to designate a supplying company or brick and mortar store location + */ + affiliation?: string; + /** + * Coupon code for a purchasable item. + */ + coupon?: string; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + + items?: Item[]; + /** + * Shipping cost. + */ + shipping?: number; + /** + * Tax amount. + */ + tax?: number; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value?: number; + /** + * A single ID for a ecommerce group transaction. + */ + transaction_id?: string; + /** + * Custom event parameters. + */ + [key: string]: any; +} + +export interface ScreenViewParameters { + /** + * Screen name the user is currently viewing. + */ + screen_name?: string; + /** + * Current class associated with the view the user is currently viewing. + */ + screen_class?: string; + + /** + * Custom event parameters. + */ + [key: string]: any; +} + +export interface RefundEventParameters { + /** + * A product affiliation to designate a supplying company or brick and mortar store location + */ + affiliation?: string; + /** + * Coupon code for a purchasable item. + */ + coupon?: string; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + + items?: Item[]; + /** + * Shipping cost. + */ + shipping?: number; + /** + * Tax amount. + */ + tax?: number; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value?: number; + /** + * A single ID for a ecommerce group transaction. + */ + transaction_id?: string; +} + +export interface RemoveFromCartEventParameters { + items?: Item[]; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value?: number; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + x */ + currency?: string; +} + +export interface SearchEventParameters { + search_term: string; + /** + * Number of nights staying at hotel. + */ + number_of_nights?: number; + /** + * Number of rooms for travel events. + */ + number_of_rooms?: number; + /** + * Number of passengers traveling. + */ + number_of_passengers?: number; + /** + * Flight or Travel origin. E.g. `Mountain View, CA`. + */ + origin?: string; + /** + * Flight or Travel destination. E.g. `Mountain View, CA`. + */ + destination?: string; + /** + * The departure date, check-in date, or rental start date for the item (String). The parameter expects a date formatted as YYYY-MM-DD. + */ + start_date?: string; + /** + * The arrival date, check-out date, or rental end date for the item (String). The parameter expects a date formatted as YYYY-MM-DD. + */ + end_date?: string; + /** + * Travel class. E.g. `business`. + */ + travel_class?: string; +} + +export interface SelectContentEventParameters { + content_type: string; + /** + * An item ID. + */ + item_id: string; +} + +export interface SelectItemEventParameters { + items?: Item[]; + content_type: string; + /** + * The ID of the list in which the item was presented to the user + */ + item_list_id: string; + /** + * The name of the list in which the item was presented to the user + */ + item_list_name: string; +} + +export interface SetCheckoutOptionEventParameters { + checkout_step?: EventParams['checkout_step']; + checkout_option?: EventParams['checkout_option']; + + [key: string]: any; +} + +export interface SelectPromotionEventParameters { + /** + * The name of a creative used in a promotional spot + */ + creative_name: string; + /** + * The name of a creative slot + */ + creative_slot: string; + items?: Item[]; + /** + * The location associated with the event. Preferred to be the Google Place ID that corresponds to the associated item but could be overridden to a custom location ID string + */ + location_id: string; + /** + * The ID of a product promotion + */ + promotion_id: string; + /** + * The name of a product promotion + */ + promotion_name: string; +} + +export interface ShareEventParameters { + /** + * Type of content selected. + */ + content_type: string; + /** + * An item ID. + */ + item_id: string; + /** + * A particular approach used in an operation; for example, "facebook" or "email" in the context of a sign_up or login event. + */ + method: string; +} + +export interface SignUpEventParameters { + /** + * A particular approach used in an operation; for example, "facebook" or "email" in the context of a sign_up or login event. + */ + method: string; +} + +export interface SpendVirtualCurrencyEventParameters { + /** + * An item name. + */ + item_name: string; + /** + * Name of virtual currency type. E.g. `gems`. + */ + virtual_currency_name: string; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value: number; +} + +export interface UnlockAchievementEventParameters { + /** + * Game achievement ID (String). + */ + achievement_id: string; +} + +export interface ViewCartEventParameters { + items?: Item[]; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value?: number; +} + +export interface ViewItemEventParameters { + items?: Item[]; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value?: number; +} + +export interface ViewSearchResultsParameters { + /** + * The search string/keywords used. + */ + search_term: string; +} + +export interface ViewItemListEventParameters { + items?: Item[]; + /** + * The ID of the list in which the item was presented to the user + */ + item_list_id?: string; + /** + * The name of the list in which the item was presented to the user + */ + item_list_name?: string; +} + +export interface ViewPromotionEventParameters { + items?: Item[]; + /** + * The location associated with the event. Preferred to be the Google Place ID that corresponds to the associated item but could be overridden to a custom location ID string + */ + location_id?: string; + /** + * The name of a creative used in a promotional spot + */ + creative_name?: string; + /** + * The name of a creative slot + */ + creative_slot?: string; + /** + * The ID of a product promotion + */ + promotion_id?: string; + /** + * The name of a product promotion + */ + promotion_name?: string; +} + +export interface AddShippingInfoParameters { + items?: Item[]; + /** + * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. + */ + currency?: string; + /** + * A context-specific numeric value which is accumulated automatically for each event type. Values + * can include revenue, distance, time and points. When a value is set, the accompanying `currency` + * parameter should also be defined. + */ + value?: number; + /** + * Coupon code for a purchasable item. + */ + coupon?: string; + /** + * The shipping tier (e.g. Ground, Air, Next-day) selected for delivery of the purchased item + */ + shipping_tier?: string; +} + +/** + * Standard gtag.js event parameters. For more information, see the GA4 reference documentation. Web only. + */ +export interface EventParams { + checkout_option?: string; + checkout_step?: number; + item_id?: string; + content_type?: string; + coupon?: string; + currency?: string; + description?: string; + fatal?: boolean; + items?: Item[]; + method?: string; + number?: string; + promotions?: Promotion[]; + screen_name?: string; + /** + * Firebase-specific. Use to log a `screen_name` to Firebase Analytics. + */ + firebase_screen?: string; + /** + * Firebase-specific. Use to log a `screen_class` to Firebase Analytics. + */ + firebase_screen_class?: string; + search_term?: string; + shipping?: Currency; + tax?: Currency; + transaction_id?: string; + value?: number; + event_label?: string; + event_category?: string; + shipping_tier?: string; + item_list_id?: string; + item_list_name?: string; + promotion_id?: string; + promotion_name?: string; + payment_type?: string; + affiliation?: string; + page_title?: string; + page_location?: string; + page_path?: string; + + [key: string]: unknown; +} + +/** + * Unsupported in "Enhanced Ecommerce reports": + * https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-view_search_results + */ +// export interface ViewSearchResults { +// /** +// * The search string/keywords used. +// */ +// search_term: string; +// } + +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +export interface Statics {} + +/** + * Analytics instance initialization options. Web only. + */ +export interface AnalyticsSettings { + config?: GtagConfigParams | EventParams; +} + +/** + * Additional options that can be passed to Analytics method calls such as logEvent. Web only. + */ +export interface AnalyticsCallOptions { + /** + * If true, this config or event call applies globally to all Google Analytics properties on the page. Web only. + */ + global: boolean; +} + +/** + * A set of common Google Analytics config settings recognized by gtag.js. Web only. + */ +export interface GtagConfigParams { + /** + * Whether or not a page view should be sent. + * If set to true (default), a page view is automatically sent upon initialization + * of analytics. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views } + */ + send_page_view?: boolean; + /** + * The title of the page. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views } + */ + page_title?: string; + /** + * The URL of the page. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views } + */ + page_location?: string; + /** + * Defaults to `auto`. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } + */ + cookie_domain?: string; + /** + * Defaults to 63072000 (two years, in seconds). + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } + */ + cookie_expires?: number; + /** + * Defaults to `_ga`. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } + */ + cookie_prefix?: string; + /** + * If set to true, will update cookies on each page load. + * Defaults to true. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } + */ + cookie_update?: boolean; + /** + * Appends additional flags to the cookie when set. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } + */ + cookie_flags?: string; + /** + * If set to false, disables all advertising features with `gtag.js`. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features } + */ + allow_google_signals?: boolean; + /** + * If set to false, disables all advertising personalization with `gtag.js`. + * See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features } + */ + allow_ad_personalization_signals?: boolean; + + [key: string]: unknown; +} + +/** + * Consent status settings for each consent type. + * For more information, see + * {@link https://developers.google.com/tag-platform/tag-manager/templates/consent-apis + * | the GA4 reference documentation for consent state and consent types}. + */ +export interface ConsentSettings { + /** Enables storage, such as cookies, related to advertising */ + ad_storage?: boolean; + /** Sets consent for sending user data to Google for online advertising purposes */ + ad_user_data?: boolean; + /** Sets consent for personalized advertising */ + ad_personalization?: boolean; + /** Enables storage, such as cookies, related to analytics (for example, visit duration) */ + analytics_storage?: boolean; + /** + * Enables storage that supports the functionality of the website or app such as language settings + */ + functionality_storage?: boolean; + /** Enables storage related to personalization such as video recommendations */ + personalization_storage?: boolean; + /** + * Enables storage related to security such as authentication functionality, fraud prevention, + * and other user protection. + */ + security_storage?: ConsentStatusString; + + [key: string]: unknown; +} + +/** + * Specifies custom options for your Firebase Analytics instance. + * You must set these before initializing `firebase.analytics()`. + */ +export interface SettingsOptions { + /** Sets custom name for `gtag` function. */ + gtagName?: string; + /** Sets custom name for `dataLayer` array used by `gtag.js`. */ + dataLayerName?: string; +} + +/** + * Any custom event name string not in the standard list of recommended event names. + */ +export declare type CustomEventName = T extends EventNameString ? never : T; +/** + * Type for standard Google Analytics event names. logEvent also accepts any custom string and interprets it as a custom event name. + * See https://firebase.google.com/docs/reference/js/analytics.md#eventnamestring + */ +export declare type EventNameString = + | 'add_payment_info' + | 'add_shipping_info' + | 'add_to_cart' + | 'add_to_wishlist' + | 'begin_checkout' + | 'checkout_progress' + | 'exception' + | 'generate_lead' + | 'login' + | 'page_view' + | 'purchase' + | 'refund' + | 'remove_from_cart' + | 'screen_view' + | 'search' + | 'select_content' + | 'select_item' + | 'select_promotion' + | 'set_checkout_option' + | 'share' + | 'sign_up' + | 'timing_complete' + | 'view_cart' + | 'view_item' + | 'view_item_list' + | 'view_promotion' + | 'view_search_results'; From 86fbd1472b4470c4626ce5572081b36459b4c3d0 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 12 Aug 2025 15:58:55 +0100 Subject: [PATCH 15/49] chore: moved types to analytics types --- packages/analytics/lib/index.d.ts | 1936 -------------------------- packages/analytics/lib/index.ts | 112 +- packages/analytics/lib/namespaced.ts | 129 +- 3 files changed, 148 insertions(+), 2029 deletions(-) delete mode 100644 packages/analytics/lib/index.d.ts diff --git a/packages/analytics/lib/index.d.ts b/packages/analytics/lib/index.d.ts deleted file mode 100644 index 4f2071ed96..0000000000 --- a/packages/analytics/lib/index.d.ts +++ /dev/null @@ -1,1936 +0,0 @@ -/* - * Copyright (c) 2016-present Invertase Limited & Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this library except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -import { ReactNativeFirebase } from '@react-native-firebase/app'; - -/** - * Firebase Analytics package for React Native. - * - * #### Example: Access the firebase export from the `analytics` package: - * - * ```js - * import { firebase } from '@react-native-firebase/analytics'; - * - * // firebase.analytics().X - * ``` - * - * #### Example: Using the default export from the `analytics` package: - * - * ```js - * import analytics from '@react-native-firebase/analytics'; - * - * // analytics().X - * ``` - * - * #### Example: Using the default export from the `app` package: - * - * ```js - * import firebase from '@react-native-firebase/app'; - * import '@react-native-firebase/analytics'; - * - * // firebase.analytics().X - * ``` - * - * @firebase analytics - */ -export namespace FirebaseAnalyticsTypes { - import FirebaseModule = ReactNativeFirebase.FirebaseModule; - - /** - * A currency amount. - */ - export type Currency = number; - - /** - * Consent status string values. - */ - export type ConsentStatusString = 'granted' | 'denied'; - - /** - * Promotion object for analytics events. - */ - export interface Promotion { - /** - * The name of a creative used in a promotional spot - */ - creative_name?: string; - /** - * The name of a creative slot - */ - creative_slot?: string; - /** - * The ID of a product promotion - */ - promotion_id?: string; - /** - * The name of a product promotion - */ - promotion_name?: string; - [key: string]: any; - } - - export interface Item { - /** - * The item's brand. - */ - item_brand?: string; - /** - * An item ID. - */ - item_id?: string; - /** - * An item name. - */ - item_name?: string; - /** - * First class item category. - */ - item_category?: string; - /** - * Second class item category. - */ - item_category2?: string; - /** - * Third class item category. - */ - item_category3?: string; - /** - * Fourth class item category. - */ - item_category4?: string; - /** - * Fifth class item category. - */ - item_category5?: string; - /** - * The ID of the list in which the item was presented to the user. - */ - item_list_id?: string; - /** - * The name of the list in which the item was presented to the user. - */ - item_list_name?: string; - /** - * The Google [Place ID](https://developers.google.com/places/place-id) that corresponds to the associated item (String). Alternatively, you can supply your own custom Location ID. - */ - location_id?: string; - /** - * The Item variant. - */ - item_variant?: string; - /** - * The Item quantity. - */ - quantity?: number; - /** - * The Item price. - * Note that firebase analytics will display this as an integer with trailing zeros, due to some firebase-internal conversion. - * See https://github.com/invertase/react-native-firebase/issues/4578#issuecomment-771703420 for more information - */ - price?: number; - /** - * The affiliation of the item. - */ - affiliation?: string; - /** - * The coupon associated with the item. - */ - coupon?: string; - /** - * The creative name associated with the item. - */ - creative_name?: string; - /** - * The creative slot associated with the item. - */ - creative_slot?: string; - /** - * The discount applied to the item. - */ - discount?: Currency; - /** - * The index of the item. - */ - index?: number; - /** - * The promotion ID associated with the item. - */ - promotion_id?: string; - /** - * The promotion name associated with the item. - */ - promotion_name?: string; - /** - * Custom event parameters. The parameter names can be up to 40 characters long and must start with an alphabetic character and contain only alphanumeric characters and underscores. String parameter values can be up to 100 characters long. - * The "firebase_", "google_" and "ga_" prefixes are reserved and should not be used for parameter names. - */ - [key: string]: string | number; - } - - export interface AddPaymentInfoEventParameters { - items?: Item[]; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - value?: number; - /** - * Coupon code for a purchasable item. - */ - coupon?: string; - /** - * The chosen method of payment - */ - payment_type?: string; - } - - export interface AddShippingInfoEventParameters { - items?: Item[]; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - value?: number; - /** - * Coupon code for a purchasable item. - */ - coupon?: string; - /** - * The shipping tier (e.g. Ground, Air, Next-day) selected for delivery of the purchased item - */ - shipping_tier?: string; - } - - export interface AddToCartEventParameters { - items?: Item[]; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - /** - * value of item - */ - value?: number; - } - - export interface AddToWishlistEventParameters { - items?: Item[]; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - value?: number; - } - - export interface BeginCheckoutEventParameters { - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - //TODO if value is a param, so must currency: https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-add_to_wishlist - currency?: string; - value?: number; - /** - * Coupon code for a purchasable item. - */ - coupon?: string; - - items?: Item[]; - /** - * Custom event parameters. - */ - [key: string]: any; - } - - export interface CampaignDetailsEventParameters { - /** - * Used to identify a search engine, newsletter, or other source. - */ - source: string; - /** - * Used to identify a medium such as email or cost-per-click (cpc). - */ - medium: string; - /** - * Used for keyword analysis to identify a specific product promotion or strategic campaign. - */ - campaign: string; - /** - * Used with paid search to supply the keywords for ads. - */ - term?: string; - /** - * Used for A/B testing and content-targeted ads to differentiate ads or links that point to the same URL. - */ - content?: string; - /** - * A campaign detail click ID. - */ - aclid?: string; - cp1?: string; - } - - // - // Unsupported in "Enhanced Ecommerce reports": - // https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-checkout_progress - // - // export interface CheckoutProgressEventParameters { - // checkout_step: string; - // checkout_options: string; - // } - - export interface EarnVirtualCurrencyEventParameters { - /** - * Name of virtual currency type. E.g. `gems`. - */ - virtual_currency_name: string; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. - */ - value: number; - } - - export interface GenerateLeadEventParameters { - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value?: number; - } - - export interface JoinGroupEventParameters { - /** - * Group/clan/guild id. - */ - group_id: string; - } - - export interface LevelEndEventParameters { - /** - * Level in game. - */ - level: number; - /** - * The result of an operation. - */ - success?: string; - } - - export interface LevelStartEventParameters { - /** - * Level in game. - */ - level: number; - } - - export interface LevelUpEventParameters { - /** - * Level in game. - */ - level: number; - /** - * Character used in game. - */ - character?: string; - } - - export interface LoginEventParameters { - /** - * The login method. E.g. `facebook.com`. - */ - method: string; - } - - export interface PostScoreEventParameters { - /** - * Score in game. - */ - score: number; - /** - * Level in game. - */ - level?: number; - /** - * Character used in game. - */ - character?: string; - } - - export interface PurchaseEventParameters { - /** - * A product affiliation to designate a supplying company or brick and mortar store location - */ - affiliation?: string; - /** - * Coupon code for a purchasable item. - */ - coupon?: string; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - - items?: Item[]; - /** - * Shipping cost. - */ - shipping?: number; - /** - * Tax amount. - */ - tax?: number; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value?: number; - /** - * A single ID for a ecommerce group transaction. - */ - transaction_id?: string; - /** - * Custom event parameters. - */ - [key: string]: any; - } - - export interface ScreenViewParameters { - /** - * Screen name the user is currently viewing. - */ - screen_name?: string; - /** - * Current class associated with the view the user is currently viewing. - */ - screen_class?: string; - - /** - * Custom event parameters. - */ - [key: string]: any; - } - - export interface RefundEventParameters { - /** - * A product affiliation to designate a supplying company or brick and mortar store location - */ - affiliation?: string; - /** - * Coupon code for a purchasable item. - */ - coupon?: string; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - - items?: Item[]; - /** - * Shipping cost. - */ - shipping?: number; - /** - * Tax amount. - */ - tax?: number; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value?: number; - /** - * A single ID for a ecommerce group transaction. - */ - transaction_id?: string; - } - - export interface RemoveFromCartEventParameters { - items?: Item[]; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value?: number; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - x */ - currency?: string; - } - - export interface SearchEventParameters { - search_term: string; - /** - * Number of nights staying at hotel. - */ - number_of_nights?: number; - /** - * Number of rooms for travel events. - */ - number_of_rooms?: number; - /** - * Number of passengers traveling. - */ - number_of_passengers?: number; - /** - * Flight or Travel origin. E.g. `Mountain View, CA`. - */ - origin?: string; - /** - * Flight or Travel destination. E.g. `Mountain View, CA`. - */ - destination?: string; - /** - * The departure date, check-in date, or rental start date for the item (String). The parameter expects a date formatted as YYYY-MM-DD. - */ - start_date?: string; - /** - * The arrival date, check-out date, or rental end date for the item (String). The parameter expects a date formatted as YYYY-MM-DD. - */ - end_date?: string; - /** - * Travel class. E.g. `business`. - */ - travel_class?: string; - } - - export interface SelectContentEventParameters { - content_type: string; - /** - * An item ID. - */ - item_id: string; - } - - export interface SelectItemEventParameters { - items?: Item[]; - content_type: string; - /** - * The ID of the list in which the item was presented to the user - */ - item_list_id: string; - /** - * The name of the list in which the item was presented to the user - */ - item_list_name: string; - } - - export interface SetCheckoutOptionEventParameters { - checkout_step?: EventParams['checkout_step']; - checkout_option?: EventParams['checkout_option']; - - [key: string]: any; - } - - export interface SelectPromotionEventParameters { - /** - * The name of a creative used in a promotional spot - */ - creative_name: string; - /** - * The name of a creative slot - */ - creative_slot: string; - items?: Item[]; - /** - * The location associated with the event. Preferred to be the Google Place ID that corresponds to the associated item but could be overridden to a custom location ID string - */ - location_id: string; - /** - * The ID of a product promotion - */ - promotion_id: string; - /** - * The name of a product promotion - */ - promotion_name: string; - } - - export interface ShareEventParameters { - /** - * Type of content selected. - */ - content_type: string; - /** - * An item ID. - */ - item_id: string; - /** - * A particular approach used in an operation; for example, "facebook" or "email" in the context of a sign_up or login event. - */ - method: string; - } - - export interface SignUpEventParameters { - /** - * A particular approach used in an operation; for example, "facebook" or "email" in the context of a sign_up or login event. - */ - method: string; - } - - export interface SpendVirtualCurrencyEventParameters { - /** - * An item name. - */ - item_name: string; - /** - * Name of virtual currency type. E.g. `gems`. - */ - virtual_currency_name: string; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value: number; - } - - export interface UnlockAchievementEventParameters { - /** - * Game achievement ID (String). - */ - achievement_id: string; - } - - export interface ViewCartEventParameters { - items?: Item[]; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value?: number; - } - - export interface ViewItemEventParameters { - items?: Item[]; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value?: number; - } - - export interface ViewSearchResultsParameters { - /** - * The search string/keywords used. - */ - search_term: string; - } - - export interface ViewItemListEventParameters { - items?: Item[]; - /** - * The ID of the list in which the item was presented to the user - */ - item_list_id?: string; - /** - * The name of the list in which the item was presented to the user - */ - item_list_name?: string; - } - - export interface ViewPromotionEventParameters { - items?: Item[]; - /** - * The location associated with the event. Preferred to be the Google Place ID that corresponds to the associated item but could be overridden to a custom location ID string - */ - location_id?: string; - /** - * The name of a creative used in a promotional spot - */ - creative_name?: string; - /** - * The name of a creative slot - */ - creative_slot?: string; - /** - * The ID of a product promotion - */ - promotion_id?: string; - /** - * The name of a product promotion - */ - promotion_name?: string; - } - - export interface AddShippingInfoParameters { - items?: Item[]; - /** - * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. - */ - currency?: string; - /** - * A context-specific numeric value which is accumulated automatically for each event type. Values - * can include revenue, distance, time and points. When a value is set, the accompanying `currency` - * parameter should also be defined. - */ - value?: number; - /** - * Coupon code for a purchasable item. - */ - coupon?: string; - /** - * The shipping tier (e.g. Ground, Air, Next-day) selected for delivery of the purchased item - */ - shipping_tier?: string; - } - - /** - * Unsupported in "Enhanced Ecommerce reports": - * https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-view_search_results - */ - // export interface ViewSearchResults { - // /** - // * The search string/keywords used. - // */ - // search_term: string; - // } - - // eslint-disable-next-line @typescript-eslint/no-empty-object-type - export interface Statics {} - - /** - * Analytics instance initialization options. Web only. - */ - export interface AnalyticsSettings { - config?: GtagConfigParams | EventParams; - } - - /** - * Additional options that can be passed to Analytics method calls such as logEvent. Web only. - */ - export interface AnalyticsCallOptions { - /** - * If true, this config or event call applies globally to all Google Analytics properties on the page. Web only. - */ - global: boolean; - } - - /** - * A set of common Google Analytics config settings recognized by gtag.js. Web only. - */ - export interface GtagConfigParams { - /** - * Whether or not a page view should be sent. - * If set to true (default), a page view is automatically sent upon initialization - * of analytics. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views } - */ - send_page_view?: boolean; - /** - * The title of the page. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views } - */ - page_title?: string; - /** - * The URL of the page. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view | Page views } - */ - page_location?: string; - /** - * Defaults to `auto`. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } - */ - cookie_domain?: string; - /** - * Defaults to 63072000 (two years, in seconds). - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } - */ - cookie_expires?: number; - /** - * Defaults to `_ga`. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } - */ - cookie_prefix?: string; - /** - * If set to true, will update cookies on each page load. - * Defaults to true. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } - */ - cookie_update?: boolean; - /** - * Appends additional flags to the cookie when set. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/cookies-user-id | Cookies and user identification } - */ - cookie_flags?: string; - /** - * If set to false, disables all advertising features with `gtag.js`. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features } - */ - allow_google_signals?: boolean; - /** - * If set to false, disables all advertising personalization with `gtag.js`. - * See {@link https://developers.google.com/analytics/devguides/collection/ga4/display-features | Disable advertising features } - */ - allow_ad_personalization_signals?: boolean; - - [key: string]: unknown; - } - - /** - * Standard gtag.js event parameters. For more information, see the GA4 reference documentation. Web only. - */ - export interface EventParams { - checkout_option?: string; - checkout_step?: number; - item_id?: string; - content_type?: string; - coupon?: string; - currency?: string; - description?: string; - fatal?: boolean; - items?: Item[]; - method?: string; - number?: string; - promotions?: Promotion[]; - screen_name?: string; - /** - * Firebase-specific. Use to log a `screen_name` to Firebase Analytics. - */ - firebase_screen?: string; - /** - * Firebase-specific. Use to log a `screen_class` to Firebase Analytics. - */ - firebase_screen_class?: string; - search_term?: string; - shipping?: Currency; - tax?: Currency; - transaction_id?: string; - value?: number; - event_label?: string; - event_category?: string; - shipping_tier?: string; - item_list_id?: string; - item_list_name?: string; - promotion_id?: string; - promotion_name?: string; - payment_type?: string; - affiliation?: string; - page_title?: string; - page_location?: string; - page_path?: string; - - [key: string]: unknown; - } - - /** - * Consent status settings for each consent type. - * For more information, see - * {@link https://developers.google.com/tag-platform/tag-manager/templates/consent-apis - * | the GA4 reference documentation for consent state and consent types}. - */ - export interface ConsentSettings { - /** Enables storage, such as cookies, related to advertising */ - ad_storage?: boolean; - /** Sets consent for sending user data to Google for online advertising purposes */ - ad_user_data?: boolean; - /** Sets consent for personalized advertising */ - ad_personalization?: boolean; - /** Enables storage, such as cookies, related to analytics (for example, visit duration) */ - analytics_storage?: boolean; - /** - * Enables storage that supports the functionality of the website or app such as language settings - */ - functionality_storage?: boolean; - /** Enables storage related to personalization such as video recommendations */ - personalization_storage?: boolean; - /** - * Enables storage related to security such as authentication functionality, fraud prevention, - * and other user protection. - */ - security_storage?: ConsentStatusString; - - [key: string]: unknown; - } - - /** - * Specifies custom options for your Firebase Analytics instance. - * You must set these before initializing `firebase.analytics()`. - */ - export interface SettingsOptions { - /** Sets custom name for `gtag` function. */ - gtagName?: string; - /** Sets custom name for `dataLayer` array used by `gtag.js`. */ - dataLayerName?: string; - } - - /** - * The Firebase Analytics service interface. - * - * > This module is available for the default app only. - * - * #### Example - * - * Get the Analytics service for the default app: - * - * ```js - * const defaultAppAnalytics = firebase.analytics(); - * ``` - */ - export class Module extends FirebaseModule { - /** - * Log a custom event with optional params. Note that there are various limits that applied - * to event parameters (total parameter count, etc), but analytics applies the limits during - * cloud processing, the errors will not be seen as Promise rejections when you call logEvent. - * While integrating this API in your app you are strongly encouraged to enable - * [DebugView](https://firebase.google.com/docs/analytics/debugview) - - * any errors in your events will show up in the firebase web console with links to relevant documentation - * - * #### Example - * - * ```js - * await firebase.analytics().logEvent('product_view', { - * id: '1234', - * }); - * ``` - * - * > 100 characters is the maximum length for param key names. - * - * @param name Event name must not conflict with any Reserved Events. - * @param params Parameters to be sent and displayed with the event. - * @param options Additional options that can be passed. Web only. - */ - logEvent( - name: string, - params?: { [key: string]: any }, - options?: AnalyticsCallOptions, - ): Promise; - - /** - * If true, allows the device to collect analytical data and send it to - * Firebase. Useful for GDPR. - * - * #### Example - * - * ```js - * // Disable collection - * await firebase.analytics().setAnalyticsCollectionEnabled(false); - * ``` - * - * @param enabled A boolean value representing whether Analytics collection is enabled or disabled. Analytics collection is enabled by default. - */ - setAnalyticsCollectionEnabled(enabled: boolean): Promise; - - /** - * Sets the duration of inactivity that terminates the current session. - * - * #### Example - * - * ```js - * // 20 minutes - * await firebase.analytics().setMinimumSessionDuration(900000); - * ``` - * - * @param milliseconds The default value is 1800000 (30 minutes). - */ - setSessionTimeoutDuration(milliseconds?: number): Promise; - - /** - * Retrieve the app instance id of the application. - * - * #### Example - * - * ```js - * const appInstanceId = await firebase.analytics().getAppInstanceId(); - * ``` - * - * @returns Returns the app instance id or null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. - */ - getAppInstanceId(): Promise; - - /** - * Retrieves the session id from the client. - * On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details. - * - * #### Example - * - * ```js - * const sessionId = await firebase.analytics().getSessionId(); - * ``` - * - * @returns Returns the session id or null if session is expired, null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. - */ - getSessionId(): Promise; - - /** - * Gives a user a unique identification. - * - * #### Example - * - * ```js - * // Set User - * await firebase.analytics().setUserId('123456789'); - * // Remove User - * await firebase.analytics().setUserId(null); - * ``` - * - * @param id Set to null to remove a previously assigned ID from analytics - * events - */ - setUserId(id: string | null): Promise; - - /** - * Sets a key/value pair of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - * - * #### Example - * - * ```js - * await firebase.analytics().setUserProperty('account_type', 'gold'); - * ``` - * - * @param name A user property identifier. - * @param value Set to null to remove a previously assigned ID from analytics events. - */ - setUserProperty(name: string, value: string | null): Promise; - - /** - * Sets multiple key/value pairs of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - * - * #### Example - * - * ```js - * await firebase.analytics().setUserProperties({ - * account_type: 'gold', - * account_name: 'Gold Badge', - * }); - * ``` - * - * > When you set user properties, be sure to never include personally identifiable information such as names, social security numbers, or email addresses, even in hashed form. - * - * @react-native-firebase - * @param properties Set a property value to null to remove it. - * @param options Additional options that can be passed. Web only. - */ - setUserProperties( - properties: { [key: string]: string | null }, - options?: AnalyticsCallOptions, - ): Promise; - - /** - * Clears all analytics data for this instance from the device and resets the app instance ID. - * - * #### Example - * - * ```js - * await firebase.analytics().resetAnalyticsData(); - * ``` - */ - resetAnalyticsData(): Promise; - - /** - * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported - * automatically for Google Play-based apps. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `purchase` - * - * #### Example - * - * ```js - * await firebase.analytics().logPurchase({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - */ - logPurchase(params: PurchaseEventParameters): Promise; - - /** - * Sets or clears the screen name and class the user is currently viewing - * - * #### Example - * - * ```js - * await firebase.analytics().logScreenView({ - * screen_class: 'ProductScreen', - * screen_name: 'ProductScreen', - * }); - * ``` - * - */ - logScreenView(params: ScreenViewParameters): Promise; - - /** - * Add Payment Info event. This event signifies that a user has submitted their payment information to your app. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `add_payment_info` - * - * #### Example - * - * ```js - * await firebase.analytics().logAddPaymentInfo({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - */ - logAddPaymentInfo(params: AddPaymentInfoEventParameters): Promise; - - /** - * E-Commerce Add To Cart event. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `add_to_cart` - * - * #### Example - * - * ```js - * await firebase.analytics().logAddToCart({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.AddToCartEventParameters}. - */ - logAddToCart(params: AddToCartEventParameters): Promise; - - /** - * E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. - * Use this event to identify popular gift items in your app. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `add_to_wishlist` - * - * #### Example - * - * ```js - * await firebase.analytics().logAddToWishlist({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.AddToWishlistEventParameters}. - */ - logAddToWishlist(params: AddToWishlistEventParameters): Promise; - - /** - * E-Commerce Add Shipping Info event. This event signifies that a user has submitted their shipping information. - * Use this event to identify popular gift items in your app. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `add_shipping_info` - * - * #### Example - * - * ```js - * await firebase.analytics().logAddShippingInfo({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.AddShippingInfoParameters}. - */ - logAddShippingInfo(params: AddShippingInfoParameters): Promise; - - /** - * App Open event. By logging this event when an App is moved to the foreground, developers can - * understand how often users leave and return during the course of a Session. Although Sessions - * are automatically reported, this event can provide further clarification around the continuous - * engagement of app-users. - * - * Logged event name: `app_open` - * - * #### Example - * - * ```js - * await firebase.analytics().logAppOpen(); - * ``` - */ - logAppOpen(): Promise; - - /** - * E-Commerce Begin Checkout event. This event signifies that a user has begun the process of - * checking out. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `begin_checkout` - * - * #### Example - * - * ```js - * await firebase.analytics().logBeginCheckout({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.BeginCheckoutEventParameters}. - */ - logBeginCheckout(params?: BeginCheckoutEventParameters): Promise; - - /** - * Log this event to supply the referral details of a re-engagement campaign. - * - * Logged event name: `campaign_details` - * - * #### Example - * - * ```js - * await firebase.analytics().logCampaignDetails({ - * source: 'email', - * medium: 'cta_button', - * campaign: 'newsletter', - * }); - * ``` - * - * @param params See {@link analytics.CampaignDetailsEventParameters}. - */ - logCampaignDetails(params: CampaignDetailsEventParameters): Promise; - - /** - * View Promotion event. This event signifies that a promotion was shown to a user. - * - * Logged event name: `view_promotion` - * - * #### Example - * - * ```js - * await firebase.analytics().logViewPromotion({ - * creative_name: 'the promotion', - * creative_slot: 'evening', - * location_id: 'london', - * promotion_id: '230593', - * promotion_name: 'london evening event', - * }); - * ``` - * - * @param params See {@link analytics.ViewPromotionEventParameters}. - */ - logViewPromotion(params: ViewPromotionEventParameters): Promise; - - /** - * Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app. Log this along with - * {@link analytics.logSpendVirtualCurrency} to better understand your virtual economy. - * - * Logged event name: `earn_virtual_currency` - * - * #### Example - * - * ```js - * await firebase.analytics().logEarnVirtualCurrency({ - * virtual_currency_name: 'coins', - * value: 100, - * }); - * ``` - * - * @param params See {@link analytics.EarnVirtualCurrencyEventParameters}. - */ - logEarnVirtualCurrency(params: EarnVirtualCurrencyEventParameters): Promise; - - /** - * Generate Lead event. Log this event when a lead has been generated in the app to understand - * the efficacy of your install and re-engagement campaigns. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `generate_lead` - * - * #### Example - * - * ```js - * await firebase.analytics().logGenerateLead({ - * currency: 'USD', - * value: 123, - * }); - * ``` - * - * @param params See {@link analytics.GenerateLeadEventParameters}. - */ - logGenerateLead(params?: GenerateLeadEventParameters): Promise; - - /** - * Join Group event. Log this event when a user joins a group such as a guild, team or family. - * Use this event to analyze how popular certain groups or social features are in your app - * - * Logged event name: `join_group` - * - * #### Example - * - * ```js - * await firebase.analytics().logJoinGroup({ - * group_id: '12345', - * }); - * ``` - * - * @param params See {@link analytics.JoinGroupEventParameters}. - */ - logJoinGroup(params: JoinGroupEventParameters): Promise; - - /** - * Level End event. - * - * Logged event name: `level_end` - * - * #### Example - * - * ```js - * await firebase.analytics().logLevelEnd({ - * level: 12, - * success: 'true' - * }); - * ``` - * - * @param params See {@link analytics.LevelEndEventParameters}. - */ - logLevelEnd(params: LevelEndEventParameters): Promise; - - /** - * Level Start event. - * - * Logged event name: `level_start` - * - * #### Example - * - * ```js - * await firebase.analytics().logLevelStart({ - * level: 12, - * }); - * ``` - * - * @param params See {@link analytics.LevelStartEventParameters}. - */ - logLevelStart(params: LevelStartEventParameters): Promise; - - /** - * Level Up event. This event signifies that a player has leveled up in your gaming app. - * It can help you gauge the level distribution of your userbase and help you identify certain levels that are difficult to pass. - * - * Logged event name: `level_up` - * - * #### Example - * - * ```js - * await firebase.analytics().logLevelUp({ - * level: 12, - * character: 'Snake', - * }); - * ``` - * - * @param params See {@link analytics.LevelUpEventParameters}. - */ - logLevelUp(params: LevelUpEventParameters): Promise; - - /** - * Login event. Apps with a login feature can report this event to signify that a user has logged in. - * - * Logged event name: `login` - * - * #### Example - * - * ```js - * await firebase.analytics().logLogin({ - * method: 'facebook.com', - * }); - * ``` - * - * @param params See {@link analytics.LoginEventParameters}. - */ - logLogin(params: LoginEventParameters): Promise; - - /** - * Post Score event. Log this event when the user posts a score in your gaming app. This event can - * help you understand how users are actually performing in your game and it can help you correlate - * high scores with certain audiences or behaviors. - * - * Logged event name: `post_score` - * - * #### Example - * - * ```js - * await firebase.analytics().logPostScore({ - * score: 567334, - * level: 3, - * character: 'Pete', - * }); - * ``` - * - * @param params See {@link analytics.PostScoreEventParameters}. - */ - logPostScore(params: PostScoreEventParameters): Promise; - - /** - * Remove from cart event. - * - * Logged event name: `remove_from_cart` - * - * #### Example - * - * ```js - * await firebase.analytics().logRemoveFromCart({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.RemoveFromCartEventParameters}. - */ - logRemoveFromCart(params: RemoveFromCartEventParameters): Promise; - - /** - * E-Commerce Refund event. This event signifies that a refund was issued. - * - * Logged event name: `remove_from_cart` - * - * #### Example - * - * ```js - * await firebase.analytics().logRefund({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.RefundEventParameters}. - */ - logRefund(params: RefundEventParameters): Promise; - - /** - * Search event. Apps that support search features can use this event to contextualize search - * operations by supplying the appropriate, corresponding parameters. This event can help you - * identify the most popular content in your app. - * - * Logged event name: `search` - * - * #### Example - * - * ```js - * await firebase.analytics().logSearch({ - * search_term: 't-shirts', - * }); - * ``` - * - * @param params See {@link analytics.SearchEventParameters}. - */ - logSearch(params: SearchEventParameters): Promise; - - /** - * Select Content event. This general purpose event signifies that a user has selected some - * content of a certain type in an app. The content can be any object in your app. This event - * can help you identify popular content and categories of content in your app. - * - * Logged event name: `select_content` - * - * #### Example - * - * ```js - * await firebase.analytics().logSelectContent({ - * content_type: 'clothing', - * item_id: 'abcd', - * }); - * ``` - * - * @param params See {@link analytics.SelectContentEventParameters}. - */ - logSelectContent(params: SelectContentEventParameters): Promise; - - /** - * Select Item event. This event signifies that an item was selected by a user from a list. - * Use the appropriate parameters to contextualize the event. - * Use this event to discover the most popular items selected. - * - * Logged event name: `select_item` - * - * #### Example - * - * ```js - * await firebase.analytics().logSelectItem({ - * item_list_id: '54690834', - * item_list_name: 't-shirts', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.SelectItemEventParameters}. - */ - logSelectItem(params: SelectItemEventParameters): Promise; - - /** - * Set checkout option event. - * - * Logged event name: `set_checkout_option` - * - * #### Example - * - * ```js - * await firebase.analytics().logSetCheckoutOption({ - * checkout_step: 2, - * checkout_option: 'false', - * }); - * ``` - * - * @param params See {@link analytics.SetCheckoutOptionEventParameters}. - */ - logSetCheckoutOption(params: any): Promise; - - /** - * Share event. Apps with social features can log the Share event to identify the most viral content. - * - * Logged event name: `share` - * - * #### Example - * - * ```js - * await firebase.analytics().logShare({ - * content_type: 't-shirts', - * item_id: '12345', - * method: 'twitter.com', - * }); - * ``` - * - * @param params See {@link analytics.ShareEventParameters}. - */ - logShare(params: ShareEventParameters): Promise; - - /** - * Sign Up event. This event indicates that a user has signed up for an account in your app. - * The parameter signifies the method by which the user signed up. Use this event to understand - * the different behaviors between logged in and logged out users. - * - * Logged event name: `sign_up` - * - * #### Example - * - * ```js - * await firebase.analytics().logSignUp({ - * method: 'facebook.com', - * }); - * ``` - * - * @param params See {@link analytics.SignUpEventParameters}. - */ - logSignUp(params: SignUpEventParameters): Promise; - - /** - * Spend Virtual Currency event. This event tracks the sale of virtual goods in your app and can - * help you identify which virtual goods are the most popular objects of purchase. - * - * Logged event name: `spend_virtual_currency` - * - * #### Example - * - * ```js - * await firebase.analytics().logSpendVirtualCurrency({ - * item_name: 'battle_pass', - * virtual_currency_name: 'coins', - * value: 100, - * }); - * ``` - * - * @param params See {@link analytics.SpendVirtualCurrencyEventParameters}. - */ - logSpendVirtualCurrency(params: SpendVirtualCurrencyEventParameters): Promise; - - /** - * Tutorial Begin event. This event signifies the start of the on-boarding process in your app. - * Use this in a funnel with {@link analytics#logTutorialComplete} to understand how many users - * complete this process and move on to the full app experience. - * - * Logged event name: `tutorial_begin` - * - * #### Example - * - * ```js - * await firebase.analytics().logTutorialBegin(); - * ``` - */ - logTutorialBegin(): Promise; - - /** - * Tutorial End event. Use this event to signify the user's completion of your app's on-boarding process. - * Add this to a funnel with {@link analytics#logTutorialBegin} to understand how many users - * complete this process and move on to the full app experience. - * - * Logged event name: `tutorial_complete` - * - * #### Example - * - * ```js - * await firebase.analytics().logTutorialComplete(); - * ``` - */ - logTutorialComplete(): Promise; - - /** - * Select promotion event. This event signifies that a user has selected a promotion offer. Use the - * appropriate parameters to contextualize the event, such as the item(s) for which the promotion applies. - * - * Logged event name: `select_promotion` - * - * #### Example - * - * ```js - * await firebase.analytics().logSelectPromotion({ - * creative_name: 'the promotion', - * creative_slot: 'evening', - * location_id: 'london', - * promotion_id: '230593', - * promotion_name: 'london evening event', - * }); - * ``` - * @param params See {@link analytics.SelectPromotionEventParameters}. - */ - logSelectPromotion(params: SelectPromotionEventParameters): Promise; - - /** - * Unlock Achievement event. Log this event when the user has unlocked an achievement in your game. - * Since achievements generally represent the breadth of a gaming experience, this event can help - * you understand how many users are experiencing all that your game has to offer. - * - * Logged event name: `unlock_achievement` - * - * #### Example - * - * ```js - * await firebase.analytics().logUnlockAchievement({ - * achievement_id: '12345', - * }); - * ``` - * - * @param params See {@link analytics.UnlockAchievementEventParameters}. - */ - logUnlockAchievement(params: UnlockAchievementEventParameters): Promise; - - /** - * View Item event. This event signifies that some content was shown to the user. This content - * may be a product, a screen or just a simple image or text. Use the appropriate parameters - * to contextualize the event. Use this event to discover the most popular items viewed in your app. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `view_item` - * - * #### Example - * - * ```js - * await firebase.analytics().logViewItem({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.ViewItemEventParameters}. - */ - logViewItem(params: ViewItemEventParameters): Promise; - - /** - * E-commerce View Cart event. This event signifies that a user has viewed their cart. Use this to analyze your purchase funnel. - * - * If you supply the `value` parameter, you must also supply the `currency` parameter so that revenue metrics can be computed accurately. - * - * Logged event name: `view_cart` - * - * #### Example - * - * ```js - * await firebase.analytics().logViewCart({ - * value: 100, - * currency: 'usd', - * items: [{ - * item_brand: 'cool-shirt-brand', - * item_id: '23456', - * item_name: 'orange t-shirt', - * item_category: 'round necked t-shirts', - * }] - * }); - * ``` - * - * @param params See {@link analytics.ViewCartEventParameters}. - */ - logViewCart(params: ViewCartEventParameters): Promise; - - /** - * View Item List event. Log this event when the user has been presented with a list of items of a certain category. - * - * Logged event name: `view_item_list` - * - * #### Example - * - * ```js - * await firebase.analytics().logViewItemList({ - * item_list_name: 't-shirts', - * }); - * ``` - * - * @param params See {@link analytics.ViewItemListEventParameters}. - */ - logViewItemList(params: ViewItemListEventParameters): Promise; - - /** - * View Search Results event. Log this event when the user has been presented with the results of a search. - * - * Logged event name: `view_search_results` - * - * #### Example - * - * ```js - * await firebase.analytics().logViewSearchResults({ - * search_term: 'clothing', - * }); - * ``` - * - * @param params See {@link analytics.ViewSearchResultsParameters}. - */ - logViewSearchResults(params: ViewSearchResultsParameters): Promise; - - /** - * Adds parameters that will be set on every event logged from the SDK, including automatic ones. - * - * #### Example - * - * ```js - * await firebase.analytics().setDefaultEventParameters({ - * userId: '1234', - * }); - * ``` - * - * - * @param params Parameters to be added to the map of parameters added to every event. - * They will be added to the map of default event parameters, replacing any existing - * parameter with the same name. Valid parameter values are String, long, and double. - * Setting a key's value to null will clear that parameter. Passing in a null bundle - * will clear all parameters. - */ - setDefaultEventParameters(params?: { [key: string]: any }): Promise; - - /** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * - * @platform ios - * @param emailAddress email address, properly formatted complete with domain name e.g, 'user@example.com' - */ - initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress: string): Promise; - - /** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * You need to pass the sha256-hashed of normalized email address to this function. See [this link](https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials) for more information. - * - * @platform ios - * @param hashedEmailAddress sha256-hashed of normalized email address, properly formatted complete with domain name e.g, 'user@example.com' - */ - initiateOnDeviceConversionMeasurementWithHashedEmailAddress( - hashedEmailAddress: string, - ): Promise; - - /** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * - * @platform ios - * @param phoneNumber phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - */ - initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber: string): Promise; - - /** - * Start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile. - * You need to pass the sha256-hashed of phone number in E.164 format. See [this link](https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials) for more information. - * - * @platform ios - * @param hashedPhoneNumber sha256-hashed of normalized phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - */ - initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( - hashedPhoneNumber: string, - ): Promise; - - /** - * For Consent Mode! - * - * #### Example - * - * ```js - * // Disable consent - * await firebase.analytics().setConsent({ - * ad_personalization: false, - * analytics_storage: false, - * ad_storage: false, - * ad_user_data: false, - * }); - * ``` - * - * Sets the applicable end user consent state (e.g., for device identifiers) for this app on this device. - * Use the consent map to specify individual consent type values. - * Settings are persisted across app sessions. - * @param consentSettings Consent status settings for each consent type. - */ - setConsent(consentSettings: ConsentSettings): Promise; - } - - /** - * Any custom event name string not in the standard list of recommended event names. - */ - export declare type CustomEventName = T extends EventNameString ? never : T; - /** - * Type for standard Google Analytics event names. logEvent also accepts any custom string and interprets it as a custom event name. - * See https://firebase.google.com/docs/reference/js/analytics.md#eventnamestring - */ - export declare type EventNameString = - | 'add_payment_info' - | 'add_shipping_info' - | 'add_to_cart' - | 'add_to_wishlist' - | 'begin_checkout' - | 'checkout_progress' - | 'exception' - | 'generate_lead' - | 'login' - | 'page_view' - | 'purchase' - | 'refund' - | 'remove_from_cart' - | 'screen_view' - | 'search' - | 'select_content' - | 'select_item' - | 'select_promotion' - | 'set_checkout_option' - | 'share' - | 'sign_up' - | 'timing_complete' - | 'view_cart' - | 'view_item' - | 'view_item_list' - | 'view_promotion' - | 'view_search_results'; -} - -declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< - FirebaseAnalyticsTypes.Module, - FirebaseAnalyticsTypes.Statics ->; - -export const firebase: ReactNativeFirebase.Module & { - analytics: typeof defaultExport; - app( - name?: string, - ): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsTypes.Module }; -}; - -export * from './modular'; - -export default defaultExport; - -/** - * Attach namespace to `firebase.` and `FirebaseApp.`. - */ -declare module '@react-native-firebase/app' { - namespace ReactNativeFirebase { - import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics; - - interface Module { - analytics: FirebaseModuleWithStatics< - FirebaseAnalyticsTypes.Module, - FirebaseAnalyticsTypes.Statics - >; - } - - interface FirebaseApp { - analytics(): FirebaseAnalyticsTypes.Module; - } - } -} diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index 9605817464..c3dc70501a 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -3,6 +3,44 @@ import { getApp } from '@react-native-firebase/app'; import { Platform } from 'react-native'; import type { ReactNativeFirebase } from '@react-native-firebase/app'; import type { FirebaseAnalyticsTypes } from './types'; +import type { + AnalyticsSettings, + AnalyticsCallOptions, + ConsentSettings, + AddPaymentInfoEventParameters, + ScreenViewParameters, + AddShippingInfoParameters, + AddToCartEventParameters, + AddToWishlistEventParameters, + BeginCheckoutEventParameters, + CampaignDetailsEventParameters, + EarnVirtualCurrencyEventParameters, + GenerateLeadEventParameters, + JoinGroupEventParameters, + LevelEndEventParameters, + LevelStartEventParameters, + LevelUpEventParameters, + LoginEventParameters, + PostScoreEventParameters, + SelectContentEventParameters, + PurchaseEventParameters, + RefundEventParameters, + RemoveFromCartEventParameters, + SearchEventParameters, + SelectItemEventParameters, + SetCheckoutOptionEventParameters, + SelectPromotionEventParameters, + ShareEventParameters, + SignUpEventParameters, + SpendVirtualCurrencyEventParameters, + UnlockAchievementEventParameters, + ViewCartEventParameters, + ViewItemEventParameters, + ViewItemListEventParameters, + ViewPromotionEventParameters, + ViewSearchResultsParameters, + SettingsOptions, +} from '../types/analytics'; /** * Returns an Analytics instance for the given app. @@ -19,7 +57,7 @@ export function getAnalytics(app?: ReactNativeFirebase.FirebaseApp): FirebaseAna */ export function initializeAnalytics( app: ReactNativeFirebase.FirebaseApp, - _options?: FirebaseAnalyticsTypes.AnalyticsSettings, + _options?: AnalyticsSettings, ): FirebaseAnalyticsTypes.Module { return getApp(app.name).analytics(); } @@ -45,7 +83,7 @@ export function logEvent( analytics: FirebaseAnalyticsTypes.Module, name: string, params: { [key: string]: any } = {}, - options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, + options: AnalyticsCallOptions = { global: false }, ): Promise { // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally return analytics.logEvent.call(analytics, name, params, options, MODULAR_DEPRECATION_ARG); @@ -123,7 +161,7 @@ export function setUserProperty( export function setUserProperties( analytics: FirebaseAnalyticsTypes.Module, properties: { [key: string]: string | null }, - options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, + options: AnalyticsCallOptions = { global: false }, ): Promise { // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally return analytics.setUserProperties.call(analytics, properties, options, MODULAR_DEPRECATION_ARG); @@ -143,7 +181,7 @@ export function resetAnalyticsData(analytics: FirebaseAnalyticsTypes.Module): Pr */ export function logAddPaymentInfo( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.AddPaymentInfoEventParameters, + params: AddPaymentInfoEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logAddPaymentInfo(params); @@ -154,7 +192,7 @@ export function logAddPaymentInfo( */ export function logScreenView( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.ScreenViewParameters, + params: ScreenViewParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logScreenView(params); @@ -165,7 +203,7 @@ export function logScreenView( */ export function logAddShippingInfo( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.AddShippingInfoParameters, + params: AddShippingInfoParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logAddShippingInfo(params); @@ -176,7 +214,7 @@ export function logAddShippingInfo( */ export function logAddToCart( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.AddToCartEventParameters, + params: AddToCartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logAddToCart(params); @@ -187,7 +225,7 @@ export function logAddToCart( */ export function logAddToWishlist( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.AddToWishlistEventParameters, + params: AddToWishlistEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logAddToWishlist(params); @@ -206,7 +244,7 @@ export function logAppOpen(analytics: FirebaseAnalyticsTypes.Module): Promise { // This is deprecated for both namespaced and modular. return analytics.logBeginCheckout(params); @@ -217,7 +255,7 @@ export function logBeginCheckout( */ export function logCampaignDetails( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.CampaignDetailsEventParameters, + params: CampaignDetailsEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logCampaignDetails(params); @@ -228,7 +266,7 @@ export function logCampaignDetails( */ export function logEarnVirtualCurrency( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.EarnVirtualCurrencyEventParameters, + params: EarnVirtualCurrencyEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logEarnVirtualCurrency(params); @@ -239,7 +277,7 @@ export function logEarnVirtualCurrency( */ export function logGenerateLead( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.GenerateLeadEventParameters, + params: GenerateLeadEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logGenerateLead(params); @@ -250,7 +288,7 @@ export function logGenerateLead( */ export function logJoinGroup( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.JoinGroupEventParameters, + params: JoinGroupEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logJoinGroup(params); @@ -261,7 +299,7 @@ export function logJoinGroup( */ export function logLevelEnd( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.LevelEndEventParameters, + params: LevelEndEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logLevelEnd(params); @@ -272,7 +310,7 @@ export function logLevelEnd( */ export function logLevelStart( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.LevelStartEventParameters, + params: LevelStartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logLevelStart(params); @@ -283,7 +321,7 @@ export function logLevelStart( */ export function logLevelUp( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.LevelUpEventParameters, + params: LevelUpEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logLevelUp(params); @@ -294,7 +332,7 @@ export function logLevelUp( */ export function logLogin( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.LoginEventParameters, + params: LoginEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logLogin(params); @@ -305,7 +343,7 @@ export function logLogin( */ export function logPostScore( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.PostScoreEventParameters, + params: PostScoreEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logPostScore(params); @@ -319,7 +357,7 @@ export function logPostScore( */ export function logSelectContent( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.SelectContentEventParameters, + params: SelectContentEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logSelectContent(params); @@ -333,7 +371,7 @@ export function logSelectContent( */ export function logPurchase( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.PurchaseEventParameters, + params: PurchaseEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logPurchase(params); @@ -347,7 +385,7 @@ export function logPurchase( */ export function logRefund( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.RefundEventParameters, + params: RefundEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logRefund(params); @@ -361,7 +399,7 @@ export function logRefund( */ export function logRemoveFromCart( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.RemoveFromCartEventParameters, + params: RemoveFromCartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logRemoveFromCart(params); @@ -375,7 +413,7 @@ export function logRemoveFromCart( */ export function logSearch( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.SearchEventParameters, + params: SearchEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logSearch(params); @@ -389,7 +427,7 @@ export function logSearch( */ export function logSelectItem( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.SelectItemEventParameters, + params: SelectItemEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logSelectItem(params); @@ -403,7 +441,7 @@ export function logSelectItem( */ export function logSetCheckoutOption( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.SetCheckoutOptionEventParameters, + params: SetCheckoutOptionEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logSetCheckoutOption(params); @@ -417,7 +455,7 @@ export function logSetCheckoutOption( */ export function logSelectPromotion( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.SelectPromotionEventParameters, + params: SelectPromotionEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logSelectPromotion(params); @@ -431,7 +469,7 @@ export function logSelectPromotion( */ export function logShare( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.ShareEventParameters, + params: ShareEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logShare(params); @@ -445,7 +483,7 @@ export function logShare( */ export function logSignUp( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.SignUpEventParameters, + params: SignUpEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logSignUp(params); @@ -459,7 +497,7 @@ export function logSignUp( */ export function logSpendVirtualCurrency( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.SpendVirtualCurrencyEventParameters, + params: SpendVirtualCurrencyEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logSpendVirtualCurrency(params); @@ -493,7 +531,7 @@ export function logTutorialComplete(analytics: FirebaseAnalyticsTypes.Module): P */ export function logUnlockAchievement( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.UnlockAchievementEventParameters, + params: UnlockAchievementEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logUnlockAchievement(params); @@ -507,7 +545,7 @@ export function logUnlockAchievement( */ export function logViewCart( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.ViewCartEventParameters, + params: ViewCartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logViewCart(params); @@ -521,7 +559,7 @@ export function logViewCart( */ export function logViewItem( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.ViewItemEventParameters, + params: ViewItemEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logViewItem(params); @@ -535,7 +573,7 @@ export function logViewItem( */ export function logViewItemList( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.ViewItemListEventParameters, + params: ViewItemListEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logViewItemList(params); @@ -549,7 +587,7 @@ export function logViewItemList( */ export function logViewPromotion( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.ViewPromotionEventParameters, + params: ViewPromotionEventParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logViewPromotion(params); @@ -563,7 +601,7 @@ export function logViewPromotion( */ export function logViewSearchResults( analytics: FirebaseAnalyticsTypes.Module, - params: FirebaseAnalyticsTypes.ViewSearchResultsParameters, + params: ViewSearchResultsParameters, ): Promise { // This is deprecated for both namespaced and modular. return analytics.logViewSearchResults(params); @@ -683,7 +721,7 @@ export function isSupported(): Promise { */ export function setConsent( analytics: FirebaseAnalyticsTypes.Module, - consentSettings: FirebaseAnalyticsTypes.ConsentSettings, + consentSettings: ConsentSettings, ): Promise { // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally return analytics.setConsent.call(analytics, consentSettings, MODULAR_DEPRECATION_ARG); @@ -695,7 +733,7 @@ export function setConsent( * @param {SettingsOptions} options - See SettingsOptions. * @returns {void} */ -export function settings(_options: FirebaseAnalyticsTypes.SettingsOptions): void { +export function settings(_options: SettingsOptions): void { // Returns nothing until Web implemented. } diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 868f04c6eb..98316b7acc 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -41,10 +41,43 @@ import { validateStruct, validateCompound } from './struct'; import { RNFBAnalyticsModule } from './web/RNFBAnalyticsModule'; import { version } from './version'; import * as structs from './structs'; -import { Statics } from '../types/analytics'; - -// Import types from the index file -import type { FirebaseAnalyticsTypes } from './types'; +import { + Statics, + AnalyticsCallOptions, + ConsentSettings, + AddPaymentInfoEventParameters, + ScreenViewParameters, + AddShippingInfoParameters, + AddToCartEventParameters, + AddToWishlistEventParameters, + BeginCheckoutEventParameters, + CampaignDetailsEventParameters, + EarnVirtualCurrencyEventParameters, + GenerateLeadEventParameters, + JoinGroupEventParameters, + LevelEndEventParameters, + LevelStartEventParameters, + LevelUpEventParameters, + LoginEventParameters, + PostScoreEventParameters, + SelectContentEventParameters, + PurchaseEventParameters, + RefundEventParameters, + RemoveFromCartEventParameters, + SearchEventParameters, + SelectItemEventParameters, + SetCheckoutOptionEventParameters, + SelectPromotionEventParameters, + ShareEventParameters, + SignUpEventParameters, + SpendVirtualCurrencyEventParameters, + UnlockAchievementEventParameters, + ViewCartEventParameters, + ViewItemEventParameters, + ViewItemListEventParameters, + ViewPromotionEventParameters, + ViewSearchResultsParameters, +} from '../types/analytics'; export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< FirebaseAnalyticsModule, @@ -93,7 +126,7 @@ const ReservedEventNames: readonly string[] = [ 'user_engagement', ] as const; -const statics: FirebaseAnalyticsTypes.Statics = {}; +const statics: Statics = {}; const namespace = 'analytics'; @@ -105,7 +138,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { logEvent( name: string, params: { [key: string]: any } = {}, - options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, + options: AnalyticsCallOptions = { global: false }, ): Promise { if (!isString(name)) { throw new Error("firebase.analytics().logEvent(*) 'name' expected a string value."); @@ -202,7 +235,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { setUserProperties( properties: { [key: string]: string | null }, - options: FirebaseAnalyticsTypes.AnalyticsCallOptions = { global: false }, + options: AnalyticsCallOptions = { global: false }, ): Promise { if (!isObject(properties)) { throw new Error( @@ -241,7 +274,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { return this.native.resetAnalyticsData(); } - setConsent(consentSettings: FirebaseAnalyticsTypes.ConsentSettings): Promise { + setConsent(consentSettings: ConsentSettings): Promise { if (!isObject(consentSettings)) { throw new Error( 'firebase.analytics().setConsent(*): The supplied arg must be an object of key/values.', @@ -266,7 +299,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { /** ------------------- * EVENTS * -------------------- */ - logAddPaymentInfo(object: FirebaseAnalyticsTypes.AddPaymentInfoEventParameters): Promise { + logAddPaymentInfo(object: AddPaymentInfoEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logAddPaymentInfo(*): The supplied arg must be an object of key/values.', @@ -281,7 +314,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logScreenView(object: FirebaseAnalyticsTypes.ScreenViewParameters): Promise { + logScreenView(object: ScreenViewParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logScreenView(*): The supplied arg must be an object of key/values.', @@ -294,7 +327,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logAddShippingInfo(object: FirebaseAnalyticsTypes.AddShippingInfoParameters = {}): Promise { + logAddShippingInfo(object: AddShippingInfoParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logAddShippingInfo(*): The supplied arg must be an object of key/values.', @@ -313,7 +346,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logAddToCart(object: FirebaseAnalyticsTypes.AddToCartEventParameters = {}): Promise { + logAddToCart(object: AddToCartEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logAddToCart(*): The supplied arg must be an object of key/values.', @@ -328,9 +361,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logAddToWishlist( - object: FirebaseAnalyticsTypes.AddToWishlistEventParameters = {}, - ): Promise { + logAddToWishlist(object: AddToWishlistEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logAddToWishlist(*): The supplied arg must be an object of key/values.', @@ -349,9 +380,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { return this.logEvent('app_open'); } - logBeginCheckout( - object: FirebaseAnalyticsTypes.BeginCheckoutEventParameters = {}, - ): Promise { + logBeginCheckout(object: BeginCheckoutEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logBeginCheckout(*): The supplied arg must be an object of key/values.', @@ -366,7 +395,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logCampaignDetails(object: FirebaseAnalyticsTypes.CampaignDetailsEventParameters): Promise { + logCampaignDetails(object: CampaignDetailsEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logCampaignDetails(*): The supplied arg must be an object of key/values.', @@ -383,9 +412,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logEarnVirtualCurrency( - object: FirebaseAnalyticsTypes.EarnVirtualCurrencyEventParameters, - ): Promise { + logEarnVirtualCurrency(object: EarnVirtualCurrencyEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logEarnVirtualCurrency(*): The supplied arg must be an object of key/values.', @@ -402,7 +429,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logGenerateLead(object: FirebaseAnalyticsTypes.GenerateLeadEventParameters = {}): Promise { + logGenerateLead(object: GenerateLeadEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logGenerateLead(*): The supplied arg must be an object of key/values.', @@ -417,7 +444,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logJoinGroup(object: FirebaseAnalyticsTypes.JoinGroupEventParameters): Promise { + logJoinGroup(object: JoinGroupEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logJoinGroup(*): The supplied arg must be an object of key/values.', @@ -430,7 +457,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logLevelEnd(object: FirebaseAnalyticsTypes.LevelEndEventParameters): Promise { + logLevelEnd(object: LevelEndEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logLevelEnd(*): The supplied arg must be an object of key/values.', @@ -443,7 +470,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logLevelStart(object: FirebaseAnalyticsTypes.LevelStartEventParameters): Promise { + logLevelStart(object: LevelStartEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logLevelStart(*): The supplied arg must be an object of key/values.', @@ -456,7 +483,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logLevelUp(object: FirebaseAnalyticsTypes.LevelUpEventParameters): Promise { + logLevelUp(object: LevelUpEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logLevelUp(*): The supplied arg must be an object of key/values.', @@ -469,7 +496,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logLogin(object: FirebaseAnalyticsTypes.LoginEventParameters): Promise { + logLogin(object: LoginEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logLogin(*): The supplied arg must be an object of key/values.', @@ -482,7 +509,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logPostScore(object: FirebaseAnalyticsTypes.PostScoreEventParameters): Promise { + logPostScore(object: PostScoreEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logPostScore(*): The supplied arg must be an object of key/values.', @@ -495,7 +522,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logSelectContent(object: FirebaseAnalyticsTypes.SelectContentEventParameters): Promise { + logSelectContent(object: SelectContentEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logSelectContent(*): The supplied arg must be an object of key/values.', @@ -508,7 +535,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logPurchase(object: FirebaseAnalyticsTypes.PurchaseEventParameters = {}): Promise { + logPurchase(object: PurchaseEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logPurchase(*): The supplied arg must be an object of key/values.', @@ -523,7 +550,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logRefund(object: FirebaseAnalyticsTypes.RefundEventParameters = {}): Promise { + logRefund(object: RefundEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logRefund(*): The supplied arg must be an object of key/values.', @@ -538,9 +565,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logRemoveFromCart( - object: FirebaseAnalyticsTypes.RemoveFromCartEventParameters = {}, - ): Promise { + logRemoveFromCart(object: RemoveFromCartEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logRemoveFromCart(*): The supplied arg must be an object of key/values.', @@ -555,7 +580,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logSearch(object: FirebaseAnalyticsTypes.SearchEventParameters): Promise { + logSearch(object: SearchEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logSearch(*): The supplied arg must be an object of key/values.', @@ -568,7 +593,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logSelectItem(object: FirebaseAnalyticsTypes.SelectItemEventParameters): Promise { + logSelectItem(object: SelectItemEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logSelectItem(*): The supplied arg must be an object of key/values.', @@ -581,9 +606,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logSetCheckoutOption( - object: FirebaseAnalyticsTypes.SetCheckoutOptionEventParameters, - ): Promise { + logSetCheckoutOption(object: SetCheckoutOptionEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logSetCheckoutOption(*): The supplied arg must be an object of key/values.', @@ -600,7 +623,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logSelectPromotion(object: FirebaseAnalyticsTypes.SelectPromotionEventParameters): Promise { + logSelectPromotion(object: SelectPromotionEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logSelectPromotion(*): The supplied arg must be an object of key/values.', @@ -617,7 +640,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logShare(object: FirebaseAnalyticsTypes.ShareEventParameters): Promise { + logShare(object: ShareEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logShare(*): The supplied arg must be an object of key/values.', @@ -630,7 +653,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logSignUp(object: FirebaseAnalyticsTypes.SignUpEventParameters): Promise { + logSignUp(object: SignUpEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logSignUp(*): The supplied arg must be an object of key/values.', @@ -643,9 +666,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logSpendVirtualCurrency( - object: FirebaseAnalyticsTypes.SpendVirtualCurrencyEventParameters, - ): Promise { + logSpendVirtualCurrency(object: SpendVirtualCurrencyEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logSpendVirtualCurrency(*): The supplied arg must be an object of key/values.', @@ -670,9 +691,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { return this.logEvent('tutorial_complete'); } - logUnlockAchievement( - object: FirebaseAnalyticsTypes.UnlockAchievementEventParameters, - ): Promise { + logUnlockAchievement(object: UnlockAchievementEventParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logUnlockAchievement(*): The supplied arg must be an object of key/values.', @@ -689,7 +708,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logViewCart(object: FirebaseAnalyticsTypes.ViewCartEventParameters = {}): Promise { + logViewCart(object: ViewCartEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logViewCart(*): The supplied arg must be an object of key/values.', @@ -704,7 +723,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logViewItem(object: FirebaseAnalyticsTypes.ViewItemEventParameters = {}): Promise { + logViewItem(object: ViewItemEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logViewItem(*): The supplied arg must be an object of key/values.', @@ -718,7 +737,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logViewItemList(object: FirebaseAnalyticsTypes.ViewItemListEventParameters = {}): Promise { + logViewItemList(object: ViewItemListEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logViewItemList(*): The supplied arg must be an object of key/values.', @@ -731,9 +750,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { ); } - logViewPromotion( - object: FirebaseAnalyticsTypes.ViewPromotionEventParameters = {}, - ): Promise { + logViewPromotion(object: ViewPromotionEventParameters = {}): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logViewPromotion(*): The supplied arg must be an object of key/values.', @@ -749,7 +766,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { * Unsupported in "Enhanced Ecommerce reports": * https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-view_search_results */ - logViewSearchResults(object: FirebaseAnalyticsTypes.ViewSearchResultsParameters): Promise { + logViewSearchResults(object: ViewSearchResultsParameters): Promise { if (!isObject(object)) { throw new Error( 'firebase.analytics().logViewSearchResults(*): The supplied arg must be an object of key/values.', From 392d88299f988045d63946614873936f8e0450ff Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 07:12:01 +0100 Subject: [PATCH 16/49] chore: fix export types --- packages/analytics/lib/namespaced.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 98316b7acc..4f9793e5a1 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -79,18 +79,6 @@ import { ViewSearchResultsParameters, } from '../types/analytics'; -export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< - FirebaseAnalyticsModule, - Statics ->; - -// export declare firebase: FirebaseAnalyticsModule & { -// analytics: typeof defaultExport; -// app( -// name?: string, -// ): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsTypes.Module }; -// }; - const ReservedEventNames: readonly string[] = [ 'ad_activeview', 'ad_click', @@ -880,10 +868,18 @@ export default createModuleNamespace({ ModuleClass: FirebaseAnalyticsModule, }); +// Register the interop module for non-native platforms. +setReactNativeModule(nativeModuleName, RNFBAnalyticsModule); + // import analytics, { firebase } from '@react-native-firebase/analytics'; // analytics().logEvent(...); // firebase.analytics().logEvent(...); -export const firebase = getFirebaseRoot(); +export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< + FirebaseAnalyticsModule, + Statics +>; -// Register the interop module for non-native platforms. -setReactNativeModule(nativeModuleName, RNFBAnalyticsModule); +export const firebase: FirebaseAnalyticsModule & { + analytics: typeof defaultExport; + app(name?: string): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsModule }; +} = getFirebaseRoot(); From 66870da9a7ca9f3be1b525c72076a64e86a58462 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 07:34:11 +0100 Subject: [PATCH 17/49] chore: use correct type return + extend getApp() --- packages/analytics/lib/index.ts | 117 ++++++++++++++------------- packages/analytics/lib/namespaced.ts | 3 + 2 files changed, 63 insertions(+), 57 deletions(-) diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index c3dc70501a..b0d9517504 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -1,8 +1,8 @@ import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; +import { FirebaseAnalyticsModule } from './namespaced'; import { getApp } from '@react-native-firebase/app'; import { Platform } from 'react-native'; import type { ReactNativeFirebase } from '@react-native-firebase/app'; -import type { FirebaseAnalyticsTypes } from './types'; import type { AnalyticsSettings, AnalyticsCallOptions, @@ -42,10 +42,16 @@ import type { SettingsOptions, } from '../types/analytics'; +declare module '@react-native-firebase/app' { + function getApp( + name?: string, + ): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsModule }; +} + /** * Returns an Analytics instance for the given app. */ -export function getAnalytics(app?: ReactNativeFirebase.FirebaseApp): FirebaseAnalyticsTypes.Module { +export function getAnalytics(app?: ReactNativeFirebase.FirebaseApp): FirebaseAnalyticsModule { if (app) { return getApp(app.name).analytics(); } @@ -58,7 +64,7 @@ export function getAnalytics(app?: ReactNativeFirebase.FirebaseApp): FirebaseAna export function initializeAnalytics( app: ReactNativeFirebase.FirebaseApp, _options?: AnalyticsSettings, -): FirebaseAnalyticsTypes.Module { +): FirebaseAnalyticsModule { return getApp(app.name).analytics(); } @@ -66,7 +72,7 @@ export function initializeAnalytics( * Retrieves a unique Google Analytics identifier for the web client. */ export async function getGoogleAnalyticsClientId( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, ): Promise { if (Platform.OS === 'android' || Platform.OS === 'ios') { throw new Error('getGoogleAnalyticsClientId is web-only.'); @@ -80,7 +86,7 @@ export async function getGoogleAnalyticsClientId( * Log a custom event with optional params. */ export function logEvent( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, name: string, params: { [key: string]: any } = {}, options: AnalyticsCallOptions = { global: false }, @@ -93,7 +99,7 @@ export function logEvent( * If true, allows the device to collect analytical data and send it to Firebase. Useful for GDPR. */ export function setAnalyticsCollectionEnabled( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, enabled: boolean, ): Promise { // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally @@ -104,7 +110,7 @@ export function setAnalyticsCollectionEnabled( * Sets the duration of inactivity that terminates the current session. */ export function setSessionTimeoutDuration( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, milliseconds: number = 1800000, ): Promise { // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS @@ -115,7 +121,7 @@ export function setSessionTimeoutDuration( /** * Retrieve the app instance id of the application. */ -export function getAppInstanceId(analytics: FirebaseAnalyticsTypes.Module): Promise { +export function getAppInstanceId(analytics: FirebaseAnalyticsModule): Promise { // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally return analytics.getAppInstanceId.call(analytics, MODULAR_DEPRECATION_ARG); @@ -125,7 +131,7 @@ export function getAppInstanceId(analytics: FirebaseAnalyticsTypes.Module): Prom * Retrieves the session id from the client. * On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details. */ -export function getSessionId(analytics: FirebaseAnalyticsTypes.Module): Promise { +export function getSessionId(analytics: FirebaseAnalyticsModule): Promise { // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally return analytics.getSessionId.call(analytics, MODULAR_DEPRECATION_ARG); @@ -134,10 +140,7 @@ export function getSessionId(analytics: FirebaseAnalyticsTypes.Module): Promise< /** * Gives a user a unique identification. */ -export function setUserId( - analytics: FirebaseAnalyticsTypes.Module, - id: string | null, -): Promise { +export function setUserId(analytics: FirebaseAnalyticsModule, id: string | null): Promise { // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally return analytics.setUserId.call(analytics, id, MODULAR_DEPRECATION_ARG); } @@ -146,7 +149,7 @@ export function setUserId( * Sets a key/value pair of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. */ export function setUserProperty( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, name: string, value: string | null, ): Promise { @@ -159,7 +162,7 @@ export function setUserProperty( * Sets multiple key/value pairs of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. */ export function setUserProperties( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, properties: { [key: string]: string | null }, options: AnalyticsCallOptions = { global: false }, ): Promise { @@ -170,7 +173,7 @@ export function setUserProperties( /** * Clears all analytics data for this instance from the device and resets the app instance ID. */ -export function resetAnalyticsData(analytics: FirebaseAnalyticsTypes.Module): Promise { +export function resetAnalyticsData(analytics: FirebaseAnalyticsModule): Promise { // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally return analytics.resetAnalyticsData.call(analytics, MODULAR_DEPRECATION_ARG); @@ -180,7 +183,7 @@ export function resetAnalyticsData(analytics: FirebaseAnalyticsTypes.Module): Pr * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported automatically for Google Play-based apps. */ export function logAddPaymentInfo( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: AddPaymentInfoEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -191,7 +194,7 @@ export function logAddPaymentInfo( * Sets or clears the screen name and class the user is currently viewing. */ export function logScreenView( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: ScreenViewParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -202,7 +205,7 @@ export function logScreenView( * Add Payment Info event. This event signifies that a user has submitted their payment information to your app. */ export function logAddShippingInfo( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: AddShippingInfoParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -213,7 +216,7 @@ export function logAddShippingInfo( * E-Commerce Add To Cart event. */ export function logAddToCart( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: AddToCartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -224,7 +227,7 @@ export function logAddToCart( * E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. */ export function logAddToWishlist( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: AddToWishlistEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -234,7 +237,7 @@ export function logAddToWishlist( /** * App Open event. By logging this event when an App is moved to the foreground, developers can understand how often users leave and return during the course of a Session. */ -export function logAppOpen(analytics: FirebaseAnalyticsTypes.Module): Promise { +export function logAppOpen(analytics: FirebaseAnalyticsModule): Promise { // This is deprecated for both namespaced and modular. return analytics.logAppOpen(); } @@ -243,7 +246,7 @@ export function logAppOpen(analytics: FirebaseAnalyticsTypes.Module): Promise { // This is deprecated for both namespaced and modular. @@ -254,7 +257,7 @@ export function logBeginCheckout( * Log this event to supply the referral details of a re-engagement campaign. */ export function logCampaignDetails( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: CampaignDetailsEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -265,7 +268,7 @@ export function logCampaignDetails( * Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app. */ export function logEarnVirtualCurrency( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: EarnVirtualCurrencyEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -276,7 +279,7 @@ export function logEarnVirtualCurrency( * Generate Lead event. Log this event when a lead has been generated in the app. */ export function logGenerateLead( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: GenerateLeadEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -287,7 +290,7 @@ export function logGenerateLead( * Join Group event. Log this event when a user joins a group such as a guild, team or family. */ export function logJoinGroup( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: JoinGroupEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -298,7 +301,7 @@ export function logJoinGroup( * Level End event. */ export function logLevelEnd( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: LevelEndEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -309,7 +312,7 @@ export function logLevelEnd( * Level Start event. */ export function logLevelStart( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: LevelStartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -320,7 +323,7 @@ export function logLevelStart( * Level Up event. This event signifies that a player has leveled up in your gaming app. */ export function logLevelUp( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: LevelUpEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -331,7 +334,7 @@ export function logLevelUp( * Login event. Apps with a login feature can report this event to signify that a user has logged in. */ export function logLogin( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: LoginEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -342,7 +345,7 @@ export function logLogin( * Post Score event. Log this event when the user posts a score in your gaming app. */ export function logPostScore( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: PostScoreEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -356,7 +359,7 @@ export function logPostScore( * @returns {Promise} */ export function logSelectContent( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: SelectContentEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -370,7 +373,7 @@ export function logSelectContent( * @returns {Promise} */ export function logPurchase( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: PurchaseEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -384,7 +387,7 @@ export function logPurchase( * @returns {Promise} */ export function logRefund( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: RefundEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -398,7 +401,7 @@ export function logRefund( * @returns {Promise} */ export function logRemoveFromCart( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: RemoveFromCartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -412,7 +415,7 @@ export function logRemoveFromCart( * @returns {Promise} */ export function logSearch( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: SearchEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -426,7 +429,7 @@ export function logSearch( * @returns {Promise} */ export function logSelectItem( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: SelectItemEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -440,7 +443,7 @@ export function logSelectItem( * @returns {Promise} */ export function logSetCheckoutOption( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: SetCheckoutOptionEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -454,7 +457,7 @@ export function logSetCheckoutOption( * @returns {Promise} */ export function logSelectPromotion( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: SelectPromotionEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -468,7 +471,7 @@ export function logSelectPromotion( * @returns {Promise} */ export function logShare( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: ShareEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -482,7 +485,7 @@ export function logShare( * @returns {Promise} */ export function logSignUp( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: SignUpEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -496,7 +499,7 @@ export function logSignUp( * @returns {Promise} */ export function logSpendVirtualCurrency( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: SpendVirtualCurrencyEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -508,7 +511,7 @@ export function logSpendVirtualCurrency( * @param {FirebaseAnalytics} analytics - Analytics instance. * @returns {Promise} */ -export function logTutorialBegin(analytics: FirebaseAnalyticsTypes.Module): Promise { +export function logTutorialBegin(analytics: FirebaseAnalyticsModule): Promise { // This is deprecated for both namespaced and modular. return analytics.logTutorialBegin(); } @@ -518,7 +521,7 @@ export function logTutorialBegin(analytics: FirebaseAnalyticsTypes.Module): Prom * @param {FirebaseAnalytics} analytics - Analytics instance. * @returns {Promise} */ -export function logTutorialComplete(analytics: FirebaseAnalyticsTypes.Module): Promise { +export function logTutorialComplete(analytics: FirebaseAnalyticsModule): Promise { // This is deprecated for both namespaced and modular. return analytics.logTutorialComplete(); } @@ -530,7 +533,7 @@ export function logTutorialComplete(analytics: FirebaseAnalyticsTypes.Module): P * @returns {Promise} */ export function logUnlockAchievement( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: UnlockAchievementEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -544,7 +547,7 @@ export function logUnlockAchievement( * @returns {Promise} */ export function logViewCart( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: ViewCartEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -558,7 +561,7 @@ export function logViewCart( * @returns {Promise} */ export function logViewItem( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: ViewItemEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -572,7 +575,7 @@ export function logViewItem( * @returns {Promise} */ export function logViewItemList( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: ViewItemListEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -586,7 +589,7 @@ export function logViewItemList( * @returns {Promise} */ export function logViewPromotion( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: ViewPromotionEventParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -600,7 +603,7 @@ export function logViewPromotion( * @returns {Promise} */ export function logViewSearchResults( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: ViewSearchResultsParameters, ): Promise { // This is deprecated for both namespaced and modular. @@ -614,7 +617,7 @@ export function logViewSearchResults( * @returns {Promise} */ export function setDefaultEventParameters( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, params: { [key: string]: any } = {}, ): Promise { // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally @@ -629,7 +632,7 @@ export function setDefaultEventParameters( * @returns {Promise} */ export function initiateOnDeviceConversionMeasurementWithEmailAddress( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, emailAddress: string, ): Promise { return analytics.initiateOnDeviceConversionMeasurementWithEmailAddress.call( @@ -650,7 +653,7 @@ export function initiateOnDeviceConversionMeasurementWithEmailAddress( * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials */ export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, hashedEmailAddress: string, ): Promise { return analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress.call( @@ -669,7 +672,7 @@ export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( * @returns {Promise} */ export function initiateOnDeviceConversionMeasurementWithPhoneNumber( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, phoneNumber: string, ): Promise { return analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber.call( @@ -690,7 +693,7 @@ export function initiateOnDeviceConversionMeasurementWithPhoneNumber( * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials */ export function initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, hashedPhoneNumber: string, ): Promise { return analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber.call( @@ -720,7 +723,7 @@ export function isSupported(): Promise { * @returns {Promise} */ export function setConsent( - analytics: FirebaseAnalyticsTypes.Module, + analytics: FirebaseAnalyticsModule, consentSettings: ConsentSettings, ): Promise { // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 4f9793e5a1..4c50b5ea9b 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -852,6 +852,9 @@ class FirebaseAnalyticsModule extends FirebaseModule { } } +// Export the FirebaseAnalyticsModule class for use in modular types +export { FirebaseAnalyticsModule }; + // import { SDK_VERSION } from '@react-native-firebase/analytics'; export const SDK_VERSION: string = version; From 118c892d2592ba22f19400ac0cdfa7662718edbe Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 07:43:54 +0100 Subject: [PATCH 18/49] fix: export just the type --- packages/analytics/lib/index.ts | 2 +- packages/analytics/lib/namespaced.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index b0d9517504..c58646496d 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -1,5 +1,5 @@ import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; -import { FirebaseAnalyticsModule } from './namespaced'; +import type { FirebaseAnalyticsModule } from './namespaced'; import { getApp } from '@react-native-firebase/app'; import { Platform } from 'react-native'; import type { ReactNativeFirebase } from '@react-native-firebase/app'; diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 4c50b5ea9b..0753eef4a7 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -852,8 +852,7 @@ class FirebaseAnalyticsModule extends FirebaseModule { } } -// Export the FirebaseAnalyticsModule class for use in modular types -export { FirebaseAnalyticsModule }; +export type { FirebaseAnalyticsModule }; // import { SDK_VERSION } from '@react-native-firebase/analytics'; export const SDK_VERSION: string = version; From 4c52e8977f940027629812875dfd0c35f9e3f1b8 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 08:25:50 +0100 Subject: [PATCH 19/49] use TS from root package --- packages/analytics/package.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/analytics/package.json b/packages/analytics/package.json index 5a218a7295..604dff56a7 100644 --- a/packages/analytics/package.json +++ b/packages/analytics/package.json @@ -10,7 +10,8 @@ "build": "genversion --esm --semi lib/version.ts", "build:clean": "rimraf android/build && rimraf ios/build", "compile": "bob build", - "prepare": "yarn run build && yarn compile" + "prepare": "yarn run build && yarn compile", + "tsc": "../../node_modules/.bin/tsc" }, "repository": { "type": "git", @@ -73,7 +74,12 @@ "esm": true } ], - "typescript" + [ + "typescript", + { + "tsc": "../../node_modules/.bin/tsc" + } + ] ] }, "eslintIgnore": [ From b4849e8db2fae6bef0990c45385e91dcd4c8aac0 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 08:25:56 +0100 Subject: [PATCH 20/49] yarn.lock --- yarn.lock | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index eb71c99b65..cfb2cadeae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -291,6 +291,13 @@ __metadata: languageName: node linkType: hard +"@babel/helper-plugin-utils@npm:^7.27.1": + version: 7.27.1 + resolution: "@babel/helper-plugin-utils@npm:7.27.1" + checksum: 10/96136c2428888e620e2ec493c25888f9ceb4a21099dcf3dd4508ea64b58cdedbd5a9fb6c7b352546de84d6c24edafe482318646932a22c449ebd16d16c22d864 + languageName: node + linkType: hard + "@babel/helper-remap-async-to-generator@npm:^7.25.9": version: 7.25.9 resolution: "@babel/helper-remap-async-to-generator@npm:7.25.9" @@ -656,6 +663,17 @@ __metadata: languageName: node linkType: hard +"@babel/plugin-syntax-flow@npm:^7.27.1": + version: 7.27.1 + resolution: "@babel/plugin-syntax-flow@npm:7.27.1" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.27.1" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/7baca3171ed595d04c865b0ce46fca7f21900686df9d7fcd1017036ce78bb5483e33803de810831e68d39cf478953db69f49ae3f3de2e3207bc4ba49a96b6739 + languageName: node + linkType: hard + "@babel/plugin-syntax-import-assertions@npm:^7.26.0": version: 7.26.0 resolution: "@babel/plugin-syntax-import-assertions@npm:7.26.0" @@ -1024,6 +1042,18 @@ __metadata: languageName: node linkType: hard +"@babel/plugin-transform-flow-strip-types@npm:^7.26.5": + version: 7.27.1 + resolution: "@babel/plugin-transform-flow-strip-types@npm:7.27.1" + dependencies: + "@babel/helper-plugin-utils": "npm:^7.27.1" + "@babel/plugin-syntax-flow": "npm:^7.27.1" + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 10/22e260866b122b7d0c35f2c55b2d422b175606b4d14c9ba116b1fbe88e08cc8b024c1c41bb62527cfc5f7ccc0ed06c752e5945cb1ee22465a30aa5623e617940 + languageName: node + linkType: hard + "@babel/plugin-transform-for-of@npm:^7.24.7": version: 7.25.9 resolution: "@babel/plugin-transform-for-of@npm:7.25.9" @@ -5352,6 +5382,7 @@ __metadata: version: 0.0.0-use.local resolution: "@react-native-firebase/analytics@workspace:packages/analytics" dependencies: + react-native-builder-bob: "npm:^0.40.13" superstruct: "npm:^2.0.2" peerDependencies: "@react-native-firebase/app": 23.0.0 @@ -7707,6 +7738,15 @@ __metadata: languageName: node linkType: hard +"babel-plugin-syntax-hermes-parser@npm:^0.28.0": + version: 0.28.1 + resolution: "babel-plugin-syntax-hermes-parser@npm:0.28.1" + dependencies: + hermes-parser: "npm:0.28.1" + checksum: 10/2cbc921e663463480ead9ccc8bb229a5196032367ba2b5ccb18a44faa3afa84b4dc493297749983b9a837a3d76b0b123664aecc06f9122618c3246f03e076a9d + languageName: node + linkType: hard + "babel-plugin-transform-flow-enums@npm:^0.0.2": version: 0.0.2 resolution: "babel-plugin-transform-flow-enums@npm:0.0.2" @@ -10621,7 +10661,7 @@ __metadata: languageName: node linkType: hard -"escape-string-regexp@npm:5.0.0": +"escape-string-regexp@npm:5.0.0, escape-string-regexp@npm:^5.0.0": version: 5.0.0 resolution: "escape-string-regexp@npm:5.0.0" checksum: 10/20daabe197f3cb198ec28546deebcf24b3dbb1a5a269184381b3116d12f0532e06007f4bc8da25669d6a7f8efb68db0758df4cd981f57bc5b57f521a3e12c59e @@ -11365,7 +11405,7 @@ __metadata: languageName: node linkType: hard -"fast-glob@npm:^3.3.0": +"fast-glob@npm:^3.3.0, fast-glob@npm:^3.3.3": version: 3.3.3 resolution: "fast-glob@npm:3.3.3" dependencies: @@ -13089,6 +13129,13 @@ __metadata: languageName: node linkType: hard +"hermes-estree@npm:0.28.1": + version: 0.28.1 + resolution: "hermes-estree@npm:0.28.1" + checksum: 10/3195a1aa7035d96b77839e6bfd6832b51830518aaf8dabfca11248b84d6fb6abd27e21c8caa84229954a76b4f8a1e346b65d421a4daecd3053bd2ea08fe6abc9 + languageName: node + linkType: hard + "hermes-parser@npm:0.23.1": version: 0.23.1 resolution: "hermes-parser@npm:0.23.1" @@ -13107,6 +13154,15 @@ __metadata: languageName: node linkType: hard +"hermes-parser@npm:0.28.1": + version: 0.28.1 + resolution: "hermes-parser@npm:0.28.1" + dependencies: + hermes-estree: "npm:0.28.1" + checksum: 10/cb2aa4d386929825c3bd8184eeb4e3dcf34892c1f850624d09a80aee0674bc2eb135eccaeb7ac33675552130229ee6160025c4e4f351d6a61b503bd8bfdf63f5 + languageName: node + linkType: hard + "highlight.js@npm:^10.7.1": version: 10.7.3 resolution: "highlight.js@npm:10.7.3" @@ -20135,6 +20191,38 @@ __metadata: languageName: node linkType: hard +"react-native-builder-bob@npm:^0.40.13": + version: 0.40.13 + resolution: "react-native-builder-bob@npm:0.40.13" + dependencies: + "@babel/core": "npm:^7.25.2" + "@babel/plugin-transform-flow-strip-types": "npm:^7.26.5" + "@babel/plugin-transform-strict-mode": "npm:^7.24.7" + "@babel/preset-env": "npm:^7.25.2" + "@babel/preset-react": "npm:^7.24.7" + "@babel/preset-typescript": "npm:^7.24.7" + arktype: "npm:^2.1.15" + babel-plugin-syntax-hermes-parser: "npm:^0.28.0" + browserslist: "npm:^4.20.4" + cross-spawn: "npm:^7.0.3" + dedent: "npm:^0.7.0" + del: "npm:^6.1.1" + escape-string-regexp: "npm:^4.0.0" + fs-extra: "npm:^10.1.0" + glob: "npm:^8.0.3" + is-git-dirty: "npm:^2.0.1" + json5: "npm:^2.2.1" + kleur: "npm:^4.1.4" + prompts: "npm:^2.4.2" + react-native-monorepo-config: "npm:^0.1.8" + which: "npm:^2.0.2" + yargs: "npm:^17.5.1" + bin: + bob: bin/bob + checksum: 10/7359398d32f237c5b3366dd6dc86862ac2059ec9878d21f4dccb10b432d154afffb68bcdfa3ce6781c1391ea08ca8d93bd2592b7d86c8d013d123736e7b5112a + languageName: node + linkType: hard + "react-native-builder-bob@npm:^0.40.6": version: 0.40.6 resolution: "react-native-builder-bob@npm:0.40.6" @@ -20336,6 +20424,16 @@ __metadata: languageName: node linkType: hard +"react-native-monorepo-config@npm:^0.1.8": + version: 0.1.9 + resolution: "react-native-monorepo-config@npm:0.1.9" + dependencies: + escape-string-regexp: "npm:^5.0.0" + fast-glob: "npm:^3.3.3" + checksum: 10/c92d339ab592488996f77a49cc97d0ab8b1d528fb2d15001c255aa03eea48e013175cdaaddc2bb8b1ebdee620448bcf1901410996aaaf4a5fea470a2e354b0c2 + languageName: node + linkType: hard + "react-native-url-polyfill@npm:2.0.0": version: 2.0.0 resolution: "react-native-url-polyfill@npm:2.0.0" From 82e75fd6af9259d25b1906fadc1fecb2b072cba0 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 08:26:08 +0100 Subject: [PATCH 21/49] chore: rm unneeded type --- packages/analytics/lib/namespaced.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 0753eef4a7..092eb0a87b 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -121,8 +121,6 @@ const namespace = 'analytics'; const nativeModuleName = 'RNFBAnalyticsModule'; class FirebaseAnalyticsModule extends FirebaseModule { - // Explicitly declare native property from parent class - declare native: any; logEvent( name: string, params: { [key: string]: any } = {}, From f5ac76f1e606dc114483dae0cdfd08c79b7e8387 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 08:26:19 +0100 Subject: [PATCH 22/49] test: update unit test import --- packages/analytics/__tests__/analytics.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/analytics/__tests__/analytics.test.ts b/packages/analytics/__tests__/analytics.test.ts index 438bdf1065..de6efd7c6f 100644 --- a/packages/analytics/__tests__/analytics.test.ts +++ b/packages/analytics/__tests__/analytics.test.ts @@ -1,7 +1,7 @@ import { jest, afterAll, beforeAll, describe, expect, it, xit, beforeEach } from '@jest/globals'; // @ts-ignore test -import FirebaseModule from '../../app/lib/internal/FirebaseModule'; +import FirebaseModule from '@react-native-firebase/app/lib/internal/FirebaseModule'; import { firebase, @@ -65,7 +65,7 @@ import { import { createCheckV9Deprecation, CheckV9DeprecationFunction, -} from '../../app/lib/common/unitTestUtils'; +} from '@react-native-firebase/app/lib/common/unitTestUtils'; describe('Analytics', function () { describe('namespace', function () { From 81f4f361c9abd5ceb73c8b37f1f8a5034f21c8a2 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 08:43:20 +0100 Subject: [PATCH 23/49] chore: write type declaration files for web --- packages/app/lib/internal/asyncStorage.d.ts | 47 +++++++++++++++++++ .../internal/web/firebaseInstallations.d.ts | 45 ++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 packages/app/lib/internal/asyncStorage.d.ts create mode 100644 packages/app/lib/internal/web/firebaseInstallations.d.ts diff --git a/packages/app/lib/internal/asyncStorage.d.ts b/packages/app/lib/internal/asyncStorage.d.ts new file mode 100644 index 0000000000..5be94ee0fb --- /dev/null +++ b/packages/app/lib/internal/asyncStorage.d.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// AsyncStorage interface compatible with React Native AsyncStorage +export interface AsyncStorageStatic { + setItem(key: string, value: string): Promise; + getItem(key: string): Promise; + removeItem(key: string): Promise; +} + +// Memory storage Map instance +export const memoryStorage: Map; + +// Storage key prefix +export const prefix: string; + +// Get the current AsyncStorage instance (either React Native AsyncStorage or memory storage) +export function getReactNativeAsyncStorageInternal(): Promise; + +// Set the AsyncStorage instance to use (React Native AsyncStorage or fallback to memory storage) +export function setReactNativeAsyncStorageInternal(asyncStorageInstance?: AsyncStorageStatic): void; + +// Check if currently using memory storage (fallback) +export function isMemoryStorage(): boolean; + +// Set an item in storage with the React Native Firebase prefix +export function setItem(key: string, value: string): Promise; + +// Get an item from storage with the React Native Firebase prefix +export function getItem(key: string): Promise; + +// Remove an item from storage with the React Native Firebase prefix +export function removeItem(key: string): Promise; diff --git a/packages/app/lib/internal/web/firebaseInstallations.d.ts b/packages/app/lib/internal/web/firebaseInstallations.d.ts new file mode 100644 index 0000000000..c051fe8646 --- /dev/null +++ b/packages/app/lib/internal/web/firebaseInstallations.d.ts @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { ReactNativeFirebase } from '../../index'; + +// Firebase Installations service interface +export interface Installations { + app: ReactNativeFirebase.FirebaseApp; +} + +// Unsubscribe function type for onIdChange +export type Unsubscribe = () => void; + +// getApp function - returns ReactNativeFirebase.FirebaseApp +export function getApp(appName?: string): ReactNativeFirebase.FirebaseApp; + +// getInstallations function - gets the installations service for an app +export function getInstallations(app?: ReactNativeFirebase.FirebaseApp): Installations; + +// getId function - gets the installation ID +export function getId(installations: Installations): Promise; + +// onIdChange function - listens for installation ID changes +export function onIdChange( + installations: Installations, + observer: (installationId: string) => void, + onError?: (error: Error) => void +): Unsubscribe; + +// makeIDBAvailable function - makes IndexedDB available in environments that don't have it +export function makeIDBAvailable(): void; From 7f4dd1625c5168b22ae93a636680230f0f4f277e Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 08:52:59 +0100 Subject: [PATCH 24/49] chore: move types/ dir and remove re-export of analytics --- packages/analytics/lib/index.ts | 2 +- packages/analytics/lib/namespaced.ts | 2 +- packages/analytics/lib/types.ts | 19 ------------------- .../analytics/{ => lib}/types/analytics.ts | 0 packages/analytics/{ => lib}/types/web.ts | 0 .../analytics/lib/web/RNFBAnalyticsModule.ts | 2 +- packages/analytics/lib/web/api.ts | 2 +- packages/analytics/tsconfig.json | 2 +- 8 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 packages/analytics/lib/types.ts rename packages/analytics/{ => lib}/types/analytics.ts (100%) rename packages/analytics/{ => lib}/types/web.ts (100%) diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index c58646496d..2c5137ab63 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -40,7 +40,7 @@ import type { ViewPromotionEventParameters, ViewSearchResultsParameters, SettingsOptions, -} from '../types/analytics'; +} from './types/analytics'; declare module '@react-native-firebase/app' { function getApp( diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 092eb0a87b..c89fd3fc0e 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -77,7 +77,7 @@ import { ViewItemListEventParameters, ViewPromotionEventParameters, ViewSearchResultsParameters, -} from '../types/analytics'; +} from './types/analytics'; const ReservedEventNames: readonly string[] = [ 'ad_activeview', diff --git a/packages/analytics/lib/types.ts b/packages/analytics/lib/types.ts deleted file mode 100644 index 25a84e1daa..0000000000 --- a/packages/analytics/lib/types.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2016-present Invertase Limited & Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this library except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// Re-export the FirebaseAnalyticsTypes namespace from the .d.ts file -export type { FirebaseAnalyticsTypes } from './index.d'; diff --git a/packages/analytics/types/analytics.ts b/packages/analytics/lib/types/analytics.ts similarity index 100% rename from packages/analytics/types/analytics.ts rename to packages/analytics/lib/types/analytics.ts diff --git a/packages/analytics/types/web.ts b/packages/analytics/lib/types/web.ts similarity index 100% rename from packages/analytics/types/web.ts rename to packages/analytics/lib/types/web.ts diff --git a/packages/analytics/lib/web/RNFBAnalyticsModule.ts b/packages/analytics/lib/web/RNFBAnalyticsModule.ts index c8fa9e43dd..58637db0c3 100644 --- a/packages/analytics/lib/web/RNFBAnalyticsModule.ts +++ b/packages/analytics/lib/web/RNFBAnalyticsModule.ts @@ -7,7 +7,7 @@ import type { AnalyticsUserProperties, AnalyticsConsent, RNFBAnalyticsModule, -} from '../../types/web'; +} from '../types/web'; interface AnalyticsInstances { [measurementId: string]: AnalyticsApi; diff --git a/packages/analytics/lib/web/api.ts b/packages/analytics/lib/web/api.ts index dc6fbf2bc6..c44375b5b5 100644 --- a/packages/analytics/lib/web/api.ts +++ b/packages/analytics/lib/web/api.ts @@ -18,7 +18,7 @@ import type { AnalyticsUserProperties, AnalyticsConsent, AnalyticsApi as IAnalyticsApi, -} from '../../types/web'; +} from '../types/web'; /** * Generates a Google Analytics client ID. diff --git a/packages/analytics/tsconfig.json b/packages/analytics/tsconfig.json index cce2f9edcd..8e22ab22c4 100644 --- a/packages/analytics/tsconfig.json +++ b/packages/analytics/tsconfig.json @@ -24,7 +24,7 @@ "target": "ESNext", "verbatimModuleSyntax": false, "baseUrl": ".", - "typeRoots": ["./types", "./node_modules/@types"], + "typeRoots": ["lib/types", "./node_modules/@types"], "paths": { "@react-native-firebase/app": ["../app/lib"] } From 5d9901c84f0bcdd8d455a1436e87b12eb3f0cd70 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 08:53:44 +0100 Subject: [PATCH 25/49] rm unneeded Ts declaration file --- packages/analytics/lib/web/api.d.ts | 32 ----------------------------- 1 file changed, 32 deletions(-) delete mode 100644 packages/analytics/lib/web/api.d.ts diff --git a/packages/analytics/lib/web/api.d.ts b/packages/analytics/lib/web/api.d.ts deleted file mode 100644 index 0368a2e912..0000000000 --- a/packages/analytics/lib/web/api.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2016-present Invertase Limited & Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this library except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -import type { AnalyticsApi as IAnalyticsApi } from '../../types'; - -export declare class AnalyticsApi implements IAnalyticsApi { - constructor(appName: string, measurementId: string); - logEvent(name: string, params?: any): void; - setUserId(userId: string | null): void; - setUserProperty(key: string, value: string | null): void; - setUserProperties(properties: any): void; - setDefaultEventParameters(params: any): void; - setConsent(consent: any): void; - setAnalyticsCollectionEnabled(enabled: boolean): void; - setDebug(enabled: boolean): void; - setCurrentScreen(screenName: string | null): void; - _getCid(): Promise; -} From 12a0c2aa532b379aa1ab8bad53ad8a7e7046c750 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 10:04:37 +0100 Subject: [PATCH 26/49] fix internal types --- packages/app/lib/index.d.ts | 10 ---------- packages/app/lib/internal.d.ts | 10 +++++----- packages/app/lib/internal/nativeModule.d.ts | 2 ++ 3 files changed, 7 insertions(+), 15 deletions(-) create mode 100644 packages/app/lib/internal/nativeModule.d.ts diff --git a/packages/app/lib/index.d.ts b/packages/app/lib/index.d.ts index 31545f8532..daf28f7829 100644 --- a/packages/app/lib/index.d.ts +++ b/packages/app/lib/index.d.ts @@ -264,16 +264,6 @@ export namespace ReactNativeFirebase { * The current `FirebaseApp` instance for this Firebase service. */ app: FirebaseApp; - - /** - * The native module instance for this Firebase service. - */ - private native: any; - - /** - * Returns the shared event emitter instance used for all JS event routing. - */ - private emitter: any; } // eslint-disable-next-line @typescript-eslint/no-empty-object-type diff --git a/packages/app/lib/internal.d.ts b/packages/app/lib/internal.d.ts index a5475553d8..0531871988 100644 --- a/packages/app/lib/internal.d.ts +++ b/packages/app/lib/internal.d.ts @@ -14,17 +14,17 @@ * limitations under the License. * */ +import type { ReactNativeFirebase } from './index'; // Type definitions for internal modules used by other packages during TypeScript migration declare module '@react-native-firebase/app/lib/internal' { - export function createModuleNamespace(config: any): any; - export class FirebaseModule { - constructor(...args: any[]); + import BaseFirebaseModule = ReactNativeFirebase.FirebaseModule; + export class FirebaseModule extends BaseFirebaseModule { native: any; - firebaseJson: any; - _customUrlOrRegion: string | null; + emitter: any; } + export function createModuleNamespace(config: any): any; export function getFirebaseRoot(): any; export class NativeFirebaseError { static getStackWithMessage(message: string, jsStack?: string): string; diff --git a/packages/app/lib/internal/nativeModule.d.ts b/packages/app/lib/internal/nativeModule.d.ts new file mode 100644 index 0000000000..b901315eb0 --- /dev/null +++ b/packages/app/lib/internal/nativeModule.d.ts @@ -0,0 +1,2 @@ +export declare function getReactNativeModule(moduleName: string): any; +export declare function setReactNativeModule(moduleName: string, module: any): any; From 75978c29389f4a9fb6874be950541ab2d2c3ae60 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 10:11:35 +0100 Subject: [PATCH 27/49] split modular and namespaced. import into index --- packages/analytics/lib/index.ts | 749 +-------------------------- packages/analytics/lib/modular.ts | 741 ++++++++++++++++++++++++++ packages/analytics/lib/namespaced.ts | 17 +- 3 files changed, 758 insertions(+), 749 deletions(-) create mode 100644 packages/analytics/lib/modular.ts diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index 2c5137ab63..97e531039b 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -1,743 +1,10 @@ -import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; -import type { FirebaseAnalyticsModule } from './namespaced'; -import { getApp } from '@react-native-firebase/app'; -import { Platform } from 'react-native'; import type { ReactNativeFirebase } from '@react-native-firebase/app'; -import type { - AnalyticsSettings, - AnalyticsCallOptions, - ConsentSettings, - AddPaymentInfoEventParameters, - ScreenViewParameters, - AddShippingInfoParameters, - AddToCartEventParameters, - AddToWishlistEventParameters, - BeginCheckoutEventParameters, - CampaignDetailsEventParameters, - EarnVirtualCurrencyEventParameters, - GenerateLeadEventParameters, - JoinGroupEventParameters, - LevelEndEventParameters, - LevelStartEventParameters, - LevelUpEventParameters, - LoginEventParameters, - PostScoreEventParameters, - SelectContentEventParameters, - PurchaseEventParameters, - RefundEventParameters, - RemoveFromCartEventParameters, - SearchEventParameters, - SelectItemEventParameters, - SetCheckoutOptionEventParameters, - SelectPromotionEventParameters, - ShareEventParameters, - SignUpEventParameters, - SpendVirtualCurrencyEventParameters, - UnlockAchievementEventParameters, - ViewCartEventParameters, - ViewItemEventParameters, - ViewItemListEventParameters, - ViewPromotionEventParameters, - ViewSearchResultsParameters, - SettingsOptions, -} from './types/analytics'; - -declare module '@react-native-firebase/app' { - function getApp( - name?: string, - ): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsModule }; -} - -/** - * Returns an Analytics instance for the given app. - */ -export function getAnalytics(app?: ReactNativeFirebase.FirebaseApp): FirebaseAnalyticsModule { - if (app) { - return getApp(app.name).analytics(); - } - return getApp().analytics(); -} - -/** - * Returns an Analytics instance for the given app. - */ -export function initializeAnalytics( - app: ReactNativeFirebase.FirebaseApp, - _options?: AnalyticsSettings, -): FirebaseAnalyticsModule { - return getApp(app.name).analytics(); -} - -/** - * Retrieves a unique Google Analytics identifier for the web client. - */ -export async function getGoogleAnalyticsClientId( - analytics: FirebaseAnalyticsModule, -): Promise { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - throw new Error('getGoogleAnalyticsClientId is web-only.'); - } else { - const instanceId = await getAppInstanceId(analytics); - return instanceId || ''; - } -} - -/** - * Log a custom event with optional params. - */ -export function logEvent( - analytics: FirebaseAnalyticsModule, - name: string, - params: { [key: string]: any } = {}, - options: AnalyticsCallOptions = { global: false }, -): Promise { - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.logEvent.call(analytics, name, params, options, MODULAR_DEPRECATION_ARG); -} - -/** - * If true, allows the device to collect analytical data and send it to Firebase. Useful for GDPR. - */ -export function setAnalyticsCollectionEnabled( - analytics: FirebaseAnalyticsModule, - enabled: boolean, -): Promise { - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.setAnalyticsCollectionEnabled.call(analytics, enabled, MODULAR_DEPRECATION_ARG); -} - -/** - * Sets the duration of inactivity that terminates the current session. - */ -export function setSessionTimeoutDuration( - analytics: FirebaseAnalyticsModule, - milliseconds: number = 1800000, -): Promise { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.setSessionTimeoutDuration.call(analytics, milliseconds, MODULAR_DEPRECATION_ARG); -} - -/** - * Retrieve the app instance id of the application. - */ -export function getAppInstanceId(analytics: FirebaseAnalyticsModule): Promise { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.getAppInstanceId.call(analytics, MODULAR_DEPRECATION_ARG); -} - -/** - * Retrieves the session id from the client. - * On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details. - */ -export function getSessionId(analytics: FirebaseAnalyticsModule): Promise { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.getSessionId.call(analytics, MODULAR_DEPRECATION_ARG); -} - -/** - * Gives a user a unique identification. - */ -export function setUserId(analytics: FirebaseAnalyticsModule, id: string | null): Promise { - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.setUserId.call(analytics, id, MODULAR_DEPRECATION_ARG); -} - -/** - * Sets a key/value pair of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - */ -export function setUserProperty( - analytics: FirebaseAnalyticsModule, - name: string, - value: string | null, -): Promise { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.setUserProperty.call(analytics, name, value, MODULAR_DEPRECATION_ARG); -} - -/** - * Sets multiple key/value pairs of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. - */ -export function setUserProperties( - analytics: FirebaseAnalyticsModule, - properties: { [key: string]: string | null }, - options: AnalyticsCallOptions = { global: false }, -): Promise { - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.setUserProperties.call(analytics, properties, options, MODULAR_DEPRECATION_ARG); -} - -/** - * Clears all analytics data for this instance from the device and resets the app instance ID. - */ -export function resetAnalyticsData(analytics: FirebaseAnalyticsModule): Promise { - // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.resetAnalyticsData.call(analytics, MODULAR_DEPRECATION_ARG); -} - -/** - * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported automatically for Google Play-based apps. - */ -export function logAddPaymentInfo( - analytics: FirebaseAnalyticsModule, - params: AddPaymentInfoEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logAddPaymentInfo(params); -} - -/** - * Sets or clears the screen name and class the user is currently viewing. - */ -export function logScreenView( - analytics: FirebaseAnalyticsModule, - params: ScreenViewParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logScreenView(params); -} - -/** - * Add Payment Info event. This event signifies that a user has submitted their payment information to your app. - */ -export function logAddShippingInfo( - analytics: FirebaseAnalyticsModule, - params: AddShippingInfoParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logAddShippingInfo(params); -} - -/** - * E-Commerce Add To Cart event. - */ -export function logAddToCart( - analytics: FirebaseAnalyticsModule, - params: AddToCartEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logAddToCart(params); -} - -/** - * E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. - */ -export function logAddToWishlist( - analytics: FirebaseAnalyticsModule, - params: AddToWishlistEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logAddToWishlist(params); -} - -/** - * App Open event. By logging this event when an App is moved to the foreground, developers can understand how often users leave and return during the course of a Session. - */ -export function logAppOpen(analytics: FirebaseAnalyticsModule): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logAppOpen(); -} - -/** - * E-Commerce Begin Checkout event. This event signifies that a user has begun the process of checking out. - */ -export function logBeginCheckout( - analytics: FirebaseAnalyticsModule, - params: BeginCheckoutEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logBeginCheckout(params); -} - -/** - * Log this event to supply the referral details of a re-engagement campaign. - */ -export function logCampaignDetails( - analytics: FirebaseAnalyticsModule, - params: CampaignDetailsEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logCampaignDetails(params); -} - -/** - * Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app. - */ -export function logEarnVirtualCurrency( - analytics: FirebaseAnalyticsModule, - params: EarnVirtualCurrencyEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logEarnVirtualCurrency(params); -} - -/** - * Generate Lead event. Log this event when a lead has been generated in the app. - */ -export function logGenerateLead( - analytics: FirebaseAnalyticsModule, - params: GenerateLeadEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logGenerateLead(params); -} - -/** - * Join Group event. Log this event when a user joins a group such as a guild, team or family. - */ -export function logJoinGroup( - analytics: FirebaseAnalyticsModule, - params: JoinGroupEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logJoinGroup(params); -} - -/** - * Level End event. - */ -export function logLevelEnd( - analytics: FirebaseAnalyticsModule, - params: LevelEndEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logLevelEnd(params); -} - -/** - * Level Start event. - */ -export function logLevelStart( - analytics: FirebaseAnalyticsModule, - params: LevelStartEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logLevelStart(params); -} - -/** - * Level Up event. This event signifies that a player has leveled up in your gaming app. - */ -export function logLevelUp( - analytics: FirebaseAnalyticsModule, - params: LevelUpEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logLevelUp(params); -} - -/** - * Login event. Apps with a login feature can report this event to signify that a user has logged in. - */ -export function logLogin( - analytics: FirebaseAnalyticsModule, - params: LoginEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logLogin(params); -} - -/** - * Post Score event. Log this event when the user posts a score in your gaming app. - */ -export function logPostScore( - analytics: FirebaseAnalyticsModule, - params: PostScoreEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logPostScore(params); -} - -/** - * Select Content event. This general purpose event signifies that a user has selected some content of a certain type in an app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SelectContentEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSelectContent( - analytics: FirebaseAnalyticsModule, - params: SelectContentEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logSelectContent(params); -} - -/** - * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {PurchaseEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logPurchase( - analytics: FirebaseAnalyticsModule, - params: PurchaseEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logPurchase(params); -} - -/** - * E-Commerce Refund event. This event signifies that a refund was issued. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {RefundEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logRefund( - analytics: FirebaseAnalyticsModule, - params: RefundEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logRefund(params); -} - -/** - * Remove from cart event. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {RemoveFromCartEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logRemoveFromCart( - analytics: FirebaseAnalyticsModule, - params: RemoveFromCartEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logRemoveFromCart(params); -} - -/** - * Search event. Apps that support search features can use this event to contextualize search operations by supplying the appropriate, corresponding parameters. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SearchEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSearch( - analytics: FirebaseAnalyticsModule, - params: SearchEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logSearch(params); -} - -/** - * Select Item event. This event signifies that an item was selected by a user from a list. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SelectItemEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSelectItem( - analytics: FirebaseAnalyticsModule, - params: SelectItemEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logSelectItem(params); -} - -/** - * Set checkout option event. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SetCheckoutOptionEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSetCheckoutOption( - analytics: FirebaseAnalyticsModule, - params: SetCheckoutOptionEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logSetCheckoutOption(params); -} - -/** - * Select promotion event. This event signifies that a user has selected a promotion offer. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SelectPromotionEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSelectPromotion( - analytics: FirebaseAnalyticsModule, - params: SelectPromotionEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logSelectPromotion(params); -} - -/** - * Share event. Apps with social features can log the Share event to identify the most viral content. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ShareEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logShare( - analytics: FirebaseAnalyticsModule, - params: ShareEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logShare(params); -} - -/** - * Sign Up event. This event indicates that a user has signed up for an account in your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SignUpEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSignUp( - analytics: FirebaseAnalyticsModule, - params: SignUpEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logSignUp(params); -} - -/** - * Spend Virtual Currency event. This event tracks the sale of virtual goods in your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {SpendVirtualCurrencyEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logSpendVirtualCurrency( - analytics: FirebaseAnalyticsModule, - params: SpendVirtualCurrencyEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logSpendVirtualCurrency(params); -} - -/** - * Tutorial Begin event. This event signifies the start of the on-boarding process in your app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} - */ -export function logTutorialBegin(analytics: FirebaseAnalyticsModule): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logTutorialBegin(); -} - -/** - * Tutorial End event. Use this event to signify the user's completion of your app's on-boarding process. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @returns {Promise} - */ -export function logTutorialComplete(analytics: FirebaseAnalyticsModule): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logTutorialComplete(); -} - -/** - * Unlock Achievement event. Log this event when the user has unlocked an achievement in your game. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {UnlockAchievementEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logUnlockAchievement( - analytics: FirebaseAnalyticsModule, - params: UnlockAchievementEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logUnlockAchievement(params); -} - -/** - * E-commerce View Cart event. This event signifies that a user has viewed their cart. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewCartEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewCart( - analytics: FirebaseAnalyticsModule, - params: ViewCartEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logViewCart(params); -} - -/** - * View Item event. This event signifies that some content was shown to the user. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewItemEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewItem( - analytics: FirebaseAnalyticsModule, - params: ViewItemEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logViewItem(params); -} - -/** - * View Item List event. Log this event when the user has been presented with a list of items of a certain category. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewItemListEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewItemList( - analytics: FirebaseAnalyticsModule, - params: ViewItemListEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logViewItemList(params); -} - -/** - * View Promotion event. This event signifies that a promotion was shown to a user. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewPromotionEventParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewPromotion( - analytics: FirebaseAnalyticsModule, - params: ViewPromotionEventParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logViewPromotion(params); -} - -/** - * View Search Results event. Log this event when the user has been presented with the results of a search. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ViewSearchResultsParameters} params - Event parameters. - * @returns {Promise} - */ -export function logViewSearchResults( - analytics: FirebaseAnalyticsModule, - params: ViewSearchResultsParameters, -): Promise { - // This is deprecated for both namespaced and modular. - return analytics.logViewSearchResults(params); -} - -/** - * Adds parameters that will be set on every event logged from the SDK, including automatic ones. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {object} [params={}] - Parameters to be added to the map of parameters added to every event. - * @returns {Promise} - */ -export function setDefaultEventParameters( - analytics: FirebaseAnalyticsModule, - params: { [key: string]: any } = {}, -): Promise { - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.setDefaultEventParameters.call(analytics, params, MODULAR_DEPRECATION_ARG); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {string} emailAddress - Email address, properly formatted complete with domain name e.g, 'user@example.com'. - * @returns {Promise} - */ -export function initiateOnDeviceConversionMeasurementWithEmailAddress( - analytics: FirebaseAnalyticsModule, - emailAddress: string, -): Promise { - return analytics.initiateOnDeviceConversionMeasurementWithEmailAddress.call( - analytics, - emailAddress, - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile - * - * @param analytics Analytics instance. - * @param hashedEmailAddress sha256-hashed of normalized email address, properly formatted complete with domain name e.g, 'user@example.com' - * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials - */ -export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( - analytics: FirebaseAnalyticsModule, - hashedEmailAddress: string, -): Promise { - return analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress.call( - analytics, - hashedEmailAddress, - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {string} phoneNumber - Phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - * @returns {Promise} - */ -export function initiateOnDeviceConversionMeasurementWithPhoneNumber( - analytics: FirebaseAnalyticsModule, - phoneNumber: string, -): Promise { - return analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber.call( - analytics, - phoneNumber, - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * start privacy-sensitive on-device conversion management. - * This is iOS-only. - * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile - * - * @param analytics Analytics instance. - * @param hashedPhoneNumber sha256-hashed of normalized phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. - * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials - */ -export function initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( - analytics: FirebaseAnalyticsModule, - hashedPhoneNumber: string, -): Promise { - return analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber.call( - analytics, - hashedPhoneNumber, - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - MODULAR_DEPRECATION_ARG, - ); -} - -/** - * Checks four different things. - * 1. Checks if it's not a browser extension environment. - * 2. Checks if cookies are enabled in current browser. - * 3. Checks if IndexedDB is supported by the browser environment. - * 4. Checks if the current browser context is valid for using IndexedDB.open(). - * @returns {Promise} - */ -export function isSupported(): Promise { - return Promise.resolve(true); -} - -/** - * Sets the applicable end user consent state for this app. - * @param {FirebaseAnalytics} analytics - Analytics instance. - * @param {ConsentSettings} consentSettings - See ConsentSettings. - * @returns {Promise} - */ -export function setConsent( - analytics: FirebaseAnalyticsModule, - consentSettings: ConsentSettings, -): Promise { - // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally - return analytics.setConsent.call(analytics, consentSettings, MODULAR_DEPRECATION_ARG); -} - -/** - * Configures Firebase Analytics to use custom gtag or dataLayer names. - * Intended to be used if gtag.js script has been installed on this page independently of Firebase Analytics, and is using non-default names for either the gtag function or for dataLayer. Must be called before calling `getAnalytics()` or it won't have any effect. Web only. - * @param {SettingsOptions} options - See SettingsOptions. - * @returns {void} - */ -export function settings(_options: SettingsOptions): void { - // Returns nothing until Web implemented. -} - +import defaultExport, { FirebaseAnalyticsModule } from './namespaced'; +import { Statics } from './types/analytics'; +export * from './modular'; export * from './namespaced'; + +export default defaultExport as ReactNativeFirebase.FirebaseModuleWithStatics< + FirebaseAnalyticsModule, + Statics +>; diff --git a/packages/analytics/lib/modular.ts b/packages/analytics/lib/modular.ts new file mode 100644 index 0000000000..de3a67d25d --- /dev/null +++ b/packages/analytics/lib/modular.ts @@ -0,0 +1,741 @@ +import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; +import type { FirebaseAnalyticsModule } from './namespaced'; +import { getApp } from '@react-native-firebase/app'; +import { Platform } from 'react-native'; +import type { ReactNativeFirebase } from '@react-native-firebase/app'; +import type { + AnalyticsSettings, + AnalyticsCallOptions, + ConsentSettings, + AddPaymentInfoEventParameters, + ScreenViewParameters, + AddShippingInfoParameters, + AddToCartEventParameters, + AddToWishlistEventParameters, + BeginCheckoutEventParameters, + CampaignDetailsEventParameters, + EarnVirtualCurrencyEventParameters, + GenerateLeadEventParameters, + JoinGroupEventParameters, + LevelEndEventParameters, + LevelStartEventParameters, + LevelUpEventParameters, + LoginEventParameters, + PostScoreEventParameters, + SelectContentEventParameters, + PurchaseEventParameters, + RefundEventParameters, + RemoveFromCartEventParameters, + SearchEventParameters, + SelectItemEventParameters, + SetCheckoutOptionEventParameters, + SelectPromotionEventParameters, + ShareEventParameters, + SignUpEventParameters, + SpendVirtualCurrencyEventParameters, + UnlockAchievementEventParameters, + ViewCartEventParameters, + ViewItemEventParameters, + ViewItemListEventParameters, + ViewPromotionEventParameters, + ViewSearchResultsParameters, + SettingsOptions, +} from './types/analytics'; + +declare module '@react-native-firebase/app' { + function getApp( + name?: string, + ): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsModule }; +} + +/** + * Returns an Analytics instance for the given app. + */ +export function getAnalytics(app?: ReactNativeFirebase.FirebaseApp): FirebaseAnalyticsModule { + if (app) { + return getApp(app.name).analytics(); + } + return getApp().analytics(); +} + +/** + * Returns an Analytics instance for the given app. + */ +export function initializeAnalytics( + app: ReactNativeFirebase.FirebaseApp, + _options?: AnalyticsSettings, +): FirebaseAnalyticsModule { + return getApp(app.name).analytics(); +} + +/** + * Retrieves a unique Google Analytics identifier for the web client. + */ +export async function getGoogleAnalyticsClientId( + analytics: FirebaseAnalyticsModule, +): Promise { + if (Platform.OS === 'android' || Platform.OS === 'ios') { + throw new Error('getGoogleAnalyticsClientId is web-only.'); + } else { + const instanceId = await getAppInstanceId(analytics); + return instanceId || ''; + } +} + +/** + * Log a custom event with optional params. + */ +export function logEvent( + analytics: FirebaseAnalyticsModule, + name: string, + params: { [key: string]: any } = {}, + options: AnalyticsCallOptions = { global: false }, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.logEvent.call(analytics, name, params, options, MODULAR_DEPRECATION_ARG); +} + +/** + * If true, allows the device to collect analytical data and send it to Firebase. Useful for GDPR. + */ +export function setAnalyticsCollectionEnabled( + analytics: FirebaseAnalyticsModule, + enabled: boolean, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setAnalyticsCollectionEnabled.call(analytics, enabled, MODULAR_DEPRECATION_ARG); +} + +/** + * Sets the duration of inactivity that terminates the current session. + */ +export function setSessionTimeoutDuration( + analytics: FirebaseAnalyticsModule, + milliseconds: number = 1800000, +): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setSessionTimeoutDuration.call(analytics, milliseconds, MODULAR_DEPRECATION_ARG); +} + +/** + * Retrieve the app instance id of the application. + */ +export function getAppInstanceId(analytics: FirebaseAnalyticsModule): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.getAppInstanceId.call(analytics, MODULAR_DEPRECATION_ARG); +} + +/** + * Retrieves the session id from the client. + * On iOS, Firebase SDK may return an error that is handled internally and may take many minutes to return a valid value. Check native debug logs for more details. + */ +export function getSessionId(analytics: FirebaseAnalyticsModule): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.getSessionId.call(analytics, MODULAR_DEPRECATION_ARG); +} + +/** + * Gives a user a unique identification. + */ +export function setUserId(analytics: FirebaseAnalyticsModule, id: string | null): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setUserId.call(analytics, id, MODULAR_DEPRECATION_ARG); +} + +/** + * Sets a key/value pair of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. + */ +export function setUserProperty( + analytics: FirebaseAnalyticsModule, + name: string, + value: string | null, +): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setUserProperty.call(analytics, name, value, MODULAR_DEPRECATION_ARG); +} + +/** + * Sets multiple key/value pairs of data on the current user. Each Firebase project can have up to 25 uniquely named (case-sensitive) user properties. + */ +export function setUserProperties( + analytics: FirebaseAnalyticsModule, + properties: { [key: string]: string | null }, + options: AnalyticsCallOptions = { global: false }, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setUserProperties.call(analytics, properties, options, MODULAR_DEPRECATION_ARG); +} + +/** + * Clears all analytics data for this instance from the device and resets the app instance ID. + */ +export function resetAnalyticsData(analytics: FirebaseAnalyticsModule): Promise { + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.resetAnalyticsData.call(analytics, MODULAR_DEPRECATION_ARG); +} + +/** + * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. Note: This is different from the in-app purchase event, which is reported automatically for Google Play-based apps. + */ +export function logAddPaymentInfo( + analytics: FirebaseAnalyticsModule, + params: AddPaymentInfoEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddPaymentInfo(params); +} + +/** + * Sets or clears the screen name and class the user is currently viewing. + */ +export function logScreenView( + analytics: FirebaseAnalyticsModule, + params: ScreenViewParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logScreenView(params); +} + +/** + * Add Payment Info event. This event signifies that a user has submitted their payment information to your app. + */ +export function logAddShippingInfo( + analytics: FirebaseAnalyticsModule, + params: AddShippingInfoParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddShippingInfo(params); +} + +/** + * E-Commerce Add To Cart event. + */ +export function logAddToCart( + analytics: FirebaseAnalyticsModule, + params: AddToCartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddToCart(params); +} + +/** + * E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. + */ +export function logAddToWishlist( + analytics: FirebaseAnalyticsModule, + params: AddToWishlistEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAddToWishlist(params); +} + +/** + * App Open event. By logging this event when an App is moved to the foreground, developers can understand how often users leave and return during the course of a Session. + */ +export function logAppOpen(analytics: FirebaseAnalyticsModule): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logAppOpen(); +} + +/** + * E-Commerce Begin Checkout event. This event signifies that a user has begun the process of checking out. + */ +export function logBeginCheckout( + analytics: FirebaseAnalyticsModule, + params: BeginCheckoutEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logBeginCheckout(params); +} + +/** + * Log this event to supply the referral details of a re-engagement campaign. + */ +export function logCampaignDetails( + analytics: FirebaseAnalyticsModule, + params: CampaignDetailsEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logCampaignDetails(params); +} + +/** + * Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app. + */ +export function logEarnVirtualCurrency( + analytics: FirebaseAnalyticsModule, + params: EarnVirtualCurrencyEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logEarnVirtualCurrency(params); +} + +/** + * Generate Lead event. Log this event when a lead has been generated in the app. + */ +export function logGenerateLead( + analytics: FirebaseAnalyticsModule, + params: GenerateLeadEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logGenerateLead(params); +} + +/** + * Join Group event. Log this event when a user joins a group such as a guild, team or family. + */ +export function logJoinGroup( + analytics: FirebaseAnalyticsModule, + params: JoinGroupEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logJoinGroup(params); +} + +/** + * Level End event. + */ +export function logLevelEnd( + analytics: FirebaseAnalyticsModule, + params: LevelEndEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLevelEnd(params); +} + +/** + * Level Start event. + */ +export function logLevelStart( + analytics: FirebaseAnalyticsModule, + params: LevelStartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLevelStart(params); +} + +/** + * Level Up event. This event signifies that a player has leveled up in your gaming app. + */ +export function logLevelUp( + analytics: FirebaseAnalyticsModule, + params: LevelUpEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLevelUp(params); +} + +/** + * Login event. Apps with a login feature can report this event to signify that a user has logged in. + */ +export function logLogin( + analytics: FirebaseAnalyticsModule, + params: LoginEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logLogin(params); +} + +/** + * Post Score event. Log this event when the user posts a score in your gaming app. + */ +export function logPostScore( + analytics: FirebaseAnalyticsModule, + params: PostScoreEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logPostScore(params); +} + +/** + * Select Content event. This general purpose event signifies that a user has selected some content of a certain type in an app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SelectContentEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSelectContent( + analytics: FirebaseAnalyticsModule, + params: SelectContentEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSelectContent(params); +} + +/** + * E-Commerce Purchase event. This event signifies that an item(s) was purchased by a user. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {PurchaseEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logPurchase( + analytics: FirebaseAnalyticsModule, + params: PurchaseEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logPurchase(params); +} + +/** + * E-Commerce Refund event. This event signifies that a refund was issued. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {RefundEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logRefund( + analytics: FirebaseAnalyticsModule, + params: RefundEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logRefund(params); +} + +/** + * Remove from cart event. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {RemoveFromCartEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logRemoveFromCart( + analytics: FirebaseAnalyticsModule, + params: RemoveFromCartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logRemoveFromCart(params); +} + +/** + * Search event. Apps that support search features can use this event to contextualize search operations by supplying the appropriate, corresponding parameters. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SearchEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSearch( + analytics: FirebaseAnalyticsModule, + params: SearchEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSearch(params); +} + +/** + * Select Item event. This event signifies that an item was selected by a user from a list. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SelectItemEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSelectItem( + analytics: FirebaseAnalyticsModule, + params: SelectItemEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSelectItem(params); +} + +/** + * Set checkout option event. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SetCheckoutOptionEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSetCheckoutOption( + analytics: FirebaseAnalyticsModule, + params: SetCheckoutOptionEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSetCheckoutOption(params); +} + +/** + * Select promotion event. This event signifies that a user has selected a promotion offer. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SelectPromotionEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSelectPromotion( + analytics: FirebaseAnalyticsModule, + params: SelectPromotionEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSelectPromotion(params); +} + +/** + * Share event. Apps with social features can log the Share event to identify the most viral content. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ShareEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logShare( + analytics: FirebaseAnalyticsModule, + params: ShareEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logShare(params); +} + +/** + * Sign Up event. This event indicates that a user has signed up for an account in your app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SignUpEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSignUp( + analytics: FirebaseAnalyticsModule, + params: SignUpEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSignUp(params); +} + +/** + * Spend Virtual Currency event. This event tracks the sale of virtual goods in your app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {SpendVirtualCurrencyEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logSpendVirtualCurrency( + analytics: FirebaseAnalyticsModule, + params: SpendVirtualCurrencyEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logSpendVirtualCurrency(params); +} + +/** + * Tutorial Begin event. This event signifies the start of the on-boarding process in your app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @returns {Promise} + */ +export function logTutorialBegin(analytics: FirebaseAnalyticsModule): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logTutorialBegin(); +} + +/** + * Tutorial End event. Use this event to signify the user's completion of your app's on-boarding process. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @returns {Promise} + */ +export function logTutorialComplete(analytics: FirebaseAnalyticsModule): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logTutorialComplete(); +} + +/** + * Unlock Achievement event. Log this event when the user has unlocked an achievement in your game. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {UnlockAchievementEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logUnlockAchievement( + analytics: FirebaseAnalyticsModule, + params: UnlockAchievementEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logUnlockAchievement(params); +} + +/** + * E-commerce View Cart event. This event signifies that a user has viewed their cart. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewCartEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewCart( + analytics: FirebaseAnalyticsModule, + params: ViewCartEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewCart(params); +} + +/** + * View Item event. This event signifies that some content was shown to the user. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewItemEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewItem( + analytics: FirebaseAnalyticsModule, + params: ViewItemEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewItem(params); +} + +/** + * View Item List event. Log this event when the user has been presented with a list of items of a certain category. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewItemListEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewItemList( + analytics: FirebaseAnalyticsModule, + params: ViewItemListEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewItemList(params); +} + +/** + * View Promotion event. This event signifies that a promotion was shown to a user. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewPromotionEventParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewPromotion( + analytics: FirebaseAnalyticsModule, + params: ViewPromotionEventParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewPromotion(params); +} + +/** + * View Search Results event. Log this event when the user has been presented with the results of a search. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ViewSearchResultsParameters} params - Event parameters. + * @returns {Promise} + */ +export function logViewSearchResults( + analytics: FirebaseAnalyticsModule, + params: ViewSearchResultsParameters, +): Promise { + // This is deprecated for both namespaced and modular. + return analytics.logViewSearchResults(params); +} + +/** + * Adds parameters that will be set on every event logged from the SDK, including automatic ones. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {object} [params={}] - Parameters to be added to the map of parameters added to every event. + * @returns {Promise} + */ +export function setDefaultEventParameters( + analytics: FirebaseAnalyticsModule, + params: { [key: string]: any } = {}, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setDefaultEventParameters.call(analytics, params, MODULAR_DEPRECATION_ARG); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {string} emailAddress - Email address, properly formatted complete with domain name e.g, 'user@example.com'. + * @returns {Promise} + */ +export function initiateOnDeviceConversionMeasurementWithEmailAddress( + analytics: FirebaseAnalyticsModule, + emailAddress: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithEmailAddress.call( + analytics, + emailAddress, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile + * + * @param analytics Analytics instance. + * @param hashedEmailAddress sha256-hashed of normalized email address, properly formatted complete with domain name e.g, 'user@example.com' + * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials + */ +export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( + analytics: FirebaseAnalyticsModule, + hashedEmailAddress: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress.call( + analytics, + hashedEmailAddress, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {string} phoneNumber - Phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. + * @returns {Promise} + */ +export function initiateOnDeviceConversionMeasurementWithPhoneNumber( + analytics: FirebaseAnalyticsModule, + phoneNumber: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber.call( + analytics, + phoneNumber, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * start privacy-sensitive on-device conversion management. + * This is iOS-only. + * This is a no-op if you do not include '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true' in your Podfile + * + * @param analytics Analytics instance. + * @param hashedPhoneNumber sha256-hashed of normalized phone number in E.164 format - that is a leading + sign, then up to 15 digits, no dashes or spaces. + * @link https://firebase.google.com/docs/tutorials/ads-ios-on-device-measurement/step-3#use-hashed-credentials + */ +export function initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( + analytics: FirebaseAnalyticsModule, + hashedPhoneNumber: string, +): Promise { + return analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber.call( + analytics, + hashedPhoneNumber, + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + MODULAR_DEPRECATION_ARG, + ); +} + +/** + * Checks four different things. + * 1. Checks if it's not a browser extension environment. + * 2. Checks if cookies are enabled in current browser. + * 3. Checks if IndexedDB is supported by the browser environment. + * 4. Checks if the current browser context is valid for using IndexedDB.open(). + * @returns {Promise} + */ +export function isSupported(): Promise { + return Promise.resolve(true); +} + +/** + * Sets the applicable end user consent state for this app. + * @param {FirebaseAnalytics} analytics - Analytics instance. + * @param {ConsentSettings} consentSettings - See ConsentSettings. + * @returns {Promise} + */ +export function setConsent( + analytics: FirebaseAnalyticsModule, + consentSettings: ConsentSettings, +): Promise { + // @ts-ignore - MODULAR_DEPRECATION_ARG is filtered out internally + return analytics.setConsent.call(analytics, consentSettings, MODULAR_DEPRECATION_ARG); +} + +/** + * Configures Firebase Analytics to use custom gtag or dataLayer names. + * Intended to be used if gtag.js script has been installed on this page independently of Firebase Analytics, and is using non-default names for either the gtag function or for dataLayer. Must be called before calling `getAnalytics()` or it won't have any effect. Web only. + * @param {SettingsOptions} options - See SettingsOptions. + * @returns {void} + */ +export function settings(_options: SettingsOptions): void { + // Returns nothing until Web implemented. +} diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index c89fd3fc0e..864742e3fc 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -857,6 +857,15 @@ export const SDK_VERSION: string = version; // import analytics from '@react-native-firebase/analytics'; // analytics().logEvent(...); + +// import analytics, { firebase } from '@react-native-firebase/analytics'; +// analytics().logEvent(...); +// firebase.analytics().logEvent(...); +export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< + FirebaseAnalyticsModule, + Statics +>; + export default createModuleNamespace({ statics, version, @@ -871,14 +880,6 @@ export default createModuleNamespace({ // Register the interop module for non-native platforms. setReactNativeModule(nativeModuleName, RNFBAnalyticsModule); -// import analytics, { firebase } from '@react-native-firebase/analytics'; -// analytics().logEvent(...); -// firebase.analytics().logEvent(...); -export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< - FirebaseAnalyticsModule, - Statics ->; - export const firebase: FirebaseAnalyticsModule & { analytics: typeof defaultExport; app(name?: string): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsModule }; From 24a47709e4f85bd59d23cdfd04b31589339d6261 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 10:43:56 +0100 Subject: [PATCH 28/49] fix index.ts --- packages/analytics/lib/index.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/analytics/lib/index.ts b/packages/analytics/lib/index.ts index 97e531039b..a2eeeddc5c 100644 --- a/packages/analytics/lib/index.ts +++ b/packages/analytics/lib/index.ts @@ -1,10 +1,6 @@ -import type { ReactNativeFirebase } from '@react-native-firebase/app'; -import defaultExport, { FirebaseAnalyticsModule } from './namespaced'; -import { Statics } from './types/analytics'; +import defaultExport from './namespaced'; + export * from './modular'; export * from './namespaced'; -export default defaultExport as ReactNativeFirebase.FirebaseModuleWithStatics< - FirebaseAnalyticsModule, - Statics ->; +export default defaultExport; From e58a35497c1ba796a6ebb63aad6f32e8932ca764 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 10:52:52 +0100 Subject: [PATCH 29/49] attempt at fixing type test problem --- packages/analytics/lib/namespaced.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 864742e3fc..095a76e651 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -866,7 +866,7 @@ export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatic Statics >; -export default createModuleNamespace({ +const module = createModuleNamespace({ statics, version, namespace, @@ -875,7 +875,9 @@ export default createModuleNamespace({ hasMultiAppSupport: false, hasCustomUrlOrRegionSupport: false, ModuleClass: FirebaseAnalyticsModule, -}); +}) as typeof defaultExport; + +export default module; // Register the interop module for non-native platforms. setReactNativeModule(nativeModuleName, RNFBAnalyticsModule); From a34fa9508553353562df2c6e5ebac39bd11e0e3c Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 10:59:06 +0100 Subject: [PATCH 30/49] use default --- packages/analytics/lib/namespaced.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index 095a76e651..a07f282a77 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -866,7 +866,7 @@ export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatic Statics >; -const module = createModuleNamespace({ +export default createModuleNamespace({ statics, version, namespace, @@ -877,8 +877,6 @@ const module = createModuleNamespace({ ModuleClass: FirebaseAnalyticsModule, }) as typeof defaultExport; -export default module; - // Register the interop module for non-native platforms. setReactNativeModule(nativeModuleName, RNFBAnalyticsModule); From 1ab90acb94a5e17ab74ef0adb2eca8d411b1d20b Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 11:23:32 +0100 Subject: [PATCH 31/49] fix web api types --- packages/analytics/lib/web/api.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/analytics/lib/web/api.ts b/packages/analytics/lib/web/api.ts index c44375b5b5..42c74b8289 100644 --- a/packages/analytics/lib/web/api.ts +++ b/packages/analytics/lib/web/api.ts @@ -63,7 +63,7 @@ class AnalyticsApi implements IAnalyticsApi { private debug: boolean; private currentScreen: string | null; private sessionId?: number; - private cid?: string; + private cid?: string | null; constructor(appName: string, measurementId: string) { this.appName = appName; @@ -151,7 +151,11 @@ class AnalyticsApi implements IAnalyticsApi { } private async _getInstallationId(): Promise { - (navigator as any).onLine = true; + // @ts-ignore + if (navigator !== null) { + // @ts-ignore + (navigator as any).onLine = true; + } makeIDBAvailable(); const app = getApp(this.appName); const installations = getInstallations(app); From 9d983167b641e8ac361a517ca35870c7d7a6f910 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 11:26:23 +0100 Subject: [PATCH 32/49] fix SDK_VERSION problem --- packages/analytics/lib/namespaced.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/analytics/lib/namespaced.ts b/packages/analytics/lib/namespaced.ts index a07f282a77..32618826c2 100644 --- a/packages/analytics/lib/namespaced.ts +++ b/packages/analytics/lib/namespaced.ts @@ -861,6 +861,22 @@ export const SDK_VERSION: string = version; // import analytics, { firebase } from '@react-native-firebase/analytics'; // analytics().logEvent(...); // firebase.analytics().logEvent(...); + +// Override the createModuleNamespace type for this specific usage using module augmentation + +// declare module '@react-native-firebase/app/lib/internal' { +// function createModuleNamespace(config: { +// statics: any; +// version: string; +// namespace: string; +// nativeModuleName: string; +// nativeEvents: boolean; +// hasMultiAppSupport: boolean; +// hasCustomUrlOrRegionSupport: boolean; +// ModuleClass: any; +// }): ReactNativeFirebase.FirebaseModuleWithStatics; +// } + export declare const defaultExport: ReactNativeFirebase.FirebaseModuleWithStatics< FirebaseAnalyticsModule, Statics @@ -875,12 +891,13 @@ export default createModuleNamespace({ hasMultiAppSupport: false, hasCustomUrlOrRegionSupport: false, ModuleClass: FirebaseAnalyticsModule, -}) as typeof defaultExport; +}); // Register the interop module for non-native platforms. setReactNativeModule(nativeModuleName, RNFBAnalyticsModule); export const firebase: FirebaseAnalyticsModule & { analytics: typeof defaultExport; + SDK_VERSION: string; app(name?: string): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsModule }; } = getFirebaseRoot(); From 6b070ffae4bb55b8d66ce1ec9e3feee3c1b1bd15 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 13 Aug 2025 12:08:52 +0100 Subject: [PATCH 33/49] chore: update example app with analytics --- tests/ios/Podfile.lock | 162 ++++++++++---------- tests/test-app/examples/analytics/index.tsx | 44 ++++++ tests/test-app/index.js | 1 + 3 files changed, 126 insertions(+), 81 deletions(-) create mode 100644 tests/test-app/examples/analytics/index.tsx diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index 1de5d89df8..6895daa56c 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -1803,69 +1803,69 @@ PODS: - Yoga - RNDeviceInfo (14.0.4): - React-Core - - RNFBAnalytics (22.4.0): + - RNFBAnalytics (23.0.0): - FirebaseAnalytics/Core (= 12.1.0) - FirebaseAnalytics/IdentitySupport (= 12.1.0) - GoogleAdsOnDeviceConversion - React-Core - RNFBApp - - RNFBApp (22.4.0): + - RNFBApp (23.0.0): - Firebase/CoreOnly (= 12.1.0) - React-Core - - RNFBAppCheck (22.4.0): + - RNFBAppCheck (23.0.0): - Firebase/AppCheck (= 12.1.0) - React-Core - RNFBApp - - RNFBAppDistribution (22.4.0): + - RNFBAppDistribution (23.0.0): - Firebase/AppDistribution (= 12.1.0) - React-Core - RNFBApp - - RNFBAuth (22.4.0): + - RNFBAuth (23.0.0): - Firebase/Auth (= 12.1.0) - React-Core - RNFBApp - - RNFBCrashlytics (22.4.0): + - RNFBCrashlytics (23.0.0): - Firebase/Crashlytics (= 12.1.0) - FirebaseCoreExtension - React-Core - RNFBApp - - RNFBDatabase (22.4.0): + - RNFBDatabase (23.0.0): - Firebase/Database (= 12.1.0) - React-Core - RNFBApp - - RNFBFirestore (22.4.0): + - RNFBFirestore (23.0.0): - Firebase/Firestore (= 12.1.0) - React-Core - RNFBApp - - RNFBFunctions (22.4.0): + - RNFBFunctions (23.0.0): - Firebase/Functions (= 12.1.0) - React-Core - RNFBApp - - RNFBInAppMessaging (22.4.0): + - RNFBInAppMessaging (23.0.0): - Firebase/InAppMessaging (= 12.1.0) - React-Core - RNFBApp - - RNFBInstallations (22.4.0): + - RNFBInstallations (23.0.0): - Firebase/Installations (= 12.1.0) - React-Core - RNFBApp - - RNFBMessaging (22.4.0): + - RNFBMessaging (23.0.0): - Firebase/Messaging (= 12.1.0) - FirebaseCoreExtension - React-Core - RNFBApp - - RNFBML (22.4.0): + - RNFBML (23.0.0): - React-Core - RNFBApp - - RNFBPerf (22.4.0): + - RNFBPerf (23.0.0): - Firebase/Performance (= 12.1.0) - React-Core - RNFBApp - - RNFBRemoteConfig (22.4.0): + - RNFBRemoteConfig (23.0.0): - Firebase/RemoteConfig (= 12.1.0) - React-Core - RNFBApp - - RNFBStorage (22.4.0): + - RNFBStorage (23.0.0): - Firebase/Storage (= 12.1.0) - React-Core - RNFBApp @@ -2234,85 +2234,85 @@ SPEC CHECKSUMS: nanopb: fad817b59e0457d11a5dfbde799381cd727c1275 PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 PromisesSwift: 9d77319bbe72ebf6d872900551f7eeba9bce2851 - RCT-Folly: e78785aa9ba2ed998ea4151e314036f6c49e6d82 + RCT-Folly: 36fe2295e44b10d831836cc0d1daec5f8abcf809 RCTDeprecation: be794de7dc6ed8f9f7fbf525f86e7651b8b68746 RCTRequired: a83787b092ec554c2eb6019ff3f5b8d125472b3b RCTTypeSafety: 48ad3c858926b1c46f46a81a58822b476e178e2c React: 3b5754191f1b65f1dbc52fbea7959c3d2d9e39c9 React-callinvoker: 6beeaf4c7db11b6cc953fac45f2c76e3fb125013 - React-Core: 8a10ac9de53373a3ecb5dfcbcf56df1d3dad0861 - React-CoreModules: af6999b35c7c01b0e12b59d27f3e054e13da43b1 - React-cxxreact: 833f00155ce8c2fda17f6d286f8eaeff2ececc69 + React-Core: 88e817c42de035378cc71e009193b9a044d3f595 + React-CoreModules: dcf764d71efb4f75d38fcae8d4513b6729f49360 + React-cxxreact: 8cdcc937c5fbc406fe843a381102fd69440ca78a React-debug: 0a9fb34ecb645333d905645dabdcfdc945626078 - React-defaultsnativemodule: e3129434d3fc44832b7121bcbdffbe86c29ef34d - React-domnativemodule: 0dd52f92aae48f433ae5fa56876b4d10ab543faf - React-Fabric: 413d5fbb4b5df36df2d63520d529118884c9410e - React-FabricComponents: faa9035cdd551de0eaf2752afaf0b0327932696a - React-FabricImage: d43f0147c170c73cc7b546f95b7b7da82a6f34fc + React-defaultsnativemodule: b5b92d4b4716825afa8c848b793fc7efdf8aeb5a + React-domnativemodule: 073b3161e1b49dfe9045884369ae1ec2b987de26 + React-Fabric: f62d9ce5c158ae40c2a7b2805b7c055297c9dad7 + React-FabricComponents: 4c48b1052f8f6c3b03c3c3e2a231f1abd6d89703 + React-FabricImage: 5ad03b0081353e1e047ae3471bb129c521bf02b1 React-featureflags: 1bfa283a0e6f26eac629e8cef2add1b2670b6f4e - React-featureflagsnativemodule: 82733d2214096feaf44c411de375749ee1cd564f - React-graphics: 87a183c58b6a5bd5c57ae8c9a8105955f07f3947 - React-hermes: 63df5ac5a944889c8758a6213b39ed825863adb7 - React-idlecallbacksnativemodule: 6eac06a2d491a4b081ac45ab03a5ecf8b12404fa - React-ImageManager: f30c60d98a0a41eb116bf7e22a0258c821747ad2 - React-jserrorhandler: d68cef591c019bd8cd93169d253d6fe860b17844 - React-jsi: 99d6207ec802ad73473a0dad3c9ad48cd98463f6 - React-jsiexecutor: 8c8097b4ba7e7f480582d6e6238b01be5dcc01c0 - React-jsinspector: 434f39b00a5850b5479c7c0f0d06b480482d51a1 - React-jsinspectortracing: d43a8b9f953510ecebe3b5ec7e9676bef2d2c7f0 - React-jsitracing: 1df3b12bab22b3bc9078f54eefa53f82ba981dee - React-logger: 763728cf4eebc9c5dc9bfc3649e22295784f69f3 - React-Mapbuffer: 86e068fae064bbd3f24781d6ae5445b0266b2a10 - React-microtasksnativemodule: fd98e3e44af51599576705ec7a85a36e35978913 - React-NativeModulesApple: 5c61cef9e7f0e1d6216ff0af41a3b882806a5cec - React-perflogger: 5f8fa36a8e168fb355efe72099efe77213bc2ac6 - React-performancetimeline: 4f3521ee6238c9caf1b0969da2c4f610ff72b922 + React-featureflagsnativemodule: 7dc781f04bbd4b394fccb85e187bdda954362bca + React-graphics: 7eefc878da8a522942358f53abd6a7170d757bf3 + React-hermes: 08ad9fb832d1b9faef391be17309aa6a69fad23b + React-idlecallbacksnativemodule: 4a5d5ee0f8d7a9fa94ebd1426d349e866c223979 + React-ImageManager: ce227ed251701b3f37e25a2beede459078fcd82c + React-jserrorhandler: 6e5ffaef9b3364351ef6ef58d6665beabf615a0e + React-jsi: afa286d7e0c102c2478dc420d4f8935e13c973fc + React-jsiexecutor: 08f5b512b4db9e2f147416d60a0a797576b9cfef + React-jsinspector: ebe0817345b1c0194ed5c64185269b9668fadf9a + React-jsinspectortracing: 6f251cb68796f3496698127deabe5b0bbbb89b52 + React-jsitracing: 4c3fd6a14f560c52c167254a07029bcf9b60f3d8 + React-logger: 304814ae37503c8eb54359851cc55bd4f936b39c + React-Mapbuffer: 8ba61e036d346d363ad208cfb1dea6c7fce0dce0 + React-microtasksnativemodule: feb934d19767f38faf9f9f0efb7cc1dcdf2d11b7 + React-NativeModulesApple: 55d6d890aa60200292a90cc1ca6c53409650f48f + React-perflogger: 0ea25c109dba33d47dec36b2634bf7ea67c1a555 + React-performancetimeline: 21656d07aede48ca0c8c3ca7d0e755eaa17f697c React-RCTActionSheet: 2ef95837e89b9b154f13cd8401f9054fc3076aff - React-RCTAnimation: 46abefd5acfda7e6629f9e153646deecc70babd2 - React-RCTAppDelegate: 7e58e0299e304cceee3f7019fa77bc6990f66b22 - React-RCTBlob: f68c63a801ef1d27e83c4011e3b083cc86a200d7 - React-RCTFabric: ee035e3c73729b95da4ee0959b6e0d68cd512368 - React-RCTFBReactNativeSpec: 3240b9b8d792aa4be0fb85c9898fc183125ba8de - React-RCTImage: 34e0bba1507e55f1c614bd759eb91d9be48c8c5b - React-RCTLinking: a0b6c9f4871c18b0b81ea952f43e752718bd5f1d - React-RCTNetwork: bdafd661ac2b20d23b779e45bf7ac3e4c8bd1b60 - React-RCTSettings: 98aa5163796f43789314787b584a84eba47787a9 - React-RCTText: 424a274fc9015b29de89cf3cbcdf4dd85dd69f83 - React-RCTVibration: 92d9875a955b0adb34b4b773528fdbbbc5addd6c + React-RCTAnimation: 33d960d7f58a81779eea6dea47ad0364c67e1517 + React-RCTAppDelegate: 85c13403fd6f6b6cc630428d52bd8bd76a670dc9 + React-RCTBlob: 74c986a02d951931d2f6ed0e07ed5a7eb385bfc0 + React-RCTFabric: 384a6e22644799f66f545bf0de4618f4652c791f + React-RCTFBReactNativeSpec: eb1c3ec5149f76133593a516ff9d5efe32ebcecd + React-RCTImage: 2c58b5ddeb3c65e52f942bbe13ff9c59bd649b09 + React-RCTLinking: b6b14f8a3e62c02fc627ac4f3fb0c7bd941f907c + React-RCTNetwork: 1d050f2466c1541b339587d46f78d5eee218d626 + React-RCTSettings: 8148f6be0ccc0cfe6e313417ebf8a479caaa2146 + React-RCTText: 64114531ad1359e4e02a4a8af60df606dbbabc25 + React-RCTVibration: f4859417a7dd859b6bf18b1aba897e52beb72ef6 React-rendererconsistency: 80ffb3fc9635edb785c19f06eb1ba9e1d3b85ea6 - React-rendererdebug: ae050d2e1ad48d69fa20a7060766c9f132416ffa + React-rendererdebug: ea9b0383484ade00d675582d7848be6a86c3feb5 React-rncore: 7c0b895671632ea5eb84edb85f48e180816e9e33 - React-RuntimeApple: c85771bc5430980a8469ad3b28a3c8dd07f95979 - React-RuntimeCore: 45cbbed881ce89605c779b3f4111664664b63897 + React-RuntimeApple: 8e0654961ab947d3febc60f77a4d9fe97e135d0a + React-RuntimeCore: b194b603daafd68b140ab4c871f1556efc2c69bc React-runtimeexecutor: 876dfc1d8daa819dfd039c40f78f277c5a3e66a6 - React-RuntimeHermes: eb7f7ad2ad9d0bbe5e4e2521aae96de55bd4096a - React-runtimescheduler: 9957105c1d7f068a1c00760a9c332167634f945a + React-RuntimeHermes: f337612527ff2ca8bb86a861be4636f177bc3bbb + React-runtimescheduler: 307946600cf701b3ffe38b454d1d1a710e8e74e7 React-timing: 96e060d0d0bf18522d363716623ed2c61f7107c7 - React-utils: 93529ff7b4baa71aea1f42a48e9d3d06db398618 - ReactAppDependencyProvider: 4893bde33952f997a323eb1a1ee87a72764018ff - ReactCodegen: 31f8d982d351eb4dbf3af220f363c7398ae667c8 - ReactCommon: 0adf8f24a3415b6815613bad362d390726b33fc7 + React-utils: 8adf5864fc96ef51957fee06a3e43ed26559d8a7 + ReactAppDependencyProvider: b48473fe434569ff8f6cb6ed4421217ebcbda878 + ReactCodegen: dbfd0fb94c71add45b06cd6c96ccc7545489c1e6 + ReactCommon: 8fdc2d8511f4099f25d5929f7fa4284c14a7e509 RecaptchaInterop: 11e0b637842dfb48308d242afc3f448062325aba - RNCAsyncStorage: 5321442ed26760d7581b26effab82399ea5ff18b - RNDeviceInfo: d863506092aef7e7af3a1c350c913d867d795047 - RNFBAnalytics: d79de52fdb3d17d7014006734e25214b12f8d02d - RNFBApp: deff3bc877f0090ba2a16b923ae84cb1dec1d248 - RNFBAppCheck: 1a7c5bdce5688d11074cdbf516cf1a1f5f513ede - RNFBAppDistribution: 7d19ad9348dc46153c8ea71b576ce7034ca6304c - RNFBAuth: da460c1f646a62d8287af1dcc8338cd36bb72c2b - RNFBCrashlytics: e87e5d93551f022d703e5bb103400fd3b8a73420 - RNFBDatabase: ec7a6a43daea77ef8be5ad888ad336d9bc1a75bb - RNFBFirestore: efecd02807a534d6cf42b20bbcb1dddbbe058c71 - RNFBFunctions: c15d47c6ac5871a20603bf4dc8a297b901b54c0b - RNFBInAppMessaging: 4a739ccdb6f2ab7f37edc2b352d605343548be82 - RNFBInstallations: 16c00e7654de1a432035039eb374b42e264ec9b1 - RNFBMessaging: b240ddd334ad2be306eb9a4e4cd21f34b6d3c50e - RNFBML: 93997896dd4ca03ed8adb95f92ebce4ccc8be31e - RNFBPerf: 8d43c594fc01217903b2ba878d4ddd9182b065c8 - RNFBRemoteConfig: c8ae84dc55583c53b750d3ddc722c4245ae4336b - RNFBStorage: fc101abb007aeb21a0abca77876f08783eb31e81 + RNCAsyncStorage: 320c8b9217695928a64d8ae993653425c8605368 + RNDeviceInfo: feea80a690d2bde1fe51461cf548039258bd03f2 + RNFBAnalytics: dc38002a186585719bd52bd6d289db67c1dc654a + RNFBApp: b7b23d12712d8d624eb9c28141b54276f05a408b + RNFBAppCheck: 8217fdd09c3c224743b7962319d434664264a508 + RNFBAppDistribution: 1f61b11e2ae464245bcd45270b83f3c2e9f5c07e + RNFBAuth: bd3a3eafe04dacae5ff1d06680903caf3c180049 + RNFBCrashlytics: 81911d4cb263eefdce695397cec7944a4e8f2115 + RNFBDatabase: fb9c77baf9220dc2b84dcec37ad54e24517c88bc + RNFBFirestore: 2b6e10ebf7b388816643e7baae57590cd4fde6c1 + RNFBFunctions: 4597f0ae217d4a024b789271c857bde21bd8b171 + RNFBInAppMessaging: db04698e0f6355da8a69c6373673d718c98a4a8c + RNFBInstallations: 2c3bdddf7dad6800f24bed8129fc965cf94b65d1 + RNFBMessaging: 723d063ba0296d008c7293a947628f3c6982979b + RNFBML: ece0775b93a31bcc510c68d2688fd7a2c6fd645a + RNFBPerf: dfa934f54f9a82d58fc9024757c4646b0a002417 + RNFBRemoteConfig: fbdfa9d5376ff258322fe03681ad5ff0fc805364 + RNFBStorage: 8099db4850b376ed9e2cf0bd6be53028a4f919c7 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 - Yoga: 6eb60fc2c0eef63e7d2ef4a56e0a3353534143a2 + Yoga: 0c521d2eddeeff54ba1126068140b6e970a77fc0 PODFILE CHECKSUM: 3abe8cfe7b06f24b788e90bea320d8ae6ea6d11a diff --git a/tests/test-app/examples/analytics/index.tsx b/tests/test-app/examples/analytics/index.tsx new file mode 100644 index 0000000000..51ffdc0b16 --- /dev/null +++ b/tests/test-app/examples/analytics/index.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { AppRegistry, Button, Text, View } from 'react-native'; +import analytics from '@react-native-firebase/analytics'; + +function App() { + return ( + + text text text + text text text +