# How to connect Batch to Firebase Analytics?

Firebase Analytics, and in its latest form, [Google Analytics for Firebase](https://firebase.google.com/docs/analytics/), is an extensive analytics solution that enables brands to measure relevant KPIs on their app and how their users interact with it. Those key metrics will enable Batch customers to get clear performance data of their campaign, and also better understand the behaviour of users in order to encourage conversion scenarios within the app.

You can easily establish this connexion by completing the following steps:

{% stepper %}
{% step %}

## Installing the Firebase Dispatcher in Your Application <a href="#id-1-installing-the-firebase-dispatcher-in-your-application" id="id-1-installing-the-firebase-dispatcher-in-your-application"></a>

The Firebase dispatcher uses the [UTM tags](https://ga-dev-tools.appspot.com/campaign-url-builder/) (like on a lot of Google services) from your campaign to dispatch a new set of data on Firebase.

Once the dispatcher is installed, you will be able to track [different types of events](https://doc.batch.com/developer/sdk/ios/event-dispatchers#access-data-from-the-event) related to your push or In-App messaging campaigns on Firebase.

If you haven't already installed the Firebase event dispatcher, please read our technical documentation for [Android](https://doc.batch.com/developer/sdk/android/event-dispatchers) and [iOS](https://doc.batch.com/developer/sdk/ios/event-dispatchers).

**Note**: The [Google Analytics SDK has been sunsetted](https://support.google.com/firebase/answer/9167112) since October 2019 for non-Google Analytics 360 customers, meaning if you still use it on a free Google Analytics account, no data will be available and you must migrate to Firebase.
{% endstep %}

{% step %}

## Tracking campaigns with UTM tags <a href="#id-2a-tracking-a-push-campaign-with-a-utm-tag" id="id-2a-tracking-a-push-campaign-with-a-utm-tag"></a>

### a. Tracking a push campaign with a UTM tag

The dispatcher gathers the values of utm\_campaign, utm\_source and utm\_medium from the deeplink URL and from the custom payload of your campaign.

The tags utm\_source and utm\_medium are optional because they have a default value of batch and push accordingly.

You can add utm\_content only in the deeplink URL in case your push notification has several different buttons.

<figure><img src="https://2998247023-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbwlQFpRAhaFR79zae6Jf%2Fuploads%2F9xGYrUrpUMThRWGxHj1n%2FCapture.png?alt=media&#x26;token=65e27687-be0f-40fe-b4e1-d29ca1b5d3b5" alt="Tracking a push campaign with UTM tags"><figcaption><p>Tracking a push campaign with UTM tags</p></figcaption></figure>

### b. Tracking an In-App Campaign or Mobile Landings <a href="#id-2b-tracking-an-in-app-campaign-or-mobile-landings" id="id-2b-tracking-an-in-app-campaign-or-mobile-landings"></a>

{% hint style="info" %}
This feature is specific to Batch's Mobile Engagement Platform (More on the [difference between Batch's CEP and MEP](https://app.gitbook.com/s/UIK868wiiK9XOVyETGZS/other/faq/what-are-the-differences-between-batch-customer-engagement-platform-and-mobile-engagement-platform)).
{% endhint %}

The dispatcher gathers the value of utm\_campaign from the field Tracking ID of your campaign.

You can't customize the utm\_source and utm\_medium tags, they have a default value of batch and in-app accordingly.

You can add utm\_content only in the deeplink URL in case your in-app message has two different buttons.

<figure><img src="https://2998247023-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbwlQFpRAhaFR79zae6Jf%2Fuploads%2FJ0Ir66lXRZ5KhmGHt9OL%2FAnalytics_Firebase_TrackingInAppMobileLanding_17042025.png?alt=media&#x26;token=39e580ba-95ee-4dbb-a3c8-c7f1b5875301" alt="Tracking an in-app Campaign or Mobile Landings"><figcaption><p>Tracking an in-app Campaign or Mobile Landings</p></figcaption></figure>

⚠️ Please note that the event dispatchers are only available from Batch's 1.15 SDK version and above. If you use an older version of Batch's SDK you can integrate the Firebase Batch plugin. However, this only allows you to track **push opens** and retrieve the campaign's **UTM parameters**.

### Firebase plugin integration for older SDK versions <a href="#firebase-plugin-integration-for-older-sdk-versions" id="firebase-plugin-integration-for-older-sdk-versions"></a>

The plugin's job will be to read Batch's notifications clicks and extract the right parameters before sending them to Firebase.

### Android: <a href="#android" id="android"></a>

Start by copying the `FirebaseBatchIntegration` class to your project. The code can be found here :

<https://github.com/BatchLabs/code-snippets/tree/master/integrations/firebase/android>

As shown in the `BaseActivity` example of the gist, you will have to call `FirebaseBatchIntegration.handleIntent` in **every activity**, both in **onCreate** and **onNewIntent**.

### iOS: <a href="#ios" id="ios"></a>

Copy the `FirebaseBatchIntegration` class in your project. The code can be found here (Swift 4.2):

<https://github.com/BatchLabs/code-snippets/tree/master/integrations/firebase/ios>

Then, as shown in the gist, simply call

```
FirebaseBatchIntegration.setup()
```

**in** `applicationDidFinishLaunchingWithOptions` **before** `Batch.start(withAPIKey:)`

If you call this method after starting Batch, the integration may work incorrectly.

Once you integrate the plugin, you can add your UTM parameters to your campaign's deeplink as described in section **2.a** of this article.
{% endstep %}

{% step %}

## Testing your campaign tracking <a href="#id-3-testing-your-campaign-tracking" id="id-3-testing-your-campaign-tracking"></a>

In order to test whether your Batch campaign data is correctly being tracked, you can use Firebase's Debug feature as follows:

### a.Turning on the analytics debug mode <a href="#aturning-on-the-analytics-debug-mode" id="aturning-on-the-analytics-debug-mode"></a>

### Android <a href="#android" id="android"></a>

Execute the following command to turn on the analytics debug mode on your Android device:

```
$ adb shell setprop debug.firebase.analytics.app package_name
```

Once you finish debugging, make sure you turn off the debug mode using this command:

```
$ adb shell setprop debug.firebase.analytics.app .none.
```

### iOS <a href="#ios" id="ios"></a>

Specify the following line argument in Xcode to turn on the analytics debug mode on your iOS device:

```
-FIRDebugEnabled
```

Once you finish debugging, make sure you turn off the debug mode by specifying this line argument in Xcode:

```
-FIRDebugDisabled
```

### b.Testing your integration <a href="#btesting-your-integration" id="btesting-your-integration"></a>

On Firebase, go to **Analytics → DebugView**. You should see your device and Batch events as soon as you receive, open a push or display, close, click an In-App message.

<figure><img src="https://2998247023-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbwlQFpRAhaFR79zae6Jf%2Fuploads%2FBhIvxT4OiHaPSA70V9Ed%2FAnalytics_Firebase_DebugView_17042025.png?alt=media&#x26;token=3ea63faf-15bf-4fed-a495-6f632b5000a6" alt="Debug view"><figcaption><p>Debug view</p></figcaption></figure>
{% endstep %}
{% endstepper %}
