Not able to push custom events in Firebase Analytics

My environment:
Windows
Visual Studio 2017 version 15.8.9
Nuget Packages:
Xamarin.Firebase.iOS.Analytics - 5.1.4
Xamarin.Firebase.iOS.Core - 5.1.3
Xamarin.Firebase.iOS.InstanceID - 3.2.1

I have mentioned following mlaunch and start argument in iOS project properties -> iOS Run Optionts:
--argument=-FIRAnalyticsDebugEnabled

I am getting auto events like session_start, screen_view so my iOS App is sending events to Firebase.

I have implemented following solution for Firebase Analytics:
https://stackoverflow.com/questions/48774378/firebase-analytics-in-xamarin-forms/50764452#50764452
However I am facing issues in pushing custom events to Firebase for my iOS project. Android is pushing these custom events properly.

First problem:
following code throws an ambiguous error.(https://forums.xamarin.com/discussion/136547/firebase-analytics-the-call-is-ambiguous-between-the-following-methods-or-properties)
if (parameters == null) { Analytics.LogEvent(eventId, null); return; }

So I tried following options:
option 1:
if (parameters == null) { Firebase.Analytics.Analytics.LogEvent(eventId, new Dictionary<object, object>(){{"key1", "value1"}}); return; }

Option 2:
`var keys = new List();
var values = new List();

        if (parameters == null)
        {
            //Firebase.Analytics.Analytics.LogEvent(eventId, NSDictionary<NSString, NSObject>.FromObjectsAndKeys(values.ToArray(), keys.ToArray(), keys.Count));
            //return;
            keys.Add(new NSString("Parameter"));
            values.Add(new NSString("NONE"));
        }
        else
        {
            foreach (var item in parameters)
            {
                keys.Add(new NSString(item.Key));
                values.Add(new NSString(item.Value));
            }
        }
      var parametersDictionary =
      NSDictionary<NSString, NSObject>.FromObjectsAndKeys(values.ToArray(), keys.ToArray(), keys.Count);
      Firebase.Analytics.Analytics.LogEvent(eventId, parametersDictionary);`

Both these options are not working. When I am checking debug log, I can find following

  • [I-ACS025018] Event not logged. Call +[FIRApp configure]: iOSAnalyticsStarted

I have attached whole log file. Can anyone please help?

THanks.

Best Answers

Answers

  • NirajBhattNirajBhatt Member ✭✭

    @JassimRahma , were you able to push custom events of iOS to firebase analytics? any pointers? thanks.

  • Wojciech_KulikWojciech_Kulik USMember ✭✭
    edited December 2018

    It is exactly described what you have to do:

    Call +[FIRApp configure]: iOSAnalyticsStarted

    You did not initialized Firebase in AppDelegate.
    More details: https://github.com/xamarin/GoogleApisForiOSComponents/blob/master/Firebase.Analytics/component/GettingStarted.md

  • NirajBhattNirajBhatt Member ✭✭

    Hi @Wojciech_Kulik ,
    Thank you for reply and help. I am initializing Firebase in AppDelegate actually. That's how I am able to get auto events like session_start etc. But I am not getting custom events.

    AppDelegate FinishedLaunching event code:

             public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();
            CachedImageRenderer.Init();
    
            UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);
    
            this.hasNotificationPermissions = new Subject<bool>();
            this.latestNotification = new Subject<Tuple<string, string, string>>();
            Current = this;
    
            compositionRoot = new iOSCompositionRoot();
            new SplatRegistrar().Register(Locator.CurrentMutable, compositionRoot);
            LoadApplication(compositionRoot.ResolveApp());
    
            // reset our badge
            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
    
            // Code for starting up the Xamarin Test Cloud Agent
    

    if ENABLE_TEST_CLOUD

                 Xamarin.Calabash.Start ();
    

    endif

            AppSingleton.RegisterForRemoteNotifications.WhereNotNull().Do(unit =>
            {
                RegisterForRemoteNotifications();
            })
           .SubscribeSafe();
    
            PinItemViewRenderer.Init();
            CustomWebViewRenderer.Init();
            PullToRefreshLayoutRenderer.Init();
    
            SQLitePCL.Batteries_V2.Init();
    
            UNUserNotificationCenter.Current.Delegate = new MyNotificationDelegate();
    
            Firebase.Analytics.Loader loader1 = new Firebase.Analytics.Loader();
            Firebase.InstanceID.Loader loader2 = new Firebase.InstanceID.Loader();
            //Firebase.Analytics.Loader.ForceLoad();
            //Firebase.InstanceID.Loader.ForceLoad();
            Firebase.Core.App.Configure();
            AnalyticsConfiguration.SharedInstance.Init();
            AnalyticsConfiguration.SharedInstance.SetAnalyticsCollectionEnabled(true);
    
            return base.FinishedLaunching(app, options);
        }
    
  • Wojciech_KulikWojciech_Kulik USMember ✭✭
    edited December 2018

    Did you follow all steps from:
    https://github.com/xamarin/GoogleApisForiOSComponents/blob/master/Firebase.Analytics/component/GettingStarted.md?

    As you can see, there is a new parameter for debugging in this version "--argument=-FIRDebugEnabled"

  • NirajBhattNirajBhatt Member ✭✭

    Yes @Wojciech_Kulik . I have mentioned mlaunch argument also --argument=-FIRDebugEnabled.

    I am getting auto events but only custom events are not getting logged. I have attached log file.

    thanks again for helping out

  • NirajBhattNirajBhatt Member ✭✭

    Hi @Wojciech_Kulik ,

    Thank you for help. Yes I am going to try all these and will update here.

  • NirajBhattNirajBhatt Member ✭✭
    edited December 2018

    Hi @Wojciech_Kulik ,
    You were spot on. THe issue was that I was trying to log an event before Firebase Analytics was initialized.
    I have fixed that issue and now it's trying to log the custom event.
    However I am getting an error code type 2 (https://firebase.google.com/docs/analytics/errors) firebase event error instead of my custom event which says event name is not correct.
    Any pointer on how to provide any custom event name when there are no parameters?
    My existing code:
    if (parameters == null)
    {
    Firebase.Analytics.Analytics.LogEvent(eventId, new Dictionary<object, object>() { { "key1", "value1" } });
    return;
    }

    Here eventId value is my custom string value.

  • NirajBhattNirajBhatt Member ✭✭

    Got it working after removing '-' in event name and it's working fine now. Thank you very much @Wojciech_Kulik for all the help.

Sign In or Register to comment.