Monetize through video ads in Unity.

Tulenber 11 September, 2020 ⸱ Intermediate ⸱ 6 min ⸱ 2020.1.5f1 ⸱

Even the most altruistic game developer sometimes wants to eat, and our new cycle about monetization can help him solve this issue.

We will open it with an article about one of the most popular options for generating income for free to play games, particularly displaying video ads.

Monetization

If you look at the opportunities for monetizing your game, then there are several main approaches:

  • Pay to play - take money for installing your game
  • In-app purchases - ask for money for additional services in the form of in-game purchases
  • In-app Ads - show ads
  • Bonus type - collect user data and sell it to someone for some money, then get a public lawsuit for violation of privacy, report to senators in the US Congress, etc. according to the worked-out scheme, but save this schema till the moment when your audience hit one billion of peoples =)

The essence of the advertising model

The scheme is quite well-known and simple, you display an ad (video or banner) in the application, and the ad network that provided it pays you a little money for views and a little more if the ad has reached the goal and the client has followed it. Essentially, this is no different from advertising on the Internet. To understand the amount of income, you will earn about a couple of dollars from a thousand impressions(the result is taken by analogy with advertising on sites and reflects only the order; this blog is not about marketing).

Ad networks

There are quite a few advertising providers, and the integration of any of them will be about the same process: setting up an account and a project in an advertising network, embedding an SDK into the current project, embedding ads into game logic.

Suppose this is your first project, or you just haven’t thought about this model, the most obvious candidate of all the networks, of course, will be the Unity Ads Network; I don’t presume to judge the real results that you can get with these ad networks, but what better way to showcase ad embedding than native experience? =)

Project setup

To use ads, you need:

  • Connect to Unity Services - I will not go into the details of this process, especially since it may become outdated with the release of the next engine version, but I will give a link to the official documentation (do not forget to choose the version of the engine you are interested in), which is supported by Unity developers itself (after all, they earn money from this)
  • Add integration package with Unity Ads - this part also may change over time, so I'll provide an official link too
  • Enable Unity Ads integration in the project. It is worth noting that it may not turn on the first time, and you will need to click on the switch again, be careful and check that everything is turned on
    Enable ads
  • Create a class for working with ads - last time I use a singleton to set up an ad manager

You can read more about singletons in our previous article.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using UnityEngine;
using UnityEngine.Advertisements;
using Utils;

namespace Managers
{
    public class KhtAdManager : KhtSingleton<KhtAdManager>, IUnityAdsListener
    {
        // Processing the end of the display of advertising through events
        public static event Action finishAd = delegate {  };

        // Game Id in Unity services
        private static string _gameId = "";
        // There are three types of ads; rewardedVideo is one of the standards and does not allow you to skip ads
        // More information on other types of advertising can be found in the documentation
        private static string myPlacementId = "rewardedVideo";

        // Used to determine the ability to display ads
        private static bool _isAdAvailable = false;
        public static bool IsAdAvailable => _isAdAvailable;

        // Start is called before the first frame update
        void Start()
        {
            // Singleton setup
            DontDestroyOnLoad(gameObject);
            // Configuring ad serving
            Advertisement.AddListener (this);
            Advertisement.Initialize (_gameId);
        }

        // Display ad
        public static void ShowAd()
        {
            if (ReferenceEquals(Instance, null))
            {
                return;
            }
            
            Advertisement.Show (myPlacementId);
        }

        // Ad load completion handler
        public void OnUnityAdsReady(string placementId)
        {
            Debug.Log("OnUnityAdsReady: " + placementId);

            _isAdAvailable = true;
        }

        public void OnUnityAdsDidError(string message)
        {
            Debug.Log("OnUnityAdsDidError: " + message);
        }

        public void OnUnityAdsDidStart(string placementId)
        {
            Debug.Log("OnUnityAdsDidStart: " + placementId);
        }

        // Handling ad display completion
        public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
        {
            // Define conditional logic for each ad completion status:
            if (showResult == ShowResult.Finished) {
                // Reward the user for watching the ad to completion.
            } else if (showResult == ShowResult.Skipped) {
                // Do not reward the user for skipping the ad.
            } else if (showResult == ShowResult.Failed) {
                Debug.LogWarning ("The ad did not finish due to an error.");
            }

            finishAd();
        }

        private new void OnDestroy()
        {
            Advertisement.RemoveListener(this);
            base.OnDestroy();
        }
    }
}

Test usage

Naturally, during development and testing, you cannot show commercials. Take this very seriously; otherwise, the ad network will ban you. Several options can enable test mode for you:

  • Pass parameter on initialization Advertisement.Initialize(string gameId, bool testMode)
  • Enable forced test mode on the project page in the Unity Dashboard with Override client test mode - Force test mode ON (i.e. use test ads) for all devices
    TestMode
  • Enable test mode in the project services settings (works only in the editor)
    Enable ads

Apple iOs 14

With the release of the 14th version of iOs, user interaction rules with advertising messages are changing. If you are developing a game for this platform, then you will need an additional configuration. To resolve this issue, Unity has also prepared a list of necessary steps.

Underwater rocks

I want to note a few points that I periodically meet in other projects:

  • Don't forget to mute your game music/sounds while showing ads; otherwise, you will get sound chaos
  • Ads do not load instantly, so if you are making yet another idle game, then you should pay additional attention to the availability of ads right after game loading and somehow interact with the user to whom you offer to double afk bonus for watching the video
  • There is also a possibility that the player does not have the Internet at all (for example, he plays on an airplane), so it is necessary to handle this situation, at least show a message about the absence of available advertising

Conclusion

As always, the integration of advertising from Unity itself is not a difficult task if you follow the steps described in their documentation. If you want to use any third-party advertising providers, they usually support their documentation even better. As a result, the availability and effectiveness of this monetization method make it one of the main engines of free to play applications, which cannot but frustrate me as a player. You can still show respect for loyal users and insert an internal purchase into your game that will disable ads displaying. And we will look at how to do this in our next article, dedicated to in-game purchases, in the series about series on monetization. See you next time! =)



Privacy policyCookie policyTerms of service
Tulenber 2020