Skip to content

Unity

Adiz Unity

Adiz Unity is an advertising module for Unity provided Hive SDK, making it easier to use the advertising features offered by AdMob. The types of ads offered by Adiz Unity are as follows:

  • Interstitial ads
  • Banner ads
  • Native ads
  • Rewarded ads
  • Rewarded Interstitial ads
  • App Open ads

To install and use Adiz Unity, follow the guide in order below.

Installation or update

  1. Configure Adiz Unity developer environment.
  2. Download the latest version of Adiz here and unzip it.
  3. In Unity, go to Assets > Import Package > Custom Package…, select the .unitypackage file, and click Import.

    4. Check if Adiz files and folders have been created under the Assets folder.

    5. Download and install the latest version of EDM4U. EDM4U is included in Hive SDK v4. If you are using Hive SDK v4, you do not need to install EDM4U separately.

To update the currently used version of Adiz, delete Adiz and download and install the latest version.

Unity setup

Android

Add the AdMobId value in the format of ca-app-pub-XXXXX~YYYYY to the Assets/Plugins/Android/AndroidManifest.xml file created in your Unity project.

    <manifest>
        <application>
            <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
            <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
        </application>
    </manifest>

To display video ads, hardware acceleration must be enabled. Add settings for hardware acceleration to the AndroidManifest.xml file. Adding it to the application tag will enable hardware acceleration for the entire application. Adding it to the activity tag will enable hardware acceleration only for specific Activity where you want to display ads.

    <application android:hardwareAccelerated="true">
            <!-- For activities that use ads, hardwareAcceleration should be true. -->
            <activity android:hardwareAccelerated="true" />
    </application>   

Check Use Jetifier in Unity's Android Resolver Settings (Assets > External Dependency Manager > Android Resolver > Settings).

In the Player Settings > Player > Build settings screen, check the following three items.

When using Proguard, the Proguard rules for the Adiz are already included in the Adiz module. Therefore, there is no need to add Proguard rules to your project.

Check your current version of Gradle. For a stable Android build, the Gradle version should be 6.7.1 or higher, and the Gradle plugin version should be 4.2.0 or higher. Here's how to change the Gradle version and Gradle plugin version:

  1. Use the Custom Base Gradle Template.

    • Check Build Settings > Project Settings > Player > Custom Base Gradle Template.
    • Assets/Plugins/Android/baseProjectTemplate.gradle will be created.
  2. Change the Gradle Plugin version. Open the file Assets/Plugins/Android/baseProjectTemplate.gradle* and change the version like com.android.tools.build:gradle:4.2.0.

  3. Download the required version of Gradle, then unzip it in your desired path.
  4. Change the Gradle installation path in Unity.
    • Uncheck Preferences > External Tools > Gradle Installed with Unity.
    • Set the path where you unzipped Gradle.
  5. Check that the Target API Level is 33 or higher in Player > Other Settings > Identification > Target API Level before building.

iOS

Uncheck the static_framework build setting in *Assets > External Dependency Manager > iOS Resolver > Settings.

Configure the Podfile created during the Unity build as follows.

    source 'https://github.com/CocoaPods/Specs.git'
    source 'https://github.com/Com2uSPlatformCorp/HiveAdiz-iOS.git'
    platform :ios, '12.0'
    target 'UnityFramework' do
        pod 'HiveAdizUnityPlugin', '2.0.1'
    end
    target 'Unity-iPhone' do
    end
    use_frameworks!
    # fix for dyld issue in pods when using Project
    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                # xcode 15 Toolchain Issue
                xcconfig_path = config.base_configuration_reference.real_path
                xcconfig = File.read(xcconfig_path)
                xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
                File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
                # end

                config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
                if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 12.0
                    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
                end
            end
        end
    end

Add the GADApplicationIdentifier key to the Info.plist file of the Xcode project created during the Unity build, and enter the AdMobId value (in the format ca-app-pub-XXXXX~YYYYY) as the key value. Or, you can uncomment the GADApplicationIdentifier setting line in the Assets/HiveAdiz/Editor/AdizPostProcess.cs file and add the AdMobId to automatically set it.

    GADApplicationIdentifier
    ca-app-pub-XXXXX~YYYYY

Additionally, for iOS 14 and above, refer to the Update your info.plist guide to add the SKAdNetwork list to the Info.plist file. The Assets/HiveAdiz/Editor/AdizPostProcess.cs file can be used to automatically add it to the Info.plist file during the build.

Setup test ads

Adiz allows you to display test ads in two ways.

  1. Enable test mode: Only display test ads issued by AdMob.
  2. Register test devices and display ads: Display real ads for testing purposes. Register the devices to display test ads to ensure no invalid traffic occurs during testing.

Enable test mode

