Unity SDK

This page describes how to install the AdGate Media Unity SDK.

Requirements

  • Unity version 2019.1 and up

1. Install SDK

  1. Download the latest Unity Package Release from the GitHub Releases page.

  2. Double-click on the package or drag the package into your Unity scene to import it.

  3. This SDK depends on the following third-party assets, if you have any of the following in your project please do not re-import them.

    1. JsonDotNet

    2. UniWebView

  4. Click import to complete the SDK installation.

  5. Locate the config file located in AdGate/Resources/Config/AdGateConfig.asset. You can turn debug mode on or off depending on your requirements. Debug messages will be completely ignored by the SDK when this is turned off.

2. Using the SDK

To start using the SDK, You need to implement usage of the “AdGate” namespace by adding this above the script:

using AdGate;

Now you can use any of the SDK methods.

Load Offer Wall

AdGateManager.LoadOfferWall(string wallCode, string userId, List<string> subIds = null, Action onOfferWallLoadedSuccess = null, Action<int> onOfferWallLoadingFailed = null);

Parameters:

  • wallCode: a string that corresponds to the ID of your offer wall, which you can retrieve from this page.

  • userId: a string that corresponds to the current user accessing the wall

  • subIds: a list of subids you wish to use. They may be any string up to 255 characters long. The available sub ids are s2, s3, s4, and s5.

  • onOfferWallLoadedSuccess: A C# delegate action that is called as soon as the offer wall loading succeeded. It does not pass any variable back as it assumes anytime you get this callback, the offerwall loading was successful.

  • onOfferWallLoadingFailed: A C# delegate action with an error code variable. If this is ever fired, the error code can tell you more about what has happened. You can get more information about the meaning of the codes here.

Example code:

public string wallCode;
public string userId;
public List<string> subIds = new List<string>();

AdGateManager.LoadOfferWall(wallCode, userId, subIds,
() =>
{
        offerWallStatus.text = "Offers Loaded";
        offerWallLoaded = true;
        showOfferBtn.interactable = true;
},
(code) =>
{
        loadOfferBtn.interactable = true;
        showOfferBtn.interactable = false;
        offerWallStatus.text = "Offer loading failed with errorcode " + code;
});

Show Offer Wall

AdGateManager.ShowOfferWall(Action onOfferWallShown = null, Action onOfferWallClosed = null);

Parameters:

  • onOfferWallShown: A C# delegate that is fired once the offer wall has been displayed to the user

  • onOfferWallClosed: A C# delegate that is fired once the offer wall has been closed by the user

Example code:

AdGateManager.ShowOfferWall(() =>
{
        offerWallStatus.text = "Offer was shown";
},
() =>
{
        showOfferBtn.interactable = false;
        offerWallStatus.text = "No more offers, Please load some more";
});

Get Latest Conversions

AdGateManager.GetConversionDetails(string wallCode, string userId, List<string> subIds = null, Action<ConversionResponse> onConversionDetailsAvailable = null, Action<string, int> onConversionDetailsFailedToLoad = null);

Parameters:

  • wallCode: a string that corresponds to the ID of your offer wall

  • userId: a string that corresponds to the current user accessing the wall

  • subIds: a list of subids you wish to use. They may be any string up to 255 characters long. The available sub ids are s2, s3, s4, and s5.

  • onConversionDetailsAvailable: A C# delegate action that is called as soon as the offer wall loading succeeded. It does not pass any variable back as it assumes anytime you get this callback, the offerwall loading was successful.

  • onOfferWallLoadingFailed: A C# delegate action that is called as soon as conversion details are received from the server. It returns a variable of ConversionResponse type. Here is a sample of the class structure:

public class ConversionResponse : AdGateDefaultResponse
{
    public AdGateConversionData data { get; set; }
}

public class AdGateConversionData
{
    public string tool_id { get; set; }
    public string user_id { get; set; }
    public AdGateConversion[] conversions { get; set; }
}

If this callback is fired, it is assumed that connection to the server was successful. However, the conversions variable can be null or an empty array if there is no conversion available at the moment the server request was made.

  • onConversionDetailsFailedToLoad: A C# delegate action with an error and error code variable. If this is ever fired, the error code can tell you more about what has happened. This would be a standard server error code, while the error message would be any message sent from the server.

Example code:

AdGateManager.GetConversionDetails(wallCode, userId,
subIds, (response) =>
{
     if (response.success)
     {
        conversionBtn.interactable = true;
        conversionDetails.text = response.text;
      }
},
(message, code) =>
{
        conversionDetails.text = "Conversion Details failed with error " + message;
        conversionBtn.interactable = true;
});

Example Project

You can view an example project from the SDK github page. In this project you will find sample code on how to use the SDK.

Updating the SDK

Please follow the same installation guide above but remember to untick AdGate/Resources/Config/AdGateConfig.asset from being imported. Otherwise, your config choice will be lost. Please also remember that if you made prior changes to the SDK code, it will be overwritten by the new code.

Last updated