Skip to content

Collecting MoPub Impression-Level Data as a Firebase Event

Today MoPub doesn’t offer an API providing impression-level events. The information is only allowed as a post-back to the app.

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:

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:

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;
    }
Previous ironSource Ad Revenue Measurement (ARM) Integration
Next Tracking IAP & Subscriptions in Firebase
Table of Contents