Integrate with AdMob
This page covers every SDK platform and version. A part that applies only to some platforms starts with Platform: …, and a part that applies only to some SDK versions starts with SDK version: ….
If you use AdMob, you can track Ad Revenue from Impressions with the justtrack SDK.
Forward AdMob impressions
Platform: AndroidEvery AdMob ad format exposes an OnPaidEventListener. Set it on each ad object, and forward the value to justtrack:
import com.google.android.gms.ads.OnPaidEventListener
import io.justtrack.ads.AdImpression
import io.justtrack.ads.AdUnit
import io.justtrack.events.Money
rewardedAd.onPaidEventListener = OnPaidEventListener { adValue ->
sdk.forwardAdImpression(
AdImpression(
unit = AdUnit.Rewarded,
sdkName = "admob",
network = rewardedAd.responseInfo.loadedAdapterResponseInfo?.adSourceName,
placement = rewardedAd.adUnitId,
revenue = Money(adValue.valueMicros / 1_000_000.0, adValue.currencyCode),
)
)
}
Each ad object holds one listener. If you set onPaidEventListener again, or another SDK sets it, the last assignment wins and the earlier one stops receiving events.
Every AdMob ad format exposes a paidEventHandler property. Set it on each ad object, and forward the value to justtrack:
import GoogleMobileAds
import JustTrackSDK
let network = rewardedAd.responseInfo.loadedAdNetworkResponseInfo?.adSourceName
rewardedAd.paidEventHandler = { adValue in
_ = sdk.forward(
adImpression: AdImpression(unit: .rewarded, sdkName: "admob")
.set(network: network)
.set(placement: adUnitID)
.set(revenue: Money(value: adValue.value.doubleValue, currency: adValue.currencyCode))
)
}
Reading responseInfo outside the closure keeps the ad object from being captured, which avoids a retain cycle.
Each ad object holds one handler. If you set paidEventHandler again, or another SDK sets it, the last assignment wins and the earlier one stops receiving events.
Every AdMob ad format exposes an OnAdPaid event. Subscribe to it on each ad object, and forward the value to justtrack:
using GoogleMobileAds.Api;
using JustTrack;
rewardedAd.OnAdPaid += adValue =>
{
var responseInfo = rewardedAd.GetResponseInfo().GetLoadedAdapterResponseInfo();
JustTrackSDK.ForwardAdImpression(
new AdImpression(AdUnit.Rewarded, "admob")
.SetNetwork(responseInfo?.AdSourceName)
.SetPlacement(adUnitId)
.SetRevenue(new Money(adValue.Value / 1_000_000.0, adValue.CurrencyCode)));
};
The Google Mobile Ads Unity Plugin can raise ad events on a background thread, so call .ForwardAdImpression() from the Unity main thread. For details, see Google's Global settings.
Repeat this for every ad object you create, using the AdUnit value that matches the AdMob format: app open, banner, interstitial, native, rewarded, or rewarded interstitial.
Ad values don't use the same unit on every platform. Android and Unity report micro units, so divide by 1,000,000: a value of 5,000 means the ad is worth $0.005. On iOS, GADAdValue.value is already a decimal amount, so pass it to Money unchanged. Adjust this whenever you move a snippet between platforms.
The SDK name must be lowercase. Use admob, not AdMob. A different spelling splits your ad revenue across several SDK names in your reports.
Set the handler as soon as you create or receive the ad object, and always before you show the ad. Otherwise you miss paid event callbacks, and the impressions they represent. Forward each impression inside the handler rather than storing it for later, so you don't drop callbacks.
AdMob also returns the winning ad source, the instance name, and mediation group details in its response info. You can map any of these onto the other AdImpression dimensions described in Track ad impressions.
An AdMob guide isn't available for the justtrack React Native SDK yet. To track ad revenue from AdMob, forward each impression with .forwardAdImpression(). See Track ad impressions.
An AdMob guide isn't available for the justtrack Flutter SDK yet. To track ad revenue from AdMob, forward each impression with .forwardAdImpression(). See Track ad impressions.
An AdMob guide isn't available for the justtrack Godot SDK yet. To track ad revenue from AdMob, forward each impression manually. See Track ad impressions.
Platform: UnrealAn AdMob guide isn't available for the justtrack Unreal SDK yet. To track ad revenue from AdMob, forward each impression manually. See Track ad impressions.