Is this a correct and efficient way to implement Firebase Analytics?

核能气质少年 提交于 2020-06-01 07:22:25

问题


I went through the documentation and some tutorials, but I still don't feel confident that I understand what parts of the code are necessary and what are just an example. Because the analytics don't update immediately and could take a few days if not more then I can't really check if I am implementing it correctly. I would appreciate if someone could tell me if I'm doing it right and if not, what am I doing wrong.

I have about 10 actions I want to track in my app. All the fragments in my app implement a certain interface. In my interface I've created the following method:

fun event(firebaseAnalytics : FirebaseAnalytics, name : String){
    val bundle = Bundle()
    bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name)
    firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle)
}

at both my activities I've initialized firebaseAnalytics as as a public variable as follows:

firebaseAnalytics = FirebaseAnalytics.getInstance(this)

Now in the fragments, whenever one of the actions I want to track is being executed, I call the function like this

event(firebaseAnalytics, "some_action_name_I_chose")

so for example I ould have:

//when someone takes a photo
event(firebaseAnalytics, "photo_taken")

//when someone likes a photo
event(firebaseAnalytics, "photo_liked")

//when someone comments
event(firebaseAnalytics, "photo_commented")

Would this work? Is it as simple as that?

In the documentation this code was given:

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id)
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name)
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image")
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle)

I can't understand if I need all these fields or not. Item id? content type? It's not very clear. Thanks.


回答1:


In order to test your analytics if it went up to the server or not, it does not take a few days. All you need to do is to make your app go to the background and back to the foreground and it should sync with the server.

You can log events with whatever info you want, there's no need for specific fields to be present



来源:https://stackoverflow.com/questions/56033290/is-this-a-correct-and-efficient-way-to-implement-firebase-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!