로딩중입니다
adPOPcorn DA : Unity Android
10/26/2015 2:23:13 PM

adPOPcorn DA

adPOPcorn DA(图片广告,展示广告) 是为了开发者带来收益的工具。广告形式包括广告条、弹窗、全屏广告、结束画面广告和原生广告。

Mediation 功能无中间手续费,为开发者提供最大的收益。

请通过以下链接了解服务详情。

[adPOPcorn DA 服务指南]


注意事项
  1. 集成 adPOPcorn add-on 之前,必须先完成 IGAW 共同集成。[IGAW 共同集成 : Unity Android]

Unity Android

Unity Android Project 内,请参考如下添加 IGAW DA Plugin Package 方式。


添加 Package

[SDK 下载中心] 下载最新的 IgaworksDisplayAdUnityPlugin_aos~* 文件须将添加 Unity Project 内。

+ 已使用 adPOPcorn、adbrix 等的服务时,IgawCommon_v0.0.0a.jar 维持最高的版本。


正常添加后,可以在 Assets 文件下确认到已添加 Package。 



AndroidManifest.xml

为了集成 adPOPcorn DA 需修改 AndroidManifest。

添加共同集成中设置的 AppKey、HashKey、Permission 外,还需添加为了使用展示广告所需的 activity。


<application></application> 标签内添加需要的 activity。

<!-- IGAWorks DA 最初要求 SDK ver : 8 -->
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />

<!-- DA 添加必备 Activity -->
<activity android:name="com.igaworks.displayad.activity.InterstitialActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar" />
<!-- 登录基本信息 -->
<meta-data android:name="igaworks_app_key" android:value="아이지에이웍스 앱키"/>
<meta-data android:name="igaworks_hash_key" android:value="아이지에이웍스 해시키"/>
<meta-data android:name="igaworks_market_info" android:value="google"/>
</application>
</manifest>

+ 如果需要使用 Mediation 功能曝光其他 DA Network 的广告时,请参考各个 DA Network 的指南。



adPOPcorn DA 基本集成

adPOPcorn DA 提供广告条、全屏广告、弹窗广告、结束画面原生广告。在集成各个形式的广告之前,需使用基本 API 进行初始化。


SDK 初始化

在应用启动后最初加载的 activity 或需要曝光的 DA 广告的 activity 上调用 init API 初始化 SDK。

void Start (){
	Debug.Log ("Start");
	IgawDisplayAdPlugin.init();
} 


Resource 解除

在应用终止时, 使用 destroy API,解除 Memory 中分配的 DA 相关的 Resource (View,Memory)。

应用终止时,在调用的 activity 的 onDestroy() 中进行调用。

void OnDestroy(){
	Debug.Log ("OnDestroy");
	IgawDisplayAdPlugin.destroy();
}

+ 为了使用 Delegate 而登录的情况时,需解除 OnDestory() 里登录的 Delegate。



广告条

广告条是 DA 最基本的广告形式,在应用的下端或上端显示条形的广告。


Instance 生成

为了曝光广告条,生成 Instance。

public class IgawDASampleScene : MonoBehaviour{

	private string BANNER_SPOTKEY = "bannerspotkey";
	private Banner bannerAd = null;

	void Start(){   
		bannerAd = new Banner(BANNER_SPOTKEY, Banner.GRAVITY_BOTTOM); 
	}
}

+ 广告条 SpotKey : adPOPcorn DA 管理页面中生成的 SpotKey 


控制广告

控制广告条点上调用 API,可以控制广告。 

//曝光广告条
void SomeAction(){
	if(bannerAd != null)   
	bannerAd.startBannerAd();
}

//暂停广告条
void SomeAction(){
	if(bannerAd != null)  
	bannerAd.pauseBannerAd();
}

//结束广告条
void SomeAction(){
	if(bannerAd != null) 
	bannerAd.stopBannerAd();
}
+应用在 Pause 或 restart 时,广告也同时进行 pause/start 处理。使用 Unity 提供的 onApplicationPause(bool pauseStatue) 进行处理。


Delegate

提供对加载广告条的成功/失败的 Delegate。提供的 Delegate 实现和示例如下。

  • OnBannerAdReceiveSuccess : 广告条加载成功
  • OnBannerAdReceiveFailed : 广告条加载失败 (传达的错误代码请参考文件最后部分)
//登录广告条 Delegate
void SomeAction(){
	if(bannerAd != null)
		bannerAd.OnBannerAdReceiveSuccess += OnBannerAdReceiveSuccess;
		bannerAd.OnBannerAdReceiveFailed += OnBannerAdReceiveFailed;
}

//实现广告条 Delegate
public void OnBannerAdReceiveSuccess(object sender, System.EventArgs args){
	Debug.Log("OnBannerAdReceiveSuccess event received.");
}
public void OnBannerAdReceiveFailed(object sender, ErrorResult errorResult){
	Debug.Log("OnBannerAdReceiveFailed event received. > errorCode : " +
	errorResult.errorCode + ", errorMessage : " + errorResult.errorMessage);
}

