Unity Campaigns SDK

SDK Integration

Here you can find short video instruction.

Installation

Important note: Please remove any versions of Mixpanel previously installed via Package Manager. The Mixpanel is now added directly into the SDK.

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

Or using mklink command on Windows:

mklink /D [full path to your project]\Assets\MonetizrCampaigns [full path to Campaigns SDK]\The-Monetizr-Campaigns-Unity-SDK\Assets\MonetizrCampaigns

You can find sample scene here:

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

Migrating from SDK 0.0.20 to 1.0.0

While there aren't any significant changes in the integration process, there are still a few adjustments to review:

Using custom gradle templates on Android

If you are utilizing the Custom Main Gradle Template on Unity and encounter a java.lang.NoClassDefFoundError exception when attempting to start a video or access the terms and conditions page from our reward center, please ensure that the following lines are included within the dependencies object:

	implementation(name: 'omsdk-android-1.4.0-release', ext:'aar')
	implementation(name: 'UniWebView', ext:'aar')

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 user behavior inside the Monetizr SDK. The userEvent has 3 arguments:

campaignId is always an active campaign in which the event has been triggered; it usually looks like this "e4585d08-76ea-4dce-ab3c-4a6f6472b8da"

placement is a placement id; in the current version, there are possible ids such as:

  • TinyTeaser - tiny teaser/mini banner on the main screen
  • Html5VideoScreen - video screen
  • NotificationScreen - notification screen, that is usually shown when OnMainMenuShow(true) called
  • EmailEnterScreen - enter email screen
  • CongratsScreen - congrats screen after any completed mission (video, minigame, etc)
  • MiniGameScreen - minigame
  • SurveyScreen - survey
  • HtmlPageScreen - for html page views (rarely used; mainly for terms and conditions screens)
  • RewardsCenterScreen - for main reward center

eventType argument basically shows what kind of event it is - just an impression or tapping on Ok or Skip button.

For example, you want to fire events on any kind of impressions and also on TinyTeaser:

private void userEvent(string campaignId, string placement, MonetizrManager.EventType eventType)
{
    if (eventType == MonetizrManager.EventType.Impression)
    {
        fireAnyImpressionEvent();

        switch (placement)
        {
            case "TinyTeaser": fireTinyTeaserEvent(); break;
            default: break;
        }
     }
}

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
  • Duplicate classes issue between androidx.browser:browser:1.2.0 and 1.4.0.
    If you are experiencing this issue, please follow these steps to fix it:
    • Go to Assets/MonetizrCampaign/Scripts/UniWebView5/UniWebView/Editor/UniWebViewPostBuildProcessor.cs
    • Modify the versions at line 55 and 58 to match the version already present in the project.
    • In MonetizrDependencies.xml, also modify the versions accordingly.