來
今天簡單介紹下國外的一些主流廣告平臺,主要介紹其中的視頻獎勵廣告
- Vungle
領先的In-app視頻廣告平臺,被Business Insider評爲15家熱門的未上市廣告技術公司。主要應用在遊戲類app上,其中娛樂場類遊戲佔比較高。
集成方式:
- 添加依賴
dependencies {
// Vungle SDK
implementation 'com.vungle:publisher-sdk-android:6.4.11'
// Either appcompat-v7 or support-v4 is need for SDK operation
implementation 'com.android.support:appcompat-v7:28.0.0' // Either
implementation 'com.android.support:support-v4:27.1.1' // Or
// Recommended for SDK to be able to get Android Advertising ID
implementation 'com.google.android.gms:play-services-basement:16.0.0'
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
}
- 初始化
Vungle.init("YOUR_VUNGLE_APP_ID", getApplicationContext(), new InitCallback() {
@Override
public void onSuccess() {
// Initialization has succeeded and SDK is ready to load an ad or play one if there
// is one pre-cached already
}
@Override
public void onError(Throwable throwable) {
// Initialization error occurred - throwable.getLocalizedMessage() contains error message
}
@Override
public void onAutoCacheAdAvailable(String placementId) {
// Callback to notify when an ad becomes available for the cache optimized placement
// NOTE: This callback works only for the cache optimized placement. Otherwise, please use
// LoadAdCallback with loadAd API for loading placements.
}
};
- 請求廣告
if (Vungle.isInitialized()) {
Vungle.loadAd("YOUR_REWARD_Placement_reference_id", new LoadAdCallback() {
@Override
public void onAdLoad(String placementReferenceId) { }
@Override
public void onError(String placementReferenceId, Throwable throwable) {
// Load ad error occurred - throwable.getLocalizedMessage() contains error message
}
});
}
- 播放廣告
if (Vungle.canPlayAd("YOUR_REWARD_Placement_reference_id")) {
AdConfig adConfig = new AdConfig();
// 靜音播放
// adConfig.setMuted(true);
// 自動控制廣告方向
// adConfig.setAutoRotate(true);
Vungle.playAd("YOUR_REWARD_Placement_reference_id", adConfig, new PlayAdCallback() {
@Override
public void onAdStart(String placementReferenceId) { }
@Override
public void onAdEnd(String placementReferenceId, boolean completed, boolean isCTAClicked) {
// Load Next ad
}
@Override
public void onError(String placementReferenceId, Throwable throwable) {
// Play ad error occurred - throwable.getLocalizedMessage() contains error message
}
});
}
- Applovin
AppLovin是一家移動廣告公司,主要經營廣告網絡,利用移動網絡幫助廣告主向特徵類似的消費者進行精準投放。
- 添加依賴和Key
dependencies {
implementation "'com.applovin:applovin-sdk:+'"
}
<meta-data android:name="applovin.sdk.key"
android:value="" />
- 初始化
AppLovinSdk.initializeSdk(context);
- 請求廣告(加載廣告)
private AppLovinIncentivizedInterstitial incentivizedInterstitial;
incentivizedInterstitial = AppLovinIncentivizedInterstitial.create(AppContext.getInstance());
incentivizedInterstitial.preload(new AppLovinAdLoadListener() {
@Override
public void adReceived(AppLovinAd appLovinAd) {
Log.e(TAG, "adReceived");
}
@Override
public void failedToReceiveAd(int errorCode) {
}
});
- 播放廣告
/**
* 播放Applovin廣告
*/
private void playAppLovinAds(final Activity mActivity) {
if (!incentivizedInterstitial.isAdReadyToDisplay()){
return;
}
AppLovinAdRewardListener adRewardListener = ;
// Video Playback Listener
AppLovinAdVideoPlaybackListener adVideoPlaybackListener = ;
// Ad Dispaly Listener
AppLovinAdDisplayListener adDisplayListener =;
// Ad Click Listener
AppLovinAdClickListener adClickListener = ;
incentivizedInterstitial.show(mActivity, adRewardListener, adVideoPlaybackListener, adDisplayListener, adClickListener);
}
- 添加依賴和Key
allprojects {
repositories {
google()
jcenter()
}
}
dependencies {
implementation 'com.google.android.gms:play-services-ads:18.2.0'
}
<manifest>
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
- 初始化
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
private RewardedAd rewardedAd;
rewardedAd = new RewardedAd(this,"廣告單元 ID");
- 請求廣告(加載廣告)
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
@Override
public void onRewardedAdLoaded() {
// Ad successfully loaded.
}
@Override
public void onRewardedAdFailedToLoad(int errorCode) {
// Ad failed to load.
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
- 播放廣告
if (rewardedAd.isLoaded()) {
Activity activityContext = ...;
RewardedAdCallback adCallback = new RewardedAdCallback() {
public void onRewardedAdOpened() {
// Ad opened.
}
public void onRewardedAdClosed() {
// Ad closed.
}
public void onUserEarnedReward(@NonNull RewardItem reward) {
// User earned reward.
}
public void onRewardedAdFailedToShow(int errorCode) {
// Ad failed to display
}
};
rewardedAd.show(activityContext, adCallback);
} else {
Log.d("TAG", "The rewarded ad wasn't loaded yet.");
}
- 預加載廣告(示例)
public RewardedAd createAndLoadRewardedAd() {
RewardedAd rewardedAd = new RewardedAd(this,
"ca-app-pub-3940256099942544/5224354917");
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
@Override
public void onRewardedAdLoaded() {
// Ad successfully loaded.
}
@Override
public void onRewardedAdFailedToLoad(int errorCode) {
// Ad failed to load.
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
return rewardedAd;
}
@Override
public void onRewardedAdClosed() {
this.rewardedAd = createAndLoadRewardedAd();
}
- 添加依賴和Key
repositories {
// Ensure that you have mavenCentral() in list of repositories.
mavenCentral()
}
dependencies {
implementation 'com.android.support:support-annotations:28.0.0' // Required Dependency by Audience Network SDK
implementation 'com.facebook.android:audience-network-sdk:5.+'
}
- 初始化
AudienceNetworkAds.initialize(context);
- 請求廣告(加載廣告)
private void loadInstreamAd() {
// Instantiate an InstreamVideoAdView object.
// NOTE: the placement ID will eventually identify this as your App, you can ignore it for
// now, while you are testing and replace it later when you have signed up.
// While you are using this temporary code you will only get test ads and if you release
// your code like this to the Google Play your users will not receive ads (you will get a no fill error).
adView = new InstreamVideoAdView(
this,
"YOUR_PLACEMENT_ID",
new AdSize(
pxToDP(adContainer.getMeasuredWidth()),
pxToDP(adContainer.getMeasuredHeight()))
);
// set ad listener to handle events
adView.setAdListener(new InstreamVideoAdListener() {
@Override
public void onError(Ad ad, AdError adError) {
// Instream video ad failed to load
Log.e(TAG, "Instream video ad failed to load: " + adError.getErrorMessage());
}
@Override
public void onAdLoaded(Ad ad) {
// Instream video ad is loaded and ready to be displayed
Log.d(TAG, "Instream video ad is loaded and ready to be displayed!");
// Race condition, load() called again before last ad was displayed
if(adView == null || !adView.isAdLoaded()) {
return;
}
}
@Override
public void onAdVideoComplete(Ad ad) {
// Instream Video View Complete - the video has been played to the end.
// You can use this event to continue your video playing
Log.d(TAG, "Instream video completed!");
}
@Override
public void onAdClicked(Ad ad) {
Log.d(TAG, "Instream video ad clicked!");
}
@Override
public void onLoggingImpression(Ad ad) {
// Instream Video ad impression - the event will fire when the
// video starts playing
Log.d(TAG, "Instream video ad impression logged!");
}
});
adView.loadAd();
}
- 播放廣告
private void showInstreamVideoAdWithDelay() {
// Check if adView has been loaded successfully
if (adView == null || !adView.isAdLoaded() ) {
return;
}
// Check if ad is already expired or invalidated, and do not show ad if that is the case.
if (adView.isAdInvalidated()) {
return;
}
adView.show();
}
####至此,四個廣告平臺的集成都已完畢。
要注意的是,如果需要多次播放廣告的話,建議每次播放廣告完成之後馬上去預加載下一個廣告,每個廣告平臺都是,否則有可能無法繼續播放廣告(相當於每次加載的廣告只能播放一次)。具體做法可以參考google廣告的第五點廣告預加載示例,其他廣告同理。
謝謝大家支持!
——積木