deltaDNA Tutorial on using Engage and Smart Ads to personalize ad rewards and frequency
C# Objective-C Objective-C++
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.vs/tutorial-smartads-personalization/v15/sqlite3
Assets
Images
ProjectSettings
.gitattributes
.gitignore
README.md

README.md

tutorial-smartads-personalization

This tutorial shows how to use Engage with deltaDNA Ads to personalize Ads at different points in your game. This is a Unity tutorial that has been built and tested on Android using deltaDNA Unity SDK v4.8.1.

screenshot

Two Engage campaigns have been created on the DEV environment of Demo Account > Tutorial :: SmartAds Personalization campaigns

Both campaigns target “All Players” but could easily have used player segmentation to present different Ad options to different player segments. They personalize Ads by passing some predefined parameters, that the SDK knows how to react to, from Engage.

The predefined parameters are:

  • ddnaAdRewardType - The type of reward (GOLD, SILVER, GEMS etc..)
  • ddnaAdRewardAmount - The amount of the reward as an integer
  • ddnaAdSessionCount - The maximum number of times this ad point should be rewarded each session
  • ddnaAdDailyCount - The maximum number of times this ad point should be rewarded each day
  • ddnaAdShowWaitSecs - The number of seconds delay between ads on a specific ad point. If these parameters are not already present in your game schema you will need to add them using the setup > Game Parameters tool

Don't worry about using the parameters though, the Smart Ads campaign action UI provides a mechanism for populating them.

Campaign #1

The first campaign is configured to gift the player 500 GOLD each time they watch an ad, to ensure the number of ads per day or per sessions isn't constrained they have been set to very high values.

Controlling the reward type and amount is achieved by creating an game parameter actions in the Engage -> In Game -> Actions tool.

campaign action 1

The action is then attached to a campaign that is called from the game when it is launched and registers for ads.

campaign steps

Implementing this on the client is straightforward. An Engage Rewarded Ad request is created when the game has successfully registered for Rewarded Ads. The request is made to the decision point specified in the campaign that will control the ad, in this case we have defined that as showAdPoint1. The campaign response contains the parameters that will control the reward type and amount that were configured in the Rewarded Ad action attached to the campaign.

The Rewarded Ad request is also used to hook up the callbacks that will fire when an Ad is loaded, opened, closed etc..

        // Setup Rewarded Ad notifications (NB: We have NOT registered for Interstitials in this demo)
        SmartAds.Instance.OnDidRegisterForRewardedAds += () => {
            Debug.Log("Registered for rewarded ads.");

            DDNA.Instance.EngageFactory.RequestRewardedAd(
                "showAdPoint1",
                (action => {
                    rewardedAd1 = action;
                    rewardedAd1.OnRewardedAdLoaded += OnRewardedAdLoaded;
                    rewardedAd1.OnRewardedAdExpired += OnRewardedAdExpired;
                    rewardedAd1.OnRewardedAdOpened += OnRewardedAdOpened;
                    rewardedAd1.OnRewardedAdFailedToOpen += OnRewardedAdFailedToOpen;
                    rewardedAd1.OnRewardedAdClosed += OnRewardedAdClosed;

                    BttnAdPoint1.GetComponentInChildren<Text>().text = string.Format("Reward : {0} {1}", rewardedAd1.RewardType, rewardedAd1.RewardAmount);
                    BttnAdPoint1.interactable = false;
                    txtAd1SessionLimit.text = "";

                }));
.
.
.

We can then use the csharp OnRewardedAdLoaded callback to control the visibility of a rewarded ad button.

    private void OnRewardedAdLoaded(RewardedAd ad)
    {
        if (ad == rewardedAd1 && ad.IsReady())
        {
            BttnAdPoint1.interactable = true;       
            Debug.Log("Rewarded Ad #1 Loaded");
        }
        else if (ad == rewardedAd2 && ad.IsReady())
        {
            BttnAdPoint2.interactable = true;            
            Debug.Log("Rewarded Ad #2 Loaded");
        }
    }

then show the ad when the button is clicked.

    public void BttnAdPoint1_Click()
    {

        if (rewardedAd1 != null && rewardedAd1.IsReady())
        {
            rewardedAd1.Show();
        }
        else
        {
            Debug.Log("Rewarded Ad not ready");
        }
    }

And finally reward the player if they watch the ad then close it.

    private void OnRewardedAdClosed(RewardedAd ad, bool completed)
    {
        Debug.Log("Rewarded Ad closed its ad with reward: " + (completed ? "YES" : "NO"));

        if (completed)
        {
            RewardPlayer(ad.RewardType, ad.RewardAmount);           
        }
    }

    // This is where we give the player their reward
    private void RewardPlayer(string rewardType, long rewardAmount)
    {
        if (!string.IsNullOrEmpty(rewardType) && rewardAmount > 0)
        {
            Debug.Log(string.Format("Player Rewarded {0} x {1}", rewardType, rewardAmount));

            // Record an event here so we can see who is getting rewarded and the reward they are collecting.
            // we will get automated adRequest, adShow and adClosed events in the data but they don't contain 
            // reward type and amount values, so lets do that ourselves.
            var gameEvent = new GameEvent("adRewardCollected")
                .AddParam("virtualCurrencyName", rewardType)
                .AddParam("virtualCurrencyType", "GRIND")
                .AddParam("virtualCurrencyAmount", rewardAmount);

            DDNA.Instance.RecordEvent(gameEvent);
        }
    }

Campaign #2

This campaign works in just the same way, but has been setup as an AB Test. It will use two different Actions (sets of game parameters) to present different ad configuration to the player depending what variant group they fall in to. The player will be assigned to a variant group the first time they are selected by the campaign and will remain in that group on all subsequent sessions.

campaign action 2B campaign action 2C

Campaigns are controlled from the Engage > In Game > Campaigns screen. You can view basic participation data from within a campaign and each campaign will also generate events that can be used to drive detailed reporting. Each time a request is made to Engage, to retrieve the ad configuration for the player, an engageResponse event will be also be generated so you can see what configuration or variant any player falls in to.

Each ad will also generate its own adRequest, adShown and adClosed events

So you can build detailed reports on any Rewarded Ad experiments. Ad AB Test report