Skip to main content

Track Events

Events represent how users interact with your application.

Send Basic Events

val sdk = B2MetricSDK.getInstance(context)
sdk.logEvent("button_clicked")

Send Events with Properties

sdk.logEvent(
name = "product_viewed",
properties = mapOf(
"product_id" to "12345",
"product_name" to "Wireless Headphones",
"price" to 299.99,
"currency" to "TRY"
)
)

Supported Property Types

TypeKotlin TypeExample
StringString"value"
NumberInt, Long, Double, Float42, 3.14
BooleanBooleantrue, false
ListList<Any>listOf(1, 2, 3)
MapMap<String, Any>mapOf("key" to "value")
Nullnullnull

Unsupported types (will be filtered with a warning):

  • Date objects → send as String: "2024-01-15"
  • Custom objects → convert to Map
sdk.logEvent(
name = "purchase_completed",
properties = mapOf(
"order_id" to "ORD-123", // String
"total_amount" to 499.90, // Double
"item_count" to 3, // Int
"is_gift" to false, // Boolean
"items" to listOf("SKU-1", "SKU-2") // List
)
)

Full Event Payload Examples

Every event sent to B2Metric includes user_properties automatically.

product_viewed

{
"api_key": "sdk_47815a01a4624f96",
"body": {
"id": "22903eeb-f93b-4d2c-8c3f-e87b185ad961",
"type": "product_viewed",
"timestamp": "2026-02-18T07:45:02.552Z",
"properties": {
"product_id": "SKU-123",
"product_name": "Wireless Headphones",
"category": "Electronics",
"price": 299.99,
"currency": "TRY"
},
"user_properties": {
"app_name": "B2MetricAnalytics",
"app_package_name": "com.b2metric.analytics",
"app_version": "0.0.1",
"country_code": "TR",
"device_hardware": "qcom",
"device_id": "cfd78e73-030f-4f3b-b023-26c2151784c5",
"device_model": "samsung SM-G780G",
"device_token": "fVIVEPTuSkykBnCdTjWswW:APA91bGGzJtu...",
"language": "tr_TR",
"os_version": "13",
"platform": "Android",
"screen_resolution": "1080x2186",
"timezone": "Europe/Istanbul"
}
}
}

add_to_cart

{
"api_key": "...",
"body": {
"type": "add_to_cart",
"properties": {
"product_id": "SKU-123",
"quantity": 2,
"price": 299.99,
"currency": "TRY"
},
"user_properties": { "...": "same as above" }
}
}

purchase_completed

{
"api_key": "...",
"body": {
"type": "purchase_completed",
"properties": {
"order_id": "ORD-789",
"total_amount": 599.98,
"currency": "TRY",
"item_count": 2,
"payment_method": "credit_card",
"is_gift": false
},
"user_properties": { "...": "same as above" }
}
}