MoPub 광고 수익 연동

MoPub 광고 수익 연동을 진행하면 MoPub 을 통해서 획득한 광고 수익 데이터를 수집하고, 해당 데이터를 Airbridge Dashboard 에서 Attribution, User 별로 나누어 확인할 수 있습니다.

MoPub 광고 수익 연동은 MoPub 광고 수익 데이터를 MoPub SDK 를 통해 받아와서 Airbridge SDK 에 전달하는 방식으로 이루어집니다. 그런데 MoPub 광고 수익 데이터는 MoPub Dashboard 에서 ILRD 설정을 켜야만 수집이 가능하기 때문에 연동을 위해서는 MoPub SDK 설치MoPub 광고 수익 연동 설정이 필요합니다.

16021602

MoPub SDK 설치

MoPub SDK 문서에 따라 5.7.0 이상 SDK 를 설치해주세요.

MoPub 광고 수익 연동

MoPub SDK 문서의 Impression Data 연동 가이드를 미리 확인해 주세요.

MoPub 대시보드 Impression-Level Revenue Data (ILRD) 설정

MoPub 문서에 따라 MoPub 대시보드 에서 ILRD 설정을 켜주세요.

🚧

MoPub’s full platform publisher 만 ILRD 설정을 사용할 수 있습니다.

만약 MoPub’s full platform publisher 가 아니라면 MoPub 에 문의해주세요.

MoPub Impression Data 를 에어브릿지로 전달

MoPub SDK 를 이용해서 광고 Impression Callback 을 설정하고, 이를 이용해서 광고 수익 데이터를 Airbridge SDK 로 전달해 주세요.

private void OnEnable() {
    MoPubManager.OnImpressionTrackedEvent += OnImpressionTrackedEvent;
}

private void OnImpressionTrackedEvent(string adUnitId, MoPub.ImpressionData impressionData)
{
    if (impressionData != null) {
      AirbridgeEvent @event = new AirbridgeEvent("airbridge.adImpression");
      var myImpressionObject = JsonUtility.FromJson<ImpressionObject>(impressionData.JsonRepresentation);
      var mopub = new Dictionary<string, object>();
      mopub["app_version"] = myImpressionObject.app_version;
      mopub["adunit_id"] = myImpressionObject.adunit_id;
      mopub["adunit_name"] = myImpressionObject.adunit_name;
      mopub["adunit_format"] = myImpressionObject.adunit_format;
      mopub["currency"] = myImpressionObject.currency;
      mopub["publisher_revenue"] = myImpressionObject.publisher_revenue;
      mopub["adgroup_id"] = myImpressionObject.adgroup_id;
      mopub["adgroup_name"] = myImpressionObject.adgroup_name;
      mopub["adgroup_type"] = myImpressionObject.adgroup_type;
      mopub["adgroup_priority"] = myImpressionObject.adgroup_priority;
      mopub["country"] = myImpressionObject.country;
      mopub["precision"] = myImpressionObject.precision;
      mopub["network_name"] = myImpressionObject.network_name;
      mopub["network_placement_id"] = myImpressionObject.network_placement_id;
      var adPartners = new Dictionary<string, object>();
      adPartners["mopub"] = mopub;
      @event.SetAction(myImpressionObject.network_name);
      @event.SetLabel(myImpressionObject.adunit_format);
      @event.SetValue(Convert.ToDouble(myImpressionObject.publisher_revenue));
      @event.AddSemanticAttribute("adPartners", adPartners);
      AirbridgeUnity.TrackEvent(@event);
    }
}

[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;
}
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(onImpressionTracked:)
                                             name:kMPImpressionTrackedNotification
                                           object:nil];

- (void)onImpressionTracked:(NSNotification *)notification {
    // nil for Rewarded Ad, otherwise your MPAdView/MPInterstitialAdController/MPNativeAd
    id<MPMoPubAd> adObject = notification.object;
    // nonnull
    NSString* adUnitID = notification.userInfo[kMPImpressionTrackedInfoAdUnitIDKey];
    // the impression's impression data, or nil if ILRD is not enabled
    MPImpressionData* impressionData = notification.userInfo[kMPImpressionTrackedInfoImpressionDataKey];
    if (impressionData != nil)
    {
        ABInAppEvent* event = [[ABInAppEvent alloc] init];
        [event setCategory:@"airbridge.adImpression"];
        [event setAction:impressionData.networkName];
        [event setLabel:impressionData.adUnitFormat];
        [event setValue:impressionData.publisherRevenue];
      
        NSData* jsonData = impressionData.jsonRepresentation;
        if (jsonData != nil) {
            NSError* error;
            NSDictionary* json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];;
          
            [event setSemantics:json];
        }

        [event send];
    }
}
NotificationCenter.default.addObserver(self,
                                       selector: #selector(onImpressionData(notification:)),
                                       name: NSNotification.Name.mpImpressionTracked,
                                       object: nil)

