A cross platform plugin for Firebase Analytics. A wrapper for Xamarin.Firebase.iOS.Analytics and Xamarin.Firebase.Analytics.
Install Nuget package to each projects.
- Add GoogleService-Info.plist to iOS project. Select BundleResource as build action.
- Initialize as follows in AppDelegate.
Firebase.Core.App.Configure();
- Add google-services.json to Android project. Select GoogleServicesJson as build action. (If you can't select GoogleServicesJson, reload this android project.)
- Target framework version needs to be Android 10.0.
- This Plugin uses Plugin.CurrentActivity. Setup as follows in MainActivity.
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
CrossFirebaseAnalytics.Current.LogEvent(EventName.SelectContent,
new Parameter(ParameterName.ItemId, itemId),
new Parameter(ParameterName.ItemName, itemName));
var parameters = new Dictionary<string, object>
{
[ParameterName.ItemId] = 1,
[ParameterName.ItemName] = "test"
};
CrossFirebaseAnalytics.Current.LogEvent(EventName.SelectContent, parameters);
CrossFirebaseAnalytics.Current.SetUserProperty("name", userName);
CrossFirebaseAnalytics.Current.SetUserId(userId);
CrossFirebaseAnalytics.Current.SetCurrentScreen(screenName, screenClass));
var id = await CrossFirebaseAnalytics.Current.GetAppInstanceIdAsync();
CrossFirebaseAnalytics.Current.ResetAnalyticsData();
CrossFirebaseAnalytics.Current.SetAnalyticsCollectionEnabled(enabled);
CrossFirebaseAnalytics.Current.SetSessionTimeoutDuration(sessionTimeoutDuration);