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¶
- Set up the Adiz Unity development environment.
- Download the latest version of Adiz from here and extract it.
- In Unity, select the Assets > Import Package > Custom Package… option, choose the .unitypackage file, and click Import.
- Check if the Adiz files and folders have been created under the Assets folder.
- Download and install the latest version of EDM4U. The Hive SDK v4 includes EDM4U. If you are using the Hive SDK v4, you do not 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. Adding it to the application
tag enables hardware acceleration for the entire application. Adding it to the activity
tag enables hardware acceleration only 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 Unity's Android Resolver Settings (Assets > External Dependency Manager > Android Resolver > Settings).
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, disable 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.0
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 uncomment the GADApplicationIdentifier
setting line inside the Assets/HiveAdiz/Editor/AdizPostProcess.cs file and add the AdMobId
, which will be set automatically.
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 setup¶
Adiz can display test ads in two ways. 1. Activate test mode: Only display test ads issued by AdMob 2. Register test devices and display ads: Display real ads for testing, ensuring that invalid traffic does not occur, and proceed by registering devices that will display test ads
Test mode activation¶
In the development stage, activate test mode so that clicking on test ads does not charge advertisers. When test mode is activated, only test ads will be displayed. In test mode, test ads will be displayed without entering the AdMob ad key in the console. Disable test mode during commercial distribution.
There are two ways to activate test mode.
- After registering the test device in the Hive console, set it to demo advertisement (recommended):
Refer to the Test Device Management section of the console guide. - Use the Adiz class's
setTestMode()
method:
Refer to the example code below.
Warning
When not in test mode during the development stage, excessive clicks on ads may be considered invalid traffic, and your AdMob account may be reported, resulting in ads not being displayed.
Using Adiz.SetTestMode() method¶
using hiveAdiz; // Activate test mode. Comment out this line for production deployment.
Adiz.SetTestMode(true);
// Activating 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¶
In the following situations, you need to register a test device to expose test ads.
- 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 ads 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 Managing Test Devices section of the console guide. -
Use the Adiz class's
setTestDevice()
method:
Please refer to the example code below.
Note
If you conduct a test that displays 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" (for native ads) will be displayed during ad exposure. You must deactivate the test device during commercial distribution.
Banner, interstitial ads, or rewarded ads
Native Advertising
Using 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()
: -
After calling
Adiz.Initialize()
, regardless of the ad type, callinitialize()
→load()
and check the Logcat logs:
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 log after calling
Adiz.Initialize()
: -
After calling
Adiz.Initialize()
, regardless of the ad type, callinitialize()
→load()
and check the Logcat logs:
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() {
// 테스트 디바이스 설정
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 failure if the ad fails to display. You can also specify a particular ad network to check if the ads are displaying correctly, and if there are issues, you can debug at the code level. All of this is done 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 higher, and can be used by calling AdizDeveloperTool.OpenAdInspector
.
To use the ad inspector, register a test device must be set up.
Adiz AppID configuration¶
Set the Adiz AppID that was 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, activating 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 advertising revenue by displaying user-specific ads, you need to write an IDFA (Identifier for Advertisers) message.
AdMob Follow the IDFA message writing guide below on the dashboard to create and publish your messages.
- IDFA Implementation Guide
- IDFA Message Writing Guide
- Explanation of IDFA Messages and ATT Notifications
When you publish the IDFA message on the AdMob dashboard, the IDFA message will automatically be displayed during Adiz initialization on iOS 14.5 and above. When the user clicks "Continue" in the IDFA message window, the ATT consent popup will be displayed.
When the user clicks "Allow" in 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 agreed 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 agreed to the GDPR items before, the IDFA message will be displayed normally before showing the ATT consent popup.
GDPR consent popup exposure (Europe, UK)¶
If the game targets Europe and the UK (EEA & UK), a GDPR (General Data Protection Regulation) consent popup must be displayed. 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 the display 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 areas outside of Europe and the UK, for example, if you are only planning to provide services 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 the Adiz initialization to proceed normally.
Writing GDPR message¶
Access the Google AdMob console to write your GDPR message. Before writing the GDPR message, please refer to the GDPR Message Writing Guide.
If you have written a GDPR message, the GDPR consent popup will automatically appear when Adiz is initialized.
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.
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 to view personalized ads, or conversely, a user may have initially consented to GDPR but no longer wish to provide personal information and want to withdraw their consent. 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 GDPR consent/withdrawal functionality, follow these steps.
- Implement a button UI in the app that can reopen the GDPR consent popup.
- When implementing Adiz initialization, call
isPrivacyOptionsRequired()
to display the button UI for users accessing from Europe and the UK, and do not display it for others. If a user from Europe or the UK clicks the button, callshowPrivacyOptionsForm
to reopen the GDPR consent popup. After that, users can modify their consent for GDPR details at any time by clicking a button like "Manage Options" in the app. TheshowPrivacyOptionsForm
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 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 limited data processing targets when making advertising requests. For apps that target children, you can set the user to be under the age of consent using AdizConsentManager.setUserPrivacySettings
. While there are some differences among European countries, GDPR defines the age requiring parental consent as under 16. The under age of 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
. Therefore, do not set both to true
and use them simultaneously.
Note
Hive SDK v4 24.2.0 or higher and Adiz 2.0.1 or higher can be used together, so the user consent age set in the Hive SDK will be automatically applied, and there is no need to call AdizConsentManager.setUserPrivacySettings
.
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. Please follow the steps below to set up the GDPR test device. The following content is the same as how to display ads on the test device.
- Initialize Adiz by initializing. This is an initialization to check the test device ID, and there is no need to write a GDPR consent message.
Output the Android Studio or Xcode logs to check the device ID. Example logs are as follows.
- Android: from
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
33BE2250B43518CCDA7DE426D04EE231
- iOS: At
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[B74F6468-1516-467C-99AD-CC5973C5DB52]
B74F6468-1516-467C-99AD-CC5973C5DB52
- Copy the device ID.
- Add
AdizGDPRManager.setTestDevice(DEVICE_ID)
before executingAdiz.initialize
in the existing Adiz initialization code. - Write a GDPR consent message and reinitialize Adiz to check if 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 targeting tag settings¶
In accordance with the Children's Online Privacy Protection Act (COPPA), app developers can specify whether Google should treat content as child-directed by using the child targeting tag setting (tagForChildDirectedTreatment, TFCD) when making ad requests. If you want to have it treated as child-directed, you must call AdizConsentManager.SetUserPrivacySettings
before executing Adiz.initialize
. When using Adiz with the Hive SDK, the child targeting tag is applied automatically, so no additional 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 mediation¶
Adiz can display ads using AdMob mediation. To add AdMob mediation, follow the steps below.
Adding AdMob nediation¶
We will proceed with the integration of ad sources in the AdMob console. Follow the table below to proceed.
AppLovin | Pangle | Unity Ads | Meta | |
---|---|---|---|---|
Step 1: Settings | 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 |
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.0"/>
<!-- AppLovin -->
<androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-applovin:2.1.0"/>
<!-- Pangle -->
<androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-pangle:2.1.0"/>
<!-- Unity Ads -->
<androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-unityads:2.1.0"/>
<!-- Meta -->
<androidPackage spec="com.com2us.android.adiz:hive-adiz-adapter-meta:2.1.0"/>
</androidPackages>
<iosPods>
<sources>
<source>https://github.com/Com2uSPlatformCorp/HiveAdiz-iOS.git</source>
</sources>
<iosPod name="HiveAdizUnityPlugin" version="2.1.0"/>
<iosPod name="HiveAdizAdapterAppLovin" version="2.1.0"/>
<iosPod name="HiveAdizAdapterPangle" version="2.1.0"/>
<iosPod name="HiveAdizAdapterUnityAds" version="2.1.0"/>
<iosPod name="HiveAdizAdapterMeta" version="2.1.0"/>
</iosPods>
</dependencies>
To verify that 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 step that must be performed before displaying ads of all types. By initializing Adiz, you will receive the ad key necessary for displaying ads. If you are in test mode, you will receive a test key. If you are using the Hive SDK, proceed with Adiz initialization after calling AuthV4.setup
.
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, the app may be rejected during Apple's 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 list of ad keys 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 a 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 must delete the existing default advertisement in 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 according to the changes in ad 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 advertising revenue information is delivered. | O |
.OnAdClose(OnAdCloseCB) | Ad End
| 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 when the ad fails to show for other reasons.
Debug.Log(TAG + "::OnAdLoadFailedCB errorCode "+error.errorCode);
Debug.Log(TAG + "::OnAdLoadFailedCB errorMessage "+error.errorMessage);
}
private void OnAdShowCB()
{
// This will be 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 advertisement.
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 needed |
-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 | Need to reload due to ad exposure time expiration |
-103 | NotEnoughInventory | The mediation response was successful, but there are no ads filled due to insufficient inventory |
-104 | MissingAppId | AppID error for mediation request |
-105 | InternalNetworkError | Mediation network-related error |
-106 | InvalidUnitId | Invalid Unit Id |
-107 | MediationNoFill | The mediation adapter could not 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 exposure and ad termination¶
Follow these steps to expose and terminate ads.
- Create an ad instance 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 must 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. - Load the ad you want to display (
load()
). - Load the ad you want to display (
load()
). - Display the loaded ad (
show()
). To re-display the ad, you must callload()
again and then callshow()
. - To close the ad, call
destroy()
.
Interstitial advertising¶
A full-screen advertisement that occupies 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;
}
Banner advertising (Banner)¶
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 (Width x Height) | Description | Supported Devices | 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 (Native)¶
This is a native advertisement that exposes a native template of a specific size. Native ads are optimized for portrait 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 the top or the bottom, and the default value is the bottom.
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 period 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, it will automatically reload the ad before displaying it. 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