//解除广告条 Delegate
void OnDestroy(){
	if (bannerAd != null) {
		bannerAd.OnBannerAdReceiveSuccess -= OnBannerAdReceiveSuccess;
		bannerAd.OnBannerAdReceiveFailed -= OnBannerAdReceiveFailed;
		bannerAd.stopBannerAd ();
	}
	IgawDisplayAdPlugin.destroy ();
}



全屏广告

全屏广告是在整个画面的广告形式。参考以下内容集成全屏广告。


Instance 生成

为了曝光全屏广告,生成 Instance。

public class IgawDASampleScene : MonoBehaviour{
	private string INTERSTITIAL_SPOTKEY = "interstitialspotkey";
	private Interstitial interstitialAd = null;
	
	void Start(){
		interstitialAd = new Interstitial(INTERSTITIAL_SPOTKEY);
	}
}

+ 全屏广告 SpotKey : adPOPcorn DA 管理页面中生成的全屏广告 SpotKey。 


控制广告

控制广告条时点上调用 API。 

//曝光全屏广告
void SomeAction(){
	if(interstitialAd != null)
	interstitialAd.showInterstitialAd();
}


Delegate

提供对加载全屏广告的成功/失败/结束窗的 Delegate。提供的 Delegate 实现和示例如下。

  • OnInterstitialReceiveSuccess : 全屏广告下载成功
  • OnInterstitialReceiveFailed : 全屏广告加载失败 (传达的错误代码请参考最后部分)
  • OnInterstitialClosed : 终止全屏广告窗
//登录全屏 Delegate
void SomeAction(){
	if(interstitialAd != null)
		interstitialAd.OnInterstitialReceiveSuccess += OnInterstitialReceiveSuccess;
		interstitialAd.OnInterstitialReceiveFailed += OnInterstitialReceiveFailed;
		interstitialAd.OnInterstitialClosed += OnInterstitialClosed;
}

//实现全屏 Delegate
public void OnInterstitialReceiveSuccess(object sender, System.EventArgs args){
	Debug.Log("OnInterstitialReceiveSuccess event received.");
}
public void OnInterstitialReceiveFailed(object sender, ErrorResult errorResult){
	Debug.Log("OnInterstitialReceiveFailed event received. > errorCode : " +
	errorResult.errorCode + ", errorMessage : " + errorResult.errorMessage);
}
public void OnInterstitialClosed(object sender, System.EventArgs args){
	Debug.Log("OnInterstitialClosed event received.");
}

//解除全屏 Delegate
void OnDestroy(){
	if (interstitialAd != null) {
		interstitialAd.OnInterstitialReceiveSuccess -= OnInterstitialReceiveSuccess;
		interstitialAd.OnInterstitialReceiveFailed -= OnInterstitialReceiveFailed;
		interstitialAd.OnInterstitialClosed -= OnInterstitialClosed;
	}
	IgawDisplayAdPlugin.destroy ();
}


弹窗广告

广告不完全覆盖整个画面,可以看见背景画面的广告形式。


Instance 生成

为了曝光弹窗广告,生成 Instance。

public class IgawDASampleScene : MonoBehaviour{
	private string POPUP_SPOTKEY = "popupspotkey";
	private PopupAd popupAd = null;
	
	void Start(){
		popupAd = new PopupAd(POPUP_SPOTKEY);
	}
}

+ 弹窗广告 SpotKey : adPOPcorn DA 管理页面中生成的弹窗广告 SpotKey 


控制广告

控制弹窗广告时点上调用 API,可以控制广告。 

//曝光弹窗广告
void SomeAction(){
	if(popupAd != null)
	popupAd.showPopupAd();
}

+弹窗广告 SpotKey : adPOPcorn DA 管理页面中生成的弹窗广告 SpotKey。


Delegate

提供对加载弹窗广告的成果/失败/结束窗的 Delegate。提供的 Delegate 实现和示例如下。

  • OnPopupAdReceiveSuccess : 弹窗广告加载成功
  • OnPopupAdReceiveFailed : 弹窗广告加载失败 (传达的错误代码请参考文件最后的部分)
  • OnPopupAdClosed : 终止弹窗广告窗
//登录弹窗 Delegate
Void SomeAction(){
	if (popupAd != null){
		popupAd.OnPopupAdReceiveSuccess += OnPopupAdReceiveSuccess;
		popupAd.OnPopupAdReceiveFailed += OnPopupAdReceiveFailed;
		popupAd.OnPopupAdClosed += OnPopupAdClosed;
	}
}

//实现弹窗 Delegate
public void OnPopupAdReceiveSuccess(object sender, System.EventArgs args){
	Debug.Log("OnPopupAdReceiveSuccess event received.");
}
public void OnPopupAdReceiveFailed(object sender, ErrorResult errorResult){
	Debug.Log("OnPopupAdReceiveFailed event received. > errorCode : " +
	errorResult.errorCode + ", errorMessage : " + errorResult.errorMessage);
}
public void OnPopupAdClosed(object sender, System.EventArgs args){
Debug.Log("OnPopupAdClosed event received.");
}

