Tool native ads for Unity
- Download and import Google Mobile Ads plugin
- Download and import GoogleMobileAds-native and ToolNativeAd sdk
Force resolve the dependencies from Assets/External Dependency Manager/Android Resolver/Force Resolve if the resolver did not open automatically.
- You can open this from Assets/Google Mobile Ads/Settings
- Add the AdMob application IDs here
- Via
Tools -> NativeAd Settings
to open NativeAdSettings Window
- Add Native Ads Ids here
Use TestMode
equalstrue
, you will use the Google Mobile Ads test Id
- Drag and drop any of the Native ad unit prefab from the path
Assets > ToolNativeAd > Prefabs > NativeAdHolderTemplate
into your gameplay scene.
- Edit the size, layout and image PlaceHolder in NativeAdHolder to suit your needs
(Note: When the ad fails to load, PlaceHolder will display)
public NativeAdHolder nativeAdHolder;
/// <summary>
/// Fetch and show Native Ad
/// </summary>
public void FetchAd()
{
nativeAdHolder.FetchAd();
}
/// <summary>
/// Hide visual NativeAd and show PlaceHolder
/// </summary>
public void BlockAd()
{
nativeAdHolder.Block();
}
/// <summary>
/// Show visual NativeAd and hide PlaceHolder
/// </summary>
public void ActiveAd()
{
nativeAdHolder.Active();
}
Note: In some cases the click goes through the popup and triggers the NativeAd, call the Block
method to prevent this. The Active
method is the opposite of Block
public NativeAdHolder nativeAdHolder;
private void OnEnable()
{
nativeAdHolder.Event_OnAdPaid += OnAdPaid;
}
private void OnDisable()
{
nativeAdHolder.Event_OnAdPaid -= OnAdPaid;
}
private void OnAdPaid(AdValue adValue)
{
Debug.Log(adValue.CurrencyCode);
Debug.Log(adValue.Value);
}
- Use the
Event OnAdPaid
event to register a callback to perform tracking