Once installed, you can access the
firebase_analytics plugin by importing it in your Dart code:
Before using Firebase Analytics, you must first have ensured you have initialized FlutterFire.
To create a new Firebase Analytics instance, call the
instance getter on
By default, this allows you to interact with Firebase Analytics using the default Firebase App used whilst installing FlutterFire on your platform.
If you'd like to use a secondary Firebase Analytics, use the
instanceFor method - note multi-app support
is only available on the web:
The plugin supports logging both custom and predefined events to Analytics.
You can log custom events by calling the
logEvent method. The method accepts an event name (which will
be shown in the Analytics dashboard), along with any additional parameters for the event.
Note; if the event name is reserved or starts with
firebase_, an error will be thrown.
The plugin exposes a number of methods which accept a set of parameters which Firebase Analytics expects
when a given event is called. For example, the
logBeginCheckout event can be called when the user
starts a checkout flow on your application. It accepts the value, currency, checkout items and coupon
AnalyticsEventItem class provided above is a class which represents some item which is sent to Analytics. It
accepts a number of predefined parameters which will be used for analysis on the dashboard. Although
optional, to get the best experience from Firebase Analytics it is best to ensure as many relevant
parameters are provided.
You can learn more about the
AnalyticsEventItem class here.
Below is a table containing all predefined events available from the plugin:
|This event signifies that a user has submitted their payment information to your app.|
|This event signifies that a user has submitted their shipping information to your app.|
|This event signifies that an item was added to a cart for purchase.|
|This event signifies that an item was added to a wish list. Use this event to identify popular gift items in your app.|
|This event signifies an ad impression. Use this when an ad has been shown to the user.|
|Logs that the application has been opened.|
|This event signifies that a user has begun the process of checking out.|
|Log this event to supply the referral details of a re-engagement campaign.|
|This event tracks the awarding of virtual currency in your app.|
|Log this event when a lead has been generated in the app to understand the efficacy of your install and re-engagement campaigns.|
|Log this event when a user joins a group such as a guild, team or family.|
|This event signifies that a player has leveled up in your gaming app.|
|This event signifies that a player has started a level in your gaming app.|
|This event signifies that a player has ended a level in your gaming app.|
|Log this event when the user posts a score in your gaming app.|
|This event signifies that an item(s) was purchased by a user.|
|This event signifies that an item(s) was removed from a cart.|
|This event signifies a screen view. Use this when a screen transition occurs.|
|This event signifies that an item was selected by a user from a list.|
|This event signifies that a user has selected a promotion offer.|
|This event signifies that a user has viewed their cart. Use this to analyze your purchase funnel.|
|Apps that support search features can use this event to contextualize search operations by supplying the appropriate, corresponding parameters.|
|This general purpose event signifies that a user has selected some content of a certain type in an app.|
|Apps with social features can log the Share event to identify the most viral content.|
|This event indicates that a user has signed up for an account in your app.|
|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.|
|This event signifies the start of the on-boarding process in your app.|
|Use this event to signify the user's completion of your app's on-boarding process|
|Log this event when the user has unlocked an achievement in your game.|
|This event signifies that some content was shown to the user.|
|Log this event when the user has been presented with a list of items of a certain category.|
|This event signifies that a promotion was shown to a user.|
|Log this event when the user has been presented with the results of a search.|
|This event signifies that a refund was issued.|
setCurrentScreen to track each unique screen the user is selecting and build a picture of the most relevant screens in your application:
setDefaultEventParameters method if you have common parameters which need to be sent with each event. Please
note that this API is not supported on web.
setUserId method to set the current analytics session to assign events to the user's
id can be set to
null to remove the ID.
If you have any user properties to attach to the user, call the
You can provide a
null value to remove any previous properties.
To clear all data associated with the current session, use the
resetAnalyticsData method. Please
note that this API is not supported on web.
Set the applicable end user consent state.
default value for adStorageConsentGranted
& analyticsStorageConsentGranted is true`.
Please note that this API is not supported on web.
Set the duration of inactivity that terminates the current session. Please note that this API is android only.
Generally, events logged by your app are batched together over the period of approximately one hour and uploaded together. This approach conserves the battery on end users’ devices and reduces network data usage. However, for the purposes of validating your analytics implementation (and, in order to view your analytics in the DebugView report), you can enable Debug mode on your development device to upload events with a minimal delay. For further information, please read the official Firebase debug documentation.
To enable Analytics Debug mode on an Android device, execute the following command in your terminal:
This behavior persists until you explicitly disable Debug mode by executing the following command:
To enable Analytics Debug mode on your development device, specify the following command line argument in Xcode :
This behavior persists until you explicitly disable Debug mode by specifying the following command line argument :
To enable Analytics Debug mode in your browser, it is recommended you install the Google Analytics Debugger Chrome extension.
Once installed, enable the extension and refresh the page. From that point on, the extension will log events in your app in debug mode.
You can view events logged in the DebugView in the Firebase console.