Version 4.0.0-beta

Installation

The TyrAds Unity SDK available from a Git URL. To install:

  1. Open the Package Manager window in Unity, if it’s not already open.

  2. Open the Add (+) menu in the Package Manager’s toolbar.

  3. Select Install package from git URL from the install menu.

  4. Enter a Git URL in the text box: https://github.com/tyrads-com/tyrads-unity-sdk-package.git#v4.0.0-pre.1

  5. Select `Install`.

To explore how to use the TyrAds Unity SDK, import the Demo example from the package’s Samples section in the Unity Package Manager. To run a Demo scene, please add at least one session configuation with one of the id: Coin, Diamond or Crystal.

Initialization

To initializes the TyrAds Unity SDK you must provide the necessary credentials obtained from the TyrAds platform. These credentials allow your application to establish secure communication with the TyrAds' backend services.

a. Adding Credentials via the Editor

After importing the SDK, follow these steps to configure it in your project:

  • Open the Configuration Window

    • Navigate to TyrSDK > TyrSDK Settings to access the TyrSDK Settings panel.

  • Manage Session Credentials

    The settings panel allows you to create and configure multiple session entries. Each entry includes:

    • Unique Identifier: A string used to reference this session configuration.

    • API Key: A 32-character hexadecimal string (Mandatory. Provided by TyrAds).

    • API Secret: A 92-character hexadecimal string (Mandatory. Provided by TyrAds).

    • Encryption Key: A 32-character hexadecimal string (Optional. Provided by TyrAds).

You can add or remove session entries using the +/– buttons. All configured sessions will be available to the SDK at runtime.

b. Adding Credentials via the Code

You can initialize credentials programmatically. Two methods are available depending on your needs:

Initialize a Single Session

If your application uses only one session configuration, you can initialize it directly:

TyrSDKPlugin.Instance.Init("API_KEY", "API_SECRET", "ENCRYPTION_KEY");

Initialize Multiple Sessions

For applications that require multiple session configurations, use:

var sessions = new[]
{
    new SessionConfig("session_1","API_KEY_1","API_SECRET_1","ENCRYPTION_KEY_1"),
    new SessionConfig("session_2","API_KEY_2","API_SECRET_2","ENCRYPTION_KEY_2")
};

TyrSDKPlugin.Instance.Init(sessions);

Each SessionConfig entry corresponds to one set of credentials, matching the format used in the editor.

Notes

  • When using multiple sessions, ensure that any operation requiring authentication references the correct unique identifier.

  • If both Editor-configured sessions and code-based initialization are used, programmatic initialization will override editor settings at runtime unless documented otherwise.

  • Make a Init call before making a LoginUser call to ensure that your credentials are properly set before the initialization process begins.

Using Different Credentials for Android and iOS

In some projects, you may need to initialize the SDK with different credentials per platform (e.g., separate API keys for iOS and Android).

Editor-based configuration does not support platform-specific credentials, this type of configuration cannot be handled through the Settings Editor window.

To support platform-specific credentials, you must use the code-based initialization approach.

On the developer side, the application should detect the active platform at runtime and provide the correct credentials accordingly.

Below is a simple example demonstrating how to configure this:

#if UNITY_ANDROID
var config = new SessionConfig(
    uniqIdentifier: "coin",
    apiKey: "ANDROID_API_KEY",
    apiSecret: "ANDROID_API_SECRET",
    encryptionKey: "ANDROID_ENCRYPTION_KEY"
);
#elif UNITY_IOS
var config = new SessionConfig(
    uniqIdentifier: "coin",
    apiKey: "IOS_API_KEY",
    apiSecret: "IOS_API_SECRET",
    encryptionKey: "IOS_ENCRYPTION_KEY"
);
#else
//default credentials could be used for the editor test run
var config = new SessionConfig(
    uniqIdentifier: "coin",
    apiKey: "DEFAULT_API_KEY",
    apiSecret: "DEFAULT_API_SECRET",
    encryptionKey: "DEFAULT_ENCRYPTION_KEY"
);
#endif

TyrSDKPlugin.Instance.Init(new[] { config });

Configure SDK Initialization Wizard

By default TyrAds SDK before open any offers page show initialization wizard, where user could read and accept TyrAds Privacy Policy, give acess to usege stats permit (only on Android) and provide information about age and gender. You able to disable presentation of the privacy policy and usege stats permit pages.

