> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paraminternationalltd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ad SDK Initialization

> Set up the Ad SDK by adding the dependency and initializing it in your Application class to start capturing ad-related insights.

#### Add the Ad SDK Dependency

Add the following dependency to your app-level `build.gradle` file.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  implementation("com.twinalyze:ads:1+")
  ```

  ```groovy Java theme={null}
  implementation 'com.twinalyze:ads:1+'
  ```
</CodeGroup>

> 📝 **Note:**\
> If you're using the **Ad Analytics SDK**, you **do not need to add the Analytics SDK dependency separately**. The Ad SDK already includes all analytics features, events, and insights. However, you **must initialize the SDK** in your `Application` class.

#### Initializing Analytics SDK in Android

Initialize the **SDK** in your `Application` class to start tracking sessions, events, and insights.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  class MyApp : Application() {
      override fun onCreate() {
          super.onCreate()

          MyApp.init(
              this,
              "YOUR_API_KEY",
              "YOUR_ORG_ID",
              false
          )
      }
  }
  ```

  ```java Java theme={null}
  public class MyApp extends Application {
      @Override
      public void onCreate() {
          super.onCreate();

          MyApp.init(
              this,
              "YOUR_API_KEY",
              "YOUR_ORG_ID",
              false
          );
      }
  }
  ```
</CodeGroup>

<div className="twinalyze-event-data-types not-prose">
  <details className="twinalyze-event-accordion" open>
    <summary>
      <span>Parameter Reference</span>

      <svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
        <path d="m6 9 6 6 6-6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
      </svg>
    </summary>

    <div className="twinalyze-event-table-wrapper">
      <table className="twinalyze-event-table twinalyze-parameter-table">
        <thead>
          <tr>
            <th>Parameter</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td>
              <code>application</code>
            </td>

            <td>Android application context</td>
          </tr>

          <tr>
            <td>
              <code>apiKey</code>
            </td>

            <td>Your Project API key</td>
          </tr>

          <tr>
            <td>
              <code>orgId</code>
            </td>

            <td>
              Your organization ID, for example{" "}
              <code>twinalyze\_demo\_7356297484</code>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </details>
</div>

