Getting Started
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-analytics`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/firebase-analytics/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
Section titled “Install”You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsThen use the following prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-analytics` plugin in my project.If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
bun add @capgo/capacitor-firebase-analyticsbunx cap syncImport
Section titled “Import”import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';API Overview
Section titled “API Overview”getAppInstanceId
Section titled “getAppInstanceId”Retrieves the app instance id.
Only available for Android and iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.getAppInstanceId();getSessionId
Section titled “getSessionId”Retrieves the current session id (ga_session_id).
Only available for Android and iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.getSessionId();setConsent
Section titled “setConsent”Sets the user’s consent mode.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.setConsent({} as SetConsentOptions);setUserId
Section titled “setUserId”Sets the user ID property.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.setUserId({} as SetUserIdOptions);setUserProperty
Section titled “setUserProperty”Sets a custom user property to a given value.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.setUserProperty({} as SetUserPropertyOptions);setCurrentScreen
Section titled “setCurrentScreen”Sets the current screen name.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.setCurrentScreen({} as SetCurrentScreenOptions);logEvent
Section titled “logEvent”Logs an app event.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.logEvent({} as LogEventOptions);setSessionTimeoutDuration
Section titled “setSessionTimeoutDuration”Sets the duration of inactivity that terminates the current session.
Only available for Android and iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.setSessionTimeoutDuration({} as SetSessionTimeoutDurationOptions);setEnabled
Section titled “setEnabled”Enables/disables automatic data collection. The value does not apply until the next run of the app.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.setEnabled({} as SetEnabledOptions);isEnabled
Section titled “isEnabled”Returns whether or not automatic data collection is enabled.
Only available for Web.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.isEnabled();resetAnalyticsData
Section titled “resetAnalyticsData”Clears all analytics data for this app from the device. Resets the app instance id.
Only available for Android and iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.resetAnalyticsData();initiateOnDeviceConversionMeasurementWithEmailAddress
Section titled “initiateOnDeviceConversionMeasurementWithEmailAddress”Initiates on-device conversion measurement with an email address.
Only available for iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.initiateOnDeviceConversionMeasurementWithEmailAddress({} as InitiateOnDeviceConversionMeasurementWithEmailAddressOptions);initiateOnDeviceConversionMeasurementWithPhoneNumber
Section titled “initiateOnDeviceConversionMeasurementWithPhoneNumber”Initiates on-device conversion measurement with a phone number.
Only available for iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.initiateOnDeviceConversionMeasurementWithPhoneNumber({} as InitiateOnDeviceConversionMeasurementWithPhoneNumberOptions);initiateOnDeviceConversionMeasurementWithHashedEmailAddress
Section titled “initiateOnDeviceConversionMeasurementWithHashedEmailAddress”Initiates on-device conversion measurement with a hashed email address.
Only available for iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress({} as InitiateOnDeviceConversionMeasurementWithHashedEmailAddressOptions);initiateOnDeviceConversionMeasurementWithHashedPhoneNumber
Section titled “initiateOnDeviceConversionMeasurementWithHashedPhoneNumber”Initiates on-device conversion measurement with a hashed phone number.
Only available for iOS.
import { FirebaseAnalytics } from '@capgo/capacitor-firebase-analytics';
await FirebaseAnalytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber({} as InitiateOnDeviceConversionMeasurementWithHashedPhoneNumberOptions);Type Reference
Section titled “Type Reference”GetAppInstanceIdResult
Section titled “GetAppInstanceIdResult”export interface GetAppInstanceIdResult { /** * The app instance id. * * Not defined if `FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE` has been set to `FirebaseAnalytics.ConsentStatus.DENIED`. * * @since 1.4.0 */ appInstanceId?: string;}GetSessionIdResult
Section titled “GetSessionIdResult”export interface GetSessionIdResult { /** * The current session id. * * Matches Firebase Analytics `ga_session_id`. * * Not defined if `FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE` has been set to `FirebaseAnalytics.ConsentStatus.DENIED`. * * @since 8.0.1 */ sessionId?: number;}SetConsentOptions
Section titled “SetConsentOptions”export interface SetConsentOptions { /** * The consent type. * * @since 6.0.0 */ type: ConsentType; /** * The consent status. * * @since 6.0.0 */ status: ConsentStatus;}SetUserIdOptions
Section titled “SetUserIdOptions”export interface SetUserIdOptions { /** * @since 0.1.0 */ userId: string | null;}SetUserPropertyOptions
Section titled “SetUserPropertyOptions”export interface SetUserPropertyOptions { /** * @since 0.1.0 */ key: string; /** * @since 0.1.0 */ value: string | null;}SetCurrentScreenOptions
Section titled “SetCurrentScreenOptions”export interface SetCurrentScreenOptions { /** * @since 0.1.0 */ screenName: string | null; /** * Only available for Android and iOS. * * @default null * @since 0.1.0 */ screenClassOverride?: string | null;}LogEventOptions
Section titled “LogEventOptions”export interface LogEventOptions { /** * The event name. * * @since 0.1.0 */ name: string; /** * The optional event params. * * @since 0.1.0 */ params?: { [key: string]: any };}SetSessionTimeoutDurationOptions
Section titled “SetSessionTimeoutDurationOptions”export interface SetSessionTimeoutDurationOptions { /** * Duration in seconds. * * @default 1800 * @since 0.1.0 */ duration: number;}SetEnabledOptions
Section titled “SetEnabledOptions”export interface SetEnabledOptions { /** * @since 0.1.0 */ enabled: boolean;}IsEnabledResult
Section titled “IsEnabledResult”export interface IsEnabledResult { /** * @since 0.1.0 */ enabled: boolean;}InitiateOnDeviceConversionMeasurementWithEmailAddressOptions
Section titled “InitiateOnDeviceConversionMeasurementWithEmailAddressOptions”export interface InitiateOnDeviceConversionMeasurementWithEmailAddressOptions { /** * The email address to initiate on-device conversion measurement with. * * @since 7.2.0 */ emailAddress: string;}InitiateOnDeviceConversionMeasurementWithPhoneNumberOptions
Section titled “InitiateOnDeviceConversionMeasurementWithPhoneNumberOptions”export interface InitiateOnDeviceConversionMeasurementWithPhoneNumberOptions { /** * The phone number to initiate on-device conversion measurement with. * * @since 7.2.0 */ phoneNumber: string;}Source Of Truth
Section titled “Source Of Truth”This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.
Keep going from Getting Started
Section titled “Keep going from Getting Started”If you are using Getting Started to plan dashboard and API operations, connect it with API Overview for the implementation detail in API Overview, Introduction for the implementation detail in Introduction, API Keys for the implementation detail in API Keys, Devices for the implementation detail in Devices, and Bundles for the implementation detail in Bundles.