跳轉至

Unity

Adkit for AD(X): Unity

AdKit 是一個廣告模組,修正了在處理 AD(X) Unity 套件時發生的錯誤,並支持用戶便利性。逐一閱讀此頁面以使用 AdKit 以及支持 SDK。

安裝

訪問 Hive 開發者並下載和應用 AdKit。

  1. 從 Hive 開發者下載最新版本的 AdKit 並在 這裡 解壓縮。
  2. 在 Unity 工具欄中,選擇 .unitypackage 文件,位於 資產 > 匯入包 > 自定義包…,然後點擊 匯入。

  1. 匯入完成後,檢查是否在 Assets 資料夾下創建了與 AdKit 和 AD(X) 相關的檔案和資料夾。

Warning

在開發期間測試 AdKit 時,您必須應用 測試 廣告金鑰。

更新

卸載 您正在使用的 AdKit,然後安裝最新版本以進行更新。

如何使用

iOS(Unity 2019.4 及以上版本){ #apply-ios }

使用 Unity 2019.4 及以上版本建置 iOS 專案時,會產生以 Dynamic Framework 方式運作的 UnityFramework target。

  1. 設定 EDM4U。 在 Unity 的 iOS Resolver Settings(Assets > External Dependency Manager > iOS Resolver > Settings)中檢查 static_framework 建置設定(Link frameworks statically)。 (1.2.171) Facebook SDK 僅提供 Dynamic Framework,而 Podfile 只能選擇兩種框架方式中的一種。因此,啟用 Link frameworks statically 並使用 Facebook SDK 時,請取消註解下方對應的項目。

    string[] frameworksToEmbed = {
        ...
        "FBAudienceNetwork.xcframework",
    
        // 使用 Facebook SDK 時,請取消註解正在使用的 SDK。
        // "FBAEMKit.xcframework",
        // ...
    };
    

    Warning
    • 僅取消註解目前使用的 Facebook SDK。
    • 停用 Link frameworks statically 時,如果在使用 Dynamic Framework 的情況下取消註解,可能會發生衝突。
  2. 建置專案。

    Warning

    產生 Xcode 專案時如果 pod install 失敗,且已在上方啟用 Link frameworks statically,請勿在產生的專案路徑中直接執行 pod install,而應在 Unity Editor 中重新建置專案。

特點

  • 獎勵廣告
    • 同時使用AdKit API和SDK或使用獨立模組時,是否傳送日誌資訊取決於呼叫的RewardVideo API。日誌資訊將傳送到Analytics伺服器。支援此功能的最低版本如下:
      • SDK v4.11.0
      • SDK v1.17.2
      • 獨立模組 ModuleManager v2.6.0
      • 獨立模組 CommonModule v1.5.0
  • 插頁式廣告
  • 自適應橫幅廣告

有關如何使用 AdKit 的詳細資訊,請閱讀以下指南。

初始化 AdKit

初始化、加載和顯示所有類型廣告(AD)之前的必要步驟

歐洲和英國目標

如果您的游戏面向欧洲和英国(EEA和英国),则需要显示GDPR(通用数据保护条例)同意弹出窗口。Adkit支持Google的UMP(用户消息平台)来显示GDPR同意弹出窗口。要使用Google UMP,请首先参考GDPR消息创建指南来撰写您的GDPR消息。

使用 Hive SDK 时,AuthV4.setup 会公开 IDFA 消息,因此构建 IDFA 消息在根本上是可选的。然而,如果您使用 GDPR 消息,则必须根据 有关 IDFA 消息和 ATT 通知的详细说明 来构建 IDFA 消息。

如果您已經製作了GDPR消息和IDFA消息,請使用如下所示的InitializeWithShowADXConsent初始化Hive AdKit。

Important

如果您正在使用Hive SDK,則必須在完成Hive AdKit的初始化後執行AuthV4.setup。如果在顯示ATT(應用程序跟踪透明度)同意通知後出現GDPR同意屏幕,則您的應用可能會在Apple的應用審核中被拒絕。

// When targeting Europe & the UK for commercial distribution
int debugState = 0;
HIVEAdKit.InitializeWithShowADXConsent(appId, debugState, null, adkitConsentState =>
{
    /*
    * adkitConsentState : User's personal information usage and collection status for AD(X)
    * - 0 : No consent status exists
    * - 1 : Region where consent is not required
    * - 2 : User has refused the usage and collection of personal information
    * - 3 : User has consented to the usage and collection of personal information
    */
});

/* 
 * To test the GDPR consent popup, set debugState to 1 and configure testDeviceId to display the GDPR test popup.
 * The device ID for the Test Device (testDeviceId) can be found in the Android Logcat and Xcode console logs.
 * The testDeviceId is used only for testing. You must specify testDeviceId as null during commercial distribution.
 * Example Android log: Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("ABCDEFGHIJKLMNOPQRSTUVWXYZ") to set this as a debug device.
 * Example Xcode log: To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[ABCDEFGHIJKLMNOPQRSTUVWXYZ]
 */

int debugState = 1;
string testDeviceId = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
List testDevices = new List();
testDevices.Add(testDeviceId);

HIVEAdKit.InitializeWithShowADXConsent(appId, debugState, testDevices, adkitConsentState =>
{
    /*
    * adkitConsentState : User's personal information usage and collection status for AD(X)
    * - 0 : No consent status exists
    * - 1 : Region where consent is not required
    * - 2 : User has refused the usage and collection of personal information
    * - 3 : User has consented to the usage and collection of personal information
    */
});

當初始化 Hive AdKit 時,如果目標地區被確定為歐洲和英國(EEA 和 UK),則將自動顯示 GDPR 同意屏幕,如下所示。

在 iOS 環境中,IDFA 解釋訊息會自動顯示在歐洲和英國以外的地區。

指定其他地區

指定歐洲和英國以外的地區時,請使用 InitializeWithSetConsentState 進行初始化。

/*
 * Set the user's personal information usage and collection status for AD(X)
 * 0 : No consent status exists
 * 1 : Region where consent is not required
 * 2 : User has refused the usage and collection of personal information
 * 3 : User has consented to the usage and collection of personal information
 */
int consentState = 1;
HIVEAdKit.InitializeWithSetConsentState(appId, consentState);

高級設定

// GameData Example
[Serializable]
public class SendInfo 
{
    public int level;
    public int gold;
}
SendInfo addtionalInfo = new SendInfo();
addtionalInfo.level = 1;
addtionalInfo.gold = 100;

// Send as a JSON Obejct format
HIVEAdKit.SetAdditionalInfo(JsonUtility.ToJson(addtionalInfo));

獎勵類型

// Initialize Rewarded AD
// Initialize Rewarded AD
EventHandlers eventHandlers = new EventHandlers.Builder()
                                                .OnAdLoaded(OnAdLoadedCB)
                                                .OnAdOpening(OnAdOpeningCB)
                                                .OnAdClosed(OnAdClosedCB)
                                                .OnAdFailedToLoad(OnAdFailedToLoadCB)
                                                .OnAdFailedToShow(OnAdFailedToShowCB)
                                                .OnAdReward(OnAdRewardCB)
                                                .OnPaidEvent(OnPaidEventCB)
                                                .Build();
// Generate an instance
RewardVideoAd = HIVEAdKit.RewardVideo.Initialize(rewardVideoUnitId, eventHandlers);

// Load Rewarded AD
// Send AD loading information to Analytics
if( HIVEAdKit.RewardVideo.IsInitialzed(RewardVideoAd) ) {
    HIVEAdKit.RewardVideo.LoadAd(RewardVideoAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}

// Show RewardVideo type
// Send AD loading information to Analytics
if( HIVEAdKit.RewardVideo.IsLoaded(RewardVideoAd) ) {
    HIVEAdKit.RewardVideo.Show(RewardVideoAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}

插頁類型

EventHandlers eventHandlers = new EventHandlers.Builder()
                                                .OnAdLoaded(OnAdLoadedCB)
                                                .OnAdOpening(OnAdOpeningCB)
                                                .OnAdClosed(OnAdClosedCB)
                                                .OnAdFailedToLoad(OnAdFailedToLoadCB)
                                                .OnAdClick(OnAdClickCB)
                                                .OnPaidEvent(OnPaidEventCB)
                                                .Build();
// Generate an instance
InterstitialAd = HIVEAdKit.Interstitial.Initialize(InterstitialAdUnitId, eventHandlers);

// Load
// Send AD loading information to Analytics
if( HIVEAdKit.Interstitial.IsInitialzed(InterstitialAd) ) {
     HIVEAdKit.Interstitial.Load(InterstitialAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}

// Show
// Send AD loading information to Analytics
if( HIVEAdKit.Interstitial.IsLoaded(InterstitialAd) ) {
     HIVEAdKit.Interstitial.Show(InterstitialAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}

自適應橫幅類型

EventHandlers eventHandlers = new EventHandlers.Builder()
                                                            .OnAdLoaded(OnBannerAdLoadedCB)
                                                            .OnAdOpening(OnAdOpeningCB)
                                                            .OnAdClosed(OnAdClosedCB)
                                                            .OnAdFailedToLoad(OnAdFailedToLoadCB)
                                                            .OnAdClick(OnAdClickCB)
                                                            .OnPaidEvent(OnPaidEventCB)
                                                            .Build();
HIVEAdKit.AdaptiveBanner.AdPosition bannerPosition = HIVEAdKit.AdaptiveBanner.AdPosition.Top;
HIVEAdKit.AdaptiveBanner.AdSize adaptiveSize = HIVEAdKit.AdaptiveBanner.AdSize.AD_SIZE_320x50;

// Generate an instance
AdaptiveBannerAd = HIVEAdKit.AdaptiveBanner.Initialize(AdaptiveBannerAdUnitId, adaptiveSize, bannerPosition, eventHandlers);

// Load and show
// Send AD loading information to Analytics
HIVEAdKit.AdaptiveBanner.LoadAd(AdaptiveBannerAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");

// Hide
HIVEAdKit.AdaptiveBanner.Destroy(AdaptiveBannerAd);

支援 iOS 14

以下是支持 iOS 14 及更高版本的 SKAdNetwork AD(X) 列表。AdKitPostprocess 是基于 2021 年 1 月 29 日的更新。别忘了查看最新的更新。

支援 Android 11

一個標籤 <queries> 被添加到 AD(X) 庫的 AndroidManifest.xml 文件中,以支持 Android 11。如果您在 Unity 上構建項目時檢查到以下錯誤日誌,請參考使用 Unity-Android 11 的指南。

  • Unity上的範例錯誤日誌
  AndroidManifest.xml: AAPT: error: unexpected element <queries> found in <manifest>.

ADX Proguard 設定

該庫 AAR 文件包含 Proguard 的規則,因此設置會自動執行。  

Unity 整合通知

如果在 GoogleMobileAdsSettings 上移除 App ID,请前往 Unity > Assets > Google Mobile Ads > Settings 并选择 延迟应用测量 复选框,然后再次清除它。

 

測試廣告

在开发过程中,广告主在测试广告被点击时不应被收费是很重要的。如果您在测试模式之外过多点击广告,这将被视为无效操作。因此,请注意不要成为被举报的目标账户。请参考Google Developers以使用测试广告。

 

錯誤代碼

有關廣告載入失敗時的代碼和訊息,請參閱AD(X)的Ad Error。

卸載

要卸載 AdKit for AD(X),請刪除以下文件和文件夾列表。

    • 與 AdKit 相關
      • /Assets/HIVEAdKit
      • /Assets/HIVEAdKit_Example
    • 與 AD(X) 相關
      • /Assets/ADXLibrary
      • /Assets/GoogleMobileAds
      • /Assets/Plugins/Android/GoogleMobileAdsPlugins
Note

與 AD(X) 相關的文件列表可能會根據 AdKit 中包含的 AD(X) 版本而有所不同。