During the development phase, enable test mode to prevent charging advertisers when test ads are clicked. When test mode is activated, only test ads are displayed. In test mode, you can display test ads without entering the AdMob ad key in the Hive Console. Disable test mode for commercial distribution.

Note

Excessive clicking on ads when not in test mode during the development phase may be considered invalid traffic and could lead to your AdMob account being reported and unable to display ads.

    using hiveAdiz;
    // Enable test mode. Comment out the below line when distributing commercially.
    Adiz.SetTestMode(true);
    // Enable logging for the Adiz module. Logging should only be used in test mode. Comment out the below line when distributing commercially.
    Adiz.SetLogEnable(true);

Displaying ads on test devices

In the following situations, it is necessary to register a test device to display test ads:

  • When testing if the AdMob ad key registered in the Hive Console is working properly
  • When writing a GDPR message and need to verify that the GDPR consent popup works correctly
  • When running the Ad Inspector to analyze and debug ad requests

If you test by displaying real ads without registering the test device, it may be considered invalid traffic, resulting in your AdMob account being blocked and ads no longer being displayed. When you register a test device, “Test Mode” or “Test Ad” (for native ads) will be shown when displaying ads. Ensure to disable the test device for commercial releases.

Banner, Interstitial, or Rewarded ads

Native ads

To register a test device, first identify the test device ID. On Android, the test device ID (e.g., 33BE2250B43518CCDA7DE426D04EE231) can be identified using the following two methods:

  1. Check the Logcat log after calling Adiz.Initialize(): Use new ConsentDebugSettings.Builder().addTestDeviceHashedI ("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
  2. Check the Logcat log after calling initialize()load() regardless of the ad type after calling

Adiz.Initialize(): I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("33BE2250B43518CCDA7DE426D04EE231")) to get test ads on this device."

On iOS, the test device ID (e.g., B74F6468-1516-467C-99AD-CC5973C5DB52) can be identified using the following two methods:

  1. Check the Logcat log after calling Adiz.Initialize(): To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[B74F6468-1516-467C-99AD-CC5973C5DB52]
  2. Check the Logcat log after calling initialize()load() regardless of the ad type after calling Adiz.Initialize(): GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [ "B74F6468-1516-467C-99AD-CC5973C5DB52" ]

After identifying the test device ID, add the line Adiz.setTestDevice(DEVICE_ID)before executing
Adiz.initialize in the existing Adiz initialization code. Enter the copied test device ID in DEVICE_ID.

using hiveAdiz;

public void Initialize() {

    // Set test device
    Adiz.SetTestDevice("33BE2250B43518CCDA7DE426D04EE231");

    Adiz.Initialize(new CommonHandlers.Builder()
                                            .OnResult(InitResultCB)
                                            .Build());
}

Using ad inspector

Ad Inspector is an in-app overlay tool that analyzes the process of requesting and displaying actual ads on a test device in real time. It informs you of the time taken to load the ad and, if the ad fails to display, it provides the reason for the failure. You can also specify a particular ad network to check if the ads are displaying correctly and debug at the code level if there are issues. This entire process is conducted through the Ad Inspector UI. It is included in Google Mobile Ads SDK Android 20.0.0 and Google Mobile Ads SDK iOS 7.68.0 or later, and can be used by calling AdizDeveloperTool.OpenAdInspector.

To use Ad Inspector, you need to meet the following two conditions:

Adiz AppID configuration

Set the Adiz AppID registered in the Hive Console AppCenter. If not set, the Package Name or Bundle ID will be used.

    Adiz.SetAppId(appId);

Hive Console server configuration

Configure the Hive Console server you want to use. The default is REAL. Even if you use the commercial server, only test ads will be displayed if test mode is enabled.

  • Test Console server: ZoneType.TEST
  • Sandbox Console server: ZoneType.SANDBOX
  • Commercial Console server: ZoneType.REAL
    ZoneType selectZone = ZoneType.REAL;    
    Adiz.SetZone((int)selectZone);

Exposing user-specific ads

With the introduction of ATT (App Tracking Transparency) in iOS 14.5+, privacy protection has been strengthened. As a result, user-specific ads can only be exposed if the user consents to activity tracking in the ATT consent popup. To maximize ad revenue by exposing user-specific ads, it is necessary to create an IDFA (Identifier for Advertisers) message. Create and publish your IDFA message following the guide on the AdMob dashboard.

Once the IDFA message is published on the AdMob dashboard, it will automatically be displayed during the initialization of Adiz in iOS 14.5+. Clicking "Continue" in the IDFA message window will display the ATT consent popup.

If the user clicks "Allow" in the ATT consent popup, IDFA is activated, and user-specific ads will be displayed.

Note

