Minimum Java version required: 17.
Installation
Add the dependency to your build.gradle file:Copy
Ask AI
dependencies {
implementation 'com.topsort:topsort-kt:2.0.0'
}
Setup
Kotlin
Copy
Ask AI
import android.app.Application
import com.topsort.analytics.Analytics
class KotlinApplication : Application() {
override fun onCreate() {
super.onCreate()
Analytics.setup(
application = this,
opaqueUserId = "<YOUR_OPAQUE_USER_ID>",
token = "<API token>"
)
}
}
Java
Copy
Ask AI
import android.app.Application;
import com.topsort.analytics.Analytics;
public class JavaApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Analytics.INSTANCE.setup(this, "<opaqueUserId>", "<API token>");
}
}
Reporting Events
Kotlin
Copy
Ask AI
// Purchase
fun reportPurchase() {
val item = PurchasedItem(
productId = "<Marketplace id for the item>",
unitPrice = 1295,
quantity = 20
)
Analytics.reportPurchase(
id = "<Marketplace id for the entire purchase>",
items = listOf(item),
)
}
// Click (promoted)
fun reportClickPromoted() {
val placement = Placement(path = "search_results", location = "position_1")
Analytics.reportClickPromoted(
id = "<Marketplace id for the item>",
resolvedBidId = "<The bid id from the auction winner>",
placement = placement
)
}
// Impression (promoted)
fun reportImpressionPromoted() {
val placement = Placement(path = "search_results", location = "position_1")
Analytics.reportImpressionPromoted(
id = "<Marketplace id for the item>",
resolvedBidId = "<The bid id from the auction winner>",
placement = placement
)
}
Banner Ads
Add BannerView to your activity XML:Copy
Ask AI
<com.topsort.analytics.banners.BannerView
android:id="@+id/bannerView"
android:layout_width="353dp"
android:layout_height="103dp" />
Copy
Ask AI
class SampleActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.sample_activity)
this.lifecycleScope.launch {
val bannerView = findViewById<BannerView>(R.id.bannerView)
val bannerConfig = BannerConfig.CategorySingle(slotId = "slot", category = "category")
bannerView.setup(
bannerConfig = bannerConfig,
screenName = "sample_activity",
onClick = { id, entityType -> onBannerClick(id, entityType) }
)
}
}
}