question

JassimAlRahma-9056 avatar image
0 Votes"
JassimAlRahma-9056 asked JarvanZhang-MSFT commented

Track screen_displayed in Firebase Analytics

Hi,

How can I track the screen_displayed in Xamarin using Firebase Analytics? Ia m currently able to track events only using below.

Interface:

 using System;
    
 namespace MyApp
 {
     public interface IFirebaseEvents
     {
         void LogEvent(string Id, string name, string value);
     }
 }


iOS:


 using System;
 using System.Collections.Generic;
 using Firebase.Analytics;
 using Foundation;
 using MyApp;
    
 [assembly: Xamarin.Forms.Dependency(typeof(IFirebaseEvents))]
 namespace MyApp.iOS
 {
     public class FirebaseEvents : IFirebaseEvents
     {
         public void LogEvent(string Id, string name, string value)
         {
             var keys = new List<NSString>()
             {
                 new NSString(name)
             };
    
             var values = new List<NSString>()
             {
                 new NSString(value)
             };
    
             Analytics.LogEvent(Id, NSDictionary<NSString, NSObject>.FromObjectsAndKeys(values.ToArray(), keys.ToArray(), keys.Count));
         }
     }
 }




Android:

 using System;
 using Android.OS;
 using Firebase.Analytics;
 using Xamarin.Forms;
 using MyApp;
    
 [assembly: Xamarin.Forms.Dependency(typeof(IFirebaseEvents))]
 namespace MyApp.Droid
 {
     public class FirebaseEvents : IFirebaseEvents
     {
         public void LogEvent(string Id, string name, string value)
         {
             var firebaseAnalytics = FirebaseAnalytics.GetInstance(Android.App.Application.Context);
    
             var bundle = new Bundle();
    
             bundle.PutString(name, value);
    
             firebaseAnalytics.LogEvent(Id, bundle);
         }
     }
 }







dotnet-csharpdotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered JarvanZhang-MSFT commented

There is nothing automatic. First define an id and naming scheme for your screens. Then add the logging calls to the screen display code.

You probably also want to add log calls to every button click callback.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

do you mean it's just a normal LogEvent?

0 Votes 0 ·

do you mean it's just a normal LogEvent

The 'IFirebaseEvents.LogEvent' works as the normal event. The important point is to call the firebaseAnalytics.LogEvent command on each platform.

0 Votes 0 ·