@objc
func onImpressionData(notification: Notification) {
    let adObject = notification.object as? MPMoPubAd
    let adUnitID = notification.userInfo?[kImpressionDataAdUnitIDKey] as? String
    let impressionData = notification.userInfo?[kMPImpressionTrackedInfoImpressionDataKey] as? MPImpressionData
    
    if impressionData != nil {
        let event = ABInAppEvent()
        event?.setCategory("airbridge.adImpression")
        event?.setAction(impressionData.networkName)
        event?.setLabel(impressionData.adUnitFormat)
        event?.setValue(impressionData.publisherRevenue)
        if let jsonData = impressionData?.jsonRepresentation {
            let json = try? JSONSerialization.jsonObject(with: jsonData, options: []) as? Dictionary<AnyHashable, AnyHashable>
            event?.setSemantics(json)
        }
      
        event?.send()
    }
}
ImpressionListener listener = new ImpressionListener() {
  @Override
  public void onImpression(@NonNull final String adUnitId, @Nullable final ImpressionData impressionData) {
    Log.i("Airbridge", "impression id: " + adUnitId);
    
    if (impressionData == null) {
      Log.w("Airbridge", "impression is not available on id: " + adUnitId);
    } else {
      Event event = new Event("airbridge.adImpression");
      Map<String, Object> mopub = new HashMap<>();
      mopub.put(ImpressionData.APP_VERSION, impressionData.getAppVersion());
      mopub.put(ImpressionData.ADUNIT_ID, impressionData.getAdUnitId());
      mopub.put(ImpressionData.ADUNIT_NAME, impressionData.getAdUnitName());
      mopub.put(ImpressionData.ADUNIT_FORMAT, impressionData.getAdUnitFormat());
      mopub.put(ImpressionData.IMPRESSION_ID, impressionData.getImpressionId());
      mopub.put(ImpressionData.CURRENCY, impressionData.getCurrency());
      mopub.put(ImpressionData.PUBLISHER_REVENUE, impressionData.getPublisherRevenue());
      mopub.put(ImpressionData.ADGROUP_ID, impressionData.getAdGroupId());
      mopub.put(ImpressionData.ADGROUP_NAME, impressionData.getAdGroupName());
      mopub.put(ImpressionData.ADGROUP_TYPE, impressionData.getAdGroupType());
      mopub.put(ImpressionData.ADGROUP_PRIORITY, impressionData.getAdGroupPriority());
      mopub.put(ImpressionData.COUNTRY, impressionData.getCountry());
      mopub.put(ImpressionData.PRECISION, impressionData.getPrecision());
      mopub.put(ImpressionData.NETWORK_NAME, impressionData.getNetworkName());
      mopub.put(ImpressionData.NETWORK_PLACEMENT_ID, impressionData.getNetworkPlacementId());
      mopub.put(ImpressionData.DEMAND_PARTNER_DATA, impressionData.getDemandPartnerData());
      Map<String, Object> adPartners = new HashMap<>();
      adPartners.put("mopub", mopub);
      Map<String, Object> semanticAttributes = new HashMap<>();
      semanticAttributes.put("adPartners", adPartners);
      event.setAction(impressionData.getNetworkName());
      event.setLabel(impressionData.getAdUnitFormat());
      event.setValue(impressionData.getPublisherRevenue() != null ? impressionData.getPublisherRevenue().floatValue() : null);
      event.setSemanticAttributes(semanticAttributes);
      Airbridge.trackEvent(event);
    }
  }
};

ImpressionsEmitter.addListener(listener);
val listener = ImpressionListener { adUnitId, impressionData ->
  Log.i("Airbridge", "impression id: $adUnitId")

  if (impressionData == null) {
    Log.w("Airbridge", "impression is not available on id: $adUnitId")
  } else {
    val event = Event("airbridge.adImpression")
    val mopub = mutableMapOf<String, Any?>()
    mopub[ImpressionData.APP_VERSION] = impressionData.appVersion
    mopub[ImpressionData.ADUNIT_ID] = impressionData.adUnitId
    mopub[ImpressionData.ADUNIT_NAME] = impressionData.adUnitName
    mopub[ImpressionData.ADUNIT_FORMAT] = impressionData.adUnitFormat
    mopub[ImpressionData.IMPRESSION_ID] = impressionData.impressionId
    mopub[ImpressionData.CURRENCY] = impressionData.currency
    mopub[ImpressionData.PUBLISHER_REVENUE] = impressionData.publisherRevenue
    mopub[ImpressionData.ADGROUP_ID] = impressionData.adGroupId
    mopub[ImpressionData.ADGROUP_NAME] = impressionData.adGroupName
    mopub[ImpressionData.ADGROUP_TYPE] = impressionData.adGroupType
    mopub[ImpressionData.ADGROUP_PRIORITY] = impressionData.adGroupPriority
    mopub[ImpressionData.COUNTRY] = impressionData.country
    mopub[ImpressionData.PRECISION] = impressionData.precision
    mopub[ImpressionData.NETWORK_NAME] = impressionData.networkName
    mopub[ImpressionData.NETWORK_PLACEMENT_ID] = impressionData.networkPlacementId
    mopub[ImpressionData.DEMAND_PARTNER_DATA] = impressionData.demandPartnerData
    val adPartners = mapOf("mopub" to mopub)
    event.action = impressionData.networkName
    event.label = impressionData.adUnitFormat
    event.value = impressionData.publisherRevenue?.toFloat()
    event.semanticAttributes = mutableMapOf("adPartners" to adPartners)
    Airbridge.trackEvent(event)
  }
}

ImpressionsEmitter.addListener(listener)