In Europe and the UK, the GDPR consent popup is displayed to users. If the user has never consented to the GDPR details, the ATT consent popup is displayed immediately after the GDPR consent popup, without displaying the IDFA message. If there has been consent to the GDPR details, the IDFA message is normally displayed followed by the ATT consent popup.

If your game targets Europe and the UK (EEA & UK), it is required to display a GDPR (General Data Protection Regulation) consent popup. The GDPR consent popup will only be shown if the user's device IP address is from Europe or the UK (EEA & UK). Adiz supports Google's UMP (User Messaging Platform) for displaying the GDPR consent popup.

After creating the GDPR message in the AdMob console, the GDPR popup will be displayed to users accessing from Europe and the UK when you initialize Adiz.

Warning

Even if you are targeting the regions outside of Europe and the UK, you must create the GDPR message in the AdMob console for the initialization of Adiz to be executed properly.

Creating GDPR message

Access the Google AdMob console to create the GDPR message. Before creating the GDPR message, refer to the GDPR message creation guide.

After creating the GDPR message, the GDPR consent popup will automatically be displayed during the initialization of Adiz.

Implementing options for GDPR consent/withdrawal

The GDPR consent popup should allow users to modify their consent at any time. For instance, users who initially did not consent to GDPR but wish to receive personalized ads may want to consent, or vice versa. To accommodate such scenarios, developers must implement functionality for users to either consent again or withdraw their previous consent. To implement GDPR consent/withdrawal functionality, follow these steps:

  1. Implement a button UI in your app to reload the GDPR consent popup window.
  2. When implementing the initialization of Adiz, call isPrivacyOptionsRequired() to display the button UI above for users accessing from Europe and the UK, and not display it otherwise. If users from Europe and the UK press the button, call showPrivacyOptionsForm to reload the GDPR consent popup, allowing users to modify their consent for GDPR details at any time through a "Manage Options" button or similar within the app. The showPrivacyOptionsForm method provided below is for illustration purposes only and can be implemented in any form desired by the developer.

    using hiveAdiz;
    
    public void Initialize() {
            // ... skipped
    
            // Initialize Adiz
            Adiz.Initialize(new CommonHandlers.Builder()
                                                                                            .OnResult(InitResultCB)
                                                                                            .Build());
    }
    
    private void InitResultCB(AdizError error, string jsonString) {
            // Initialization complete callback function
            Debug.Log(TAG + "::InitResultCB:: errorCode : "+error.errorCode+" errorMessage : "+error.errorMessage+" json : "+jsonString);
    
            if(error.isSuccess()) {
                    bool isPrivacyOptionsRequired = AdizConsentManager.IsPrivacyOptionsRequired();
                    if(isPrivacyOptionsRequired) {
                            // Show privacy options button. On click, call ShowPrivacyOptionsForm
                    } else {
                            // Hide privacy options button
                    }
            }
    }
    
    private void ShowPrivacyOptionsForm() {
            // Call privacy options form
            if(AdizConsentManager.IsPrivacyOptionsRequired()) {
                    AdizConsentManager.ShowPrivacyOptionsForm(new CommonHandlers.Builder()
                                                                                                    .OnResult(CommonResultCB)
                                                                                                    .Build());
            }
    }
    
    private void CommonResultCB(AdizError error, string jsonString) {
            // Privacy options form call complete callback. No additional error handling needed
            Debug.Log(TAG + "::CommonResultCB:: errorCode : "+error.errorCode+" errorMessage : "+error.errorMessage);
    }
    

Setting tag for users under the age of consent (TFUA)

You can use the Tag For Under the Age of Consent (TFUA) to treat users residing in the European Economic Area (EEA), the UK, and Switzerland as subjects of limited data processing when making ad requests. For apps that serve children, you can set the user as under the age of consent using AdizConsentManager.SetUserPrivacySettings. Although there are some differences between European countries, the GDPR defines the age under 16 as requiring parental consent. The under-age-of-consent setting must be configured before executing Adiz.initialize.

Warning

If both the GDPR under-age-of-consent tag SetTagForUnderAgeOfConsent and the COPPA child-directed treatment setting SetTagForChildDirectedTreatment are set to true simultaneously, the COPPA child-directed treatment setting SetTagForChildDirectedTreatment takes precedence. Therefore, do not use them both set to true at the same time.

Note

When using Hive SDK v4 24.2.0 or higher along with Adiz 2.0.1 or higher, the Hive SDK will automatically apply the tag for users under the age of consent according to the user's age. Therefore, there is no need to call AdizConsentManager.SetUserPrivacySettings.

 


using hiveAdiz;

