Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/topsort/topsort.kt
A library that helps you send events from your android app
https://github.com/topsort/topsort.kt
Last synced: about 2 months ago
JSON representation
A library that helps you send events from your android app
- Host: GitHub
- URL: https://github.com/topsort/topsort.kt
- Owner: Topsort
- License: mit
- Created: 2023-06-13T22:00:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-15T23:10:28.000Z (3 months ago)
- Last Synced: 2024-10-18T06:54:40.124Z (3 months ago)
- Language: Kotlin
- Homepage:
- Size: 154 KB
- Stars: 1
- Watchers: 10
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Topsort kotlin library
An Android library for interacting with the Topsort APIs. We currently only support sending events but will add more features shortly.
Licensed under [MIT][1].
## Installation / Getting started
We recommend installing the library via Gradle.
Simply add the dependency to your build.gradle file:```gradle
dependencies {
...implementation 'com.topsort:topsort-kt:1.1.0'
}
```The library is distributed through Maven central, which is usually included by default in your repositories.
You can also add it directly, if needed:```gradle
repositories {
mavenCentral()
}
```## Usage/Examples
#### Setup
The following sample code shows how to setup the analytics library before reporting any event:
##### Kotlin
```kotlin
import android.app.Application
import com.topsort.analytics.Analyticsclass KotlinApplication : Application() {
override fun onCreate() {
super.onCreate()// Either generate a unique session id here or hash an existing
// identifier. It should be consistent for
// each user (impression, click, purchase).Analytics.setup(
this,
"sessionId",
"bearerToken"
)
}
}
```##### Java
```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, "sessionId", "bearerToken");
}
}```
#### Reporting Events
The following samples show how report different events after setting up:
##### Kotlin
```kotlin
fun reportPurchase() {
val item = PurchasedItem(
resolvedBidId = "",
productId = "productId",
unitPrice = 1295,
quantity = 20
)Analytics.reportPurchase(
id = "marketPlaceId",
items = listOf(item)
)
}fun reportClick() {
val placement = Placement(
page = "search_results",
location = "position_1"
)Analytics.reportClick(
placement = placement,
productId = "productId"
)
}fun reportClick() {
val placement = Placement(
page = "search_results",
location = "position_1"
)Analytics.reportClickWithResolvedBidId(
resolvedBidId = "",
placement = placement
)
}fun reportImpression() {
val placement = Placement(
page = "search_results",
location = "position_1"
)val impression = Impression(
productId = "productId",
placement = placement
)Analytics.reportImpression(listOf(impression))
}fun reportImpressionWithResolvedBidId() {
val placement = Placement(
page = "search_results",
location = "position_1"
)Analytics.reportImpressionWithResolvedBidId(
resolvedBidId = "",
placement = placement
)
}```
##### Java
```Java
private void reportImpressionWithResolvedBidId() {
Placement placement = new Placement(
"search_results",
null
);Impression impression = new Impression(
placement,
null,
null,
null,
"");
Analytics
.INSTANCE
.reportImpression(Collections.singletonList(impression));
}private void reportImpression() {
Placement placement = new Placement(
"search_results",
null
);Impression impression = new Impression(
placement,
"productId",
null,
null,
null
);Analytics
.INSTANCE
.reportImpression(Collections.singletonList(impression));
}private void reportClick() {
Placement placement = new Placement(
"search_results",
null
);Analytics
.INSTANCE
.reportClick(placement, "productId", null, null, null);
}private void reportClickWithResolvedBidId() {
Placement placement = new Placement(
"search_results",
null
);Analytics
.INSTANCE
.reportClick(
placement,
null,
null,
null,
""
);
}private void reportPurchase() {
PurchasedItem item = new PurchasedItem(
"productId",
20,
1295,
null,
null
);Analytics
.INSTANCE
.reportPurchase(Collections.singletonList(item), "marketPlaceId");
}private void reportPurchaseWithResolvedBidId() {
PurchasedItem item = new PurchasedItem(
"productId",
20,
1295,
null,
""
);Analytics
.INSTANCE
.reportPurchase(Collections.singletonList(item), "marketPlaceId");
}
```#### Banners on Android
#### Kotlin
You should first add the `BannerView` into your activity `xml`. You can do so with
Android Studio's visual editor, but the end file should like like the following
```xml
```
Then, you have to call the `BannerView.setup()` function with you auction parameters.
Notice that since this makes network calls, we need to `launch` it in a co-routine.
```kotlin
class SampleActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.sample_activity)this.lifecycleScope.launch {
val bannerView = findViewById(R.id.bannerView)
val bannerConfig =
BannerConfig.CategorySingle(slotId = "slot", category = "category")
bannerView.setup(
bannerConfig,
"sample_activity",
null,
{ id, entityType -> onBannerClick(id, entityType) })
}
}
}
```[1]: ./LICENSE