Skip to main content

Add the Ad SDK Dependency

Add the following dependency to your app-level build.gradle file
implementation("com.twinalyze:ads:1+")
📝 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 and 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.
class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        MyApp.init(
            this,
            "YOUR_API_KEY",
            "YOUR_ORG_ID”,
            false
        )
    }
}
ParameterDescription
applicationAndroid application context
apiKeyYour Project API key
orgIdYour organization ID (e.g. twinalyze_demo_7356297484)

Demo Account

Email: [email protected]
Password: 123
✅ Best Practice
Always call initialize() inside your Application class not inside. an Activity to ensure complete session tracking.
class MyApp: Application() {
    override fun onCreate() {
        super.onCreate()
        MyApp.init(
            this,
            "YOUR_API_KEY",
            "YOUR_ORG_ID"
        )
    }
}

Initialize Ads in the Launch Activity

Run initAds() in the launch activity typically SplashActivity/StartActivity/MainActivity Etc
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, StartActivity::class.java)
	      startActivity(intent)
            }
            override fun failedOnAdsInit(error: ErrorType?, msg: String?) {
              val intent = Intent(this, StartActivity::class.java)
	      startActivity(intent)
            }
          })
        } else {
          val intent = Intent(this, StartActivity::class.java)
	  startActivity(intent)
        }
      } catch (e: JSONException) {
        e.printStackTrace()
        val intent = Intent(this, 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, StartActivity::class.java)
	startActivity(intent)
    }
  })
}

Add Ad View in XML

Place Two Ads in One Activity (app:position=“top” & “bottom”)
<com.twinalyze.ads.View.NativeAdView
    android:id="@+id/nativeBottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_10sdp"
    app:position="bottom"     //top or bottom
    android:layout_alignParentBottom="true"
    android:orientation="vertical" />