@firebase/analytics

  • Version 0.10.10
  • Published
  • 483 kB
  • 5 dependencies
  • Apache-2.0 license

Install

npm i @firebase/analytics
yarn add @firebase/analytics
pnpm add @firebase/analytics

Overview

The Firebase Analytics Web SDK. This SDK does not work in a Node.js environment.

Index

Functions

function getAnalytics

getAnalytics: (app?: FirebaseApp) => Analytics;

function getGoogleAnalyticsClientId

getGoogleAnalyticsClientId: (analyticsInstance: Analytics) => Promise<string>;

function initializeAnalytics

initializeAnalytics: (
app: FirebaseApp,
options?: AnalyticsSettings
) => Analytics;

function isSupported

isSupported: () => Promise<boolean>;
  • This is a public static method provided to users that wraps four different checks:

    1. Check if it's not a browser extension environment. 2. Check if cookies are enabled in current browser. 3. Check if IndexedDB is supported by the browser environment. 4. Check if the current browser context is valid for using IndexedDB.open().

    Modifiers

    • @public

function logEvent

logEvent: {
(
analyticsInstance: Analytics,
eventName: 'add_payment_info',
eventParams?: {
[key: string]: any;
coupon?: EventParams['coupon'];
currency?: EventParams['currency'];
items?: EventParams['items'];
payment_type?: EventParams['payment_type'];
value?: EventParams['value'];
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'add_shipping_info',
eventParams?: {
[key: string]: any;
coupon?: string;
currency?: string;
items?: Item[];
shipping_tier?: string;
value?: number;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'add_to_cart' | 'add_to_wishlist' | 'remove_from_cart',
eventParams?: {
[key: string]: any;
currency?: string;
value?: number;
items?: Item[];
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'begin_checkout',
eventParams?: {
[key: string]: any;
currency?: string;
coupon?: string;
value?: number;
items?: Item[];
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'checkout_progress',
eventParams?: {
[key: string]: any;
currency?: string;
coupon?: string;
value?: number;
items?: Item[];
checkout_step?: number;
checkout_option?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'exception',
eventParams?: { [key: string]: any; description?: string; fatal?: boolean },
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'generate_lead',
eventParams?: { [key: string]: any; value?: number; currency?: string },
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'login',
eventParams?: { [key: string]: any; method?: string },
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'page_view',
eventParams?: {
[key: string]: any;
page_title?: string;
page_location?: string;
page_path?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'purchase' | 'refund',
eventParams?: {
[key: string]: any;
value?: number;
currency?: string;
transaction_id: string;
tax?: Currency;
shipping?: Currency;
items?: Item[];
coupon?: string;
affiliation?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'screen_view',
eventParams?: {
[key: string]: any;
firebase_screen: string;
firebase_screen_class: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'search' | 'view_search_results',
eventParams?: { [key: string]: any; search_term?: string },
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'select_content',
eventParams?: {
[key: string]: any;
content_type?: string;
item_id?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'select_item',
eventParams?: {
[key: string]: any;
items?: Item[];
item_list_name?: string;
item_list_id?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'select_promotion' | 'view_promotion',
eventParams?: {
[key: string]: any;
items?: Item[];
promotion_id?: string;
promotion_name?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'set_checkout_option',
eventParams?: {
[key: string]: any;
checkout_step?: number;
checkout_option?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'share',
eventParams?: {
[key: string]: any;
method?: string;
content_type?: string;
item_id?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'sign_up',
eventParams?: { [key: string]: any; method?: string },
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'timing_complete',
eventParams?: {
[key: string]: any;
name: string;
value: number;
event_category?: string;
event_label?: string;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'view_cart' | 'view_item',
eventParams?: {
[key: string]: any;
currency?: string;
items?: Item[];
value?: number;
},
options?: AnalyticsCallOptions
): void;
(
analyticsInstance: Analytics,
eventName: 'view_item_list',
eventParams?: {
[key: string]: any;
items?: Item[];
item_list_name?: string;
item_list_id?: string;
},
options?: AnalyticsCallOptions
): void;
<T extends string>(
analyticsInstance: Analytics,
eventName: CustomEventName<T>,
eventParams?: { [key: string]: any },
options?: AnalyticsCallOptions
): void;
};
  • Sends a Google Analytics event with given eventParams. This method automatically associates this logged event with this Firebase web app instance on this device.

    List of recommended event parameters can be found in the GA4 reference documentation.

    Modifiers

    • @public
  • Sends a Google Analytics event with given eventParams. This method automatically associates this logged event with this Firebase web app instance on this device.

    See Measure exceptions.

    Modifiers

    • @public
  • Sends a Google Analytics event with given eventParams. This method automatically associates this logged event with this Firebase web app instance on this device.

    See Page views.

    Modifiers

    • @public
  • Sends a Google Analytics event with given eventParams. This method automatically associates this logged event with this Firebase web app instance on this device.

    See Track Screenviews.

    Modifiers

    • @public

function setAnalyticsCollectionEnabled

setAnalyticsCollectionEnabled: (
analyticsInstance: Analytics,
enabled: boolean
) => void;
  • Sets whether Google Analytics collection is enabled for this app on this device. Sets global window['ga-disable-analyticsId'] = true;

    Parameter analyticsInstance

    The Analytics instance.

    Parameter enabled

    If true, enables collection, if false, disables it.

    Modifiers

    • @public

function setConsent

setConsent: (consentSettings: ConsentSettings) => void;
  • Sets the applicable end user consent state for this web app across all gtag references once Firebase Analytics is initialized.

    Use the ConsentSettings to specify individual consent type values. By default consent types are set to "granted".

    Parameter consentSettings

    Maps the applicable end user consent state for gtag.js.

    Modifiers

    • @public

function setCurrentScreen

setCurrentScreen: (
analyticsInstance: Analytics,
screenName: string,
options?: AnalyticsCallOptions
) => void;
  • Use gtag config command to set screen_name.

    Parameter analyticsInstance

    The Analytics instance.

    Parameter screenName

    Screen name to set.

    Modifiers

    • @public

    Deprecated

    Use logEvent with eventName as 'screen_view' and add relevant eventParams. See Track Screenviews.

function setDefaultEventParameters

setDefaultEventParameters: (customParams: CustomParams) => void;
  • Adds data that will be set on every event logged from the SDK, including automatic ones. With gtag's "set" command, the values passed persist on the current page and are passed with all subsequent events.

    Parameter customParams

    Any custom params the user may pass to gtag.js.

    Modifiers

    • @public

function settings

settings: (options: SettingsOptions) => void;
  • 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.

    Parameter options

    Custom gtag and dataLayer names.

    Modifiers

    • @public

function setUserId

setUserId: (
analyticsInstance: Analytics,
id: string | null,
options?: AnalyticsCallOptions
) => void;
  • Use gtag config command to set user_id.

    Parameter analyticsInstance

    The Analytics instance.

    Parameter id

    User ID to set.

    Modifiers

    • @public

function setUserProperties

setUserProperties: (
analyticsInstance: Analytics,
properties: CustomParams,
options?: AnalyticsCallOptions
) => void;
  • Use gtag config command to set all params specified.

    Modifiers

    • @public

Interfaces

interface Analytics

interface Analytics {}
  • An instance of Firebase Analytics.

    Modifiers

    • @public

property app

app: FirebaseApp;

interface AnalyticsCallOptions

interface AnalyticsCallOptions {}
  • Additional options that can be passed to Analytics method calls such as logEvent, etc.

    Modifiers

    • @public

property global

global: boolean;
  • If true, this config or event call applies globally to all Google Analytics properties on the page.

interface AnalyticsSettings

interface AnalyticsSettings {}
  • Analytics instance initialization options.

    Modifiers

    • @public

property config

config?: GtagConfigParams | EventParams;
  • Params to be passed in the initial gtag config call during Firebase Analytics initialization.

interface ConsentSettings

interface ConsentSettings {}

property ad_personalization

ad_personalization?: ConsentStatusString;
  • Sets consent for personalized advertising.

property ad_storage

ad_storage?: ConsentStatusString;
  • Enables storage, such as cookies, related to advertising

property ad_user_data

ad_user_data?: ConsentStatusString;
  • Sets consent for sending user data to Google for advertising purposes.

property analytics_storage

analytics_storage?: ConsentStatusString;
  • Enables storage, such as cookies, related to analytics (for example, visit duration)

property functionality_storage

functionality_storage?: ConsentStatusString;
  • Enables storage that supports the functionality of the website or app such as language settings

property personalization_storage

personalization_storage?: ConsentStatusString;
  • Enables storage related to personalization such as video recommendations

property security_storage

security_storage?: ConsentStatusString;
  • Enables storage related to security such as authentication functionality, fraud prevention, and other user protection.

index signature

[key: string]: unknown;

    interface ControlParams

    interface ControlParams {}

    property event_callback

    event_callback?: () => void;

      property event_timeout

      event_timeout?: number;

        property groups

        groups?: string | string[];

          property send_to

          send_to?: string | string[];

            interface CustomParams

            interface CustomParams {}
            • Any custom params the user may pass to gtag.

              Modifiers

              • @public

            index signature

            [key: string]: unknown;

              interface EventParams

              interface EventParams {}

              property affiliation

              affiliation?: string;

                property checkout_option

                checkout_option?: string;

                  property checkout_step

                  checkout_step?: number;

                    property content_type

                    content_type?: string;

                      property coupon

                      coupon?: string;

                        property currency

                        currency?: string;

                          property description

                          description?: string;

                            property event_category

                            event_category?: string;

                              property event_label

                              event_label?: string;

                                property fatal

                                fatal?: boolean;

                                  property firebase_screen

                                  firebase_screen?: string;
                                  • Firebase-specific. Use to log a screen_name to Firebase Analytics.

                                  property firebase_screen_class

                                  firebase_screen_class?: string;
                                  • Firebase-specific. Use to log a screen_class to Firebase Analytics.

                                  property item_id

                                  item_id?: string;

                                    property item_list_id

                                    item_list_id?: string;

                                      property item_list_name

                                      item_list_name?: string;

                                        property items

                                        items?: Item[];

                                          property method

                                          method?: string;

                                            property number

                                            number?: string;

                                              property page_location

                                              page_location?: string;

                                                property page_path

                                                page_path?: string;

                                                  property page_title

                                                  page_title?: string;

                                                    property payment_type

                                                    payment_type?: string;

                                                      property promotion_id

                                                      promotion_id?: string;

                                                        property promotion_name

                                                        promotion_name?: string;

                                                          property promotions

                                                          promotions?: Promotion[];

                                                            property screen_name

                                                            screen_name?: string;

                                                              property search_term

                                                              search_term?: string;

                                                                property shipping

                                                                shipping?: Currency;

                                                                  property shipping_tier

                                                                  shipping_tier?: string;

                                                                    property tax

                                                                    tax?: Currency;

                                                                      property transaction_id

                                                                      transaction_id?: string;

                                                                        property value

                                                                        value?: number;

                                                                          index signature

                                                                          [key: string]: unknown;

                                                                            interface GtagConfigParams

                                                                            interface GtagConfigParams {}
                                                                            • A set of common Google Analytics config settings recognized by gtag.js.

                                                                              Modifiers

                                                                              • @public

                                                                            property 'allow_ad_personalization_signals'

                                                                            allow_ad_personalization_signals?: boolean;

                                                                            property 'allow_google_signals'

                                                                            allow_google_signals?: boolean;

                                                                            property 'cookie_domain'

                                                                            cookie_domain?: string;

                                                                            property 'cookie_expires'

                                                                            cookie_expires?: number;

                                                                            property 'cookie_flags'

                                                                            cookie_flags?: string;

                                                                            property 'cookie_prefix'

                                                                            cookie_prefix?: string;

                                                                            property 'cookie_update'

                                                                            cookie_update?: boolean;

                                                                            property 'page_location'

                                                                            page_location?: string;

                                                                            property 'page_title'

                                                                            page_title?: string;

                                                                            property 'send_page_view'

                                                                            send_page_view?: boolean;
                                                                            • 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 Page views

                                                                            index signature

                                                                            [key: string]: unknown;

                                                                              interface Item

                                                                              interface Item {}
                                                                              • Standard Google Analytics Item type.

                                                                                Modifiers

                                                                                • @public

                                                                              property affiliation

                                                                              affiliation?: string;

                                                                                property brand

                                                                                brand?: string;
                                                                                • Deprecated

                                                                                  Use item_brand instead.

                                                                                property category

                                                                                category?: string;
                                                                                • Deprecated

                                                                                  Use item_category instead.

                                                                                property coupon

                                                                                coupon?: string;

                                                                                  property creative_name

                                                                                  creative_name?: string;

                                                                                    property creative_slot

                                                                                    creative_slot?: string;

                                                                                      property discount

                                                                                      discount?: Currency;

                                                                                        property id

                                                                                        id?: string;
                                                                                        • Deprecated

                                                                                          Use item_id instead.

                                                                                        property index

                                                                                        index?: number;

                                                                                          property item_brand

                                                                                          item_brand?: string;

                                                                                            property item_category

                                                                                            item_category?: string;

                                                                                              property item_category2

                                                                                              item_category2?: string;

                                                                                                property item_category3

                                                                                                item_category3?: string;

                                                                                                  property item_category4

                                                                                                  item_category4?: string;

                                                                                                    property item_category5

                                                                                                    item_category5?: string;

                                                                                                      property item_id

                                                                                                      item_id?: string;

                                                                                                        property item_list_id

                                                                                                        item_list_id?: string;

                                                                                                          property item_list_name

                                                                                                          item_list_name?: string;

                                                                                                            property item_name

                                                                                                            item_name?: string;

                                                                                                              property item_variant

                                                                                                              item_variant?: string;

                                                                                                                property location_id

                                                                                                                location_id?: string;

                                                                                                                  property name

                                                                                                                  name?: string;
                                                                                                                  • Deprecated

                                                                                                                    Use item_name instead.

                                                                                                                  property price

                                                                                                                  price?: Currency;

                                                                                                                    property promotion_id

                                                                                                                    promotion_id?: string;

                                                                                                                      property promotion_name

                                                                                                                      promotion_name?: string;

                                                                                                                        property quantity

                                                                                                                        quantity?: number;

                                                                                                                          interface Promotion

                                                                                                                          interface Promotion {}
                                                                                                                          • Field previously used by some Google Analytics events.

                                                                                                                            Modifiers

                                                                                                                            • @public

                                                                                                                            Deprecated

                                                                                                                            Use Item instead.

                                                                                                                          property creative_name

                                                                                                                          creative_name?: string;

                                                                                                                            property creative_slot

                                                                                                                            creative_slot?: string;

                                                                                                                              property id

                                                                                                                              id?: string;

                                                                                                                                property name

                                                                                                                                name?: string;

                                                                                                                                  interface SettingsOptions

                                                                                                                                  interface SettingsOptions {}
                                                                                                                                  • Specifies custom options for your Firebase Analytics instance. You must set these before initializing firebase.analytics().

                                                                                                                                    Modifiers

                                                                                                                                    • @public

                                                                                                                                  property dataLayerName

                                                                                                                                  dataLayerName?: string;
                                                                                                                                  • Sets custom name for dataLayer array used by gtag.js.

                                                                                                                                  property gtagName

                                                                                                                                  gtagName?: string;
                                                                                                                                  • Sets custom name for gtag function.

                                                                                                                                  Type Aliases

                                                                                                                                  type ConsentStatusString

                                                                                                                                  type ConsentStatusString = 'granted' | 'denied';
                                                                                                                                  • Whether a particular consent type has been granted or denied.

                                                                                                                                    Modifiers

                                                                                                                                    • @public

                                                                                                                                  type Currency

                                                                                                                                  type Currency = string | number;
                                                                                                                                  • Standard Google Analytics currency type.

                                                                                                                                    Modifiers

                                                                                                                                    • @public

                                                                                                                                  type CustomEventName

                                                                                                                                  type CustomEventName<T> = T extends EventNameString ? never : T;
                                                                                                                                  • Any custom event name string not in the standard list of recommended event names.

                                                                                                                                    Modifiers

                                                                                                                                    • @public

                                                                                                                                  type EventNameString

                                                                                                                                  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';
                                                                                                                                  • Type for standard Google Analytics event names. logEvent also accepts any custom string and interprets it as a custom event name.

                                                                                                                                    Modifiers

                                                                                                                                    • @public

                                                                                                                                  Package Files (1)

                                                                                                                                  Dependencies (5)

                                                                                                                                  Dev Dependencies (7)

                                                                                                                                  Peer Dependencies (1)

                                                                                                                                  Badge

                                                                                                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@firebase/analytics.

                                                                                                                                  • Markdown
                                                                                                                                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@firebase/analytics)
                                                                                                                                  • HTML
                                                                                                                                    <a href="https://www.jsdocs.io/package/@firebase/analytics"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>