//解除弹窗 Delegate
void OnDestroy(){
	if (popupAd != null) {
		popupAd.OnPopupAdReceiveSuccess -= OnPopupAdReceiveSuccess;
		popupAd.OnPopupAdReceiveFailed -= OnPopupAdReceiveFailed;
		popupAd.OnPopupAdClosed -= OnPopupAdClosed;
	}
	IgawDisplayAdPlugin.destroy ();
}



结束画面广告 

在结束应用时显示弹窗,咨询是否终止应用的广告形式。


Instance 生成及广告加载

为了曝光结束画面广告,生成 Instance。使用 loadEndingAd API,加载结束画面广告。为了应用开始时点上提前加载广告信息来进行调用。

public class IgawDASampleScene : MonoBehaviour{
	private string ENDING_SPOTKEY = "endingspotkey";
	void Start(){
		IgawDisplayAdPlugin.loadEndingAd(ENDING_SPOTKEY);
	}
}

+ 结束画面广告 SpotKey : adPOPcorn DA 管理页面上生成的弹窗广告 SpotKey


曝光广告

调用 showEndingAd API,曝光广告。建议与 Android 返回键 Event 或连接其他终止动作进行使用。

void Update (){
	if (Input.GetKeyDown (KeyCode.Escape)) {
		IgawDisplayAdPlugin.showEndingAd(ENDING_SPOTKEY);
	}
}


Delegate

替代 Plugin,想直接处理终止时,可以进行登录 Delegate 及实现。实现示例如下。(但设置了 Delegate 的话,无法启动 Plugin 的终止处理 Logic)

void Start (){
	// Set Delegate
	IgawDisplayAdPlugin.setEndingAdEventCallbackListener(ENDING_SPOTKEY);
	IgawDisplayAdPlugin.OnBtnClickListener = mOnBtnClickListener;
}

// implement Delegate
// finish = true : 点击终止按钮
// finish = false : 点击取消按钮
public void mOnBtnClickListener(bool finish){
	Debug.Log("mOnBtnClickListener event received : " + finish);
}



原生广告

原生广告是使用从 adPOPcorn DA 服务器接收的 Json 字符串形式的广告信息,加工成需要的形态后显示广告。


Instance 生成

为了曝光原生广告,生成 Instance。

  • OnNativeAdRequestSucceeded : 原生广告加载成功,nativeAdInfo 的 Json 字符串形式的广告信息
  • OnNativeAdRequestFailed : 原生广告加载失败 (传达的错误代码请参考文件最后的部分)
public class IgawDASampleScene : MonoBehaviour{
	private string NATIVE_SPOTKEY = "nativespotkey";
	private NativeAd nativeAd = null;
	
	void Start(){
		nativeAd = new NativeAd(NATIVE_SPOTKEY);
		nativeAd.OnNativeAdRequestSucceeded += OnNativeAdRequestSucceeded;
		nativeAd.OnNativeAdRequestFailed += OnNativeAdRequestFailed;
	}
}

+ 原生广告 SpotKey: adPOPcorn DA 管理页面生成的原生广告 SpotKey


广告加载

调用 loadAd API 加载原生广告信息。加载的信息通过原生广告 Delegate 进行确认。

void loadNativeAdInfo(){
	if (nativeAd != null) {
		nativeAd.loadAd();
	}
}


广告跟踪

原生广告是以直接构建广告曝光,为须将集成广告曝光和跟踪点击。实现示例如下。

void showNativeAdToUser(){
	// 调用以下函数,跟踪原生广告的曝光情况。
	nativeAd.impressionAction();
}
void clickNativeAd(){
	// 调用以下函数,跟踪用户点击原生广告的动作。
	nativeAd.clickAction();
}


Delegate

加载原生广告信息的结果,通过已实现的 Delegate 传达。提供的 Delegate 和实现示例如下。

public void OnNativeAdRequestSucceeded(object sender, NativeAdModel nativeModel){

}
public void OnNativeAdRequestFailed(object sender, ErrorResult errorResult){
	Debug.Log("OnNativeAdRequestFailed event received. > errorCode : " +
	errorResult.errorCode + ", errorMessage : " + errorResult.errorMessage);
}



DA 答应错误代码定义

各个广告 Event Listener 传达的错误代码的定义。

代码信息说明
200Exception一般错误
1000Invalid ParameterParameter 错误
9999Unknown Server Error未知的服务器错误
2000Invalid Media KeyAppKey 错误
2030Invalid Spot KeySpotKey 错误
2100Empty Campaign无广告
2200Invalid Third Party Name外部 Network 的信息加载失败
3200Native Spot Does Not Initialized原生广告设置初始化错误
5000Server Timeout服务器超时
5001Load Ad Failed无法加载特定 Network 的广告
5002No Ad无法加载所有 Network 的广告



DA Mediation

使用 Mediation 时,请参考以下链接进行。

[adPOPcorn DA : Android (Mediation)]