public void Initialize() {

    bool isTagForUnderAgeOfConsent = false; // Change to true if user is a child

    PrivacySettings settings = new PrivacySettings.Builder()
                                .SetTagForUnderAgeOfConsent(isTagForUnderAgeOfConsent)
                                .Build();

    AdizConsentManager.SetUserPrivacySettings(settings);

    Adiz.Initialize(new CommonHandlers.Builder()
                                            .OnResult(InitResultCB)
                                            .Build());
}

Setting up GDPR test devices

The GDPR consent popup is displayed only if the device's IP address is from Europe or the UK. During development, you can force the GDPR consent popup to display regardless of the device IP address for testing purposes by setting up GDPR test devices. Follow the steps below to set up GDPR test devices. The following content is the same as Displaying ads on a test device

  1. Initialize Adiz. The purpose of this initialization is to check the test device ID, so you don't need to create a GDPR consent message in advance.
  2. Print Android Studio log or Xcode log to get the device ID. The following log is an example.

    Android: 33BE2250B43518CCDA7DE426D04EE231 in Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.

    iOS: B74F6468-1516-467C-99AD-CC5973C5DB52 in To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[B74F6468-1516-467C-99AD-CC5973C5DB52]

  3. Copy the device ID.

  4. Add Adiz.setTestDevice(DEVICE_ID) before executing Adiz.initialize in the existing Adiz initialization code.
  5. Create a GDPR consent message and reinitialize Adiz to ensure the GDPR consent popup appears correctly.

        using hiveAdiz;
    
        public void Initialize() {
    
                // Setting up GDPR Test Devices
                Adiz.SetTestDevice("33BE2250B43518CCDA7DE426D04EE231");
    
                Adiz.Initialize(new CommonHandlers.Builder()
                                                                                                .OnResult(InitResultCB)
                                                                                                .Build());
        }
    

Setting COPPA tag for child-directed treatment

In accordance with the Children's Online Privacy Protection Act (COPPA), app developers can specify whether Google should treat content as child-directed when making ad requests by setting the tagForChildDirectedTreatment (TFCD). If you want to treat the content as child-directed, you must call AdizConsentManager.SetUserPrivacySettings before executing Adiz.initialize. When using Adiz with Hive SDK, the tag for child-directed treatment is automatically applied, so no additional settings are necessary.


using hiveAdiz;

public void Initialize() {

    bool isTagForChildDirectedTreatment = false; // Change to true if child-directed

    PrivacySettings settings = new PrivacySettings.Builder()
                                .SetTagForChildDirectedTreatment(isTagForChildDirectedTreatment)
                                .Build();

    AdizConsentManager.SetUserPrivacySettings(settings);

    Adiz.Initialize(new CommonHandlers.Builder()
                                            .OnResult(InitResultCB)
                                            .Build());
}

Adding ad mediation

Adiz can serve ads using AdMob mediation. Follow the steps below to add AdMob mediation.

Adding AdMob mediation

Integrate ad sources in the AdMob console by following the table below.

AppLovin Pangle Unity Ads Meta
Step 1: Setup Android iOS Android iOS Android iOS Android iOS
Step 2: Add Ad Source Android iOS Android iOS Android iOS Android iOS
Step 3 Add Adiz Adapter

Add Adiz adapter

Add library dependencies in Assets/HiveAdiz/Editor/Adiz_DefaultDependencies.xml.

<dependencies>
    <androidPackages>
        <repositories>
            <repository>https://repo.maven.apache.org/maven2</repository>
            <repository>https://artifact.bytedance.com/repository/pangle/</repository>
        </repositories>

        <androidPackage spec="com.com2us.android.adiz:hive-adiz:2.0.1"/>
        <!-- AppLovin -->
        <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-applovin:2.0.1"/>
        <!-- Pangle -->
        <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-pangle:2.0.1"/>
        <!-- Unity Ads -->
        <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-unityads:2.0.1"/>
        <!-- Meta -->
        <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-meta:2.0.1"/>

    </androidPackages>
    <iosPods>
        <sources>
            <source>https://github.com/Com2uSPlatformCorp/HiveAdiz-iOS.git</source>
        </sources>

        <iosPod name="HiveAdizUnityPlugin" version="2.0.1"/>
        <iosPod name="HiveAdizAdapterAppLovin" version="2.0.1"/>
        <iosPod name="HiveAdizAdapterPangle" version="2.0.1"/>
        <iosPod name="HiveAdizAdapterUnityAds" version="2.0.1"/>
        <iosPod name="HiveAdizAdapterMeta" version="2.0.1"/>

    </iosPods>
    </dependencies>

 

To verify that the Adiz adapter configuration is correctly applied, run the app and check the configuration list on the Ad Inspector screen.

Adiz initialization

