Skip to content

Unity

Adiz Unity

Adiz Unity is an advertising module for Unity provided by Hive to make it easier to use the ad exposure features offered by AdMob. The types of ads provided by Adiz Unity are as follows.

  • Interstitial ads
  • Banner ads
  • Native ads
  • Rewarded ads
  • Rewarded interstitial ads
  • App open ads

Refer to the guide below in order to install and use Adiz Unity.

Installation or update

  1. Set up the Adiz Unity development environment.
  2. Download the latest version of Adiz from here and extract it.
  3. In Unity, select the Assets > Import Package > Custom Package… option, choose the .unitypackage file, and click Import.
  4. Check if the Adiz files and folders have been created under the Assets folder.
  5. Download and install the latest version of EDM4U. The Hive SDK v4 includes EDM4U. If you are using the Hive SDK v4, there is no need to install EDM4U separately.

 

To update the currently used version of Adiz, uninstall Adiz by clicking here and then download and install the latest version.

Unity settings

Android

Add the AdMobId value in the format ca-app-pub-XXXXX~YYYYY to the Assets/Plugins/Android/AndroidManifest.xml file created in the 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, you need to enable hardware acceleration. Add the settings for hardware acceleration in the AndroidManifest.xml file. If you add it to the application tag, hardware acceleration will be used for the entire application. If you add it to the activity tag, hardware acceleration will only be used for the 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 the Android Resolver Settings (Assets > External Dependency Manager > Android Resolver > Settings) of Unity.

 

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

 

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

iOS

In Assets > External Dependency Manager > iOS Resolver > Settings, uncheck the static_framework build setting.

 

Open the Podfile generated during the Unity build and configure it as below.

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.1.3
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 generated during the Unity build, and enter the AdMobId value (in the format ca-app-pub-XXXXX~YYYYY) as the key value. Alternatively, you can automatically set it by uncommenting the GADApplicationIdentifier setting line in the Assets/HiveAdiz/Editor/AdizPostProcess.cs file and adding the AdMobId.

\<key>GADApplicationIdentifier</key>
\<string>ca-app-pub-XXXXX~YYYYY</string>

 

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 will automatically add it to the Info.plist file during the build process.

Test ad settings

Adiz can display test ads in two ways. 1. Activate test mode: Only display test ads issued by AdMob 2. Display ads after registering test devices: Display real ads for testing, ensuring that no invalid traffic occurs, and proceed by registering devices to display test ads

Activate test mode

In the development stage, the test mode is activated so that clicking on test ads does not charge the advertiser. When the test mode is activated, only test ads will be displayed. In test mode, test ads will be displayed even without entering the AdMob ad key in the console. The test mode is deactivated during commercial distribution.

There are two ways to activate test mode.

  • After registering the test device in the Hive console, set it up with demo ads (recommended):
    Please refer to the Managing Test Devices section of the console guide.
  • Use the Adiz class's setTestMode() method:
    Please refer to the example code below.
Warning

Excessive clicks on ads while not in test mode during the development phase may be considered invalid traffic, and your AdMob account may be reported, resulting in ads not being displayed.


Using the Adiz.SetTestMode() method


using hiveAdiz; // Activate test mode. Comment out the line below for production deployment.
Adiz.SetTestMode(true);

// Enables Adiz module logging. Logging should only be used in test mode. Comment out the line below for production deployment.  
Adiz.SetLogEnable(true);

Test device advertising exposure

You need to register a test device to display test ads in the following situations.

  • Test if the AdMob ad key registered in the Hive console is working properly
  • Write a GDPR message and check if the GDPR consent popup is functioning correctly
  • Run the ad inspector to analyze and debug ad requests

There are two ways to display advertisements on the test device.

  • After registering the test device in the Hive console, set it to Use Ad Unit ID (recommended):
    Please refer to the Test Device Management section of the console guide.

  • Use the Adiz class's setTestDevice() method:
    Refer to the example code below.

Note

If you conduct tests displaying actual ads without registering a test device, it may be considered invalid traffic, and your AdMob account could be blocked, preventing further ad displays. When you register a test device, "Test Mode" or "Test Ad" (native ads) will be displayed during ad exposure. You must deactivate test devices during commercial distribution.


