Unity Campaigns SDK

SDK Integration

Here you can find short video instruction.

Installation

Ensure git is installed. In Unity, click `Window > Package Manager. Click the plus + sign and select 'Add package from Git URL' Type in the URL:

Install mix panel first from repository
You don't need to do anything with Mixpanel. Monetizr SDK will handle all setup.

  • Get your Monetizr SDK here and copy /Assets/MonetizrCampaigns/ folder into your Assets. Also another option is to create symlink to /Assets/MonetizrCampaigns/ SDK to your assets folder. For example, on Mac using ln command in the console:
ln -s [full path to Campaigns SDK]/The-Monetizr-Campaigns-Unity-SDK/Assets/MonetizrCampaigns
[full path to your project]/Assets/MonetizrCampaigns

You can find sample scene here:

The-Monetizr-Campaigns-Unity-SDK/Assets/Sample/Scenes

Important note for Unity 2020..

We're using System.IO.Compression.FileSystem in our SDK, but by default it doesn't included. So before you start, please create csc.rsp file in the root of the Assets folder with this line:

-r:System.IO.Compression.FileSystem.dll

SDK Initialization

SDK initialization. MonetizrManager.Initialize method must be called before using MonetizrManager. It starts preloading assets in the background and call onRequestComplete when it will be completed. soundSwitch method should be assigned to turn off in game sounds during the ads. Also you should define ONLY one mission with the reward.

List<MissionDescription> missions = new List<MissionDescription>()
{
    new MissionDescription(20, RewardType.Coins),
};

MonetizrManager.Initialize(string apiKey, List<MissionDescription> missions, Action<bool> onRequestComplete, Action<bool> soundSwitch, UserDefinedEvent userEvent = null);

You can define userEvent delegate to track impressions and button clicks inside the SDK.

Additional setup

After initialization it makes sense to setup teaser screen position on the screen with MonetizrManager.SetTeaserPosition. But if teaser position defined from server side - calling SetTeaserPosition will not change actual position.

MonetizrManager.SetTeaserPosition(new Vector2(-230, -765));

Connect in-game coins with Monetizr SDK by calling MonetizrManager.SetGameCoinAsset:

MonetizrManager.SetGameCoinAsset(RewardType.Coins,defaultRewardIcon, "Coins", () =>
{
  //should be defined by developer
    return GameController.I.GetCoinsTotal();
},
(int reward) =>
{   
  //should be defined by developer
    GameController.I.AddCoinsTotal(reward);
});

Main menu banner visibility

Preferable and easiest way how to change banner visibility is to add TeaserHelper script on Main Menu UI (or other UI element that will be visible among with the banner) object root and functions mentioned above will be called automatically.

Otherwise use the following methods to show and hide menu banner manually. Banner should be visible in the main menu and should be hidden when other in-game popup appears, e.g. Options, Shop, etc. Also, it should hidden during the game play.

If you want to hide notifications - duplicate TeaserHelper script and call OnMainMenuShow method with false parameter

MonetizrManager.OnMainMenuShow(bool showNotifications = true);

MonetizrManager.OnMainMenuHide();

Show campaign notifications manually

If you would like show active campaign notification manually feel free to call the following method:

public static void ShowCampaignNotificationAndEngage(OnComplete onComplete = null)

if there's no campaigns either player closed notification or if player do not complete task OnComplete will be called with parameter OnCompleteStatus.Skipped, otherwise OnComplete called with parameter OnCompleteStatus.Completed

Adding engaged user action

The following method helps to show Monetizr offer instead of RV ads. Complete status is basically the same, as in the ShowCampaignNotificationAndEngage method. Also, it's possible to remotely config amount of times per session we're showing campaign offer.

public static void EngagedUserAction(OnComplete onComplete)
  
//use sample to show reward center
MonetizrManager.EngagedUserAction((MonetizrManager.OnCompleteStatus status) =>
{
  //Player closed offer or there's no active campaigns
    if (status == MonetizrManager.OnCompleteStatus.Skipped)
    {
        Debug.Log("Try to show regular ads");

    //show interstitials
        if(IsAdVideoAvailable())
            PlayAdVideo();
    }
});

Here's the sample how to show notifications instead of ad videos:

//use sample to show reward center
MonetizrManager.ShowCampaignNotificationAndEngage((MonetizrManager.OnCompleteStatus status) =>
{
  //Player closed offer or there's no active campaigns
    if (status == MonetizrManager.OnCompleteStatus.Skipped)
    {
        Debug.Log("Try to show regular ads");

    //show interstitials
        if(IsAdVideoAvailable())
            PlayAdVideo();
    }
});

Problems

  • If teaser isn't clickable - check if you have EventSystem in your scene
  • If teaser doesn't show up - for testing purposes you can clean local data with Monetizr/Clear local data in the top menu
  • If cleaning local data doesn't help, please request Monetizr team to clean server claim data

Did this page help you?