<div className="twinalyze-sdk-demo not-prose">
  <div className="twinalyze-sdk-demo-card">
    <div className="twinalyze-sdk-demo-key">
      <svg width="28" height="28" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
        <path d="M15.5 3.5a5 5 0 0 0-4.72 6.65L3 17.93V21h3.07l1.5-1.5H10V17h2.5l1.35-1.35A5 5 0 1 0 15.5 3.5Z" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />

        <circle cx="16.5" cy="8.5" r="1" fill="currentColor" />
      </svg>
    </div>

    <div className="twinalyze-sdk-demo-title">
      Demo Account
    </div>

    <div className="twinalyze-sdk-demo-detail">
      <span>Email:</span>

      <a href="mailto:info@twinalyze.com">
        [info@twinalyze.com](mailto:info@twinalyze.com)
      </a>
    </div>

    <div className="twinalyze-sdk-demo-detail">
      <span>Password:</span>
      <span>123</span>
    </div>
  </div>

  <div className="twinalyze-sdk-demo-links">
    <a href="https://github.com/twinalyze/twinalyze-ads-android-ott-app-demo" target="_blank" rel="noreferrer" className="twinalyze-sdk-demo-link">
      <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
        <path d="M12 2C6.48 2 2 6.48 2 12c0 4.42 2.87 8.17 6.84 9.49.5.09.68-.22.68-.48 0-.24-.01-1.03-.01-1.87-2.78.6-3.37-1.18-3.37-1.18-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.35 1.09 2.92.83.09-.65.35-1.09.64-1.34-2.22-.25-4.56-1.11-4.56-4.97 0-1.1.39-1.99 1.03-2.7-.1-.25-.45-1.27.1-2.66 0 0 .84-.27 2.75 1.03A9.55 9.55 0 0 1 12 6.84c.85 0 1.7.11 2.5.33 1.91-1.3 2.75-1.03 2.75-1.03.55 1.39.2 2.41.1 2.66.64.71 1.03 1.6 1.03 2.7 0 3.87-2.34 4.71-4.57 4.96.36.31.68.93.68 1.88 0 1.36-.01 2.47-.01 2.81 0 .27.18.58.69.48A10 10 0 0 0 22 12C22 6.48 17.52 2 12 2Z" />
      </svg>

      <span>Github Demo</span>
    </a>

    <span className="twinalyze-sdk-demo-divider" />

    <a href="https://drive.google.com/drive/folders/1bctCmWwYCndBdOGcSySJTsrYOGF7U-Ag" target="_blank" rel="noreferrer" className="twinalyze-sdk-demo-link">
      <svg width="23" height="23" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" className="twinalyze-sdk-android-icon">
        <path d="M7.2 6.35 5.9 4.1a.5.5 0 1 1 .87-.5l1.32 2.28A8.55 8.55 0 0 1 12 5c1.4 0 2.73.32 3.91.88l1.32-2.28a.5.5 0 1 1 .87.5l-1.3 2.25A7.51 7.51 0 0 1 20 12H4a7.51 7.51 0 0 1 3.2-5.65ZM8 9.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2Zm8 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM4 13h16v6.5A1.5 1.5 0 0 1 18.5 21H17v-5.5a.5.5 0 0 0-1 0V21H8v-5.5a.5.5 0 0 0-1 0V21H5.5A1.5 1.5 0 0 1 4 19.5V13Z" />
      </svg>

      <span>Download APK</span>
    </a>

    <span className="twinalyze-sdk-demo-divider" />

    <a href="https://app.twinalyze.com/" target="_blank" rel="noreferrer" className="twinalyze-sdk-demo-link">
      <svg width="23" height="23" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
        <rect x="3" y="15" width="4" height="6" rx="1" fill="#2563EB" />

        <rect x="10" y="9" width="4" height="12" rx="1" fill="#3B82F6" />

        <rect x="17" y="3" width="4" height="18" rx="1" fill="#60A5FA" />
      </svg>

      <span>Demo</span>
    </a>
  </div>

  <div className="twinalyze-sdk-best-practice">
    <div className="twinalyze-sdk-best-practice-title">
      <span className="twinalyze-sdk-check-icon">
        ✓
      </span>

      <span>Best Practice</span>
    </div>

    <p>
      Always call <code>initialize()</code> inside your{" "}
      <code>Application</code> class — not inside an Activity — to ensure
      complete session tracking.
    </p>
  </div>
</div>

<CodeGroup>
  ```kotlin Kotlin theme={null}
  class MyApp : Application() {
      override fun onCreate() {
          super.onCreate()

          MyApp.init(
              this,
              "YOUR_API_KEY",
              "YOUR_ORG_ID"
          )
      }
  }
  ```

  ```java Java theme={null}
  public class MyApp extends Application {
      @Override
      public void onCreate() {
          super.onCreate();

          MyApp.Companion.init(
              this,
              "YOUR_API_KEY",
              "YOUR_ORG_ID"
          );
      }
  }
  ```
</CodeGroup>

***

#### Initialize Ads in the Launch Activity

