Unity
Adkit for AD(X): Unity¶
AdKit 是一个广告模块,修复了在处理 AD(X) Unity 包时发生的错误,并支持用户便利。逐一阅读此页面,以便使用 AdKit 以及支持 SDK。
安装¶
访问 Hive 开发者并下载和应用 AdKit。
- 从 Hive 开发者处下载最新版本的 AdKit 并在 这里 解压缩。
- 在 Unity 工具栏中,选择 .unitypackage 文件,路径为 Assets > Import Package > Custom Package…,然后点击 Import。
- 导入完成后,检查Assets文件夹下是否创建了与AdKit和AD(X)相关的文件和文件夹。
Warning
在开发期间测试 AdKit 时,您必须应用测试广告密钥。
更新¶
卸载您正在使用的AdKit并安装最新版本以进行更新。
如何使用¶
iOS (Unity 2019.4及以上)¶
在Unity 2019.4及以上版本中构建iOS项目时,会创建一个名为**UnityFramework**的目标,它作为动态框架运行。
-
EDM4U 配置(基于版本 1.2.171) 确保在 Unity 的 iOS 解析器设置 中启用了 static_framework 构建设置(菜单:资产 > 外部依赖管理器 > iOS 解析器 > 设置)。
-
从 Hive AdKit 的 1.5.0 版本开始,AppLovinSDK 作为动态框架提供。因此,如果您使用的是 static_framework,您必须执行以下步骤。
在 Assets/HIVEAdKit/Editor/AdKitPostprocess.cs 文件中,取消注释iOSAdd_DynamicFrameworks
函数中的dynamicFramework Import
。注释位置如下。(string Name, string Source) [] dynamicFrameworks = { // 从 Hive AdKit 1.5.0 版本开始,在 Pod Static 设置中取消 AppLovinSDK 和 MolocoSDK 的注释。 // ("AppLovinSDK.xcframework", "Pods/AppLovinSDK/applovin-ios-sdk-13.0.1"), // ("MolocoSDK.xcframework", "Pods/MolocoSDKiOS"), }
Warning
仅在启用static_framework并且您正在构建时才可以取消注释。在使用动态框架时取消注释可能会导致冲突。
-
构建项目。构建完成后,打开生成的项目根路径中的 Podfile 以检查文件设置。
source 'https://github.com/adxcorp/AdxLibrary_iOS_Release.git' source 'https://github.com/CocoaPods/Specs' source 'https://cdn.cocoapods.org/' platform :ios, '12.0' target 'UnityFramework' do pod 'ADXLibrary', '2.7.0' pod 'Google-Mobile-Ads-SDK', '~> 11.12.0' pod 'GoogleUserMessagingPlatform', '2.7.0' end target 'Unity-iPhone' do end use_frameworks! :linkage => :static
- 继续进行 Xcode 配置。
iOS:解决Facebook SDK与广告模块之间的冲突¶
虽然 Facebook SDK 仅提供动态框架,但广告模块仅提供静态框架,并且 Podfile 配置仅支持这两种方法中的一种。因此,要在 Unity 中的应用程序构建过程中应用 Facebook SDK,您需要解决 Facebook SDK 与广告模块之间的冲突,如下所示。
<
在HIVEAdKit/Editor/AdKitPostprocess.cs文件中的iOSAdd_DynamicFrameworks函数中取消对您正在使用的Facebook SDK的注释,以嵌入动态SDK。
(string Name, string Source) [] dynamicFrameworks = {
// Hive Starting with AdKit 1.5.0, uncomment AppLovinSDK and MolocoSDK when setting Pod Static.
// ("AppLovinSDK.xcframework", "Pods/AppLovinSDK/applovin-ios-sdk-13.0.1"),
// ("MolocoSDK.xcframework", "Pods/MolocoSDKiOS"),
// If you are using the Facebook SDK, uncomment the lines below according to the SDK type you are using.
// ("FBAEMKit.xcframework","Pods/FBAEMKit/XCFrameworks"),
// ("FBSDKCoreKit_Basics.xcframework","Pods/FBSDKCoreKit_Basics/XCFrameworks"),
// ("FBSDKCoreKit.xcframework","Pods/FBSDKCoreKit/XCFrameworks"),
// ("FBSDKLoginKit.xcframework","Pods/FBSDKLoginKit/XCFrameworks"),
// ("FBSDKShareKit.xcframework","Pods/FBSDKShareKit/XCFrameworks"),
// ("FBSDKGamingServicesKit.xcframework","Pods/FBSDKGamingServicesKit/XCFrameworks")
};
Warning
您必须仅取消注释您当前正在使用的 Facebook SDK。
特性¶
- 奖励类型
- AD(X)不提供广告曝光的API,但通知遵循AdMob指南。
- 发送日志取决于调用的RewardVideo API,如果使用AdKit API和Hive SDK。日志数据发送到分析服务器,支持此功能的最低版本如下。
- Hive SDK v4.11.0
- 插页式广告类型
- 自适应横幅类型
有关如何使用 AdKit 的详细信息,请阅读以下指南。
初始化 AdKit¶
初始化、加载和显示所有类型广告(AD)之前的必要步骤
欧洲和英国目标¶
如果您的游戏面向欧洲和英国(欧洲经济区和英国),则需要显示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同意屏幕,您的应用可能会在苹果的应用审核中被拒绝。
// 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 和英国),将自动显示 GDPR 同意屏幕,如下所示。
在iOS环境中,IDFA解释消息会在欧洲和英国以外的地区自动显示。
高级设置¶
// 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>.
- 使用Unity构建Android 11的指南
ADX Proguard 设置¶
库 AAR 文件包含 Proguard 的规则,因此设置会自动执行。
Unity 集成通知
¶如果在 GoogleMobileAdsSettings 上删除了应用程序 ID,请转到 Unity > Assets > Google Mobile Ads > Settings,然后选择 延迟应用程序测量 复选框,然后再次清除它。
Gradle 和 Gradle 插件版本配置¶
我们推荐使用 Gradle 6.7.1 或更高版本来支持 Adkit 1.4.4 或更高版本。如果您在使用 Adkit 1.4.4 或更高版本时使用较低的 Gradle 版本,您可能会遇到来自 AdMob Unity 插件的 "此功能需要 ASM7" 错误,可以通过以下解决方案之一来解决。
- 更改 Gradle 和 Gradle 插件版本(推荐解决方案)
- 更新 Unity 引擎
- 注释
android.enableDexingArtifactTransform=false
有关如何更改Gradle和Gradle插件版本(更改为Gradle 6.7.1+,Gradle插件4.2.0+),请参阅以下步骤。
- 更改为使用自定义基础Gradle模板。
- 检查构建设置 > 项目设置 > 播放器 > 自定义基础Gradle模板。
- Assets/Plugins/Android/baseProjectTemplate.gradle将被生成。
- 更改Gradle插件版本。打开Assets/Plugins/Android/baseProjectTemplate.gradle文件,并将版本更改为:com.android.tools.build:gradle:4.2.0
- 下载Gradle。可以在这里下载Gradle 6.7.1。下载后,将下载的文件解压缩到您想要的位置(例如:~/Users/honggd/gradle-6.7.1)。
- 在Unity中更改Gradle安装路径。
- 取消选中偏好设置 > 外部工具 > 随Unity安装的Gradle。
- 将安装路径设置为您解压缩下载的Gradle文件的目录(例如:~/Users/honggd/gradle-6.7.1)。
- 确保播放器 > 其他设置 > 标识 > 目标API级别为33或更高,然后构建您的项目。
测试广告¶
在开发过程中,广告商在测试广告被点击时不被收费是很重要的。如果您在测试模式之外点击广告过多,这将被视为无效行为。因此,请注意不要成为被举报的目标账户。请参考Google 开发者以使用测试广告。
卸载¶
要卸载 AdKit for AD(X),请删除以下文件和文件夹列表。
-
- 与 AdKit 相关
- /Assets/HIVEAdKit
- /Assets/HIVEAdKit_Example
- 与 AD(X) 相关
- /Assets/ADXLibrary
- /Assets/GoogleMobilesAds
- /Assets/MoPub
- /Assets/Plugins/Android/GoogleMobileAdsPlugins
- 与 AdKit 相关
Note
与 AD(X) 相关的文件列表可能会根据 AdKit 中包含的 AD(X) 版本而有所不同。