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 have attached whole log file. Can anyone please help?
THanks.
As you can see in your logs
2018-11-30 11:09:21.152525+1000 BestHealth[60482:3770317] - <AppMeasurement>[I-ACS025018] Event not logged. Call +[FIRApp configure]: iOSAnalyticsStarted
is called before initializing Firebase:
2018-11-30 11:09:23.802960+1000 BestHealth[60482:3770316] 5.8.0 - [Firebase/Analytics][I-ACS023007] Analytics v.50102000 started
Also how do you verify that events don't appear? They won't be displayed in "Events" menu for debug setting. As far as I remember they will be displayed only in "DebugView" menu.
Make sure that you have properly configured GoogleService-Info.plist. If nothing helps I would recommend you to create a new project a try there from scratch. Also you can try to turn off debug mode and check release stream.
Event names:
Event names can be up to 40 characters long, may only contain alphanumeric characters and underscores, and must start with an alphabetic character. The "firebase_", "google_", and "ga_" prefixes are reserved and should not be used.
Source: https://firebase.google.com/docs/reference/cpp/group/event-names
Parameters:
You may supply extra Params for suggested Events or custom Params for Custom events. Param names can be up to 40 characters long, may only contain alphanumeric characters and underscores, and must start with an alphabetic character. Param values can be up to 100 characters long. The "firebase_", "google_", and "ga_" prefixes are reserved and should not be used.
Source: https://firebase.google.com/docs/reference/cpp/group/parameter-names
Answers
@JassimRahma , were you able to push custom events of iOS to firebase analytics? any pointers? thanks.
It is exactly described what you have to do:
You did not initialized Firebase in AppDelegate.
More details: https://github.com/xamarin/GoogleApisForiOSComponents/blob/master/Firebase.Analytics/component/GettingStarted.md
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:
if ENABLE_TEST_CLOUD
endif
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"
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
As you can see in your logs
2018-11-30 11:09:21.152525+1000 BestHealth[60482:3770317] - <AppMeasurement>[I-ACS025018] Event not logged. Call +[FIRApp configure]: iOSAnalyticsStarted
is called before initializing Firebase:
2018-11-30 11:09:23.802960+1000 BestHealth[60482:3770316] 5.8.0 - [Firebase/Analytics][I-ACS023007] Analytics v.50102000 started
Also how do you verify that events don't appear? They won't be displayed in "Events" menu for debug setting. As far as I remember they will be displayed only in "DebugView" menu.
Make sure that you have properly configured GoogleService-Info.plist. If nothing helps I would recommend you to create a new project a try there from scratch. Also you can try to turn off debug mode and check release stream.
Hi @Wojciech_Kulik ,
Thank you for help. Yes I am going to try all these and will update here.
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.
Event names:
Source: https://firebase.google.com/docs/reference/cpp/group/event-names
Parameters:
Source: https://firebase.google.com/docs/reference/cpp/group/parameter-names
Got it working after removing '-' in event name and it's working fine now. Thank you very much @Wojciech_Kulik for all the help.