Last active
September 11, 2020 10:39
-
-
Save JakeSteam/19c4d4869001b41c81de9c5b91dfd4c3 to your computer and use it in GitHub Desktop.
"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 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
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 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 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 6
Instead of
TrackingUtil(activity!!).track(TrackingUtil.Screens.Login)
Try these:
TrackingUtil(requireActivity()).track(TrackingUtil.Screens.Login)
which will force to get the activity automatically