Skip to content

Latest commit

 

History

History
73 lines (58 loc) · 2.27 KB

README.md

File metadata and controls

73 lines (58 loc) · 2.27 KB

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.)
  • 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);

Usage

Log events

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);

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

CrossFirebaseAnalytics.Current.SetAnalyticsCollectionEnabled(enabled);

CrossFirebaseAnalytics.Current.SetSessionTimeoutDuration(sessionTimeoutDuration);