Table of Contents
- Install the SDK
- Configure your Site ID
- Initialize your SDK
- Trace Checkout Events
- Track Compose views
- Network Capture
Please refer to the complete instrumentation guide for a complete reference, release notes etc.
Install the SDK
Add the JitPack repository
Add to your project-level build.gradle:
allprojects {
repositories {
// ...
maven { url "https://jitpack.io" }
}
}
or to settings.gradle (recommended):
dependencyResolutionManagement {
repositories {
// ...
maven { url "https://jitpack.io" }
}
}
Add the SDK dependency
dependencies {
implementation("com.github.blue-triangle-tech:btt-android-sdk:2.18.4")
}
If you’re using Gradle Plugin 8.2.0+, exclude the okhttp-bom to avoid conflicts:
implementation("com.github.blue-triangle-tech:btt-android-sdk:2.18.4") {
exclude("com.squareup.okhttp3", "okhttp-bom")
}
Configure Your Site ID
Add your Site ID to the app manifest:
<meta-data
android:name="com.blue-triangle.site-id"
android:value="<BTT_SITE_ID>" />
Replace <BTT_SITE_ID> with your actual site ID.
Initialize the SDK
Initialize tracking from your Application class:
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
Tracker.init(this)
}
}
Track Checkout Events
Use a Timer to capture checkout actions such as brand value, cart value, order number, and cart count.
Brand value example:
val timer = Timer()
timer.start()
timer.setPageName("SignUp")
timer.setBrandValue(99.99)
timer.submit()
Cart + order example:
val timer = Timer()
timer.start()
timer.setPageName("Confirmation")
timer.setCartValue(99.99)
timer.setOrderNumber("XYZ1234")
timer.setCartCount(2)
timer.setCartCountCheckout(5)
timer.setOrderTime(System.currentTimeMillis()) // optional
timer.submit()
Track Compose views
To automatically track Compose screens, use the BlueTriangle Gradle plugin explained here.
Network Capture
To capture network details, you need to add one of these code snippets.
If your app uses OkHttp
Add the BlueTriangleOkHttpInterceptor & BlueTriangleOkHttpEventListener
to your OkHttpClient as follows:
import com.bluetriangle.analytics.okhttp.BlueTriangleOkHttpInterceptor
import com.bluetriangle.analytics.okhttp.BlueTriangleOkHttpEventListener
//...
val okHttpClient = OkHttpClient.Builder()
//...
// Add BlueTriangleOkHttpInterceptor
.addInterceptor(BlueTriangleOkHttpInterceptor(Tracker.instance!!.configuration))
// Add BlueTriangleOkHttpEventListener
.eventListener(BlueTriangleOkHttpEventListener(Tracker.instance!!.configuration))
//...
.build()If your app already implements and sets an EventListener object to the OkHttpClient, the SDK provides a constructor for BlueTriangleOkHttpEventListener that takes in another EventListener object. You can use this as shown below:
val okHttpClient = OkHttpClient.Builder()
//...
// Add BlueTriangleOkHttpInterceptor
.addInterceptor(BlueTriangleOkHttpInterceptor(Tracker.instance!!.configuration))
// Add BlueTriangleOkHttpEventListener
.eventListener(BlueTriangleOkHttpEventListener(Tracker.instance!!.configuration, `<your event listener instance>`))
//...
.build()Manual Network Capture
If you are not using OkHttp or you don't want to track all requests done by OkHttp, you can manually track and submit network requests by using CapturedRequest object as shown below:
// Import CapturedRequest
import com.bluetriangle.analytics.networkcapture.CapturedRequest
//...
// create a captured request object
val capturedRequest = CapturedRequest()
// set the URL which also sets the host, domain, and file parameters that could be set otherwise
capturedRequest.url = "https://bluetriangle.com/platform/business-analytics/"
// start timing the request
capturedRequest.start()
// make the network request
// end timing the request on response/error
capturedRequest.stop()
// (Optional) set HTTP response status code
capturedRequest.responseStatusCode = 200
// (Optional) set encoded body size based on response content length header
capturedRequest.encodedBodySize = 12341
// (Optional) set based on response content type
capturedRequest.requestType = RequestType.html
// submit the captured request to the tracker instance
Tracker.instance?.submitCapturedRequest(capturedRequest)
Comments
0 comments
Please sign in to leave a comment.