Skip to content

Instantly share code, notes, and snippets.

@alirezanazari
Created October 24, 2020 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alirezanazari/cecec7f8d4231d04ad9a121137e98b16 to your computer and use it in GitHub Desktop.
Save alirezanazari/cecec7f8d4231d04ad9a121137e98b16 to your computer and use it in GitHub Desktop.
object AnalyticsHelper {
fun setupAnalytic(app: Application) {
val config = YandexMetricaConfig.newConfigBuilder(Const.YANDEX_API_KEY)
.withNativeCrashReporting(false)
.withLocationTracking(false)
.withStatisticsSending(false)
.withAppVersion(BuildConfig.VERSION_NAME)
.build()
YandexMetrica.activate(app.applicationContext, config)
YandexMetrica.enableActivityAutoTracking(app)
}
fun setUserData(email: String, name: String) {
val userProfile = UserProfile.newBuilder()
.apply(Attribute.name().withValue(name))
.build()
YandexMetrica.setUserProfileID(email)
YandexMetrica.reportUserProfile(userProfile)
}
fun setCurrentScreen(title: String) {
YandexMetrica.reportEvent(title)
}
fun logEvent(viewName: String, group: String) {
YandexMetrica.reportEvent("$viewName in $group")
}
fun reportAppOpened(activity: Activity) {
YandexMetrica.reportAppOpen(activity)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment