Firebase Analytics integration with Xamarin.iOS - how to make it work?

Wojciech_KulikWojciech_Kulik USMember ✭✭
edited August 2017 in Xamarin.iOS

Hi,

I'm struggling with Firebase, I configured everything as described here:
https://components.xamarin.com/gettingstarted/firebaseiosanalytics

In my output I see:
[Firebase/Analytics][I-***] Firebase Analytics v.3700000 started 2017-08-21 18:19:29.435 Project.iOS[742] <Notice> [Firebase/Analytics][I-****] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r) 2017-08-21 18:19:29.437 Project.iOS[742] <Notice> [Firebase/Analytics][I-****] Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist 2017-08-21 18:19:29.447 Project.iOS[742] <Notice> [Firebase/Analytics][I-***] Firebase Analytics enabled

and nothig else happens:

  • In my Firebase Console I don't see any events.
  • I tried to set debug mode by adding to Run->Configuration->Default->Arguments parameter "FIRAnalyticsDebugEnabled". It doesn't work either.
  • I tested it on simulator and my iPhone 7.

Did anybody manage to integrated Xamarin.iOS app with Firebase?

Posts

  • Wojciech_KulikWojciech_Kulik USMember ✭✭
    edited August 2017

    Hallelujah, I managed to run debug mode. It turned out that there is some bug in this library.

    Check out here:
    https://bugzilla.xamarin.com/show_bug.cgi?id=43899#c27

    If Arguments textfield has something and Extra mlaunch arguments is empty, Arguments is passed to mlaunch command but if it's on the contrary, Extra mlaunch arguments are not passed to mlaunch command. If both textfields has arguments, both are passed to mlaunch. In other words, there must be something in Argument so Extra mlaunch arguments could be passed to mlaunch.

    So you need to set something in arguments and in mlaunch arguments like that:

    Also make sure that you use the latest version of Xamarin.Firebase.Analytics.

  • csampaio01csampaio01 PTMember ✭✭✭

    Hi, Im getting this:

    2017-09-07 10:46:11.044 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS012018] Saving bundle. size (bytes): 488
    2017-09-07 10:46:11.045 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS023116] Bundle added to the upload queue. BundleID, timestamp (ms): 6, 1504777570650
    2017-09-07 10:46:11.053 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS023038] Uploading events. Elapsed time since last successful upload (s): 97.21154403686523
    2017-09-07 10:46:11.054 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS023039] Measurement data sent to network. Timestamp (ms), data: 1504777571053,
    2017-09-07 10:46:11.057 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS900000] Uploading data. Host: https://app-measurement.com/a
    2017-09-07 10:46:11.238 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS901006] Received SSL challenge for host. Host: https://app-measurement.com/a
    2017-09-07 10:46:11.346 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS023044] Successful upload. Got network response. Code, size: 204, -1
    2017-09-07 10:46:11.346 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS002002] Measurement timer scheduled to fire in approx. (s): 0.3050971031188965
    2017-09-07 10:46:11.346 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS023028] Upload task scheduled to be executed in approx. (s): 0.3050971031188965
    2017-09-07 10:46:11.364 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS023024] No data to upload. Upload task will not be scheduled
    2017-09-07 10:46:11.364 RiopeleMobile.iOS[362] [Firebase/Analytics][I-ACS002003] Measurement timer canceled

    When I call this function made by me:

    public void LogEvent(string parameter, string value) { NSString[] keys = { new NSString(parameter) }; NSObject[] values = { new NSString(value) }; var parameters = NSDictionary<NSString, NSObject>.FromObjectsAndKeys(keys, values, keys.Length); Analytics.LogEvent(parameter, parameters); }

    nothing appears in the console. Did you had this problem?

  • Wojciech_KulikWojciech_Kulik USMember ✭✭
    edited September 2017

    @carlasampaio01
    It works for me, notice that you've got error in your code:
    NSDictionary<NSString, NSObject>.FromObjectsAndKeys(keys, values, keys.Length);

    first argument should be values not keys.

    My class:

        public class AnalyticsService : IAnalyticsService
        {
            public void LogNavigation(string screenName)
            {
                this.LogEvent("screen_displayed", new Dictionary<string, string>
                {
                    { AnalyticsParameters.Screen, screenName }
                });
            }
    
            public void LogEvent(string eventId)
            {
                this.LogEvent(eventId, (IDictionary<string, string>)null);
            }
    
            public void LogEvent(string eventId, string paramName, string value)
            {
                this.LogEvent(eventId, new Dictionary<string, string>
                {
                    { paramName, value }
                });
            }
    
            public void LogEvent(string eventId, IDictionary<string, string> parameters)
            {
                if (parameters == null)
                {
                    Analytics.LogEvent(eventId, null);
                    return;
                }
    
                var keys = new List<NSString>();
                var values = new List<NSString>();
                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);
                Analytics.LogEvent(eventId, parametersDictionary);
            }
        }
    
  • csampaio01csampaio01 PTMember ✭✭✭

    @WojciechKulik Thanks I got it to work perfectly. Does your app collect the user data like gender, age and name?

  • Wojciech_KulikWojciech_Kulik USMember ✭✭

    @carlasampaio01 No, but in order to collect these properties, you need to integrate app with AdMob:
    https://support.google.com/firebase/answer/6317486?hl=en

    Or you can set it manually if you are able to get those information.

  • NirajBhattNirajBhatt Member ✭✭
    edited December 2018

    Hi @Wojciech_Kulik @csampaio01 ,
    are you able to push custom events? I am not able to see it in Firebase console.

    My issue details:
    https://forums.xamarin.com/discussion/145584/not-able-to-push-custom-events-in-firebase-analytics

    Any help or pointers please?

  • Wojciech_KulikWojciech_Kulik USMember ✭✭
    edited December 2018

    @NirajBhatt yes, just follow steps described in my posts above and check out debug stream on Firebase. Make sure that your parameter name doesn't contain white spaces. Also make sure that both parameter name and value are short. There are some limits, but I don't remember now (I guess that for values something about 255 characters).

    Please also check if you properly initialize Firebase in AppDelegate.

Sign In or Register to comment.