After completing the basic AdMob setup, you can also add the Firebase SDK for Google Analytics to take advantage of other features from Google Analytics and Firebase. Learn how to get started with Google Analytics later on this page.
These increasing levels of configuration support features that can help you optimize your app's user experience and your ad revenue. Check out the following table of features and its links to learn more!
Feature |
Add Mobile Ads SDK + enable user metrics |
Add Mobile Ads SDK + enable user metrics and Link AdMob to Firebase |
Add Mobile Ads SDK + enable user metrics and Link AdMob to Firebase and Add Firebase SDK for Analytics |
View user metrics in your AdMob account | |||
Automatically collect analytics events and user properties from your app | |||
View curated user metrics in AdMob | |||
Explore and work with your analytics data via Firebase | |||
View key metrics in the Firebase console | |||
Mark conversions for ad campaigns | |||
Build custom audiences | |||
Export and analyze data in BigQuery | |||
Access more customization features for your analytics data | |||
Log custom events for analytics and models (like logging ecommerce_purchase events for ARPU and ARPPU metrics) | |||
Configure custom conversions for ad campaigns | |||
Use
other Firebase products
(like Remote Config and A/B Testing) |
Get started with Google Analytics
Google Analytics is Firebase's analytics engine that gives you access to powerful insights into your data. Start using Google Analytics in your app by adding the Firebase SDK for Google Analytics.
With the basic AdMob setup, you can view aggregated statistics from automatically collected events and user properties in the Analytics dashboard of the Firebase console without adding any additional code to your app.
However, if you want to collect additional custom event data or user
properties, you'll need to use the Firebase SDK for Google Analytics. With
this SDK, you can log up to 500 different analytics event types, and there's no
limit on the total volume of events your app logs. An example use case for
logging custom events is to include data in your revenue calculation from a
custom event called ecommerce_purchase
to help you better represent
ARPU and
ARPPU
metrics.
By adding the Firebase SDK for Google Analytics, you can also add custom conversions for ad campaigns and enable the use of other Firebase products.
The following steps describe how to start using the Firebase SDK for Google Analytics in your app. After initializing the SDK, visit the Analytics documentation to learn how to start logging events in your app.
Step 1: Add a configuration file to your app
If you registered your app with Firebase before creating an AdMob link, then
you already added a Firebase configuration file to your app.
Check for a google-services.json
file in the module (app-level) directory of
your Android project.
Add the Firebase Android configuration file to your app:
In the Your apps card of your Project settings, select the package name of the app for which you need a config file.
>Click Download google-services.json to obtain your Firebase Android config file (
google-services.json
).- You can download your Firebase Android config file again at any time from your > Project settings.
- Make sure the config file name isn't appended with additional
characters, like
(2)
.
Move your config file into the module (app-level) directory of your app.
To enable Firebase products in your app, add the Google Services plugin to your Gradle files.
In your root-level (project-level) Gradle file (
<project>/build.gradle.kts
or<project>/build.gradle
), add rules to include the Google services Gradle plugin.Kotlin
plugins { id("com.android.application") version "7.3.0" apply false // ... // Add the dependency for the Google services Gradle plugin id("com.google.gms.google-services") version "4.4.2" apply false }
Groovy
plugins { id 'com.android.application' version '7.3.0' apply false // ... // Add the dependency for the Google services Gradle plugin id 'com.google.gms.google-services' version '4.4.2' apply false }
In your module (app-level) Gradle file (usually
<project>/<app-module>/build.gradle.kts
or<project>/<app-module>/build.gradle
), apply the Google services Gradle plugin.Kotlin
plugins { id("com.android.application") // Add the Google services Gradle plugin id("com.google.gms.google-services") // ... }
Groovy
plugins { id 'com.android.application' // Add the Google services Gradle plugin id 'com.google.gms.google-services' // ... }
Step 2: Add the Firebase SDK for Analytics to your app
Add the dependency for the Firebase SDK for Google Analytics to your module (app-level) Gradle file (usually
<project>/<app-module>/build.gradle.kts
or<project>/<app-module>/build.gradle
):implementation("com.google.firebase:firebase-analytics:22.1.2")
Declare the
com.google.firebase.analytics.FirebaseAnalytics
object at the top of your activity:Kotlin
private lateinit var firebaseAnalytics: FirebaseAnalytics
Java
private FirebaseAnalytics mFirebaseAnalytics;
Initialize it in the
onCreate()
method:Kotlin
// Obtain the FirebaseAnalytics instance. firebaseAnalytics = Firebase.analytics
Java
// Obtain the FirebaseAnalytics instance. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Implement custom event logging
This section shows an example of how to implement custom event
logging in your app. This specific example is for the
custom event ecommerce_purchase
which is a helpful event to log for
AdMob-linked apps, especially for calculating
ARPU and
ARPPU.
A key metric for your app is revenue by user, which can be further segmented into ARPU and ARPPU. These two metrics display in the User metrics card of your AdMob account and in the Analytics dashboard of the Firebase console. Revenue, though, isn't directly measured; instead, it's the sum of your estimated AdMob earnings and the following two analytics event values:
in_app_purchase
: when a user completes an in-app purchase that is processed by Google Play, like an initial subscription, unlocking premium services, or buying in-game items
ecommerce_purchase
: when a user completes a purchase, like online shopping, buying coupons or discount items, or buying movie tickets
Without any additional code in your app, the Mobile Ads SDK
automatically collects analytics data for in_app_purchase
events. However, if
you want to also include ecommerce_purchase
event data in the revenue
calculation, you'll need to implement custom logging via the Firebase SDK for
Google Analytics.
Here's how to implement custom event logging in your app:
Make sure that you've completed the Get started with Google Analytics section of this page, which includes configuring your app to use Firebase, adding the Firebase SDK for Google Analytics, and initializing the SDK.
Log an
ecommerce_purchase
event. Here's an example:Kotlin
val bundle = Bundle() bundle.putString(FirebaseAnalytics.Param.COUPON, "SummerPromo") bundle.putString(FirebaseAnalytics.Param.CURRENCY, "JPY") bundle.putString(FirebaseAnalytics.Param.VALUE, "10000") bundle.putString(FirebaseAnalytics.Param.SHIPPING, "500") bundle.putString(FirebaseAnalytics.Param.TRANSACTION_ID, "192803301") firebaseAnalytics.logEvent(FirebaseAnalytics.Event.ECOMMERCE_PURCHASE, bundle)
Java
Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.COUPON, "SummerPromo"); bundle.putString(FirebaseAnalytics.Param.CURRENCY, "JPY"); bundle.putString(FirebaseAnalytics.Param.VALUE, "10000"); bundle.putString(FirebaseAnalytics.Param.SHIPPING, "500"); bundle.putString(FirebaseAnalytics.Param.TRANSACTION_ID, "192803301"); mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.ECOMMERCE_PURCHASE, bundle);
To learn more about logging custom events in your app, visit the Analytics documentation.
Use other Firebase products in your app
After you add the Firebase SDK for Google Analytics, you can also start using other Firebase products, like Firebase Remote Config and Firebase A/B Testing.
Remote Config enables you to change the behavior and appearance of your app without publishing an app update, at no cost, for unlimited daily active users.
A/B Testing gives you the power to test changes to your app’s UI, features, or engagement campaigns to learn if they make an impact on your key metrics (like revenue and retention) before rolling the changes out widely.
Optimize ad monetization for your app
Try out different ad formats or configurations with a small subset of users, and then make data driven decisions about implementing the ad for all your users. To learn more, check out the following tutorials:
Test new ad format adoption (overview | implementation).
Optimize ad frequency (overview | implementation).