Banner, interstitial ads, or rewarded ads

Native advertising

Using the Adiz.setTestDevice() method

To register a test device, you first need to check the test device ID. In the Android environment of the Unity engine, the test device ID (for example: 33BE2250B43518CCDA7DE426D04EE231) can be checked in the following two ways.

  • Check the Logcat logs after calling Adiz.Initialize():

    Use new
    ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
    
  • After calling Adiz.Initialize(), regardless of the ad type, call initialize()load() and check the Logcat logs:

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


The test device ID in the iOS environment of the Unity engine (e.g., B74F6468-1516-467C-99AD-CC5973C5DB52) can be checked in the following two ways.

  • Check the Logcat logs after calling Adiz.Initialize():

    To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[B74F6468-1516-467C-99AD-CC5973C5DB52]
    
  • After calling Adiz.Initialize(), regardless of the ad type, call initialize()load() and check the Logcat logs:

    GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [ "B74F6468-1516-467C-99AD-CC5973C5DB52" ]
    


After checking 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());
}

Ad inspector usage

The 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 provides reasons for any failures in display. You can also specify a particular ad network to check if the ads are being displayed correctly, and if there are issues, you can debug at the code level. This entire process is conducted alongside 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 the ad inspector, you must have registered a test device.

using hiveAdiz;

AdizDeveloperTool.OpenAdInspector();

Adiz AppID settings

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

Adiz.SetAppId(appId);

Hive Console server settings

Set up the Hive console server to use. The default is REAL. Even if you use the production server, enabling test mode will only display test ads.

  • Hive Test console server: ZoneType.TEST
  • Hive Sandbox console server: ZoneType.SANDBOX
  • Hive Production console server: ZoneType.REAL

ZoneType selectZone = ZoneType.REAL;
Adiz.SetZone((int)selectZone);

User-specific ad exposure

With the introduction of ATT (App Tracking Transparency) in iOS 14.5+, privacy has been enhanced. Accordingly, user-specific ads can only be displayed if the user agrees to activity tracking in the ATT consent popup. To maximize ad revenue by displaying user-specific ads, you need to create an IDFA (Identifier for Advertisers) message.

Write and publish the IDFA message on the Google AdMob dashboard as shown below.

When writing an IDFA message, you can refer to the guide below.

When you post the IDFA message on the AdMob dashboard, the IDFA message will automatically be displayed during Adiz initialization on iOS 14.5+. When the user clicks "Continue" in the IDFA message window, the ATT consent popup will be displayed.

When the user clicks "Allow" on the ATT consent popup, IDFA is activated, and user-specific ads are displayed.

Note

Users accessing from Europe and the UK will see a GDPR consent popup. If the user has never consented to the GDPR items, the ATT consent popup will be displayed immediately after the GDPR consent popup, without showing the IDFA message. If the user has previously consented to the GDPR items, the IDFA message will be displayed normally before showing the ATT consent popup.

If your game targets Europe and the UK (EEA & UK), you must expose a GDPR (General Data Protection Regulation) consent popup. The GDPR consent popup will only be displayed if the user's device IP address is from Europe and the UK (EEA & UK). Adiz supports the exposure of the GDPR consent popup through Google UMP (User Messaging Platform). After creating the GDPR message in the AdMob console, initialize Adiz to display the GDPR popup to users accessing from Europe and the UK.

Warning

If you are targeting regions outside of Europe and the UK, for example, if you are planning to provide services only domestically, you can skip the GDPR consent popup exposure (Europe, UK) step and proceed with initialization using the Adiz.InitializeForNonGDPR() method.
If you proceed with initialization using the Adiz.Initialize() method, you must create a GDPR message in the AdMob console for Adiz initialization to proceed normally.

Warning

If you are using the Hive SDK, you must run AuthV4.setup after completing the initialization of Hive Adiz. If the GDPR consent screen appears after displaying the ATT (App Tracking Transparency) consent notification, your app may be rejected during the Apple app review.

Writing a GDPR message

Access the Google AdMob console to write a GDPR message. Before writing the GDPR message, please refer to the GDPR Message Writing Guide.

