Unity Campaigns SDK

Dashboard Integration

The Monetizr Dashboard requires a registration process in order to acquire an API key for the campaigns. The API Key is used to connect with the campaign API. The campaigns are created for each game separately and added to your account. Campaigns will be included in dashboard in the near future.

SDK Integration

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:
https://github.com/mixpanel/mixpanel-unity.git#master

Then you need to install Monetizr SDK:
https://github.com/themonetizr/monetizr-challenges-unity-demo.git?path=/Assets/Monetizr#master
or
https://github.com/themonetizr/monetizr-challenges-unity-demo.git?path=/Assets/Monetizr#development

Also you would need to setup Mix Panel in the Unity settings. Here's the Mix Panel token: XXXXXXXXX
See more info regarding Mix Panel here: https://developer.mixpanel.com/docs/unity

SDK Initialization

SDK initialization. This 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.

MonetizrManager.Initalize(string apiKey, Action onRequestComplete, Action soundSwitch)

ParameterDescription
apiKeyApi key provided by Monetizr team
onRequestCompleteCallback method that will be called once MonetizrManager is ready to serve. It's not really necessary to track this event, because other SDK methods just do nothing until request complete.
soundSwitchCallback method to turn on/off in-game sounds.
MonetizrManager.Initialize(apiKey, (bool isOK) ⇒ {}, (bool isSoundOn) ⇒ {});

Show startup notification (optional)

During the first game launch you can show notification with the current active campaign.

MonetizrManager.ShowStartupNotification(Action onComplete)

ParameterDescription
onCompleteThis callback method calls when user press OK button in the notification window

Main menu teaser

Use this methods to show and hide menu teaser. Teaser 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.

MonetizrManager.HideTinyMenuTeaser();

MonetizrManager.ShowTinyMenuTeaser(()=> { UpdateGameUI(); MonetizrManager.ShowRewardCenter(); });

Show reward center

Use this method to show reward center within a game. E.g. when player presses Mission button.

MonetizrManager.ShowRewardCenter();

Adding user-defined missions

You can use this method to register internal in-game missions to show them in the reward center. See sample below

MonetizrManager.RegisterUserDefinedMission(string missionTitle, string missionDescription, Sprite missionIcon, Sprite rewardIcon, int reward, float progress, Action onClaimButtonPress)

ParameterDescription
missionTitleMission title
missionDescriptionMission desription
missionIconMission icon sprite
rewardIconReward icon sprite
rewardAmount of reward
progressProgress from 0.0 to 1.0. If progress more or equal than 1.0 Claim button will be shown.
onClaimButtonPressCallback method to track Claim button press when mission is complete
public void UpdateGameUI()
{
    foreach (var m in PlayerData.instance.missions)
    {
        Action onClaimButtonPress = () => { Claim(m); };
        var missionIcon = defaultMissionIcon;
    var rewardIcon = defaultRewardIcon;

    MonetizrManager.AddUserDefinedMission(m.GetMissionType().ToString(), m.GetMissionDesc(), missionIcon, rewardIcon, m.reward, m.progress, onClaimButtonPress);
    }
}

public void Claim(MissionBase m)
{
    PlayerData.instance.ClaimMission(m);

    UpdateGameUI();
}

Registering sponsored missions

Use this method to connect sponsored campaigns and in-game missions

MonetizrManager.RegisterSponsoredMission(int id, Sprite rewardIcon, int rewardAmount, Action onSponsoredClaim)

ParameterDescription
id unique mission id
rewardIconreward icon that will be shown in the Reward Center
rewardAmountnumber that will be shown in the Reward Center
onSponsoredClaimcall back method which will be called when player should receive his in-game reward
public void InitializeSponsoredMissions()
{
    MonetizrManager.RegisterSponsoredMission(1, defaultRewardIcon, 2, OnSponsoredClaim);

    MonetizrManager.RegisterSponsoredMission(2, defaultRewardIcon, 2, OnSponsoredClaim);

    MonetizrManager.RegisterSponsoredMission(3, defaultRewardIcon, 2, OnSponsoredClaim);
}

public void OnSponsoredClaim(int reward)
{
    PlayerData.instance.ClaimSponsoredMission(reward);
}

Obsolete documentation

SDK Integration

Installation

To use Campaigns SDK download the Unity package from GitHub and import monetizr_challenges_unity_sdk_1.0.unitypackage into your project using Assets/Import Package/Custom Package....

Detailed SDK description and source code is available at the repository.

Using

The Campaigns Unity SDK at this moment is a proof-of-concept solution. The campaign SDK utilizes the campaigns API endpoints. The SDK is not a fit-for-everyone as it will likely require customization and minor adjusting for most of the games.

You will need to to create and use one instance of ChallengesClient class and use it to communicate with the Monetizr Campaigns API. You also will need to set the current user's information in ChallengesClient.playerInfo (at least the identifier) to use the SDK. Campaigns list can be retrieved using GetList . Whenever a progress is being made by player, UpdateChallenge has to be called. When the campaign is done, a claim button must be shown in the campaign menu and ClaimChallenge must be called whenever player clicks on the claim.

Reference

Monetizr.Challenges namespace

ChallengesClient class

Constructor(string apiKey, int timeout = 30) – creates an instance of ChallengesClient and sets the API key used by the SDK to apiKey
GetList() – acquires a list of campaigns available to the player
GetSingle(string id) – acquires a single campaign identified by its id
UpdateStatus(Challenge challenge, int progress, Action onSuccess, Action onFailure) – update the player's progress for a specific campaign
ClaimChallenge(Challenge challenge, Action onSuccess, Action onFailure) – has to be invoed when a player clicks the claim button on a completed campaign
playerInfo – used to get and set player's information

AssetsHelper

Download2DAsset(Challenge.Asset asset, Action<Challenge.Asset, Sprite> onAssetDownloaded) – downloads a 2D asset and returns it as a Sprite in onAssetDownloaded callback.

DownloadAssetData(Challenge.Asset asset, Action<Challenge.Asset, byte[]> onAssetDownloaded) – Downloads any type of asset and returns its data as an array of bytes in onAssetDownloadedCallback.

PlayerInfo class

playerId – a unique identifier of the user (mandatory)

Challenge class

id – identification number of the campaign (has to be passed to UpdateChallenge and ClaimChallenge)
title – title of the campaign (has to be visible in the campaign menu).
content – description of the campaign (has to be visible in the campaign menu).
progress – players progress (has to be visible in the campaigns menu).
reward – type of reward when the campaign is completed (created for each game individually according to their requirements and agreement).
assets – a list of assets of the campaign (see Challenge.Asset).

Challenge.Asset class

id – identification number of the asset (can be ignored)
type – type of the asset (icon or banner)
title – name of the asset (can be ignored)
url – the location of the asset