Created
January 22, 2022 14:26
-
-
Save NaserKhoshfetrat/c6a50cb510b09ad64de5f5488818e00a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity | |
import android.app.Application | |
import com.yandex.metrica.YandexMetrica | |
import com.yandex.metrica.YandexMetricaConfig | |
import com.yandex.metrica.profile.Attribute | |
import com.yandex.metrica.profile.UserProfile | |
class EventTrackerUtils { | |
fun initializeTracker(application: Application) { | |
// Creating an extended library configuration. | |
val config = YandexMetricaConfig.newConfigBuilder(BuildConfig.appMetricaPostApiKey) | |
.withNativeCrashReporting(false) | |
.withLocationTracking(false) | |
.withAppVersion(BuildConfig.VERSION_NAME) | |
.build() | |
// Initializing the AppMetrica SDK. | |
YandexMetrica.activate(application, config) | |
// Automatic tracking of user activity. | |
YandexMetrica.enableActivityAutoTracking(application) | |
} | |
fun reportUserProfile(name: String, email: String, profileId: String) { | |
val userProfile = UserProfile.newBuilder() | |
.apply(Attribute.name().withValue(name)) | |
.apply(Attribute.customString("Email").withValue(email)) | |
.build() | |
YandexMetrica.setUserProfileID(profileId) | |
YandexMetrica.reportUserProfile(userProfile) | |
} | |
fun reportUnhandledException(throwable: Throwable) { | |
YandexMetrica.reportUnhandledException(throwable) | |
} | |
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