C++
AdKit for ADOP: C++¶
AdKit for ADOP (hereinafter, AdKit for ADOP) is an advertisement module that uses ADOP's API and develops by following the guideline from ADOP. Using AdKit with Hive SDK, log data is sent to Analytics server so that you can skip analyzing an advertisement.
This guide explains how to implement AdKit for ADOP with Cocos C++ so that the Hive SDK user uses ADOP under the c++ development environment. AdKit for ADOP with C++ is able to run on the iOS and Android platforms, and you can see how to set for each on this page.
Creating Development Environment¶
Follow the guide below for each platform to configure AdKit.
Android¶
Build the AdKit SourceCode embedded in SDK to use the AdKit. Android Studio 4.2 and later version are recommended.
-
ExternalNativeBuild Using #cmake, add the following code to the CMakeList.txt file.
// 'CMakeList.txt' set(HIVEADKIT_DIR_PATH ....../HIVEAdKit) #setup to HIVEAdKit path #HIVEAdKit library import after add_library( MyGame ... ) add_subdirectory(${HIVEADKIT_DIR_PATH}) #HIVEAdKit library & macro load use_hiveadkit_prebuilt(${HIVEADKIT_DIR_PATH} MyGame) #library import automatic macro to build target
-
Add the following code to the build.gradle file.
-
Add AdMobId, which is formatted in ca-app-pub-XXXXX~YYYYY, to the AndroidManifest.xml file.
iOS¶
Build the AdKit SourceCode embedded in SDK to use the AdKit.
-
Drag and drop the HIVEAdKit/src and HIVEAdKit/include folders to XCode project. * Include all files with .cpp, .hpp and .mm extensions. * AdKit provides bridge-pattern code for the actual use.
-
Add HIVEAdKit/include/bidmad to Project > BuildSetting > Search Paths.
-
Add
GADApplicationIdentifier
to Info.plist of the Xcode project generated in Unity build, and enter AdMobId, which is formatted in ca-app-pub-XXXXX~YYYYY, as string type.On iOS 14 and higher, add SKAdNetworkItems to Info.plist.
-
Add the following to CocoaPods settings.
-
Run the following to apply CocoaPod settings.
How to Use¶
Test ad key in ADOP¶
Using a test ad key that ADOP issued is required.
#if defined(ANDROID)
const char* rewardVideoId = "7d9a2c9e-5755-4022-85f1-6d4fc79e4418";
const char* InterstitialAdId = "e9acd7fc-a962-40e4-aaad-9feab1b4f821";
const char* AdaptiveBannerAdId = "944fe870-fa3a-4d1b-9cc2-38e50b2aed43";
#else// UNITY_IOS
const char* rewardVideoId = "29e1ef67-98d2-47b3-9fa2-9192327dd75d";
const char* InterstitialAdId = "228b95a9-6f42-46d8-a40d-60f17f751eb1";
const char* AdaptiveBannerAdId = "1c3e3085-333f-45af-8427-2810c26a72fc";
#endif
Initializing AdKit¶
If your app is targetting the users in the European Economic Area (EEA) and the UK, you have to obtain GDPR consent. Go to the UserMessagingPlatform Library of Google AdMob and follow the guide to get the consent.
// When distributing common use
HIVEAdKit::GDPR::Setup(false, nullptr);
// When using GDPR test
HIVEAdKit::GDPR::Reset();
HIVEAdKit::GDPR::Setup(true, testDeviceId);
Reward ads¶
Rewarded ads reward a user who watched a video for a period of time, and is able to load one ad at a time.
// Create RewardVideoAd Instance
auto rewardVideo = HIVEAdKit::RewardVideo::Initialize(rewardVideoId, this);
// Load RewardVideoAd
HIVEAdKit::RewardVideo::Load(*rewardVideo, "RewardVideo-Load-AdPlacementInfo");
// Show RewardVideoAd
if( HIVEAdKit::RewardVideo::IsLoaded(*rewardVideo) ) {
HIVEAdKit::RewardVideo::Show(*rewardVideo, "RewardVideo-Show-AdPlacementInfo");
}
Interstitial ads¶
Interstitial ads are full-screen ads that cover the interface of game.
// Create InterstitialAd Instance
auto interstitial = HIVEAdKit::Interstitial::Initialize(InterstitialAdId, this);
// Load InterstitialAd
HIVEAdKit::Interstitial::Load(*interstitial, "Interstitial-Load-AdPlacementInfo");
// Show InterstitialAd
if( HIVEAdKit::Interstitial::IsLoaded(*interstitial) ) {
HIVEAdKit::Interstitial::Show(*interstitial, "Interstitial-Show-AdPlacementInfo");
}
Adaptive Banner ads¶
Adaptive Banner ads are a type of rolling banner that occupies a spot on screen. The banner's position is adjustable with the yPos
value.
// Create AdaptiveBanner Instance
auto adaptiveBanner = HIVEAdKit::AdaptiveBanner::Initialize(AdaptiveBannerAdId, this, yPos);
// Load AdaptiveBanner
HIVEAdKit::AdaptiveBanner::Load(*adaptiveBanner, "Banner-Load-AdPlacementInfo");
// Show AdaptiveBanner
HIVEAdKit::AdaptiveBanner::Show(*adaptiveBanner, "Banner-Show-AdPlacementInfo");
// Hide AdaptiveBanner
HIVEAdKit::AdaptiveBanner::Hide(*adaptiveBanner);
Test ads¶
It is important for advertiser not to be charged when test ad is clicked in development. If you click ads too much out of test mode, it is regarded as invalid action. Therefore, be aware not to be a target account to report.
Refer to the Google Developers to use a test ad.