The Tenjin SDK can listen to AdMob impression level revenue data and send revenue events to Tenjin. This integration will send revenue related for each ad impression served from AdMob. Here are the steps to integrate:
- Install 安装 the AdMob Unity SDK: https://developers.google.com/admob/unity/quick-start#download_the_mobile_ads_unity_plugin
<aside> 💡
Please ensure you have the latest AdMob Unity SDK installed (> GoogleMobileAds-v7.0.0). Also use the Tenjin SDK version v1.15.9 or above.
</aside>
- Turn on the setting for impression-level ad revenue in your AdMob account:
- Sign in to your AdMob account at https://admob.google.com.
- 点击 Settings in the sidebar.
- 点击 Account 标签
- In the Account controls section, next to “Impression-level ad revenue” click to edit.
- Click the toggle to turn on this setting.
- 点击 保存'Save'。.
- Use the method
HandleAdPaidEventwhere you can send each impression with the fields in the below table. For value_micros, AdMob returns the value in micro units so it needs to be divided by 1,000,000 for iOS as in the sample code below.
[System.Serializable]
public class AdMobImpressionData
{
public string ad_unit_id;
public string currency_code;
public string response_id;
public long value_micros;
public string mediation_adapter_class_name;
public string precision_type;
}
private void HandleAdPaidEvent(string adUnitId, ResponseInfo responseInfo, AdValue adValue)
{
long adjustedValueMicros = adValue.Value;
#if UNITY_IOS
adjustedValueMicros /= 1000000;
#endif
// Create impression data object for serialization
var impressionData = new AdMobImpressionData
{
ad_unit_id = adUnitId,
currency_code = adValue.CurrencyCode,
response_id = responseInfo.GetResponseId(),
value_micros = adjustedValueMicros,
mediation_adapter_class_name = responseInfo.GetLoadedAdapterResponseInfo().AdapterClassName,
precision_type = adValue.Precision.ToString()
};
string json = JsonUtility.ToJson(impressionData);
Tenjin.getInstance("<YOUR-TENJIN-SDK_KEY>").AdMobImpressionFromJSON(json);
}
Here is an example impression level revenue data entry from AdMob.
| Parameter | Required? | Example |
|---|---|---|
| ad_unit_id | 没有 | ca-app-pub-3940256099942544%2F2934735716 |
| currency_code | 没有 | USD |
| response_id | 没有 | CKak5t_oovcCFRPJdwodJXQNRw |
| value_micros | 是 | 0.0001 |
| mediation_adapter_class_name | 没有 | GADMAdapterGoogleAdMobAds |
| precision_type | 没有 | Unknown |