When creating a GDPR message, you need to add the mediation you want to use to the list of advertising partners. Here’s how to add mediation.

1) Go to the Privacy & Messaging > European Regulations > Settings tab in the Google AdMob dashboard, then click the edit icon for 'Ad Partner Review > Custom Ad Partners. 2) Select all mediation partners certified by Google under GDPR to add them in bulk, or check only the desired mediation partners and click Add.

If you have written a GDPR message, the GDPR consent popup will automatically appear when Adiz is initialized.

Implementation of GDPR consent and withdrawal functionality

The items in the GDPR consent popup should provide a modification feature so that users can change their consent status at any time. For example, a user may initially not consent to GDPR but later wish to consent again in order to view personalized ads, or conversely, a user may have initially consented to GDPR but now wishes to withdraw their consent because they no longer want to provide personal information. To address these situations, app developers must implement functionality that allows users to re-consent to each item or withdraw their existing consent. To implement the GDPR consent/withdrawal functionality, follow these steps.

  1. Implement a button UI in the app that can reopen the GDPR consent popup.
  2. When implementing Adiz initialization, call isPrivacyOptionsRequired() to display the above button UI to users accessing from Europe and the UK, and not display it otherwise. If a user accessing from Europe or the UK clicks the button, call showPrivacyOptionsForm to reopen the GDPR consent popup. Afterwards, users can modify their consent to GDPR details at any time by pressing a button like "Manage Options" in the app. The showPrivacyOptionsForm below is a method implemented arbitrarily for example purposes, and the development company can change the implementation as desired.
    
        // ....
    
    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. Call ShowPrivacyOptionsForm on click
            } else {
                // Hide privacy options button
            }
        }
    }
    
    
    private void ShowPrivacyOptionsForm() {
        // Call privacy options form
        if(AdizConsentManager.IsPrivacyOptionsRequired()) {
            AdizConsentManager.ShowPrivacyOptionsForm(new CommonHandlers.Builder()
                                                    .OnResult(CommonResultCB)
                                                    .Build());
        }
    }
    
    // ....
    
    

Setting tags for users under GDPR consent age (TFUA)

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

Warning

Setting both the GDPR underage consent tag setTagForUnderAgeOfConsent and the COPPA child-directed setting setTagForChildDirectedTreatment to true at the same time will prioritize the COPPA child-directed setting setTagForChildDirectedTreatment, so do not use them both set to true.

Note

When using Hive SDK v4 24.2.0 or higher together with Adiz 2.0.1 or higher, the consent age settings applied in Hive SDK will automatically apply to users under the consent age.
However, if the user manually calls the AdizConsentManager.setUserPrivacySettings API before the Adiz.initialize initialization, the consent age settings from Hive SDK will not apply, and the values set during the AdizConsentManager.setUserPrivacySettings API call will take precedence.

using hiveAdiz;

