Skip to content

Analytics

To use Analytics, Devbase included with analytics to standardize how app track custom event, set user properties, and user id. Initialize it in Activity or Fragment like this:

private val analytics by lazy { MobileService.analytics }

Tracking custom event

Outside of automatically collected events by Analytics (you can see it here), App can track custom event based on use case needed. Track custom event using Devbase like this:

analytics.logEvent("login", bundleOf(
    Pair("user_name","Puan Maharani"),
    Pair("party","PDIP")
))

Tip

For custom event with multiple use cases, avoid naming the event like login_google and login_twitter. Instead, name the event login and add parameter type with value Google or Twitter.

Set User Property

There's some variables needed to see for each events, rather than adding the parameter multiple times in each events, set User Property. Do that like this:

analytics.setUserProperty("login_time", "11 June 2021")

By doing it, the key and value will always embedded for the next events occurred. Filtering data will be easier later on for BigQuery Analysis.

Set User Id

For setting user's id to analytics, call this method:

analytics.setUserId(userId)

By calling it, Analytics embed the id to every events in the future.

Clear data

Clear all stored data in analytics by calling this method:

analytics.clearData()

Instance Id

Analytics automatically generate instance Id everytime the app installed, so when the same app installed twice will generate different instance Id. Getting instance Id for current installation, do it like this:

analytics.instanceId {
    val instanceId = it
}