The initialization of Adiz is the essential step before exposing any type of advertisement. Initializing Adiz allows you to receive the ad keys necessary for displaying ads. If test mode is enabled, you will receive a test key. If you are using the Hive SDK, proceed with the Adiz initialization after calling AuthV4.setup.

using hiveAdiz;

public void Start() {
    /* omitted */

    // To use Adiz callbacks, you need to register AdizCallbackManager as a GameObject.    
    Adiz.InitPlugin();
}

Adiz.Initialize(new CommonHandlers.Builder()
                        .OnResult(InitResultCB)
                        .Build());

// Initialize Callback listener
private void InitResultCB(AdizError error, string jsonString) {
    Debug.Log(TAG + "::InitResultCB:: errorCode : "+error.errorCode+" errorMessage : "+error.errorMessage+" json : "+jsonString);

    if(error.isSuccess()) {

        JSONObject resJsonObject = new JSONObject (jsonString);

        JSONObject jsonArray = resJsonObject.GetField ("keys");

        if (jsonArray != null && jsonArray.count > 0) {

            List interstitialKeyList = new List();
            List bannerKeyList = new List();
            List nativeKeyList = new List();
            List rewardedKeyList = new List();
            List rewardedInterstitialKeyList = new List();
            List appOpenKeyList = new List();

            List jsonList = jsonArray.list;

            foreach (JSONObject jsonItem in jsonList) {

                bool isDefault = false;
                jsonItem.GetField(ref isDefault, "is_default");

                // This is an example of constructing a list of keys where is_default is false, in case you want to enter the ad keys directly in the game.
                if(isDefault) {
                    string hiveAdKey = null;
                    jsonItem.GetField(ref hiveAdKey, "key");

                    string form = null;
                    jsonItem.GetField(ref form, "form");

                    switch (form) {
                        case "interstitial":
                            interstitialKeyList.Add(hiveAdKey);
                            break;
                        case "banner":
                            bannerKeyList.Add(hiveAdKey);
                            break;
                        case "native":
                            nativeKeyList.Add(hiveAdKey);
                            break;
                        case "rewarded":
                            rewardedKeyList.Add(hiveAdKey);
                            break;
                        case "rewarded_interstitial":
                            rewardedInterstitialKeyList.Add(hiveAdKey);
                            break;
                        case "app_open":
                            appOpenKeyList.Add(hiveAdKey);
                            break;
                    }
                }
            }

            foreach(string hiveAdKey in interstitialKeyList) {
                Debug.Log("onSdkInitialize interstitialKeyList "+hiveAdKey);
            }

            foreach(string hiveAdKey in bannerKeyList) {
                Debug.Log("onSdkInitialize bannerKeyList "+hiveAdKey);
            }

            foreach(string hiveAdKey in nativeKeyList) {
                Debug.Log("onSdkInitialize nativeKeyList "+hiveAdKey);
            }

            foreach(string hiveAdKey in rewardedKeyList) {
                Debug.Log("onSdkInitialize rewardedKeyList "+hiveAdKey);
            }

            foreach(string hiveAdKey in rewardedInterstitialKeyList) {
                Debug.Log("onSdkInitialize rewardedInterstitialKeyList "+hiveAdKey);
            }

            foreach(string hiveAdKey in appOpenKeyList) {
                Debug.Log("onSdkInitialize appOpenKeyList "+hiveAdKey);
            }
        }
    }
}

The JSON file received as a callback during initialization contains a list of ad keys. The format of the ad key list is as follows:

    {
        "keys":[
            {
                "mediation_id":5,
                "key":"ca-app-pub-3940256099942544/5354046379",
                "form":"rewarded_interstitial",
                "is_default":true
            },
            {
                "mediation_id":4,
                "key":"ca-app-pub-3940256099942544/5224354917",
                "form":"rewarded",
                "is_default":true
            },
            {
                "mediation_id":3,
                "key":"ca-app-pub-3940256099942544/2247696110",
                "form":"native",
                "is_default":true
            },
            {
                "mediation_id":1,
                "key":"ca-app-pub-3940256099942544/1033173712",
                "form":"interstitial",
                "is_default":true
            },
            {
                "mediation_id":2,
                "key":"ca-app-pub-3940256099942544/6300978111",
                "form":"banner",
                "is_default":true
            },
            {
                "mediation_id":6,
                "key":"ca-app-pub-3940256099942544/9257395921",
                "form":"app_open",
                "is_default":true
            }
        ]
    }

When initializing in test mode, you will receive a list of test ad keys even if you haven't registered the AdMob ad key in the Hive Console. When initializing in commercial mode, you will receive a list of AdMob ad keys registered in the Hive Console.

