# Collecting MoPub Impression-Level Data as a Firebase Event

One of the easiest ways to track MoPub impression-level data is by enabling Firebase to collect ad impressions as events. This article outlines the recommended methods for doing so.

**Summary:**

1. Enable ILRD
2. Integrate listeners to collect the post-back
3. Send the information as a Firebase Event.

### **1. Enabling Impression-level Revenue Data (ILRD):**

First, data will only be sent to SDK versions v5.7.0 or higher.

Below is MoPub’s documentation on the latest versions:

* [Android](https://developers.mopub.com/publishers/android/integrate/)
* [iOS](https://developers.mopub.com/publishers/ios/integrate/)
* [Unity](https://developers.mopub.com/publishers/unity/integrate/)

Contact your MoPub account representative to enable ILRD. If you’re not assigned an account manager you can send an email to <support@mopub.com> to request this feature.

### **2. Integrate listeners to collect post-back**

The ILRD event is sent as a JSON blob, to collect the JSON delivered with the ad impression you’ll need to add listeners to capture, parse and relay the information to Firebase:

* [Android](https://developers.mopub.com/publishers/android/impression-data/)
* [iOS](https://developers.mopub.com/publishers/ios/impression-data/)
* [Unity](https://developers.mopub.com/publishers/unity/impression-data/)

### **3. Relay the information as an event to Firebase**

Note, we recommend you send all information provided with the impression:

**iOS – Sending MoPub ILRD to Firebase**

```
- (void)mopubAd:(id<mpmopubad>)ad didTrackImpressionWithImpressionData:(MPImpressionData * _Nullable)impressionData
{

// Feed impression data into internal tools or send to third-party analytics
    if (impressionData != nil)
    {
     [FIRAnalytics logEventWithName:kFIREventAdImpression
      parameters:@{
        kFIRParameterAdPlatform:@”MoPub”,
        kFIRParameterAdUnitName:impressionData.adUnitName,   
        kFIRParameterAdFormat:impressionData.adunitFormat,
        kFIRParameterValue:impressionData.publisherRevenue,
        kFIRParameterCurrency:impressionData.currency,
        kFIRParameterAdSource:impressionData.networkName,
        @“precision”:impressionData.precision
        }];
    }
}</mpmopubad>
```

**Android – Sending MoPub ILRD to Firebase**

```
@Override
public void onImpression(@NonNull final String adUnitId, @Nullable final ImpressionData impressionData) {

  if (impressionData != null) {
    // Feed impression data into internal tools or send to third-party analytics
    FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(context);

    Bundle params = new Bundle();
    params.putString(FirebaseAnalytics.Param.AD_PLATFORM, “MoPub”);
    params.putString(FirebaseAnalytics.Param.AD_SOURCE, impressionData.network_name);
    params.putString(FirebaseAnalytics.Param.AD_FORMAT, impressionData.adunit_format);
    params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, impressionData.adunit_name);
    params.putString(FirebaseAnalytics.Param.VALUE, impressionData.publisher_revenue);
    params.putString(FirebaseAnalytics.Param.CURRENCY, impressionData.currency);
    params.putString("precision", impressionData.precision);
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params);
  }

}
```

**Unity – Sending MoPub ILRD to Firebase**

```
// REGISTER TO LISTEN TO THE EVENT FROM MOPUB SDK
    private void OnEnable() {
        MoPubManager.OnImpressionTrackedEvent += OnImpressionTrackedEvent;
    }

    private void OnImpressionTrackedEvent(string adUnitId, MoPub.ImpressionData impressionData)
    {
        // Feed impression data into internal tools or send to third-party analytics
        if (impressionData != null) {
          var myImpressionObject = JsonUtility.FromJson<ImpressionObject>(impressionData.JsonRepresentation);
          var impressionParameters = new[] {
              new Firebase.Analytics.Parameter("ad_platform", “MoPub”),
              new Firebase.Analytics.Parameter("ad_source", myImpressionObject.network_name),
              new Firebase.Analytics.Parameter("ad_unit_name", myImpressionObject.adunit_name),
              new Firebase.Analytics.Parameter("ad_format", myImpressionObject.adunit_format),
              new Firebase.Analytics.Parameter("value", myImpressionObject.publisher_revenue),
              new Firebase.Analytics.Parameter("currency", myImpressionObject.currency),
              new Firebase.Analytics.Parameter("precision", myImpressionObject.precision)
          };
          Firebase.Analytics.FirebaseAnalytics.LogEvent("ad_impression", impressionParameters);
        }
    }

    [Serializable]
    public class ImpressionObject
    {
        public string adunit_id;
        public string adunit_name;
        public string adunit_format;
        public string app_version;
        public string id;
        public string currency;
        public string publisher_revenue;
        public string network_name;
        public string network_placement_id;
        public string adgroup_id;
        public string adgroup_name;
        public string adgroup_type;
        public string adgroup_priority;
        public string country;
        public string precision;
    }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.adlibertas.com/data-integrations/ad-impression-level-revenue-connections/collecting-mopub-impression-level-data-as-a-firebase-event.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