To do that follow next steps:

  • Navigate to TyrSDK > TyrSDK Settings to access the TyrSDK Settings panel.

  • Switch to Settings tab.

  • Switch toggles for 'Show Privacy Policy Page' and 'Show Usage Stats Permit Page'.

User Login

Upon initializing the SDK, the mandatory step is to log in the user. However, passing a user ID is optional and is only necessary when the publisher operates its own user system. This login process ensures that user interactions with the offerwall are accurately tracked and attributed within the application.

To determine when initialization has completed and to identify which session ID was used, you can await the login operation and read the relevant data from the returned LoginResult:

LoginData loginData = new LoginData(userId);
LoginResult result = await TyrSDKPlugin.Instance.LoginUserAsync(loginData);

if (result.IsSuccessful)
{
   //do anything what you want after successful init...
   //a list of id for successfully initialized session could be get from result.InitializedSessions 
}

You can retrieve the generated user ID after successful initialization by calling the following method:

var userId = TyrSDKPlugin.Instance.GetUserId();

Advanced Practices for personalized rewards

To maximize the value of our Tyr SDK please follow the advanced options for user login. This will allow us to personalize the rewards for the user event further and maximize the earnings for you as publisher.

var userInfo = new TyradsUserInfo(
    userPhoneNumber: "+1234567890",
    userEmail: "[email protected]",
    userGroup: "premium_users"
);

var mediaSourceInfo = new TyradsMediaSourceInfo(
    mediaSourceName: "Facebook", //mandatory
    mediaCampaignName: "Summer Sale Campaign",
    mediaSourceId: "fb_123",
    mediaSubSourceId: "fb_sub_456",
    incentivized: true,
    mediaAdsetName: "Summer Sale Adset",
    mediaAdsetId: "adset_789",
    mediaCreativeName: "Summer Sale Creative",
    mediaCreativeId: "creative_101",
    sub1: "campaign_source",
    sub2: "ad_group",
    sub3: "creative_type",
    sub4: "placement",
    sub5: "custom_param"
);

var engagementInfo = new TyradsEngagementInfo(
    engagementId: 12345  // Optional: Unique identifier for tracking user engagement
);

LoginData loginData = new LoginData(userId, userInfo, mediaSourceInfo, engagementInfo);
LoginResult result = await TyrSDKPlugin.Instance.LoginUserAsync(loginData);

Show Offerwall

Once the SDK is initialized and the user is logged in (if applicable), you can display the offerwall to the user. This typically involves calling a function provided by the Tyrads SDK, such as showOffers, passing in the context of your application. The offerwall is where users can engage with various offers, advertisements, or promotions provided by Tyrads, potentially earning rewards or incentives in the process.

// Note: Campaigns Page is the default route when no specific route is provided
TyrSDKPlugin.Instance.ShowOffers();

If you want to display offers for a specific session, you must provide its identifier in the OffersRoutingData parameter.

OffersRoutingData offersRoutingData = new OffersRoutingData("session_2"); 
TyrSDKPlugin.Instance.ShowOffers(offersRoutingData);

Also, you can specify a route to open a particular page. For campaign-specific routes, you'll need to provide the campaignID as well. Available routes and their usage:

  • TyradsDeepRoutes.Offers - opens the Campaigns Page

  • TyradsDeepRoutes.ActiveOffers - opens the Activated Campaigns Page

  • TyradsDeepRoutes.Offer - opens the Campaign Details Page (requires campaignID)

  • TyradsDeepRoutes.Support - opens the Campaign Tickets Page (requires campaignID)

//Use TyradsDeepRoutes class to avoid typos
OffersRoutingData offersRoutingData = new OffersRoutingData("session_2", TyradsDeepRoutes.Offers); 
TyrSDKPlugin.Instance.ShowOffers(offersRoutingData);

//Specify a route and campaignID
OffersRoutingData offersRoutingData = new OffersRoutingData("session_2", TyradsDeepRoutes.Offer, 111); 
TyrSDKPlugin.Instance.ShowOffers(offersRoutingData);

//If you use only one session, you can set empty string for sessionID
OffersRoutingData offersRoutingData = new OffersRoutingData(string.Empty, TyradsDeepRoutes.ActiveOffers); 
TyrSDKPlugin.Instance.ShowOffers(offersRoutingData);

Premium Widget

The Premium Widget displays offers based on the active session. To change the active session, call:

TyrSDKPlugin.Instance.SwitchToSession("session_2");

Last updated