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.)
- This Plugin uses Plugin.CurrentActivity. Setup as follows in MainActivity.
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
- Target Framework must be Android 9.0 (Pie). Multi-Dex needs to be enabled if you use other libraries, Xamarin.Forms etc.
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
CrossFirebaseAnalytics.Current.LogEvent(EventName.SelectContent,
new Parameter(ParameterName.ItemId, itemId),
new Parameter(ParameterName.ItemName, itemName));
CrossFirebaseAnalytics.Current.SetUserProperty("name", userName);
CrossFirebaseAnalytics.Current.SetUserId(userId);
CrossFirebaseAnalytics.Current.SetCurrentScreen(screenName, screenClass));
var id = await CrossFirebaseAnalytics.Current.GetAppInstanceIdAsync();
CrossFirebaseAnalytics.Current.ResetAnalyticsData();
Plugin.FirebaseAnalytics.FirebaseAnalytics.SetAnalyticsCollectionEnabled(enabled);
Plugin.FirebaseAnalytics.FirebaseAnalytics.SetSessionTimeoutDuration(sessionTimeoutDuration);