For each ad type (form), one ad is used as the default ad (ad where "is_default":true). When you first register any ad type, the first registered ad becomes the default ad. You do not need to enter the ad key (hiveAdKey) when creating an ad instance (initialize()) for the default ad. To change the default ad, you must delete the existing default ad in the Hive Console and register a new ad.

Ad callback listener configuration

By implementing AdizListener when creating each ad instance, you can receive callbacks according to the state changes of the advertisement.

Name Description Required
.OnAdLoad(OnAdLoadCB) Ad load success O
.OnAdFail(OnAdLoadFailedCB) Failure (You can know the reason for failure through error.errorCode() and error.errorMessage()) O
.OnAdShow(OnAdShowCB) Ad exposure success O
.OnAdClick(OnAdClickCB) Ad click O
.OnAdPaidEvent(OnAdPaidEventCB) The moment of receiving a paid event after ad exposure, where ad revenue information is delivered O
.OnAdClose(OnAdCloseCB) Ad closed
* After the ad is closed, to re-expose the same ad instance, you must call load() again and then show().
* If you no longer wish to expose the ad, call destroy() to remove the ad instance.
X
.OnAdReward(OnAdRewardCB) The moment a user receives a reward after ad exposure in rewarded ads (rewarded, rewarded interstitial) X
private void OnAdLoadCB()
{   
    // Called when the ad is loaded.
    // If the ad load is successful, you should call .show() of the ad instance at the desired moment to display the ad.
    Debug.Log(TAG + "::OnAdLoadCB");

    // Expose after AdizInterstitial is loaded
    // requestShowAd();
}

private void OnAdLoadFailedCB(AdizError error) {
    // Called when the ad load fails or the ad exposure fails for another reason.
    Debug.Log(TAG + "::OnAdLoadFailedCB errorCode " + error.errorCode);
    Debug.Log(TAG + "::OnAdLoadFailedCB errorMessage " + error.errorMessage);
}

private void OnAdShowCB()
{   
    // Called when the ad is exposed.
    Debug.Log(TAG + "::OnAdShowCB");
}

private void OnAdCloseCB()
{   
    // Called when the ad is closed.
    Debug.Log(TAG + "::OnAdCloseCB");

    // Remove AdizInterstitial ad after exposure
    // requestDestroyAd();
}

private void OnAdClickCB()
{   
    // Called when the ad is clicked.
    Debug.Log(TAG + "::OnAdClickCB");
}

private void OnAdRewardCB(RewardItem rewardItem)
{   
    // Called when a reward is granted for watching an ad in rewarded or rewarded interstitial ads.
    Debug.Log(TAG + "::OnAdRewardCB:: rewardItem.itemType : " + rewardItem.getItemType() + " rewardItem.itemAmount : " + rewardItem.getItemAmount());
    // Delivered only in rewarded, rewardedInterstitial ads
}

private void OnAdPaidEventCB(AdRevenueData adRevenueData)
{   
    // Called when revenue is generated for the ad.
    Debug.Log(TAG + "::OnAdPaidEventCB:: adRevenueData.revenue : " + adRevenueData.getRevenue() + " adRevenueData.currency : " + adRevenueData.getCurrency());
}

Error codes

The AdizError error codes and messages received from Adiz.Initialize and AdizListener for OnAdFail() are as follows:

Common codes

Number Case Explanation
0 Success Success

Adiz error codes

Number Case Explanation
-1 InvalidParam Invalid parameter
-2 NotSupported Not supported
-3 InProgress Process in progress
-4 Network Network error
-5 NeedInitialize Initialization needed
-6 ResponseFail Response failure
-7 Timeout Network timeout
-99 Unknown Unknown error

Ad platform error codes

Number Case Explanation
-101 NeedLoad Ad not loaded
-102 NeedReload Need to reload due to ad exposure time expiration
-103 NotEnoughInventory Mediation response was successful, but no filled ads due to insufficient inventory
-104 MissingAppId AppID error for mediation request
-105 InternalNetworkError Error related to mediation network
-106 InvalidUnitId Invalid Unit Id
-107 MediationNoFill Mediation adapter could not process ad request
-108 AlreadyLoaded Already in a loaded state
-109 CannotRequestAds Cannot request ads
-201 GdprConsentError GDPR consent error
-202 IsNotPrivacyOptionsRequired No need to display or unable to display the GDPR consent popup

Ad display and termination

To display and terminate ads, follow these steps:

  1. Create ad instances from the ad class for each ad type you want to display. If the ad you want to display is not the default ad, you must enter the ad key obtained from initialization. If you do not enter the ad key (hiveAdKey), a default ad instance is created.
  2. Load (load()) the ad you want to display.
  3. Display (show()) the loaded ad. To re-display the ad, you must call load() again and then show().
  4. To terminate the ad, call destroy().

Interstitial ads

Full-screen ads that occupy the entire screen.

