简体   繁体   English

适用于Firebase和Google Analytics(分析)的google-services.json

[英]google-services.json for Firebase and Google Analytics

I want to use Google Analytics and Firebase both in my project. 我想在我的项目中同时使用Google Analytics(分析)和Firebase。 I have downloaded google-services.json file from the Firebase console settings but after using it, I am not able to support Google Analytics. 我已经从Firebase控制台设置中下载了google-services.json文件,但是使用后,我无法支持Google Analytics(分析)。 It is showing me the error: 它向我显示了错误:

Error:(463, 49) error: cannot find symbol variable global_tracker

How to configure both in same .json file? 如何在同一个.json文件中配置两者?

Following field is missing from .json file downloaded from firebase dashboard. 从Firebase仪表板下载的.json文件缺少以下字段。

"services": {
    "analytics_service": {
      "status": 2,
      "analytics_property": {
        "tracking_id": "some_tracking_id"
      }
    },

When I downloaded google-services.json from Firebase console, analytics-service looked like this: 当我从Firebase控制台下载google-services.jsonanalytics-service看起来像这样:

"analytics_service": {
      "status": 1
    },

However, since I have configured Google analytics as instructed here using global_tracker.xml file, it seems there is no need to have it configured in the google-services.json . 但是,因为我已经配置了谷歌分析的指示, 这里使用global_tracker.xml文件,似乎没有必要把它在配置的google-services.json

You should not use Google Analytics, Firebase already includes the analytics service that you could use better. 您不应该使用Google Analytics(分析),Firebase已经包含了您可以更好地使用的分析服务。

Just have in the module build.gradle : 只需在模块build.gradle

compile 'com.google.firebase:firebase-core:10.0.1'

Declare object 声明对象

private FirebaseAnalytics mFirebaseAnalytics;

Instance in onCreate method onCreate方法中的实例

mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

So register events: 因此注册事件:

Bundle params = new Bundle();
params.putString("image_name", name);
params.putString("full_text", text);
mFirebaseAnalytics.logEvent("share_image", params);

More information: 更多信息:

https://firebase.google.com/docs/analytics/android/events https://firebase.google.com/docs/analytics/android/events

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM