Google AdMob 광고 수익 연동

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

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

AdMob SDK 설치

AdMob 노출 수준 광고 수익 기능 설정

AdMob 문서를 확인해주세요.

AdMob 광고 수익 데이터를 에어브릿지로 전달

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

private void RequestRewardedAd()
{
    RewardedAd.LoadAd(adUnitId, new AdRequest.Builder().Build(), (rewardedAd, error) => {
        if (error != null) { return; }

        this.rewardedAd = rewardedAd;
        this.rewardedAd.OnPaidEvent += this.HandleAdPaidEvent;
    }
}

public void HandleAdPaidEvent(object sender, AdValueEventArgs args)
{
    AdValue adValue = args.AdValue;
    var adUnitId = this.rewardedAd.adUnitId;
    var adNetworkAdapter = this.rewardedAd.MediationAdapterClassName();
  
    AirbridgeEvent @event = new AirbridgeEvent("airbridge.adImpression");

    var admob = new Dictionary<string, object>();
    admob["value_micros"] = adValue.Value;
    admob["currency_code"] = adValue.CurrencyCode;
    admob["precision"] = adValue.Precision;
  
    admob["ad_unit_id"] = adUnitId;
    admob["ad_network_adapter"] = adNetworkAdapter;
     
    var adPartners = new Dictionary<string, object>();
    adPartners["admob"] = admob;
  
    @event.SetAction(adUnitId);
    @event.SetLabel(adNetworkAdapter);
    @event.SetValue(adValue.Value / 1000000.0);
    @event.AddSemanticAttribute("adPartners", adPartners);
  	@event.AddSemanticAttribute("currency", adValue.CurrencyCode);
  
    AirbridgeUnity.TrackEvent(@event);
}
import GoogleMobileAds
import AirBridge
import UIKit

class ViewController: UIViewController {
    var rewardedAd: GADRewardedAd? = nil
    
    func requestRewardedAd() {
        let request = GADRequest()
        GADRewardedAd.load(
            withAdUnitID: "ad unit ID",
            request: request
        ) { ad, error in
            if let error {
                print("Rewarded ad failed to load with error: \(error.localizedDescription)")
                return
            }
            
            self.rewardedAd = ad
            self.rewardedAd?.paidEventHandler = { value in
                let (value, currencyCode, precision) = (
                    value.value,
                    value.currencyCode,
                    value.precision
                )
                
                let adUnitID = self.rewardedAd?.adUnitID
                let adNetworkAdapter = self.rewardedAd?.responseInfo.adNetworkClassName
                
                let event = ABInAppEvent()
                event?.setCategory("airbridge.adImpression")
                event?.setAction(adUnitID)
                event?.setLabel(adNetworkAdapter)
                event?.setValue(value)
                event?.setSemantics([
                    "adPartners": [
                        "admob": [
                            "value_micros": value * 1000000.0,
                            "currency_code": currencyCode,
                            "precision": precision,
                            
                            "ad_unit_id": adUnitID ?? NSNull(),
                            "ad_network_adapter": adNetworkAdapter ?? NSNull(),
                        ]
                    ],
                  	"currency": currencyCode
                ])

                event?.send()
            }
        }
    }
}
@import GoogleMobileAds;
@import AirBridge;
@import UIKit;

@interface ViewController ()
@property(nonatomic, strong) GADRewardedAd *rewardedAd;
@end

@implementation ViewController
- (void)requestRewardedAd {
    __weak ViewController* weakSelf = self;

    GADRequest* request = [GADRequest request];
    [GADRewardedAd loadWithAdUnitID:@"ad unit ID"
                            request:request
                  completionHandler:^(GADRewardedAd *ad, NSError *error) 
    {
        if (error) {
            NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
            return;
        }
        self.rewardedAd = ad;
        self.rewardedAd.paidEventHandler = ^void(GADAdValue *_Nonnull adValue){
            ViewController* strongSelf = weakSelf;

            // Extract the impression-level ad revenue data.
            NSDecimalNumber* value; = adValue.value;
            NSString* currencyCode = adValue.currencyCode;
            GADAdValuePrecision precision = adValue.precision;

            // Get the ad unit ID.
            NSString* adUnitId = strongSelf.rewardedAd.adUnitID;
            NSString* adNetworkAdapter = strongSelf.rewardedAd.responseInfo.adNetworkClassName;

            ABInAppEvent* event = [[ABInAppEvent alloc] init];
            [event setCategory:@"airbridge.adImpression"];
            [event setAction:adUnitId];
            [event setLabel:adNetworkAdapter];
            [event setValue:value];
            [event setSemantics:@{
                @"adPartners": @{
                    @"admob": @{
                        @"value_micros": [value decimalNumberByMultiplyingByPowerOf10:6],
                        @"currency_code": currencyCode,
                        @"precision": precision,
                        
                        @"ad_unit_id": adUnitId,
                        @"ad_network_adapter": adNetworkAdapter
                    }
                },
              	@"currency": currencyCode
            }];

            [event send];
        };
    }];
}
import com.google.android.gms.ads.rewarded.RewardedAd;

public class MainActivity extends Activity {
    private RewardedAd rewardedAd;
    private final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        AdRequest adRequest = new AdRequest.Builder().build();

        RewardedAd.load(this, "ad unit ID", adRequest, new RewardedAdLoadCallback(){
            @Override
            public void onAdLoaded(@NonNull RewardedAd ad) {
                rewardedAd = ad;
                // Set paid event listener
                rewardedAd.setOnPaidEventListener(new OnPaidEventListener() {
                    @Override
                    public void onPaidEvent(AdValue adValue) {
                        // Extract the impression-level ad revenue data.
                        long valueMicros = adValue.getValueMicros();
                        String currencyCode = adValue.getCurrencyCode();
                        String precision = adValue.getPrecisionType();

                        // Get the ad unit ID.
                        String adUnitId = rewardedAd.getAdUnitId();
                        String adNetworkAdapter = rewardedAd.getMediationAdapterClassName();
              
                        Event event = new Event("airbridge.adImpression");
                        Map<String, Object> admob = new HashMap<>();
                        admob.put("value_micros", valueMicros);
                        admob.put("currency_code", currencyCode);
                        admob.put("precision", precision);
              
                        admob.put("ad_unit_id", adUnitId);
                        admob.put("ad_network_adapter", adNetworkAdapter);
              
                        Map<String, Object> adPartners = new HashMap<>();
                        adPartners.put("admob", admob);
                        Map<String, Object> semanticAttributes = new HashMap<>();
                        semanticAttributes.put("adPartners", adPartners);
                        semanticAttributes.put("currency", currencyCode);
              
                        event.setAction(adUnitId);
                        event.setLabel(adNetworkAdapter);
                        event.setValue(valueMicros / 1000000.0);
                        event.setSemanticAttributes(semanticAttributes);
                        Airbridge.trackEvent(event);
                    }
                });
            }
        });
    }
}
import com.google.android.gms.ads.rewarded.RewardedAd

class MainActivity : AppCompatActivity() {
    private var rewardedAd: RewardedAd? = null
    private final var TAG = "MainActivity"

    override fun onCreate(savedInstanceState: Bundle?) {
        AdRequest adRequest = new AdRequest.Builder().build()

        RewardedAd.load(this, "ad unit ID", adRequest, object: RewardedAdLoadCallback() {
            override fun onAdLoaded(ad: RewardedAd) {
                rewardedAd = ad
                // Set paid event listener
                rewardedAd.onPaidEventListener = OnPaidEventListener { adValue ->
                    // Extract the impression-level ad revenue data.
                    val valueMicros = adValue.valueMicros
                    val currencyCode = adValue.currencyCode
                    val precision = adValue.precisionType

                    // Get the ad unit ID.
                    val adUnitId = rewardedAd.adUnitId
                    val adNetworkAdapter = rewardedAd.mediationAdapterClassName

                    val event = Event("airbridge.adImpression")
                    val admob = mutableMapOf<String, Any?>()
                    admob["value_micros"] = valueMicros
                    admob["currency_code"] = currencyCode
                    admob["precision"] = precision
                    
                    admob["ad_unit_id"] = adUnitId
                    admob["ad_network_adapter"] = adNetworkAdapter
                  
                    val adPartners = mapOf(
                        "admob" to admob,
                        "currency" to currencyCode
                    )
                    event.action = adUnitId
                    event.label = adNetworkAdapter
                    event.value = valueMicros / 1000000.0
                    event.semanticAttributes = mutableMapOf("adPartners" to adPartners)
                    Airbridge.trackEvent(event)
                }
            }
        })
    }
}

🚧

AdMob SDK는 Unity, Android 환경은 수익이 0.005달러일 때, value가 5000이 반환하고, iOS 환경은 수익이 0.005달러일 때, value가 0.005가 반환합니다. 위 예시코드는 모든 플랫폼에 대해서 Airbridge SDK에 value로 0.005를 입력하고 semanticAttributes.adPartners.admob.value_micros에는 5000을 입력하도록 가이드되어 있습니다.