# Initialization

Integrating the TyrAds offerwall functionality into your application is a straightforward process that involves a few key steps. By following these integration steps, you can seamlessly incorporate the offerwall feature, enhancing user engagement and potentially generating additional revenue for your application.

{% hint style="success" %}

### SDK Initialization best practices:

* **Initiate early:** It's advisable to initialize the SDK promptly after your app launches to ensure that all Tyr SDK functionalities are accessible when needed.
* **Initiate authentication:** Login to the SDK with current user details immediately after your user signs up or signs in to the app to set the `userId`.
  {% endhint %}

For guidance on integrating TyrSDK - including proper initialization and offer display - see the example at `Sample -> Demo`:

### 1. Scene setup

Add the **TyrSDKPlugin** prefab to your initial scene:

```
Packages/com.tyrads.unity-sdk/Runtime/Prefabs/TyrSDKPlugin.prefab
```

This enables API access via SDKPlugin.Instance in code.

### 2. **Initialization**

This step initializes the Tyrads SDK within your application. You need to provide the API key and API secret obtained from the Tyrads platform. This allows your app to communicate securely with Tyrads' servers.

#### a. Adding Credentials via the Editor&#x20;

Once **TyrSDK** is imported, follow these steps to configure it for your project:

* **Open the Configuration Window**
  * Navigate to **TyrSDK > TyrSDK Settings** to access the **TyrSDK Settings** panel.
* **Enter Your Credentials**
  * **API Key:** A **32-character** hexadecimal string.
  * **API Secret:** A **92-character** hexadecimal string.
  * **Encryption Key:** A **32**-**character** hexadecimal string.

<figure><img src="https://347922413-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbqqMYRbr0w4Hv3JxQUF7%2Fuploads%2Fy9vm2HSd0uh5dAyfLcek%2FScreenshot%202025-08-19%20at%2018.16.13.png?alt=media&#x26;token=6b0d470f-ef16-4c60-bf2c-b4e56bee43ff" alt="" width="563"><figcaption></figcaption></figure>

#### b.  Adding Credentials via the Code

Make a call:

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

**before** making a LoginUser call. This ensures that your credentials are properly set before the initialization process begins.

#### Using Different Credentials for Android and iOS&#x20;

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:

```csharp
//default credentials could be used for the editor test run
string apiKey = "DEFAULT_API_KEY";
string apiSecretv = "DEFAULT_API_SECRET";
string encryptionKey = "DEFAULT_ENCRYPTION_KEY";

#if UNITY_ANDROID
  apiKey = "ANDROID_API_KEY";
  apiSecretv = "ANDROID_API_SECRET";
  encryptionKey = "ANDROID_ENCRYPTION_KEY";
#elif UNITY_IOS
  apiKey = "IOS_API_KEY";
  apiSecretv = "IOS_API_SECRET";
  encryptionKey = "IOS_ENCRYPTION_KEY";
#endif

TyrSDKPlugin.Instance.Init(apiKey, apiSecret, encryptionKey);
```

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

```csharp
TyrSDKPlugin.Instance.LoginUser(userId); //userID is optional
```

{% 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.**&#x20;
  {% endhint %}

To receive the initialization completion result, subscribe to the event before calling LoginUser:

```csharp
TyrSDKPlugin.Instance.InitializationCompleted += OnSdkInitializationCompleted;

...

private void OnSdkInitializationCompleted(bool isSuccess)
{
    // your code here
}
```

If you don’t set a user ID in LoginUser, 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>

#### 3.1 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><code><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
);

TyrSDKPlugin.Instance.LoginUser(userId, userInfo, mediaSourceInfo, engagementInfo);
</code></pre>

[sending-media-source-data](https://sdk-doc.tyrads.com/getting-started/advanced-options/sending-media-source-data "mention")

[sending-user-segments-user-info](https://sdk-doc.tyrads.com/getting-started/advanced-options/sending-user-segments-user-info "mention")

### 4. 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
TyrSDKPlugin.Instance.ShowOffers();
```

#### 4.1 Deeplinking Routes

The Tyrads SDK supports deeplinking to specific sections of the offerwall. When initializing or interacting with the SDK, 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
TyrSDKPlugin.Instance.ShowOffers(TyradsDeepRoutes.Offers);

//Specify a route and campaignID
TyrSDKPlugin.Instance.ShowOffers(TyradsDeepRoutes.Offer, campaignId: 111);
```
