Documentation Index
Fetch the complete documentation index at: https://docs.topsort.com/llms.txt
Use this file to discover all available pages before exploring further.
Topsort’s Kotlin library enables our clients to easily send auction requests and track events within Android applications.
Minimum Java version required: 17.
Installation
Add the dependency to your build.gradle file:
dependencies {
implementation 'com.topsort:topsort-kt:2.0.0'
}
Setup
Kotlin
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
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
// 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:
<com.topsort.analytics.banners.BannerView
android:id="@+id/bannerView"
android:layout_width="353dp"
android:layout_height="103dp" />
Setup in your activity:
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) }
)
}
}
}
For full documentation, see the GitHub repository.