'How to integrate Xamarin.Firebase.Analytics to the Xamarin.forms?
Problem: But I don't see an active user in my firebase account.
I do this.
I add package the Xamarin.Firebase.Analytics to the MyName.Android project.
I add the google-services.json in My Name.Android.
Install build Action = GoogleService.json
I run the project as "Debug".
description of the problem: The project is successfully assembled and running, but the standard actions in the firebase statistics are not fixed: first_open, screen_view, session_start.
description of the problem: The firebase statistics in the realtime section are also empty.
Please tell me what I'm doing wrong? Do I need additional packages? "Xamarin.Firebase.Analytics" need to be initialized in MainActivity?
Developers create nuget packages and upload them to github. Some developers write instructions. And some do not write instructions. The question is where to look for instructions?
Solution 1:[1]
I remember using the following medium post to do the same: https://thewissen.io/using-firebase-analytics-in-your-xamarin-forms-app/
Basically, you perform the prerequisites, you create an interface
public interface IFirebaseAnalyticsService
{
void LogEvent(string eventId);
void LogEvent(string eventId, string paramName, string value);
void LogEvent(string eventId, IDictionary<string, string> parameters);
void SetUserId(string userId);
}
Then you create platform level classes for dependency injection
public class FirebaseAnalyticsService : IFirebaseAnalyticsService
{
public void LogEvent(string eventId)
{
LogEvent(eventId, null);
}
public void LogEvent(string eventId, string paramName, string value)
{
LogEvent(eventId, new Dictionary<string, string>
{
{paramName, value}
});
}
public void SetUserId(string userId)
{
#if !DEBUG
var fireBaseAnalytics = FirebaseAnalytics.GetInstance(CrossCurrentActivity.Current.AppContext);
fireBaseAnalytics.SetUserId(userId);
#endif
}
public void LogEvent(string eventId, IDictionary<string, string> parameters)
{
#if !DEBUG
var fireBaseAnalytics = FirebaseAnalytics.GetInstance(CrossCurrentActivity.Current.AppContext);
if (parameters == null)
{
fireBaseAnalytics.LogEvent(eventId, null);
return;
}
var bundle = new Bundle();
foreach (var item in parameters)
{
bundle.PutString(item.Key, item.Value);
}
fireBaseAnalytics.LogEvent(eventId, bundle);
#endif
}
}
Good luck Lemme know if you have any queries
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | FreakyAli |
