diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/data/track.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/data/track.kt index ca61ad7..34beb20 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/data/track.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/data/track.kt @@ -1,6 +1,8 @@ package com.nativebrik.sdk.data +import android.os.Build import com.nativebrik.sdk.Config +import com.nativebrik.sdk.VERSION import com.nativebrik.sdk.data.user.NativebrikUser import com.nativebrik.sdk.data.user.formatISO8601 import com.nativebrik.sdk.data.user.getCurrentDate @@ -97,10 +99,29 @@ internal sealed class TrackEvent { } } +internal data class TrackEventMeta( + val appId: String?, + val appVersion: String?, + val osName: String?, + val osVersion: String?, + val sdkVersion: String? +) { + fun encode(): JsonObject { + return JsonObject(mapOf( + "appId" to JsonPrimitive(this.appId), + "appVersion" to JsonPrimitive(this.appVersion), + "osName" to JsonPrimitive(this.osName), + "osVersion" to JsonPrimitive(this.osVersion), + "sdkVersion" to JsonPrimitive(this.sdkVersion), + )) + } +} + internal data class TrackRequest( val projectId: String, val userId: String, val events: List, + val meta: TrackEventMeta, val timestamp: ZonedDateTime = getCurrentDate(), ) { fun encode(): JsonObject { @@ -109,7 +130,8 @@ internal data class TrackRequest( "projectId" to JsonPrimitive(projectId), "userId" to JsonPrimitive(userId), "timestamp" to JsonPrimitive(formatISO8601(timestamp)), - "events" to JsonArray(events) + "events" to JsonArray(events), + "meta" to meta.encode(), )) } } @@ -175,10 +197,18 @@ internal class TrackRepositoryImpl: TrackRepository { val tempBuffer = this.buffer if (tempBuffer.isEmpty()) return this.buffer = mutableListOf() + val meta = TrackEventMeta( + appId = this.user.packageName, + appVersion = this.user.appVersion, + osVersion = Build.VERSION.SDK_INT.toString(), + osName = "Android", + sdkVersion = VERSION + ) val request = TrackRequest( projectId = config.projectId, userId = user.id, - events = tempBuffer + events = tempBuffer, + meta = meta, ) val body = Json.encodeToString(request.encode()) this.timer?.cancel() diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/data/user/user.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/data/user/user.kt index 6403cd5..a3801bb 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/data/user/user.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/data/user/user.kt @@ -53,6 +53,8 @@ class NativebrikUser { private var properties: MutableMap = mutableMapOf() internal var preferences: SharedPreferences? = null private var lastBootTime: ZonedDateTime = getCurrentDate() + internal var packageName: String? = null + internal var appVersion: String? = null val id: String get() { @@ -99,8 +101,11 @@ class NativebrikUser { try { val packageName = context.packageName + this.packageName = packageName + this.properties[BuiltinUserProperty.appId.toString()] = packageName val appVersion = context.packageManager.getPackageInfo(packageName, 0).versionName this.properties[BuiltinUserProperty.appVersion.toString()] = appVersion + this.appVersion = appVersion } catch (_: Exception) { this.properties[BuiltinUserProperty.appVersion.toString()] = "0.0.0" } diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/schema/generated.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/schema/generated.kt index cd3e992..8d062ff 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/schema/generated.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/schema/generated.kt @@ -336,6 +336,7 @@ internal enum class BuiltinUserProperty { sdkVersion, osVersion, osName, + appId, appVersion, cfBundleVersion, localYear, @@ -374,6 +375,7 @@ internal enum class BuiltinUserProperty { "sdkVersion" -> sdkVersion "osVersion" -> osVersion "osName" -> osName + "appId" -> appId "appVersion" -> appVersion "cfBundleVersion" -> cfBundleVersion "localYear" -> localYear