Looking to learn more about digital analytics? We have you covered on a wide variety of topics.
As a developer, Google Tag Manager (GTM) offers you the ability to manage measurement tags and pixels in your mobile applications without rebuilding and resubmitting the app to marketplaces. If you’re already using Google Analytics for Firebase in your Android app, integrating GTM can streamline your event management and help you easily implement changes, even after your app is live.
In this guide, we’ll walk through the setup process for integrating Google Tag Manager into your Android app using Firebase Analytics, along with clear instructions and steps for logging events, setting variables, and previewing and publishing your GTM container.
Before getting started, make sure you’ve completed the following steps:
Set up Firebase: Add your Android app to your Firebase project in the Firebase Console.
Enable Google Analytics: Ensure Google Analytics is enabled in your Firebase project, and add the Google Analytics for Firebase SDK to your app.
Create a Google Tag Manager Account: Create an account if you haven’t already, and configure a new GTM container.
To enable GTM in your Android app, you’ll need to configure dependencies and set up the container. Follow these steps:
In your app’s `build.gradle` file (usually located at `app/build.gradle`), add the following dependency for the GTM library:
Sign in to your Google Tag Manager account
Select your mobile container.
Go to Versions in the navigation bar, select the version you’d like to use, and click Download.
In your project, create a `containers` folder inside `app/src/main/assets` if it doesn’t exist.
Place the downloaded container file in this folder.
Once the GTM container is added, you can start logging events and setting variables to capture event parameters and user properties.
Using the Firebase SDK, log important events in your app. Here’s an example of logging a custom event:
To capture event parameters and user properties in GTM, set up variables in the GTM interface.
1. Event Parameter Variables: For the event above, configure event parameters for `image_name` and `full_text` in GTM.
Variable Name: `Image Name`
Variable Type: `Event Parameter`
Event Parameter Key Name: `image_name`
2. User Properties: You can set user properties similarly. For example, set a user property in your app:
Then, create a new Firebase User Property variable in GTM:
Variable Name: `Favorite Food`
Variable Type: `Firebase User Property`
Event Parameter Key Name: `favorite_food`
Google Tag Manager allows you to modify or block events before they reach Firebase Analytics.
With GTM, you can adjust event parameters or change event names without app updates. For instance, if you want to add or remove a parameter from an event, configure it in GTM directly.
If you want to prevent certain events from being sent to Firebase, you can set up a block condition in GTM. However, note that automatically collected events and properties in Firebase can’t be blocked.
Firebase Analytics events are automatically fired, but you can also use GTM triggers to control the firing of events and tags.
In GTM, triggers are conditions that determine when a tag should fire. To set up triggers:
Use Firebase event names and event parameter variables to define trigger conditions.
These conditions will be evaluated whenever you log an event in Firebase, allowing GTM to send or block events as specified.
Testing your GTM container before publishing is crucial to ensure all tags and triggers work as expected. GTM offers a preview mode that enables you to view and troubleshoot container configurations in your app.
Go to the **Google Tag Manager** web interface.
Select the container version and click **Actions > Preview**.
Save the preview URL or QR code generated by GTM.
1. Add the following preview activity to your `AndroidManifest.xml` file:
2. Replace `tagmanager.c.com.example.app` with your app’s package name.
To enable verbose logging and monitor GTM behavior in real-time, use the following ADB command:
After successfully testing your container, you can publish it:
Note: Mobile containers have a default container used initially for tag configurations until the first container download. After the initial download, the app checks for container updates periodically, typically every 12 hours.
By following these steps, you can integrate Google Tag Manager into your Android app and manage your tags and tracking pixels effectively. This setup gives you flexibility and control over your app’s analytics, without needing to update and redeploy your app with every change.
Integrating tools like GA4, Google Tag Manager, Looker Studio, and BigQuery can transform how your business tracks and optimizes marketing performance. But leveraging these platforms to their full potential requires expertise and strategy. At Tagmetrix, we specialize in helping businesses like yours turn raw data into actionable insights that drive growth and increase ROI.
Whether you’re running a small campaign or managing large-scale data, our digital analytics services are tailored to meet your specific needs. Let us handle the complexities of setup, tracking, and reporting so you can focus on what you do best—growing your business.
If you still have any questions, please feel free to reach out using our contact form and we'll be more than happy to help.
Copyright © Tagmetrix
Address: 18 Rean Drive, Toronto, Ontario, Canada, M2K0C7