将Firebase Analytics与Xamarin Android集成 [英] Integrate Firebase Analytics with Xamarin Android

查看:143
本文介绍了将Firebase Analytics与Xamarin Android集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有有关与xamarin进行分析集成的官方文档.仅有Xamarin Google Analytics(分析)示例正式可用.

There is no official documentation for analytics integration with xamarin. Only Xamarin Google Analytics Sample is available officially.

但是我们找到了一个官方的Firebase nuget包 Xamarin.Firebase.Analytics 已可用于Microsoft提供的分析.

But we found an official Firebase nuget package Xamarin.Firebase.Analytics has been available for analytics which is provided by microsoft.

但是没有适当的文档使用xamarin配置Firebase.我们已经创建了应用程序ID,并从Firebase控制台为应用程序生成了.json文件.但没有参考资料可在xamarimn android应用中对其进行配置.

But there is no proper document to configure firebase with xamarin. We have created app id and .json file got generated from firebase console for our application. But there is no reference to configure these in xamarimn android app.

推荐答案

这是因为您不需要官方的基本Android代码转换文档,就可以直接在Android Studio中使用任何简单的跟踪代码. C#方面:

This is because you do not need to have a official documentation for basic Android code conversion anything as simple as tracking code that is used by Android studio is directly available in the C# side:

在您的活动中添加FirebaseAnalytics全局字段,如下所示:

Add the FirebaseAnalytics global field in your activity like this:

FirebaseAnalytics firebaseAnalytics;

然后在活动上下文"中获取其实例:

Then get its instance in Activity Context :

firebaseAnalytics = FirebaseAnalytics.GetInstance(this);

然后定义一个包并记录事件:

Then define a bundle and log events:

var bundle = new Bundle();
bundle.PutString(FirebaseAnalytics.Param.ItemId, "1");
bundle.PutString(FirebaseAnalytics.Param.ItemName, PageNameToTrack);
firebaseAnalytics.LogEvent(FirebaseAnalytics.Event.SelectContent, bundle);

可以在以下位置找到参考: https://firebase.google.com/docs/analytics/android/start/

Reference can be found here: https://firebase.google.com/docs/analytics/android/start/

更新

在GoogleServices.Json的上下文中,只需将其添加到项目的根文件夹中,并将构建操作设置为GoogleServicesJson

In context to the GoogleServices.Json just add it to your root folder of the project and set build action as GoogleServicesJson

请遵循以下步骤:

  • 将google-services.json复制到项目文件夹.

  • Copy google-services.json to the project folder.

将google-services.json添加到应用程序项目中(在解决方案资源管理器中单击显示所有文件",右键单击google-services.json,然后选择包含在项目中".)

Add google-services.json to the app project (click Show All Files in the Solution Explorer, right-click google-services.json, then select Include in Project).

在解决方案资源管理器"窗口中选择google-services.json.

Select google-services.json in the Solution Explorer window.

在属性"窗格中,将构建操作"设置为GoogleServicesJson:

In the Properties pane, set the Build Action to GoogleServicesJson:

FCM的官方报价:

将google-services.json添加到项目中(并设置了GoogleServicesJson构建操作)后,构建过程将提取客户端ID和API密钥,然后将这些凭据添加到位于以下位置的合并/生成的AndroidManifest.xml中obj/Debug/android/AndroidManifest.xml.

When google-services.json is added to the project (and the GoogleServicesJson build action is set), the build process extracts the client ID and API key and then adds these credentials to the merged/generated AndroidManifest.xml that resides at obj/Debug/android/AndroidManifest.xml.

对于 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