# 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.2`&#x20;
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.&#x20;

## 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&#x20;

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:&#x20;

  * **Unique Identifier**: A string used to reference this session configuration.&#x20;
  * **API Key**: A 32-character hexadecimal string (Mandatory. Provided by TyrAds).&#x20;
  * **API Secret**: A 92-character hexadecimal string (Mandatory. Provided by TyrAds).&#x20;
  * **Encryption Key**: A 32-character hexadecimal string (Optional. Provided by TyrAds).

<figure><img src="https://347922413-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbqqMYRbr0w4Hv3JxQUF7%2Fuploads%2FSI4W1Cqd8NzlV9vjBm3N%2FScreenshot%202025-11-17%20at%2013.38.12.png?alt=media&#x26;token=fc2ab438-8891-4b41-9c42-a91dde1369f3" alt=""><figcaption></figcaption></figure>

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:

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

**Initialize Multiple Sessions**

For applications that require multiple session configurations, use:

```csharp
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.&#x20;
* If both Editor-configured sessions and code-based initialization are used, programmatic initialization will override editor settings at runtime unless documented otherwise.&#x20;
* 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:

<pre class="language-csharp"><code class="lang-csharp">#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

<strong>TyrSDKPlugin.Instance.Init(new[] { config });
</strong></code></pre>

### 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.&#x20;

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'.

<figure><img src="https://347922413-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbqqMYRbr0w4Hv3JxQUF7%2Fuploads%2FkKlyFhheDLyuKYVzRYuH%2FScreenshot%202025-11-17%20at%2013.38.21.png?alt=media&#x26;token=9a90eccc-5588-43d1-821e-f0ea4a10e1fb" alt=""><figcaption></figcaption></figure>

### 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.

{% hint style="warning" %}

* If you do not provide a user ID, it will be generated automatically and stored in app storage. In that case, uninstalling the app will erase the ID and the user’s progress.
* **Preferred: supply a backend-controlled, stable user ID (or equivalent) so progress persists across reinstalls and device changes.** await TyrSDKPlugin.Instance.LoginUserAsync(userId); /
  {% endhint %}

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**:

```csharp
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:

<pre class="language-csharp"><code class="lang-csharp"><strong>var userId = TyrSDKPlugin.Instance.GetUserId();
</strong></code></pre>

#### Advanced Practices for personalized rewards

{% hint style="warning" %}
To maximize the value to the user sending us more data about the user and where they came from allow us to customize the reward experience. This can be used to provide feedback of quality of users aswell as customize the earnings journey of different segments of users.&#x20;
{% endhint %}

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.&#x20;

<pre class="language-csharp"><code class="lang-csharp"><strong>var userInfo = new TyradsUserInfo(
</strong>    userPhoneNumber: "+1234567890",
    userEmail: "demo@example.com",
    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);
</code></pre>

### 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.

```csharp
// 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.

```csharp
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)

```csharp
//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:

```csharp
TyrSDKPlugin.Instance.SwitchToSession("session_2");
```
