Integrate Impression-Level Revenue Data

Use this document to start ingesting Impression-Level Revenue Data (ILRD).

Before you start this section:

  1. Make sure you are on MoPub SDK v5.7.0 or above.
  2. Read the article explaining Impression-Level Revenue Data (ILRD) to understand the flow of events that you will be implementing below.

Implement the Impression Callback Interface

MoPub SDK v5.7.0 and above has the public interface, ImnpressionListener. This listener is notified when an impression is fired for any format of ad shown.

Note that parameter data in onImpression() will be null unless you have enabled this feature with your MoPub account representative.

  1. Implement the interface ImpressionListener and subscribe to events from ImpressionEmitter to receive detailed impression data. ImpressionEmitter class is not linked to the activity lifecycle. We recommend that you subscribe to events when application starts, even before the first activity is created.

     interface ImpressionListener {
       void onImpression(@NonNull String adUnitId, @Nullable ImpressionData impressionData);
    }
    
  2. Call addListener to start listening for impression-level revenue data events.

  3. Call removeListener to unsubscribe from impression-level revenue data events.

    public void ImpressionsEmitter.addListener(ImpressionListener listener);
    public void ImpressionsEmitter.removeListener(ImpressionListener listener);
    

Make sure to not leak any ImpressionListeners. If your listener is tied to the activity lifecycle, make sure to remove the listener when the activity is destroyed.

Example

 @Override
    protected void onCreate(Bundle savedInstanceState) {

    	private ImpressionListener mImpressionListener;

    	mImpressionListener = new ImpressionListener() {
            @Override
            public void onImpression(@NonNull final String adUnitId, @Nullable final ImpressionData impressionData) {
                Log.i("ILRD", "impression for adUnitId= " + adUnitId);

                if (impressionData == null) {
                    // impression data is not available, write warning to LogCat
                    Log.w("ILRD", "impression data not available for adUnitId= " + adUnitId);
                } else {
                    try {
                        // impression data is available, process it here
                        Log.i("ILRD", "impression data adUnitId= " + adUnitId + "data=\n" + impressionData.getJsonRepresentation().toString(2));
                    } catch (JSONException e) {
                        Log.e("ILRD", "Can't format impression data. e=" + e.toString() );
                    }
                }
         	}
         }

          // subscribe to start listening for impression data
          ImpressionsEmitter.addListener(mImpressionListener);
    }



    @Override
    protected void onDestroy() {
    	// Remove the listener to unscubcribe 
      if (mImpressionListener != null) {
        ImpressionsEmitter.removeListener(mImpressionListener);
        mImpressionListener = null;
      }	
        super.onDestroy();
    }

Send MoPub ILRD Data to Third-Party Attribution and Analytics Vendors

Once you are receiving impression data, you can feed it to your internal Business Intelligence (BI) tools or send it to third-party attribution and analytics providers for further analysis. MoPub has collaborated with the following attribution & analytics vendors to support MoPub’s impression-level revenue data: Adjust, AppsFlyer, Branch, Kochava, Singular, Soomla, and Tenjin

Each third-party attribution and analytics vendor has its own required format for receiving ILRD data. Specifications to send your data to your third-party attribution and analytics vendors are below.

Example to send MoPub ILRD to Internal BI tool or Firebase

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

  // Feed impression data into internal tools or send to third-party analytics
  private FirebaseAnalytics mFirebaseAnalytics;
  mFirebaseAnalytics = FirebaseAnalytics.getInstance(context);

  if (impressionData != null) {
  Bundle params = new Bundle();
    params.putString("adunit", impressionData.adunit);
    params.putString("adunit_name", impressionData.adunit_name);
    params.putString("currency", impressionData.currency);
    params.putString("publisher_revenue", impressionData.publisher_revenue);
    params.putString("network_name", impressionData.network_name);
    params.putString("precision", impressionData.precision);

    mFirebaseAnalytics.logEvent("ad_impression_shown", params);


  }

}

Last updated November 07, 2019

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2019 MoPub (a division of Twitter, Inc.)