SDK Integration (in English)

SDK Integration (in English)


1.Download and Setup

  • Download the SDK: Obtain the SDK from the provided link.
  • Create a 'libs' Directory: Within your app's directory, create a folder named libs.
  • Add the AAR File: Place the downloaded .aar file into the libs directory.

2. SDK Initialization

Initialize the SDK in your Application class or the onCreate method of your main Activity:

import android.app.Application import android.view.MotionEvent import com.cleartrust.cleartrustadfraudtestingapp.android.ct_fraud_detection_sdk.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class MyApplication : Application() { private lateinit var CTSessionManager: CTSessionManager private lateinit var CTDeviceMovementMonitor: CTDeviceMovementMonitor private lateinit var CTTouchTracker: CTTouchTracker private lateinit var CTApiClient: CTApiClient private lateinit var CTDeviceInfoManager: CTDeviceInfoManager private lateinit var fraudScore: CTFraudScore private lateinit var CTAppUtils: CTAppUtils override fun onCreate() { super.onCreate() CTApiClient = CTApiClient(this) CTAppUtils = CTAppUtils(this) CTDeviceInfoManager = CTDeviceInfoManager(this) CTSessionManager = CTSessionManager(CTApiClient) CTDeviceMovementMonitor = CTDeviceMovementMonitor(application, CTAppUtils, this) CTTouchTracker = CTTouchTracker() val uuid = CTAppUtils.ctGetDeviceInfo().uuid val apiKey = "YOUR_AUTHORIZATION_KEY" fraudScore = CTFraudScore(this, uuid, apiKey, s1="", s2="", s3="", s4="", s5="", s6="") fraudScore.startFraudScoreUpdates() CTAppUtils.ctRequestPermissions(this) val coroutineScope = CoroutineScope(Dispatchers.Main) coroutineScope.launch { fraudScore.ctGetFraudScore() } CTDeviceMovementMonitor.startMonitoring() } override fun onDestroy() { super.onDestroy() CTDeviceMovementMonitor.stopMonitoring() fraudScore.stopFraudScoreUpdates() } override fun dispatchTouchEvent(event: MotionEvent): Boolean { CTTouchTracker.trackTouches(event, this) return super.dispatchTouchEvent(event) } }



3. Setting Your Authorization Key

In the above example, replace the placeholder YOUR_AUTHORIZATION_KEY with your actual authorization key:
val apiKey = "YOUR_AUTHORIZATION_KEY" 

4. Permissions

Add the following permissions to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.BLUETOOTH" />
 

5. Dependencies

Update your build.gradle.kts file with the following dependencies:

dependencies { // Your existing dependencies implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.aar")))) implementation("com.squareup.okhttp3:logging-interceptor:4.10.0") implementation("androidx.lifecycle:lifecycle-process:2.6.2") implementation("com.squareup.retrofit2:retrofit:2.9.0") implementation("com.squareup.retrofit2:converter-gson:2.9.0") implementation("com.squareup.okhttp3:logging-interceptor:4.11.0") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3") implementation("com.squareup.okhttp3:okhttp:4.9.3") implementation("com.google.code.gson:gson:2.8.8") }



6. Fraud Score Retrieval

The fraud score is calculated based on various factors. To retrieve the score from the SDK, use the following function:

val score = fraudScore.ctGetFraudScore()

If the function returns null, default the value to 0.


7. Additional Tracking Parameters

To share additional tracking information with ClearTrust, pass up to six optional parameters (s1 to s6) during the initialization of CTFraudScore:
fraudScore = CTFraudScore(this, uuid, apiKey, s1="value1", s2="value2", s3="value3", s4="value4", s5="value5", s6="value6")

8.Bundle ID and App Name

Pass your application's Bundle ID and App Name to the SDK by setting the s5 and s6 parameters
during the initialization of CTFraudScore.
fraudScore = CTFraudScore( context = this, uuid = uuid, apiKey = apiKey, s1 = "", s2 = "", s3 = "", s4 = "", s5 = "your.bundle.id", // Replace with your actual Bundle ID s6 = "YourAppName" // Replace with your actual App Name )

Ensure you replace "your.bundle.id" and "YourAppName" with your application's actual Bundle ID and App Name

This completes the integration of the ClearTrust Fraud Detection SDK into your Android project.


    • Related Articles

    • SDK Integration (in Mandarin)

      ClearTrust SDK 集成指南 1.下载和设置 下载 SDK:从提供的链接获取 SDK。 创建 'libs' 目录:在您的应用程序目录中创建一个名为 libs 的文件夹。 添加 AAR 文件:将下载的 .aar 文件放入 libs 目录。 2. SDK 初始化 在您的 Application 类或主 Activity 的 onCreate 方法中初始化 SDK: import android.app.Application import android.view.MotionEvent ...
    • API Integration with Prebid.js (GAM)

      Introduction Integrating an API with a Prebid.js setup in a GAM environment can enhance functionalities such as fraud detection, analytics, or performance tracking. Below is a professional and engaging step-by-step guide to ensure seamless ...
    • Javascript Pixel Integration via GTM

      Deploying the ClearSense Tag: A Step-by-Step Guide The ClearSense On-Site Tag can be deployed using two methods: Direct Deployment and Deployment via Google Tag Manager (GTM). Follow the detailed instructions below to ensure seamless integration. ...
    • Postback Integration

      Introduction ClearTrust’s Postback functionality empowers businesses to act decisively and swiftly by sending real-time notifications (callbacks) whenever critical events occur, such as fraudulent traffic detection or conversions. This innovative ...
    • S2S API Integration

      Introduction SafeAPI is a robust and scalable RESTful API designed to handle real-time traffic verification and blocking. It provides a secure and efficient solution for businesses and organizations to protect their digital infrastructure from ...