Share
Explore

Shinara Kotlin SDK

Shinara is a mobile-first social referral platform tailored for in-app purchases, empowering brands to grow through influencer-driven advocacy. The Kotlin SDK enables seamless integration of Shinara's referral and attribution system into your Android applications.
Website:

Overview

Install the SDK
During onboarding, add a referral code screen to ask user to input their referral code
Integrate Shinara SDK methods to your App’s Lifecycle

Shinara SDK in your App’s Lifecycle

Untitled Diagram.drawio (2).png

Installation

Installation is available via JitPack.
Add it in your root build.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
..
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation('com.github.shinara-io:shinara-kotlin-sdk:1.0.6')
}

Usage

Initialization

Initialize the SDK at app launch, typically in your AppDelegate or main view controller:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GlobalScope.launch {
try {
ShinaraSDK.instance.initialize(
applicationContext,
"API_KEY"
)
} catch (e: Exception ) {
println("Error: ${e.message}")
}
}
...

Referral Code Validation

To validate a referral code, use the validateReferralCode method. This method checks the validity of the given code.
Note: Ensure that the referral code is validated before initiating an In-App Purchase. This is crucial for proper attribution of the purchase to the referral code in the Shinara SDK.
try {
val programId = runBlocking { ShinaraSDK.instance.validateReferralCode(code) }
println("valid code")
} catch (e: Exception) {
println("invalid code")
}

Attribute Purchase

To attribute a purchase made by affiliates, use the attributePurchase method. Call this method after a successful in app purchase.
override fun onPurchasesUpdated(result: BillingResult, purchases: List<Purchase>?) {
when (result.responseCode) {
BillingClient.BillingResponseCode.OK -> {
statusTextView.text = "Purchase Successful"
purchases?.forEach { purchase ->
// Handle successful purchase
runBlocking {
ShinaraSDK.instance.attributePurchase(
purchase.products.firstOrNull() ?: "Unknown Product",
purchase.orderId.orEmpty(),
purchase.purchaseToken,
)
}
}
}
BillingClient.BillingResponseCode.USER_CANCELED -> {
statusTextView.text = "Purchase Canceled"
}
else -> {
statusTextView.text = "Purchase Failed: ${result.debugMessage}"
}
}
}

User Registration (Optional)

By default, Shinara generates a new user id and attribute to the purchase. Optionally, you can provide your own userId and other user details to make sure attribution of the purchase has the user id of your choice.
Note: Ensure that the referral code is validated before registering a user. This is crucial for proper attribution of the user to the referral code in the Shinara SDK.
ShinaraSDK.instance.registerUser(
"YOUR_INTERNAL_USER_ID",
"user@example.com", // Optional
"John Doe", // Optional
"+1234567890" // Optional
)

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.