Plugin.FirebaseAnalytics

A cross platform plugin for Firebase Analytics. A wrapper for Xamarin.Firebase.iOS.Analytics and Xamarin.Firebase.Analytics.

Setup

Install Nuget package to each projects.

Plugin.FirebaseAnalytics NuGet

iOS

  • Add GoogleService-Info.plist to iOS project. Select BundleResource as build action.
  • Initialize as follows in AppDelegate.
Firebase.Core.App.Configure();

Android

  • 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>

Usage

Log events

CrossFirebaseAnalytics.Current.LogEvent(EventName.SelectContent,
                                        new Parameter(ParameterName.ItemId, itemId),
                                        new Parameter(ParameterName.ItemName, itemName));

Set user properties

CrossFirebaseAnalytics.Current.SetUserProperty("name", userName);

Set user id

CrossFirebaseAnalytics.Current.SetUserId(userId);

Set screen name

CrossFirebaseAnalytics.Current.SetCurrentScreen(screenName, screenClass));

Get app instance id

var id = await CrossFirebaseAnalytics.Current.GetAppInstanceIdAsync();

Reset analytics data

CrossFirebaseAnalytics.Current.ResetAnalyticsData();

Set parameters for Android

Plugin.FirebaseAnalytics.FirebaseAnalytics.SetAnalyticsCollectionEnabled(enabled);

Plugin.FirebaseAnalytics.FirebaseAnalytics.SetSessionTimeoutDuration(sessionTimeoutDuration);