Run `initAds()` in the launch activity, typically `SplashActivity`, `StartActivity`, or `MainActivity`.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  initAds()

  fun initAds() {
      Ads.init(this, object : AdsInitListner {
          override fun onSuccess() {
              try {
                  val data = JSONObject(AppUtil.GetOtherData())
                  val showAppOpen =
                      data.optBoolean("isShowAppOpenOnSplash", false)

                  if (showAppOpen) {
                      AdsManagerAppOpen.initAd(
                          this@SplashActivity,
                          object : AdsInitListner {
                              override fun onSuccess() {
                                  val intent = Intent(
                                      this@SplashActivity,
                                      StartActivity::class.java
                                  )

                                  startActivity(intent)
                              }

                              override fun failedOnAdsInit(
                                  error: ErrorType?,
                                  msg: String?
                              ) {
                                  val intent = Intent(
                                      this@SplashActivity,
                                      StartActivity::class.java
                                  )

                                  startActivity(intent)
                              }
                          }
                      )
                  } else {
                      val intent = Intent(
                          this@SplashActivity,
                          StartActivity::class.java
                      )

                      startActivity(intent)
                  }
              } catch (e: JSONException) {
                  e.printStackTrace()

                  val intent = Intent(
                      this@SplashActivity,
                      StartActivity::class.java
                  )

                  startActivity(intent)
              }
          }

          override fun failedOnAdsInit(
              error: ErrorType?,
              msg: String?
          ) {
              if (error == ErrorType.NO_INTERNET) {
                  runOnUiThread {
                      Toast.makeText(
                          applicationContext,
                          "checkInternet",
                          Toast.LENGTH_SHORT
                      ).show()
                  }
              }

              val intent = Intent(
                  this@SplashActivity,
                  StartActivity::class.java
              )

              startActivity(intent)
          }
      })
  }
  ```

  ```java Java theme={null}
  private void initAds() {
      Ads.init(this, new AdsInitListner() {
          @Override
          public void onSuccess() {
              try {
                  JSONObject data =
                      new JSONObject(AppUtil.GetOtherData());

                  boolean showAppOpen =
                      data.optBoolean(
                          "isShowAppOpenOnSplash",
                          false
                      );

                  if (showAppOpen) {
                      AdsManagerAppOpen.initAd(
                          SplashActivity.this,
                          new AdsInitListner() {
                              @Override
                              public void onSuccess() {
                                  Intent intent = new Intent(
                                      SplashActivity.this,
                                      StartActivity.class
                                  );

                                  startActivity(intent);
                              }

                              @Override
                              public void failedOnAdsInit(
                                  ErrorType error,
                                  String msg
                              ) {
                                  Intent intent = new Intent(
                                      SplashActivity.this,
                                      StartActivity.class
                                  );

                                  startActivity(intent);
                              }
                          }
                      );
                  } else {
                      Intent intent = new Intent(
                          SplashActivity.this,
                          StartActivity.class
                      );

                      startActivity(intent);
                  }
              } catch (JSONException e) {
                  e.printStackTrace();

                  Intent intent = new Intent(
                      SplashActivity.this,
                      StartActivity.class
                  );

                  startActivity(intent);
              }
          }

          @Override
          public void failedOnAdsInit(
              ErrorType error,
              String msg
          ) {
              if (error == ErrorType.NO_INTERNET) {
                  runOnUiThread(() ->
                      Toast.makeText(
                          getApplicationContext(),
                          "checkInternet",
                          Toast.LENGTH_SHORT
                      ).show()
                  );
              }

              Intent intent = new Intent(
                  SplashActivity.this,
                  StartActivity.class
              );

              startActivity(intent);
          }
      });
  }
  ```
</CodeGroup>

***

#### Add Ad View in XML

Place two ads in one Activity using `app:position="top"` and `app:position="bottom"`.

<CodeGroup>
  ```xml XML theme={null}
  <com.twinalyze.ads.View.NativeAdView
      android:id="@+id/nativeBottom"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="@dimen/_10sdp"
      android:layout_alignParentBottom="true"
      android:orientation="vertical"
      app:position="bottom" />
  ```
</CodeGroup>

***

<div className="twinalyze-bottom-nav">
  <a href="/sdks/app/ad-analytics/ad-sdk-initialization" className="twinalyze-nav-side">
    <span className="twinalyze-nav-arrow">‹</span>
    <span>Previous</span>
  </a>

  <a href="/sdks/javascript/analytics/get-started" className="twinalyze-nav-center">
    <strong>Javascript SDK</strong>
    <span>Start with Javascript SDK.</span>
  </a>

  <a href="/sdks/javascript/analytics/get-started" className="twinalyze-nav-side">
    <span>Next</span>
    <span className="twinalyze-nav-arrow">›</span>
  </a>
</div>
