SDKs
Android SDK
Overview
This section explains how to integrate the DataSenses-SDK into your Android applications. This includes steps such as incorporating the SDK into your project, initializing it, and sending custom events as needed.
Prerequisites
Ensure you have the following prerequisites to start the Android integration:
- The minimum SDK requirement is 26. If you need support for older SDK versions, please reach out to our support team for assistance.
Step 1: Adding the sdk
- The DataSenses-SDK is distributed through
Maven Central
.Ensure that you have declaredmavenCentral()
in yourrepositories
section.
For example:
pluginManagement {
repositories {
mavenCentral()
}
}
- Add the dependency of DataSenses-SDK
implementation("io.datasenses:sdk:$sdkVersion")
The latest version now is 0.2.2
Step 2: Setup the google-service.json
When you register your application with the DataSenses system, you'll receive a google-service.json file. Place this file into your project as shown in the image below
Step 3: Facebook integration
If your app is not running advertising on Facebook or already integrated with facebook-ios-sdk to run ads, then no need to add the following
Add to res/values/strings
<resources>
<string name="app_name">Your Facebook App Name</string>
<string name="facebook_app_id">facebook_app_id</string>
<string name="facebook_client_token">facebook_client_token</string>
</resources>
Add to AndroidManifest.xml
<application>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
...
</application>
Step 4: Init the sdk
After adding the SDK to your project, it needs to be initialized before further usage. We recommend initializing it in your Application class, as below:
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
val token = "your_token_here"
DataSenses.init(this, token)
DataSenses.isTrackFirebaseEvent = true //if you want to send event to firebase by our sdk
DataSenses.isTrackFacebookEvent = true //if you want to send event to facebook by our sdk
}
}
Step 4: Track deeplink
val intent = intent
val deepLink:Uri? = intent.data
if (deepLink != null) {
DataSenses.trackDeepLinkEvent(deepLink)
}
Note Remember that you have comlepted your deeplink setup by following the Android guidline.
Step 5: Integrate the notification system
Read here for more details
Step6: Send Events
6.1. Send Login Event
We use login event to identify the customer. Naming convention of fields need to be followed by our format.
DataSenses.trackEvent("login",
mapOf(
"customer_id" to 123456.toString(), // String - We use customer_id field as customer's id,
"email" to "[email protected]", // String - We use email field as customer's email
"phone" to "84999999999" // String - We use phone field as customer's phone
)
)
6.2. Send Charged Event
We use charged event to calculate the revenue, ROI, Marketing performance of your project.
Note:
- If you want to monitor revenue of your product. You need to add the items filed with item_id as product's id for us to proceed this event
DataSenses.trackEvent(
"charged",
mapOf(
"items" to listOf( // Array - We use items field as list of items of the conversion event, must have item_id, name, price, qty of each item
mapOf(
"category" to "Phone",
"name" to "Iphone X",
"price" to 119000000,
"item_id" to "2",
"qty" to 1
),
mapOf(
"category" to "Phone",
"name" to "Samsung Galaxy",
"price" to 119000000,
"item_id" to "3",
"qty" to 1
)
),
"charged_id" to "123", // String - Use charged_id field as a conversion's id
"amount" to 238000000 // Number - We use amount field as a conversion's value
)
)
6.3. Send Customized Events
You can add any additional events
DataSenses.trackEvent(
"add_to_cart",
mapOf(
"category" to "Phone", // String, To analyze more efficiently, please don't change name of the field
"name" to "Iphone X", // String, To analyze more efficiently, please don't change name of the field
"price" to 119000000, // Number, To analyze more efficiently, please don't change name of the field
"item_id" to "2", // String, To analyze more efficiently, please don't change name of the field
"qty" to 1 // Number, To analyze more efficiently, please don't change name of the field
)
)