"Centralising Firebase / Google Analytics Screen Tracking In Android" @ http://blog.jakelee.co.uk/2018/10/22/centralising-firebase-google-analytics-screen-tracking-using-android-fragments
This file contains 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
| override fun onCreateView( | |
| inflater: LayoutInflater, | |
| container: ViewGroup?, | |
| savedInstanceState: Bundle? | |
| ): View? { | |
| TrackingUtil(requireActivity()).track(TrackingUtil.Screens.Login) | |
| return inflater.inflate(R.layout.fragment_login, container, false) | |
| } |
This file contains 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 com.google.firebase.analytics.FirebaseAnalytics | |
| import com.ingenie.sensor.baseui.BuildConfig | |
| import timber.log.Timber | |
| class TrackingUtil(val context: Context) { | |
| enum class Screens { | |
| ChangePassword, | |
| Contact, | |
| Dashboard, | |
| DashboardInfo, | |
| ForgottenPassword, | |
| Info, | |
| Login, | |
| Registration | |
| } | |
| fun track(screen: Screens) { | |
| if (!BuildConfig.DEBUG) { | |
| FirebaseAnalytics.getInstance(context.applicationContext) | |
| .setCurrentScreen(context, screen.name, null) | |
| Timber.d("Sending screen view of ${screen.name}") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In LoginFragment.kt on
Line 6Instead of
TrackingUtil(activity!!).track(TrackingUtil.Screens.Login)Try these:
TrackingUtil(requireActivity()).track(TrackingUtil.Screens.Login)which will force to get the activity automatically