Integrate Impression-Level Revenue Data

Before you begin:

Implement the Impression Callback Interface

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

Note that parameter data in onImpression() is null unless you have enabled the ILRD feature with your MoPub account representative.

  1. Implement the interface ImpressionListener and subscribe to events from ImpressionEmitter to receive detailed impression data. The ImpressionEmitter class is not linked to the activity lifecycle. We recommend that you subscribe to events when your 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 Data to Other Tools or Vendors

Once you receive 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 a number of attribution and analytics vendors to support MoPub’s impression-level revenue data. Each vendor has their own format for receiving impression data. Our partners and their specifications are as follows:

Attribution/Analytics Vendor Format Specifications for Receiving ILRD
Adjust Adjust format specifications
AppsFlyer AppsFlyer format specifications
Branch Branch format specifications
Kochava Kochava format specifications
Singular Singular format specifications
Soomla Soomla format specifications
Tenjin Tenjin format specifications
GameAnalytics (BETA) GameAnalytics format specifications

Example

The following is an example of sending MoPub ILRD to an 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_id", impressionData.adunit_id);
    params.putString("adunit_name", impressionData.adunit_name);
    params.putString("app_version", impressionData.app_version);
    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 August 24, 2020

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.

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