// Create AdizInterstitial Instance
private AdizInterstitial InterstitialAd = null;

public void requestInitAd(string interstitialAdKey) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


    if(string.IsNullOrEmpty(interstitialAdKey)) {
        // Initialize Default AdizInterstitial Instance (AdEventHandlers)
        InterstitialAd = AdizInterstitial.Initialize(eventHandlers);
    } else {
        // Initialize AdizInterstitial Instance (hiveAdKey, AdEventHandlers)
        InterstitialAd = AdizInterstitial.Initialize(interstitialAdKey, eventHandlers);
    }
}

public void requestLoadAd() {
    // Load AdizInterstitial
    if(InterstitialAd != null) InterstitialAd.Load();
}

public void requestShowAd() {
    // Show AdizInterstitial
    if(InterstitialAd != null) InterstitialAd.Show();
}

public void requestDestroyAd() {
    // Destroy AdizInterstitial
    if(InterstitialAd != null) InterstitialAd.Destroy();
    InterstitialAd = null;
}

Banner ads display banners of specific sizes. Banner ads do not receive the OnAdClose() callback. Therefore, you must call destroy() from another location to terminate the ad.

BannerSize follows standard banner sizes.

Size Points (Width x Height) Description Supported Devices BannerSize Constant
320x50 Banner Phone and Tablet BannerSize.NORMAL
320x100 Large Banner Phone and Tablet BannerSize.MEDIUM
300x250 IAB Medium Rectangle Phone and Tablet BannerSize.LARGE
468x60 IAB Full-Size Banner Tablet BannerSize.FULL
 

PositionType is either top or bottom. The default is bottom.

Alignment Description PositionType Constant
Top Alignment Specifies alignment at the top of the screen (For iOS, specifies top alignment based on SafeArea) PositionType.TOP
Bottom Alignment (Default) Specifies alignment at the bottom of the screen (For iOS, specifies bottom alignment based on SafeArea) PositionType.BOTTOM
// Create AdizBanner Instance
private AdizBanner BannerAd = null;

public void requestInitAd(string bannerAdKey) {
    // Set banner size
    private BannerSize bannerSize = BannerSize.NORMAL;

    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


    if(string.IsNullOrEmpty(bannerAdKey)) {
        // Initialize Default AdizBanner Instance (AdEventHandlers)
        BannerAd = AdizBanner.Initialize(bannerSize, eventHandlers);
    } else {
        // Initialize AdizBanner Instance (hiveAdKey, AdEventHandlers)
        BannerAd = AdizBanner.Initialize(bannerAdKey, bannerSize, eventHandlers);
    }
}

public void requestLoadAd() {
    // Load AdizBanner
    if(BannerAd != null) BannerAd.Load();
}

public void requestShowAd() {
    // Set position type
    private PositionType bannerPosition = PositionType.TOP;

    // Show AdizBanner
    if(BannerAd != null) BannerAd.Show(bannerPosition);
}

public void requestDestroyAd() {
    // Destroy AdizBanner
    if(BannerAd != null) BannerAd.Destroy();
    BannerAd = null;
}

Native ads (Native)

The native ads display native templates of specific sizes. Native ads are optimized for vertical screens, so it is recommended to use them in portrait mode games (vertical screen games). Native ads do not receive the OnAdClose() callback. Therefore, you must call destroy() at a different location to terminate the ad.

Currently, the template supports small or medium sizes.

Size Points (Width x Height) Template Alignment BannerSize Constants
355x91 (Aspect Ratio Adjusted) small size Top / Bottom BannerSize.NORMAL
355x370 (Aspect Ratio Adjusted) medium size Center (Fixed) BannerSize.MEDIUM, BannerSize.LARGE, BannerSize.FULL

In the small template, the PositionType is either top or bottom, with the default being bottom.

Alignment Description PositionType Constants
Top Alignment Specifies alignment to the top of the screen (iOS is aligned to the top of SafeArea) PositionType.TOP
Bottom Alignment (Default) Specifies alignment to the bottom of the screen (iOS is aligned to the bottom of SafeArea) PositionType.BOTTOM

The medium template does not allow for alignment selection and is centrally aligned by default.

// Create AdizNative Instance
private AdizNative NativeAd = null;

public void requestInitAd(string nativeAdKey) {
    // Set banner size
    private BannerSize bannerSize = BannerSize.NORMAL;

    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


    if(string.IsNullOrEmpty(nativeAdKey)) {
        // Initialize Default AdizNative Instance (AdEventHandlers)
        NativeAd = AdizNative.Initialize(bannerSize, eventHandlers);
    } else {
        // Initialize AdizNative Instance (hiveAdKey, AdEventHandlers)
        NativeAd = AdizNative.Initialize(nativeAdKey, bannerSize, eventHandlers);
    }
}

