Firebase Analytics In Flutter
Analytics — We all know they’re important building a successful app , which is why there are many different kinds of analytics tools for app developers to use. There are in app behavioral analysis which measures who your users are and what they’re doing & so on . Then you’ve got the attribution analytics which you can use to measure the effectiveness of your advertising and growth campaign , not to mention push notifications and crash reporting.But quite often this work is being done by completely different analytics libraries , which means you’ve got your reports living in various tools across the web and trying to understand trends across these different reports much less get them to talk to each other , isn’t always easy !
Google Analytics for firebase is the place where all the data that mobile developers’ need is at one place !
Content
Setting Up
STEP 1 : Go through this on how to add Firebase to your project
STEP 2 : Include this plugin in dependencies in pubspec.yaml
firebase_analytics: ^latest
STEP 3: Since firebase analytics is not retroactive meaning , events aren’t logged immediately in Dashboard , it might take upto 24 hrs ! So before running your app , you should include debugging which will enable DebugView
in firebase console using this command —
app_name should be the name of your app !
adb shell setprop debug.firebase.analytics.app com.example.app_name
This will enable DebugView
in your firebase console.
Walking through Dashboard
Simply by installing the Firebase Analytics SDK, Analytics automatically starts providing insight into your app (after some hours)
- Demographic Information — who your users are.
- Retention — how regularly they use your app.
- Engagement — how much time they spend & on what
- Average Revenue — shows how much they have spent , if your app supports in app purchases
These can include common events that Google Analytics for Firebase has already defined, like when your users add an item to their cart.
To better understand the features of dashboard , visit demo project here.
But not all apps are alike. And you can get detailed information about what your users are up to by logging events specific to your app.
Events
The lifeblood of Google Analytics for firebase is events.User research studies and focus groups , they all have their place but if you want to find out how people are really interacting with your app where they’re spending their time what they’re interacting with and where they’re getting stuck you’re gonna want to measure that using an analytics library like say Google Analytics for firebase. Firebase events help you understand what is happening in your app. Let us now look at some of the events —
- Default Events
Default events are added automatically , so all this host of events are being logged automatically for you so that you don’t have to do it for yourself and it comes right out of the box. Here’s a list of some default event. To get more details , head here.
first_open : Google Analytics will will log a first open event each time a new user starts using your app.+
in_app_purchase : if your app offers in-app purchases , automatically an in-app purchase event will be logged for you which will contain the value of the purchase and the product that was purchased.
user_engagement : Analytics will also track user engagement and sessions using the user engagement and session start event so you can track how much time people are spending engaged with your apps
app_update : Google Analytics can track events which help you understand who’s updating to the latest version of your app who’s uninstalling on Android.
crashlytics : an app exception event will be logged for you so that you can tell which crashes or which users are leading to crashes
AdMob : if you’re integrated with AdMob we log a trio of events to help you understand which users are seeing impressions and clicking on ads and being exposed to your ads in your app next by virtue of the integration with firebase Cloud messaging this trio of notification events is logged so you can help it can help you understand how users are reacting to responding to push notifications that you send to the app so all this host of events are being logged automatically for you so that you don’t have to do it for yourself and it comes right out of the box if you need more than just these automatic events we have a long list of suggested events for
2. Suggested Events
If you are actually logging these suggested events as prescribed you will be able to get reporting in a specific manner for many of these so there’s a nice little incentive there to using these suggested but you can add custom events too , to better understand even the most detailed interaction.There’s a long list of suggested events ,to get this comprehensive list head over here.
If you have an option , do prefer these events over custom events
3. Custom Events
Of course , if your app offers any features that can be neatly mapped any those suggested events you’re always welcome to use firbaseAnalytics API to log some an event with a custom name. We will go through this in brief further.
FirebaseAnalytics().logEvent(name: 'name',parameters:null);
So are you ready to add some analytics into your iOS/android app ?
Stick around and find out how !
We will design a simple app to log events like —
- Log In , Log Out , Sign Up.
- Whenever a user chooses Ice Cream or Chocolate.
- Whenever the user rates using the slider.
I have created two button press events. Whenever a user selects one of those , that activity is logged into Firebase Analytics. We will use Custom Events
to log our button press events.
LogEvent
Since this is a class method we don’t need to bring up a shared instance or anything like that.
Parameters —
- name : name of the event which will appear in your
DebugView
. If I were using a predefined event I would be entering a constant here instead of a string they all begin withAnalyticsEvents()
. Check them in the documentation
Note : Name must consist of only letters, digits or _ (underscores). Max length 40 . Otherwise It will not be logged.
- parameters : Logs a custom Flutter Analytics event with the given [name] and event [parameters]. Parameters contextualize that event to give you more context around what’s going on in your app.
Now let us check some of the Log Events which I included —
Button Press Event :
onPressed: () {
FirebaseAnalytics().logEvent(name: 'A_Product',parameters:null);
},
Slider Event :
Remember , log slider events at onChangeEnd
, otherwise you would end up having dozens of log every time somebody adjusts the slider and that’s probably not what you want.
onChangeEnd: (_value) {
FirebaseAnalytics().logEvent(name: 'Slider_Change',parameters: {'Value':_value});
},
NOTE : If your debug view is set up as mentioned from above , you should be able to see the events in the DebugView
of firebase like shown below —
Logged Events
- Session_Start (Default Event)
- Screen_View (Default Event)
- Login (Custom Event)
- A_Product (Custom Event indicating the product selected)
- Slider_Change (Custom Event indicating the user feedback)
If you have crashlytics integrated , analytics will show you where your user’s app is getting crashed!
Errors
Now , as I mentioned before that name
parameter can only have at max 40 characters , but what if I make it greater than 40. This is what DebugView
of firebase will show —
For more detailed demo watch this—
Congratulations ! You have now logged your events “lifeblood of Google Analytics” to firebase analytics
User Properties & Audiences :
So how can you use custom user properties to better understand your results in Google Analytics for Firebase?
Let’s find it out !
Google Analytics for Firebase is all about recording events that happen within your app and sending them over to the Firebase console so that you can get some information about them.
And while seeing this data in aggregate is nice, sometimes you want to break this down into more specific user segments. I mean, sure, it’s great to see people are visiting your in-app store.But who are these people?
Are they tablet owners, new users, Indians ?
Knowing who these people are can make it easier for you to personalize your app, create better user experiences, and get better results. If you have ad support enabled, you can even get the demographic information such as gender & age.
But very often your app will have its own specific user properties that you’ll want to use to filter your data !
Let’s now set some user properties for real ,
Remember the app we made for event logging , we would modify the same app to set some user properties !
Product A or Product B ?
Well, our marketing team has this theory that cat people are more likely to choose chocolate (product B) than dog people. And they want to back up that claim with data. Let’s see how —
I have created an Alert Dialog
which asks the user whether they are cat people or dog people
So what we want to do in the results is store that information in a user property.
setUserProperty(name : " ", value : " ");
If cat is selected :
FirebaseAnalytics().setUserProperty(
name: "dog_or_cat", value: "cat_person");
we can similarly do for dog !
NOTE : user properties are not retroactive. Once you set a user property for a particular user, any and all future events will be associated with that property. But don’t expect that previous events will be updated.Those remain unchanged.
But remember we also have to register this user property with a Firebase console so that it knows to filter future reports based on this value.
STEPS :
- Go to User Property
- Click on New User Property
- Add User Property Name & Description
Since Firebase Analytics is not retroactive , only the future events will now be filtered based on this user property !
After some hours ……
Steps
- Go to Events
- Now select the event on which you want to predict , in our case we will select B_Product (chocolates)
- Click on Add filter
- Now follow as shown below
- Select Filter & Date
Results :
Note : Always look for count per person because number of users in this case is only 1 but in real life scenarios number of users will be much larger , so event count can mislead you !
Dog Person = 14😕
Cat Person = 45 !!🤩
So our marketing folks were right !!
“Cat_Person tends to select B_Product more often !”
You can now use this data to target a segment of people. Let us see how !
Audiences
Audiences are groups of users you define in firebase analytics that can be used in a number of different ways —
- You can filter analytics reports and dashboard against particular audience
- You can send firebase notifications to a specific audience you can send different
- Remote config data to different audiences
- You can target these audiences in re-marketing campaigns like AdWords
NOTE:
audiences are not retroactive when you create an audience it will initially be empty.
Audiences can help you segment your analytics data to get better insights into how different segments of your users use your app differently. Let us take an example.
So our marketing team is very interested in catpeople who use the slider to rate product > 50 here. They think they’d be the perfect audience to upsell our new product of Cake too.
So we are going to want to create an audience of these people which we’ll do by combining the adjust slider event value >50 & with the dog or cat person user property.
STEPS :
- Open Audiences in Analytics
- Click on create new Audience
- Follow this —
4. Add parameter Adjust slider value > 50
Trust me when this app gets the more users it’ll be a lot more exciting so once this audience gets beyond ten users I can start using it to filter my reports and notifications or target via my AdWords campaigns and then I can finally start selling these cat people my cake upgrade
This is enough to get you started with audiences , audiences work best if you have a bunch of them already defined when you incorporate analytics into your app so start thinking about what audiences make the most sense for your app.
You can now target your cat people to sell your new products !
Wrap Up !
Observe & Analyze — This helps us observe & analyze using Firebase Analytics ,Crashlytics & Performance monitoring to see what our users are doing & discover issues before they reach everyone.
Hypothesis — we can improve the experience with them using predictions to segment the users that might be churning or spending more money 🤑
Experiments — we can run experiments on users using A/B Testing , targeting remote config & messaging
We’ll be able to analyze the changes we have made based on what users like and repeat the cycle all over again !
Now that we have added Firebase Analytics to our app , when people all across the world come to our app they will have a smooth & enjoyable experience !
Happy Fluttering !
— Anirudh Kolwadkar
Resources
flutter-devs/Firebase_Analytics
Integrating firebase analytics to Superpower your apps – flutter-devs/Firebase_Analyticsgithub.com
Google Analytics | Firebase
Google Analytics is a free app measurement solution that provides insight on app usage and user engagement. At the…firebase.google.com
Feel free to connect with us:
And read more articles from FlutterDevs.com.
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter related queries.
We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!.
We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences!.