public void Initialize() {

    bool isTagForUnderAgeOfConsent = false; // 어린이인 경우 true로 변경

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

    AdizConsentManager.SetUserPrivacySettings(settings);

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

GDPR test device setup

The GDPR consent popup will only be displayed if the device's IP address is from Europe or the UK. During the development phase, the GDPR consent popup can be forcibly displayed regardless of the IP address to test the popup display, and to do this, you need to set up a GDPR test device. Follow the steps below to set up the GDPR test device. The content below is the same as how to display ads on the test device.

  1. Initialize Adiz by initializing. This initialization is to check the test device ID and does not require writing a GDPR consent message.
  2. Output the Android Studio or Xcode logs to check the device ID. Example logs are as follows.

    • Android:
      Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
      
      from 33BE2250B43518CCDA7DE426D04EE231
    • iOS:
      <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[B74F6468-1516-467C-99AD-CC5973C5DB52]
      
      At B74F6468-1516-467C-99AD-CC5973C5DB52
  3. Copy the device ID.
  4. Add AdizGDPRManager.setTestDevice(DEVICE_ID) before executing Adiz.initialize in the existing Adiz initialization code.
  5. Write the GDPR consent message and reinitialize Adiz to ensure that the GDPR consent popup appears correctly.
        
            using hiveAdiz;
    
            public void Initialize() {
    
                    // GDPR test device setting
                    AdizGDPRManager.SetTestDevice("33BE2250B43518CCDA7DE426D04EE231");
    
                    Adiz.Initialize(new CommonHandlers.Builder()
                                                                                                    .OnResult(InitResultCB)
                                                                                                    .Build());
            }
        
        

COPPA child-directed treatment tag setting

According to the Children's Online Privacy Protection Act (COPPA), app developers can specify whether Google should treat content as child-directed by setting the child-directed treatment tag (tagForChildDirectedTreatment, TFCD) when requesting ads. If you want it to be treated as child-directed, you must call AdizConsentManager.SetUserPrivacySettings before executing Adiz.initialize. When using Adiz with the Hive SDK, the child-directed treatment tag is applied automatically, so no separate configuration is needed.


using hiveAdiz;

public void Initialize() {

    bool isTagForChildDirectedTreatment = false; // Change to true if it is for children

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

    AdizConsentManager.SetUserPrivacySettings(settings);

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

Add ad mediation

Adiz can display ads using AdMob mediation. To add AdMob mediation, follow the steps below.

Adding AdMob mediation

We will proceed with the integration of ad sources in the AdMob console. Follow the table below to proceed.

AppLovin Liftoff Monetize Meta Audience Network Pangle Unity Ads ironSource
Step 1: Setup Android iOS Android iOS Android iOS Android iOS Android iOS Android iOS
Step 2: Add Ad Sources Android iOS Android iOS Android iOS Android iOS Android iOS Android iOS
Step 3 Add Adiz Adapter

Adding Adiz adapter

Assets/HiveAdiz/Editor/Adiz_DefaultDependencies.xml adds library dependencies.

<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.1.3"/>
    <!-- AppLovin -->
    <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-applovin:2.1.3"/>
    <!-- Liftoff -->
    <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-liftoff:2.1.3"/>
    <!-- Meta -->
    <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-meta:2.1.3"/>
    <!-- Pangle -->
    <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-pangle:2.1.3"/>
    <!-- Unity Ads -->
    <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-unityads:2.1.3"/>
    <!-- ironSource -->
    <androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-ironsource:2.1.3"/>    

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

      <iosPod name="HiveAdizUnityPlugin" version="2.1.3"/>
      <iosPod name="HiveAdizAdapterAppLovin" version="2.1.3"/>
      <iosPod name="HiveAdizAdapterLiftoff" version="2.1.3"/>
      <iosPod name="HiveAdizAdapterMeta" version="2.1.3"/>
      <iosPod name="HiveAdizAdapterPangle" version="2.1.3"/>
      <iosPod name="HiveAdizAdapterUnityAds" version="2.1.3"/>
      <iosPod name="HiveAdizAdapterIronSource" version="2.1.3"/>

  </iosPods>
</dependencies>

 

To check if the Adiz adapter configuration has been applied correctly, run the app and check the configuration list on the Ad Inspector screen.

Adiz initialization

This is a mandatory step that must be performed before displaying any type of advertisement. By initializing Adiz, you will receive the advertisement key necessary for displaying ads. If you have activated test mode, you will receive a test key.

Warning

If you are using GDPR settings, you must run AuthV4.setup after completing the Hive Adiz initialization. If the GDPR consent screen appears after displaying the ATT (App Tracking Transparency) consent notification, your app may be rejected during the Apple app review.


using hiveAdiz;

public void Start() {
    /* omitted */

    // To use the HiveAdiz callback, you must register the 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 when entering the ad key directly in the game.
                if(isDefault == false) {
                    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 ad key list has the following format.

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

 

When initializing in test mode, you will receive a list of test ad keys even if you have not registered the AdMob ad key in the Hive console. When initializing in production mode, you will receive the list of AdMob ad keys registered in the Hive console.

For each type of advertisement (form), one advertisement is used as the default advertisement (the advertisement with "is_default":true). When the first advertisement of any type is registered, that advertisement becomes the default advertisement. The default advertisement does not require the advertisement key (hiveAdKey) to be entered when creating an advertisement instance (initialize()). To change the default advertisement, you need to delete the existing default advertisement from the HiveHive console and register a new advertisement.

Setting up ad callback listener

By implementing AdizListener when creating each ad instance, you can receive callbacks based on changes in the ad's status.

Name Description Required Implementation
.OnAdLoad(OnAdLoadCB) Ad load successful O
.OnAdFail(OnAdLoadFailedCB) Failure (the reason for failure can be known through `error.errorCode()` and `error.errorMessage()`) O
.OnAdShow(OnAdShowCB) Ad exposure success O
.OnAdClick(OnAdClickCB) Ad Click O
.OnAdPaidEvent(OnAdPaidEventCB) It is the point at which the paid event is received after the ad exposure, and the ad revenue information is conveyed. O
.OnAdClose(OnAdCloseCB) Ad Ended
  • To re-display the same ad instance after the ad has ended, you must call `load()` again followed by `show()`.
  • To stop displaying ads, call `destroy()` to remove the ad instance.
X
.OnAdReward(OnAdRewardCB) The point at which the user receives a reward after the ad exposure in reward-based ads (`rewarded`, `rewarded interstitial`) X

private void OnAdLoadCB()
{   
    // This will be called when the ad is loaded.
    // If the ad load is successful, you should call the ad instance's .show() at the desired time to display the ad.

    Debug.Log(TAG + "::OnAdLoadCB");

    // AdizInterstitial loaded and ready to show
    // requestShowAd();
}

private void OnAdLoadFailedCB(AdizError error) {
    // This is called when the ad load fails or fails to display for other reasons.
    Debug.Log(TAG + "::OnAdLoadFailedCB errorCode "+error.errorCode);
    Debug.Log(TAG + "::OnAdLoadFailedCB errorMessage "+error.errorMessage);
}

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

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

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

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

private void OnAdRewardCB(RewardItem rewardItem)
{   
    // This is called when a reward is given for watching an ad in reward-based ads or rewarded interstitial ads.
    Debug.Log(TAG + "::OnAdRewardCB:: rewardItem.itemType : " + rewardItem.getItemType() + " rewardItem.itemAmount : " + rewardItem.getItemAmount());
    // Only passed in rewarded, rewardedInterstitial ads
}

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

Error Codes

When receiving OnAdFail() from Adiz.Initialize and AdizListener, the AdizError error codes and error messages are as follows.

Common Code

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 required
-6 ResponseFail Response failed
-7 Timeout Network timeout
-99 Unknown Unknown error

Advertising Platform Error Codes

Number Case Explanation
-101 NeedLoad The ad has not been loaded
-102 NeedReload Reload needed due to ad exposure time expiration
-103 NotEnoughInventory Mediation response was successful, but there are no ads filled due to lack of inventory
-104 MissingAppId AppID error for mediation request
-105 InternalNetworkError Mediation network-related error
-106 InvalidUnitId Invalid Unit Id
-107 MediationNoFill Mediation adapter failed to process the ad request
-108 AlreadyLoaded Already in a loaded state
-109 CannotRequestAds Cannot request ads
-201 GdprConsentError GDPR consent error
-202 IsNotPrivacyOptionsRequired Cannot display GDPR consent popup or it is in a state where it does not need to be displayed

Ad display and ad termination

Follow the steps below to display and terminate ads.

  1. Create ad instances in the ad class for each type of ad you want to display. If the ad you want to display is not a default ad, you need to enter the ad key or placement ID obtained from initialization. If you do not enter the ad key (hiveAdKey) or placement ID (placementId), a default ad instance will be created. The placement ID can be set in the Hive console, and for more details, please refer to the Admob settings page in the console guide.
  2. Load the ad you want to display (load()).
  3. Load the ad you want to display (load()).
  4. Display the loaded ad (show()). To display the ad again, you must call load() again and then call show().
  5. To end the ad, call destroy().

Interstitial Ads

Full-screen ads that take up 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 requestInitAdWithPlacementId(string interstitialPlacementId) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


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

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

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

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

This is a banner advertisement that displays a banner of a specific size. The banner advertisement does not receive the OnAdClose() callback. Therefore, you need to call destroy() from another location to terminate the advertisement.

 

BannerSize follows the standard banner size.

Size Point (Width x Height) Description Supported Target BannerSize Constant
320x50 Banner Mobile Phones and Tablets BannerSize.NORMAL
320x100 Large Banner Mobile Phones and Tablets BannerSize.MEDIUM
300x250 IAB Medium Rectangle Mobile Phones and Tablets BannerSize.LARGE
468 x 60 IAB Full-Size Banner Tablets BannerSize.FULL

 

PositionType is either the topmost or the bottommost. The default value is the bottommost.

Alignment Description PositionType Constant
Top Alignment Specifies alignment at the top of the screen (iOS specifies top alignment based on SafeArea) PositionType.TOP
Bottom Alignment (default) Specifies alignment at the bottom of the screen (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 requestInitAdWithPlacementId(string bannerPlacementId) {
    // 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(bannerPlacementId)) {
        // Initialize Default AdizBanner Instance (AdEventHandlers)
        BannerAd = AdizBanner.Initialize(bannerSize, eventHandlers);
    } else {
        // Initialize AdizBanner Instance (placementId, AdEventHandlers)
        BannerAd = AdizBanner.InitializeWithPlacementId(bannerPlacementId, bannerSize, eventHandlers);
    }
}

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

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

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

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

Native Advertising

This is a native advertisement that exposes a native template of a specific size. Native ads are optimized for vertical screens, so it is recommended to use them in vertical games (portrait screen games). Native ads do not receive the OnAdClose() callback. Therefore, you need to call destroy() from another location to close the ad.

 

The current template supports small or medium sizes.

Size Point (Width x Height) Template Alignment BannerSize Constant
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, PositionType is either topmost or bottommost, and the default is bottommost.

Alignment Description PositionType Constant
Top Alignment Specifies alignment at the top of the screen (iOS specifies top alignment based on SafeArea) PositionType.TOP
Bottom Alignment (default) Specifies alignment at the bottom of the screen (iOS specifies bottom alignment based on SafeArea) PositionType.BOTTOM

 

The medium template does not allow for alignment selection and uses center alignment 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 requestInitAdWithPlacementId(string nativePlacementId) {
    // 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(nativePlacementId)) {
        // Initialize Default AdizNative Instance (AdEventHandlers)
        NativeAd = AdizNative.Initialize(bannerSize, eventHandlers);
    } else {
        // Initialize AdizNative Instance (placementId, AdEventHandlers)
        NativeAd = AdizNative.InitializeWithPlacementId(nativePlacementId, bannerSize, eventHandlers);
    }
}

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

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

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

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

Rewarded Ads

This is a rewarded ad where users receive rewards for watching the ad for a certain amount of time. Once the reward is granted, the reward item information is received 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 requestInitAdWithPlacementId(string rewardedPlacementId) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdReward(OnAdRewardCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


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

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

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

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

Rewarded Interstitial Ads

This is a rewarded interstitial ad where users receive rewards for watching the ad for a certain amount of time. Once the reward is granted, the reward item information is received 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 requestInitAdWithPlacementId(string rewardedInterstitialPlacementId) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdReward(OnAdRewardCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


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

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

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

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

App Opening Ads (AppOpen)

This is an app opening ad that displays pre-loaded (load()) ads when the app state changes from background to foreground. If show() is called after 3 hours have passed since the ad was loaded, the ad will automatically reload and then be displayed. Once an ad has been displayed at least once, it will not reload automatically.


// 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 requestInitAdWithPlacementId(string appOpenPlacementId) {
    AdEventHandlers eventHandlers = new AdEventHandlers.Builder()
                                                    .OnAdLoad(OnAdLoadCB)
                                                    .OnAdShow(OnAdShowCB)
                                                    .OnAdClose(OnAdCloseCB)
                                                    .OnAdFail(OnAdLoadFailedCB)
                                                    .OnAdClick(OnAdClickCB)
                                                    .OnAdPaidEvent(OnAdPaidEventCB)
                                                    .Build();


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

public void requestLoadAd() {
    // Load AdizAppOpen
    if(AppOpenAd != null && AppOpenAd.IsInitialized()) 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;
}

Uninstall HiveAdiz

To uninstall HiveAdiz, delete the folder below within your Unity project.

  • Assets/HiveAdiz
  • Assets/HiveAdiz_Example