Skip to content

unity-package/native-ads-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

Native ads for Unity

Tool native ads for Unity

Adding the SDK

1. Add the Google Mobile Ads plugin to your project

  • Download and import Google Mobile Ads plugin

2. Add the GoogleMobileAds-native and ToolNativeAd to your project

  • Download and import GoogleMobileAds-native and ToolNativeAd sdk

3. Force resolve dependencies

Force resolve the dependencies from Assets/External Dependency Manager/Android Resolver/Force Resolve if the resolver did not open automatically.

Setup Id

1. Add AdMob app ID

  • You can open this from Assets/Google Mobile Ads/Settings

image

  • Add the AdMob application IDs here

image

2. Add NativeAd ID

  • Via Tools -> NativeAd Settings to open NativeAdSettings Window

Screenshot 2024-11-29 102331

  • Add Native Ads Ids here

Screenshot 2024-11-29 102336

  • Use TestMode equals true, you will use the Google Mobile Ads test Id

Scene setup

1. Drag and Drop NativeAdHolderTemplate prefab

  • Drag and drop any of the Native ad unit prefab from the path Assets > ToolNativeAd > Prefabs > NativeAdHolderTemplate into your gameplay scene.

Screenshot 2024-11-29 102217

Screenshot 2024-11-29 102239

Screenshot 2024-11-29 102248

2. Edit NativeAdHolderTemplate

  • Edit the size, layout and image PlaceHolder in NativeAdHolder to suit your needs

(Note: When the ad fails to load, PlaceHolder will display)

Handle Script

1. FetchAd, Adtive and Block

        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

2. Tracking revenue

        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