Taku Unity plug-in 2.0.0 supports access to open-screen ads through C# API. Open-screen ads are similar to interstitial ads, but the display time is usually when the application is cold-started or hot-started.
1. Cold start (the initial startup of the application when the application process does not exist)
The preferred method of handling cold start is Create a new scene as the startup page, and load ads in the Start() method of this scene. If the loading times out, the ads will no longer be displayed. Please refer to the sample code for details.
Initiate ATSplashAd.Instance.loadSplashAd() after starting the application or game to load the open-screen advertisement
Put the preloading logic of other advertising forms and other requests that consume network resources after the opening screen ad is displayed to reduce the loading timeout of the opening screen
If the ad loading times out (onAdLoadTimeoutEvent(object sender, ATAdEventArgs erg)), there is no need to wait for the ad to be filled and you can directly enter the main interface; the open-screen ad is still loading this time, and it will be triggered if the loading is successful
onAdLoadEvent(object sender, ATAdEventArgs erg)onAdLoadEvent(object sender, ATAdEventArgs erg) callback is triggered and when the loading does not time out (when ATAdEventArgs.isTimeout is false), call ATSplashAd.Instance.showSplashAd() Display ads
2. Hot start (the application temporarily retreats to the background through the home button, and returns to the application while the application process still exists)
When the application returns to the foreground, it calls ATSplashAd.Instance.hasSplashAdReady() to determine whether there is currently an ad cache. If true, it calls ATSplashAd.Instance.showSplashAd() to display ads. If it is false, it calls ATSplashAd.Instance.showSplashAd(). ATSplashAd.Instance.loadSplashAd() performs preloading of advertisements.
3. It is recommended to call ATSplashAd.Instance.entryScenarioWithPlacementID() after entering the displayable advertising scene to count the cache status of the current advertising space. For specific statistical instructions, please view the advertising scene. Distinguish data from different business scenarios.
4. Ad preloading: After the open-screen ad is displayed, call load in the onAdLoadEvent or onAdCloseEvent callback to preload.
If you need to display open-screen ads during hot start, it is recommended to call ATSplashAd.Instance.hasSplashAdReady() when the application retreats to the background to determine whether there is currently an ad cache. , true calls ATSplashAd.Instance.showSplashAd() to display ads, false calls ATSplashAd.Instance.loadSplashAd() to preload ads.
5. Configure the bottom-opening advertising source in the background to reduce loading timeouts. For configuration methods, see Bottom-opening advertising.
6. In Unity, listen to the APP foreground event:
To receive the application foreground event For event notification, it is recommended that you listen to OnApplicationPauseevent. By overriding the OnApplicationPause method, your application will be alerted to application launch and foreground events, and will be able to display ads.
Note:
ATSplashAd:
API | Parameters | Description |
---|---|---|
loadSplashAd | string placementId, Dictionary | Loading ads |
hasSplashAdReady | string placementId | Determine whether there is ad cache |
checkAdStatus | string placementid | Get the status of the current ad slot (Json string): 1. isLoading: whether it is loading 2. isReady: whether there is ad cache ( Same function as hasSplashAdReady) 3. AdInfo: the current highest priority ad cache information (refer to ATCallbackInfo description) |
getValidAdCaches | string placementid | Get all successfully loaded ad cache information (JSON string) (ReferenceATCallbackInfo description) |
showSplashAd | string placementid, Dictionary | Display ads |
entryScenarioWithPlacementID | string placementId, string scenarioID | Set up to enter the displayable advertising scenario |
public class ExampleHomeScreen : MonoBehaviour, ATSDKInitListener
{
void Start()
{
#if UNITY_ANDROID
ATSDKAPI.initSDK("Your Android AppId", "Your Android AppKey", this);
#elif UNITY_IOS || UNITY_IPHONE
ATSDKAPI.initSDK("Your iOS AppId", "Your iOS AppKey", this);
#endif
}
void OnDestroy()
{
ATSplashAd.Instance.client.onAdLoadEvent -= onAdLoad;
ATSplashAd.Instance.client.onAdLoadTimeoutEvent -= onAdLoadTimeout;
ATSplashAd.Instance.client.onAdLoadFailureEvent -= onAdLoadFailed;
ATSplashAd.Instance.client.onAdCloseEvent -= onAdClose;
}
//SDK initialization successful
public void initSuccess()
{
ATSplashAd.Instance.client.onAdLoadEvent += onAdLoad;
ATSplashAd.Instance.client.onAdLoadTimeoutEvent += onAdLoadTimeout;
ATSplashAd.Instance.client.onAdLoadFailureEvent += onAdLoadFailed;
ATSplashAd.Instance.client.onAdCloseEvent += onAdClose;
ATSplashManager.Instance.ShowAdIfReady();
}
public void initFail(string msg)
{
Debug.Log("Developer callback SDK initFail:" + msg);
}
//If the ad is loaded successfully, it will be displayed directly.
public void onAdLoad(object sender, ATAdEventArgs erg)
{
if (!erg.isTimeout)
{
ATSplashManager.Instance.ShowAdIfReady();
}
else
{
//Loading timeout, show will no longer be called to display ads
}
}
//Ad loading timeout, no need to continue waiting for ads to fill, go directly to the homepage
public void onAdLoadTimeout(object sender, ATAdEventArgs erg)
{
}
//Ad loading failed
public void onAdLoadFailed(object sender, ATAdErrorEventArgs args)
{
}
//Close ads and go to homepage
public void onAdClose(object sender, ATAdEventArgs erg)
{
}
//Monitor APP foreground events
private void OnApplicationPause(bool pauseStatus)
{
if (!pauseStatus) //Return to the foreground from the background
{
ATSplashManager.Instance.ShowAdIfReady();
}
}
}
public class ATSplashManager
{
#if UNITY_ANDROID
private const string SPLASH_PLACEMENT_ID = "Your PlacementId";
#elif UNITY_IOS || UNITY_IPHONE
private static string SPLASH_PLACEMENT_ID = "Your PlacementId";
#endif
private static ATSplashManager instance = new ATSplashManager();
public static ATSplashManager Instance
{
get
{
return instance;
}
}
public void ShowAdIfReady()
{
var splashAd = ATSplashAd.Instance;
if (splashAd.hasSplashAdReady(SPLASH_PLACEMENT_ID))
{
splashAd.showSplashAd(SPLASH_PLACEMENT_ID, new Dictionary());
}
else
{
splashAd.loadSplashAd(SPLASH_PLACEMENT_ID, new Dictionary());
}
}
}