public void requestLoadAd() {
    // Load AdizNative
    if(NativeAd != null) NativeAd.Load();
}

public void requestShowAd() {
    // Set position type
    private PositionType bannerPosition = PositionType.TOP;

    // Show AdizNative
    if(NativeAd != null) NativeAd.Show(bannerPosition);
}

public void requestDestroyAd() {
    // Destroy AdizNative
    if(NativeAd != null) NativeAd.Destroy();
    NativeAd = null;
}

Rewarded ads (Rewarded)

The rewarded ads are the ads where users receive rewards for watching the ad for a certain period. Once the reward is distributed, you receive the reward item information through the OnAdReward() callback.

// Create AdizRewarded Instance
private AdizRewarded RewardVideoAd = null;

public void requestInitAd(string rewardedAdKey) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdReward(OnAdRewardCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


    if(string.IsNullOrEmpty(rewardedAdKey)) {
        // Initialize Default AdizRewarded Instance (AdEventHandlers)
        RewardVideoAd = AdizRewarded.Initialize(eventHandlers);
    } else {
        // Initialize AdizRewarded Instance (hiveAdKey, AdEventHandlers)
        RewardVideoAd = AdizRewarded.Initialize(rewardedAdKey, eventHandlers);
    }
}

public void requestLoadAd() {
    // Load AdizRewarded
    if(RewardVideoAd != null) RewardVideoAd.Load();
}

public void requestShowAd() {
    // Show AdizRewarded
    if(RewardVideoAd != null) RewardVideoAd.Show();
}

public void requestDestroyAd() {
    // Destroy AdizRewarded
    if(RewardVideoAd != null) RewardVideoAd.Destroy();
    RewardVideoAd = null;
}

Rewarded interstitial ads (Rewarded interstitial)

The rewarded interstitial ads are the interstitial ads where users receive rewards for watching the ad for a certain period. Once the reward is distributed, you receive the reward item information through the OnAdReward() callback.

// Create AdizRewardedInterstitial Instance
private AdizRewardedInterstitial RewardedInterstitialAd = null;

public void requestInitAd(string rewardedInterstitialAdKey) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdReward(OnAdRewardCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


    if(string.IsNullOrEmpty(rewardedInterstitialAdKey)) {
        // Initialize Default AdizRewardedInterstitial Instance (AdEventHandlers)
        RewardedInterstitialAd = AdizRewardedInterstitial.Initialize(eventHandlers);
    } else {
        // Initialize AdizRewardedInterstitial Instance (hiveAdKey, AdEventHandlers)
        RewardedInterstitialAd = AdizRewardedInterstitial.Initialize(rewardedInterstitialAdKey, eventHandlers);
    }
}

public void requestLoadAd() {
    // Load AdizRewardedInterstitial
    if(RewardedInterstitialAd != null) RewardedInterstitialAd.Load();
}

public void requestShowAd() {
    // Show AdizRewardedInterstitial
    if(RewardedInterstitialAd != null) RewardedInterstitialAd.Show();
}

public void requestDestroyAd() {
    // Destroy AdizRewardedInterstitial
    if(RewardedInterstitialAd != null) RewardedInterstitialAd.Destroy();
    RewardedInterstitialAd = null;
}

App opening ads (appopen)

The app opening ads are displayed when the app's state changes from background to foreground using the pre-loaded (load()) ads. If you call show() after 3 hours of ad loading, the ad is reloaded automatically before being displayed. Once the ad has been shown at least once, it will not automatically load again.

// Create AdizAppOpen Instance
private AdizAppOpen AppOpenAd = null;

public void requestInitAd(string appOpenAdKey) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


    if(string.IsNullOrEmpty(appOpenAdKey)) {
        // Initialize Default AdizAppOpen Instance (AdEventHandlers)
        AppOpenAd = AdizAppOpen.Initialize(eventHandlers);
    } else {
        // Initialize AdizAppOpen Instance (hiveAdKey, AdEventHandlers)
        AppOpenAd = AdizAppOpen.Initialize(appOpenAdKey, eventHandlers);
    }
}

public void requestLoadAd() {
    // Load AdizAppOpen
    if(AppOpenAd != null) AppOpenAd.Load();
}

public void requestShowAd() {
    // Show AdizAppOpen
    Debug.Log("[appOpenAd] appOpenAd don't request Show");
}

public void requestDestroyAd() {
    // Destroy AdizAppOpen
    if(AppOpenAd != null) AppOpenAd.Destroy();
    AppOpenAd = null;
}

Uninstallation

To uninstall Adiz, remove the following folders from your Unity project:

  • Assets/HiveAdiz
  • Assets/HiveAdiz_Example