Reducing ad frequency for engaged players
Adjust ad frequency for specific player groups using Game Overrides and Remote Config.
Read time 3 minutesLast updated 17 hours ago
Scenario
This topic describes how to use a sample game that illustrates:- How to display an ad to a player when their character is eliminated ("dies").
- How to target engaged players.
- How to change the frequency of engaged players they see. (An engaged player is a player who has played every day for the past seven days).
Requirements
- Unity 2019.4 and above
- Unity Ads*
- Authentication
- Remote Config
- Unity Analytics
Instructions
Here's an overview of the steps. Each step is described in more detail below.- Install Authentication, Remote Config, and Analytics.
- Link your game to Analytics in the Unity Editor.
- Set up a Remote Config key with a default value.
- Retrieve values from Remote Config in your game.
- Decide when to show ads.
- Set up an Override to adjust your Remote Config key for an Audience.
Install Analytics, Authentication and Remote Config packages
In the Unity Editor, install the Analytics, Authentication, and Remote Config packages.- In the Unity Editor, open Window > Package Manager.
- In the Package Manager, select the Unity Registry list view.
- Select and install the following packages:
- Analytics (com.unity.services.analytics)
- Authentication (com.unity.services.authentication)
- Remote Config (com.unity.remote-config)
Link your game
In the Unity Editor, select Edit > Project Settings > Services. Choose the relevant project and link it. This will link your project to the Unity Dashboard.Set up a Remote Config key
You can set up a Remote Config key in the Unity Dashboard or in the Editor. In the Unity Dashboard, open Remote Config. To add the config key to change for engaged players:- Select Add Key.
- Enter the Name .
adFrequency - Select the Type .
Integer - Select Next.
- Add an Integer value of 1. This will be the default value for all players.
- Select Submit.
- In the Remote Config overview, select Publish to publish your key and make it available for other services to use.
Setting up your game
Use the following code to fetch theadFrequencyWhen the object loads, it initializes an anonymous user. You now have the config value ofusing Unity.RemoteConfig;using Unity.Services.Authentication;using Unity.Services.Core;using UnityEngine;public class UGS : MonoBehaviour{ public struct userAttributes { } public struct appAttributes { } public int adFrequency = 1; //Default is 1 ad on death async void Start() { await UnityServices.InitializeAsync(); // remote config requires authentication for managing environment information if (!AuthenticationService.Instance.IsSignedIn) { await AuthenticationService.Instance.SignInAnonymouslyAsync(); } ConfigManager.FetchCompleted += ConfigManager_FetchCompleted; ConfigManager.FetchConfigs(new userAttributes(), new appAttributes()); } void ConfigManager_FetchCompleted(ConfigResponse configResponse) { switch (configResponse.requestOrigin) { case ConfigOrigin.Default: Debug.Log("Default values will be returned"); break; case ConfigOrigin.Cached: Debug.Log("Cached values loaded"); break; case ConfigOrigin.Remote: Debug.Log("Remote Values loaded"); adFrequency = ConfigManager.appConfig.GetInt("adFrequency"); break; } }}
adFrequencyThe initial setup is complete after following the above steps.countDeath++; if(ugs.adFrequency == countDeath) { countDeath = 0; PlayerPrefs.SetInt("countDeathForAds",countDeath); ads.ShowAd(); }
Setting up an Override
This example explains how to create an Override to target engaged players, loweringadFrequency- Select Create Override.
- Enter a name for your Override then select Next.
-
Select Audiences, select the pre-defined Audience Engaged Players, then select Next.
- Note: To enable Stateful Audiences ensure Unity Analytics is installed.
- Select Choose Content Type, select Config Overrides, and select Done.
- Select adFrequency from the Key Name dropdown, enter a value of 3, and select Next.
- Schedule the Override to run immediately, indefinitely, with a medium priority, and select Finish. You can adjust the priority to manage potential conflicts between Overrides.
- Check your changes and select Enable.