Analytics SDK for Android.
- Persistence cache
- Sync with server
- Room
- OkHttp
- Jetpack Compose
- Internet permission on App manifest
<uses-permission android:name="android.permission.INTERNET" />
Analytics SDK is hosted on Bitbucket. You can find more about Android SDK Gradle Artifact deployments in my previous post https://kanxoramesh.medium.com/bitbucket-as-maven-repository-888c7f72cfb7
- Provide Repo accesstoken in local.properties file
bitbucket.token=*******token here*****
- On Project level setting.gradle.kts
repositories { maven { url = uri("url") authentication { create<HttpHeaderAuthentication>("header") } credentials(HttpHeaderCredentials::class) { name = "Authorization" value = "Bearer ${localProperties.getProperty("bitbucket.token")}" } } }
- On App level
implementation 'com.analytics.analytics_android:analytics:1.0.2'//
-------------OR----------------------
implementation(project(":analytics-android"))
-
Initialize the SDK on Application Class
AndroidAnalytics.initialize( AndroidAnalytics.Builder(this) .setStorage(RoomAnalyticsStorage(this)) // Local Cache Storage .setLogLevel(LogLevel.INFO) // Log level .maxSessionPoolCount(2) // Max number of sessions to store in cache; after this, network sync will push data to server .setNetworkSynchronizer( AndroidAnalytics.OkHttpNetworkConnectionBuilder("http://10.0.2.2:8080/network") // Network synchronizer to push cached data to network .method(HttpMethod.POST) // HTTP method .timeout(5) // Request timeout duration in seconds .build() ) )
-
Start Session before log event
AndroidAnalytics.getInstance().startSession()
-
Add some Events. Ensure wrap with Try/Catch. Session Must start to log Events
try { AndroidAnalytics.getInstance() .addEvent("Event $event", mapOf("Tap $event" to "main")) } catch (e: Exception) { Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show() }
-
End Session
AndroidAnalytics.getInstance().endSession()
Ramesh Pokhrel - @medium - [email protected]