Skip to content

Best practices

Follow these recommendations to get the most out of your integration and to avoid the most common mistakes.

  • Initialize the SDK once, when the app starts. Subscribe to WortiseSdk.OnInitialized before calling WortiseSdk.Initialize, and wait for this event before loading ads.
  • Keep the ad objects in a persistent object. Create them in a GameObject marked with DontDestroyOnLoad, so an ad that is already loaded is not lost when the scene changes.
  • Call the SDK from the main thread. The SDK creates native views and objects, so do not call it from Task.Run or from your own threads. All the events are raised on the Unity main thread, so the handlers can use the Unity API directly.
  • Request consent on every launch and load the first ad when it has finished. RequestIfRequired only shows the dialog when it is needed, and its callback tells you when the ads can be requested. See User consent.
  • Offer an option to change the consent. Call WortiseConsentManager.Request from the settings screen of your app.
  • Set the child-directed options before initializing the SDK. If your app is directed to children, see Privacy.
  • On iOS, show the App Tracking Transparency prompt before loading the first ad, if your app requests it. The SDK does not show it.
void Start() {
WortiseSdk.OnInitialized += OnSdkInitialized;
WortiseSdk.Initialize("your app key");
}
void OnSdkInitialized() {
WortiseConsentManager.RequestIfRequired((shown) => {
interstitialAd.LoadAd();
});
}
  • Create one object per ad unit and reuse it. After an interstitial or rewarded ad is dismissed, call LoadAd again on the same object to prepare the next one.
  • Load the ads in advance, but do not call LoadAd when an ad is already available. LoadAd discards the loaded ad and requests a new one, so check IsAvailable first when the ad may already be loaded.
  • Do not retry immediately from OnFailedToLoad. After a failed load there is a cooldown period (30 seconds by default) during which LoadAd is ignored and no event is raised. Request the ad again later, or check IsInCooldown and CooldownRemainingMs.
// Prepare the next ad when the current one is closed
interstitialAd.OnDismissed += () => interstitialAd.LoadAd();
  • Check IsAvailable before calling ShowAd. When there is no ad available, ShowAd does nothing and no event is raised.
  • Do not block the game waiting for an event. Pause the game only when ShowAd has actually been called, and resume it in both OnDismissed and OnFailedToShow.
  • Grant the reward in OnCompleted, and only when reward.success is true. Do not grant it in OnDismissed or OnShown. The amount and label fields may be empty, so define the reward in your game.
// When the ad is created
rewardedAd.OnCompleted += (reward) => { if (reward.success) GrantReward(); };
rewardedAd.OnDismissed += ResumeGame;
rewardedAd.OnFailedToShow += ResumeGame;
// When the user asks for the reward
if (rewardedAd.IsAvailable) {
PauseGame();
rewardedAd.ShowAd();
}
  • Create the banner once and call LoadAd once. The banner refreshes automatically, and it also retries by itself after a failed load, so do not call LoadAd again from OnFailedToLoad or periodically.
  • Destroy the banner before creating another one. A banner stays on screen, even after a scene change, until Destroy is called. Creating a new one on every scene load stacks several banners that keep requesting ads.
  • Set AutoRefreshTime in milliseconds. The value is limited to the range between 30000 and 120000 (30 to 120 seconds).
  • Load the ad at startup and enable AutoReload, so a new ad is requested when the previous one is closed.
  • Show it when the user comes back to the app, by calling TryToShowAd from OnApplicationPause. This method shows the ad when it is available, and requests a new one otherwise.
  • Do not show it right after another ad. On Android, OnApplicationPause is also called when a fullscreen ad is closed, so skip the App Open ad in that case:
bool returningFromAd;
void ShowInterstitial() {
if (!interstitialAd.IsAvailable) {
return;
}
#if UNITY_ANDROID
returningFromAd = true;
#endif
interstitialAd.ShowAd();
}
void OnApplicationPause(bool paused) {
if (paused) {
return;
}
if (returningFromAd) {
returningFromAd = false;
return;
}
appOpenAd?.TryToShowAd();
}
  • Call Destroy on the ads you no longer need, in the OnDestroy method of the object that created them. This applies to banners and to interstitial, rewarded and App Open ads.
  • Unsubscribe your handlers. WortiseSdk.OnInitialized is a static event, so remove the handlers that belong to objects that are going to be destroyed. Otherwise, they will be called on a destroyed object.
void OnDestroy() {
WortiseSdk.OnInitialized -= OnSdkInitialized;
bannerAd?.Destroy();
interstitialAd?.Destroy();
}
  • Test on a device. The SDK does not work in the Unity Editor: the calls are ignored and no event is raised.
  • Use test ads during development. Enable the test mode or use the test ad units, and do not click on real ads in your own app.
  • Disable the test mode in the builds you publish. For example, enable it only in development builds:
WortiseAdSettings.IsTestEnabled = Debug.isDebugBuild;
  • The Google App IDs are set in Wortise -> Settings. See SDK integration.
  • The app uses your own app key and ad unit IDs, not the test ones.
  • The test mode is disabled.
  • Consent is requested at startup, and the user can change it from your app.
  • The child-directed options are set if your app is directed to children.
  • IsAvailable is checked before every ShowAd, and the game resumes after OnDismissed and OnFailedToShow.
  • Rewards are granted only in OnCompleted when reward.success is true.
  • Banners and fullscreen ads are destroyed when they are no longer needed.
  • The ads have been verified on real Android and iOS devices.