analytics package Stay organized with collections Save and categorize content based on your preferences.
The Firebase Analytics Web SDK. This SDK does not work in a Node.js environment.
Functions
| Function | Description |
|---|---|
| function(app, ...) | |
| getAnalytics(app) | Returns anAnalytics instance for the given app. |
| initializeAnalytics(app, options) | Returns anAnalytics instance for the given app. |
| function(analyticsInstance, ...) | |
| getGoogleAnalyticsClientId(analyticsInstance) | Retrieves a unique Google Analytics identifier for the web client. Seeclient_id. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.SeeTrack Screenviews. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.SeeMeasure exceptions. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.List of recommended event parameters can be found inthe GA4 reference documentation. |
| logEvent(analyticsInstance, eventName, eventParams, options) | Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.SeePage views. |
| setAnalyticsCollectionEnabled(analyticsInstance, enabled) | Sets whether Google Analytics collection is enabled for this app on this device. Sets globalwindow['ga-disable-analyticsId'] = true; |
| setCurrentScreen(analyticsInstance, screenName, options) | Use gtagconfig command to setscreen_name. |
| setUserId(analyticsInstance, id, options) | Use gtagconfig command to setuser_id. |
| setUserProperties(analyticsInstance, properties, options) | Use gtagconfig command to set all params specified. |
| function() | |
| isSupported() | 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 usingIndexedDB.open(). |
| function(consentSettings, ...) | |
| setConsent(consentSettings) | Sets the applicable end user consent state for this web app across all gtag references once Firebase Analytics is initialized.Use theConsentSettings to specify individual consent type values. By default consent types are set to "granted". |
| function(customParams, ...) | |
| setDefaultEventParameters(customParams) | 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. |
| function(options, ...) | |
| settings(options) | Configures Firebase Analytics to use customgtag ordataLayer names. Intended to be used ifgtag.js script has been installed on this page independently of Firebase Analytics, and is using non-default names for either thegtag function or fordataLayer. Must be called before callinggetAnalytics() or it won't have any effect. |
Interfaces
| Interface | Description |
|---|---|
| Analytics | An instance of Firebase Analytics. |
| AnalyticsCallOptions | Additional options that can be passed to Analytics method calls such aslogEvent, etc. |
| AnalyticsSettings | Analytics instance initialization options. |
| ConsentSettings | Consent status settings for each consent type. For more information, seethe GA4 reference documentation for consent state and consent types. |
| ControlParams | Standardgtag.js control parameters. For more information, seethe GA4 reference documentation. |
| CustomParams | Any custom params the user may pass togtag. |
| EventParams | Standardgtag.js event parameters. For more information, seethe GA4 reference documentation. |
| GtagConfigParams | A set of common Google Analytics config settings recognized bygtag.js. |
| Item | Standard Google AnalyticsItem type. |
| Promotion | Field previously used by some Google Analytics events. |
| SettingsOptions | Specifies custom options for your Firebase Analytics instance. You must set these before initializingfirebase.analytics(). |
Type Aliases
| Type Alias | Description |
|---|---|
| ConsentStatusString | Whether a particular consent type has been granted or denied. |
| Currency | Standard Google Analytics currency type. |
| CustomEventName | Any custom event name string not in the standard list of recommended event names. |
| EventNameString | Type for standard Google Analytics event names.logEvent also accepts any custom string and interprets it as a custom event name. |
function(app, ...)
getAnalytics(app)
Returns anAnalytics instance for the given app.
Signature:
exportdeclarefunctiongetAnalytics(app?:FirebaseApp):Analytics;Parameters
| Parameter | Type | Description |
|---|---|---|
| app | FirebaseApp | TheFirebaseApp to use. |
Returns:
initializeAnalytics(app, options)
Returns anAnalytics instance for the given app.
Signature:
exportdeclarefunctioninitializeAnalytics(app:FirebaseApp,options?:AnalyticsSettings):Analytics;Parameters
| Parameter | Type | Description |
|---|---|---|
| app | FirebaseApp | TheFirebaseApp to use. |
| options | AnalyticsSettings |
Returns:
function(analyticsInstance, ...)
getGoogleAnalyticsClientId(analyticsInstance)
Retrieves a unique Google Analytics identifier for the web client. Seeclient_id.
Signature:
exportdeclarefunctiongetGoogleAnalyticsClientId(analyticsInstance:Analytics):Promise<string>;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics |
Returns:
Promise<string>
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'add_payment_info',eventParams?:{coupon?:EventParams['coupon'];currency?:EventParams['currency'];items?:EventParams['items'];payment_type?:EventParams['payment_type'];value?:EventParams['value'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'add_payment_info' | |
| eventParams | { coupon?:EventParams['coupon']; currency?:EventParams['currency']; items?:EventParams['items']; payment_type?:EventParams['payment_type']; value?:EventParams['value']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'purchase'|'refund',eventParams?:{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):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'purchase' | 'refund' | |
| eventParams | { 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 |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'screen_view',eventParams?:{firebase_screen:EventParams['firebase_screen'];firebase_screen_class:EventParams['firebase_screen_class'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'screen_view' | |
| eventParams | { firebase_screen:EventParams['firebase_screen']; firebase_screen_class:EventParams['firebase_screen_class']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'search'|'view_search_results',eventParams?:{search_term?:EventParams['search_term'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'search' | 'view_search_results' | |
| eventParams | { search_term?:EventParams['search_term']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'select_content',eventParams?:{content_type?:EventParams['content_type'];item_id?:EventParams['item_id'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'select_content' | |
| eventParams | { content_type?:EventParams['content_type']; item_id?:EventParams['item_id']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'select_item',eventParams?:{items?:EventParams['items'];item_list_name?:EventParams['item_list_name'];item_list_id?:EventParams['item_list_id'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'select_item' | |
| eventParams | { items?:EventParams['items']; item_list_name?:EventParams['item_list_name']; item_list_id?:EventParams['item_list_id']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'select_promotion'|'view_promotion',eventParams?:{items?:EventParams['items'];promotion_id?:EventParams['promotion_id'];promotion_name?:EventParams['promotion_name'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'select_promotion' | 'view_promotion' | |
| eventParams | { items?:EventParams['items']; promotion_id?:EventParams['promotion_id']; promotion_name?:EventParams['promotion_name']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'set_checkout_option',eventParams?:{checkout_step?:EventParams['checkout_step'];checkout_option?:EventParams['checkout_option'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'set_checkout_option' | |
| eventParams | { checkout_step?:EventParams['checkout_step']; checkout_option?:EventParams['checkout_option']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'share',eventParams?:{method?:EventParams['method'];content_type?:EventParams['content_type'];item_id?:EventParams['item_id'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'share' | |
| eventParams | { method?:EventParams['method']; content_type?:EventParams['content_type']; item_id?:EventParams['item_id']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'sign_up',eventParams?:{method?:EventParams['method'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'sign_up' | |
| eventParams | { method?:EventParams['method']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'timing_complete',eventParams?:{name:string;value:number;event_category?:string;event_label?:string;[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'timing_complete' | |
| eventParams | { name: string; value: number; event_category?: string; event_label?: string; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'add_shipping_info',eventParams?:{coupon?:EventParams['coupon'];currency?:EventParams['currency'];items?:EventParams['items'];shipping_tier?:EventParams['shipping_tier'];value?:EventParams['value'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'add_shipping_info' | |
| eventParams | { coupon?:EventParams['coupon']; currency?:EventParams['currency']; items?:EventParams['items']; shipping_tier?:EventParams['shipping_tier']; value?:EventParams['value']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'view_cart'|'view_item',eventParams?:{currency?:EventParams['currency'];items?:EventParams['items'];value?:EventParams['value'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'view_cart' | 'view_item' | |
| eventParams | { currency?:EventParams['currency']; items?:EventParams['items']; value?:EventParams['value']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'view_item_list',eventParams?:{items?:EventParams['items'];item_list_name?:EventParams['item_list_name'];item_list_id?:EventParams['item_list_id'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'view_item_list' | |
| eventParams | { items?:EventParams['items']; item_list_name?:EventParams['item_list_name']; item_list_id?:EventParams['item_list_id']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent<Textendsstring>(analyticsInstance:Analytics,eventName:CustomEventName<T>,eventParams?:{[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | CustomEventName<T> | |
| eventParams | { [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'add_to_cart'|'add_to_wishlist'|'remove_from_cart',eventParams?:{currency?:EventParams['currency'];value?:EventParams['value'];items?:EventParams['items'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'add_to_cart' | 'add_to_wishlist' | 'remove_from_cart' | |
| eventParams | { currency?:EventParams['currency']; value?:EventParams['value']; items?:EventParams['items']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'begin_checkout',eventParams?:{currency?:EventParams['currency'];coupon?:EventParams['coupon'];value?:EventParams['value'];items?:EventParams['items'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'begin_checkout' | |
| eventParams | { currency?:EventParams['currency']; coupon?:EventParams['coupon']; value?:EventParams['value']; items?:EventParams['items']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'checkout_progress',eventParams?:{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):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'checkout_progress' | |
| eventParams | { 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 |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'exception',eventParams?:{description?:EventParams['description'];fatal?:EventParams['fatal'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'exception' | |
| eventParams | { description?:EventParams['description']; fatal?:EventParams['fatal']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'generate_lead',eventParams?:{value?:EventParams['value'];currency?:EventParams['currency'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'generate_lead' | |
| eventParams | { value?:EventParams['value']; currency?:EventParams['currency']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
List of recommended event parameters can be found inthe GA4 reference documentation.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'login',eventParams?:{method?:EventParams['method'];[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'login' | |
| eventParams | { method?:EventParams['method']; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
logEvent(analyticsInstance, eventName, eventParams, options)
Sends a Google Analytics event with giveneventParams. This method automatically associates this logged event with this Firebase web app instance on this device.
SeePage views.
Signature:
exportdeclarefunctionlogEvent(analyticsInstance:Analytics,eventName:'page_view',eventParams?:{page_title?:string;page_location?:string;page_path?:string;[key:string]:any;},options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| eventName | 'page_view' | |
| eventParams | { page_title?: string; page_location?: string; page_path?: string; [key: string]: any; } | |
| options | AnalyticsCallOptions |
Returns:
void
setAnalyticsCollectionEnabled(analyticsInstance, enabled)
Sets whether Google Analytics collection is enabled for this app on this device. Sets globalwindow['ga-disable-analyticsId'] = true;
Signature:
exportdeclarefunctionsetAnalyticsCollectionEnabled(analyticsInstance:Analytics,enabled:boolean):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | TheAnalytics instance. |
| enabled | boolean | If true, enables collection, if false, disables it. |
Returns:
void
setCurrentScreen(analyticsInstance, screenName, options)
Warning: This API is now obsolete.Use with
eventNameas 'screen_view' and add relevanteventParams. SeeTrack Screenviews.
Use gtagconfig command to setscreen_name.
Signature:
exportdeclarefunctionsetCurrentScreen(analyticsInstance:Analytics,screenName:string,options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | TheAnalytics instance. |
| screenName | string | Screen name to set. |
| options | AnalyticsCallOptions |
Returns:
void
setUserId(analyticsInstance, id, options)
Use gtagconfig command to setuser_id.
Signature:
exportdeclarefunctionsetUserId(analyticsInstance:Analytics,id:string|null,options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | TheAnalytics instance. |
| id | string | null | User ID to set. |
| options | AnalyticsCallOptions |
Returns:
void
setUserProperties(analyticsInstance, properties, options)
Use gtagconfig command to set all params specified.
Signature:
exportdeclarefunctionsetUserProperties(analyticsInstance:Analytics,properties:CustomParams,options?:AnalyticsCallOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| analyticsInstance | Analytics | |
| properties | CustomParams | |
| options | AnalyticsCallOptions |
Returns:
void
function()
isSupported()
This is a public static method provided to users that wraps four different checks:
- 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().
Signature:
exportdeclarefunctionisSupported():Promise<boolean>;Returns:
Promise<boolean>
function(consentSettings, ...)
setConsent(consentSettings)
Sets the applicable end user consent state for this web app across all gtag references once Firebase Analytics is initialized.
Use theConsentSettings to specify individual consent type values. By default consent types are set to "granted".
Signature:
exportdeclarefunctionsetConsent(consentSettings:ConsentSettings):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| consentSettings | ConsentSettings | Maps the applicable end user consent state for gtag.js. |
Returns:
void
function(customParams, ...)
setDefaultEventParameters(customParams)
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.
Signature:
exportdeclarefunctionsetDefaultEventParameters(customParams:CustomParams):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| customParams | CustomParams | Any custom params the user may pass to gtag.js. |
Returns:
void
function(options, ...)
settings(options)
Configures Firebase Analytics to use customgtag ordataLayer names. Intended to be used ifgtag.js script has been installed on this page independently of Firebase Analytics, and is using non-default names for either thegtag function or fordataLayer. Must be called before callinggetAnalytics() or it won't have any effect.
Signature:
exportdeclarefunctionsettings(options:SettingsOptions):void;Parameters
| Parameter | Type | Description |
|---|---|---|
| options | SettingsOptions | Custom gtag and dataLayer names. |
Returns:
void
ConsentStatusString
Whether a particular consent type has been granted or denied.
Signature:
exporttypeConsentStatusString='granted'|'denied';Currency
Standard Google Analytics currency type.
Signature:
exporttypeCurrency=string|number;CustomEventName
Any custom event name string not in the standard list of recommended event names.
Signature:
exporttypeCustomEventName<T>=TextendsEventNameString?never:T;EventNameString
Type for standard Google Analytics event names.logEvent also accepts any custom string and interprets it as a custom event name.
Signature:
exporttypeEventNameString='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';Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-11-14 UTC.