Firebase Analytics supports for Xamarin.Forms?

kalkotekedarkalkotekedar USMember ✭✭

I want to integrate Firebase analytic with the Xamarin.Form application so I wanted to know

Firebase analytics support for Xamarin.forms?

How can I integrate with it?

Answers

  • RaymondKellyRaymondKelly USMember ✭✭✭

    Yes, it does, but you need to handle the logic in each project. So basically:
    1. Add Firebase Analytics nuget package to each platform project (you don't need it in the Forms project)
    2. Follow the instructions for each platform for initializing Firebase.

    iOS AppDelegate - FinishedLaunching
    Firebase.Analytics.App.Configure();

    Android MainActivity - OnCreate
    firebaseAnalytics = FirebaseAnalytics.GetInstance(this);

  • kalkotekedarkalkotekedar USMember ✭✭

    @RaymondKelly Then how can I manage the click events happen through the xamarin.forms?

  • RaymondKellyRaymondKelly USMember ✭✭✭
    edited August 11

    You will need to create a dependancy service in each platform. In my case I made a class called Analytics. IOS example:

    [assembly: Xamarin.Forms.Dependency(typeof(App.iOS.Analytics))] namespace App.iOS { public class Analytics : IAnalytics {....

    I then have a function for each type of event I want to log. E.g.
    'public void ConnectToServer(Server server)
    {

            try
            {
                NSString[] keys = { new NSString(Global.ANALYTICS_CONNECTION_ESTABLISHED) };
                NSObject[] values = { new NSString(server.FullAddress) };
                var parameters = NSDictionary<NSString, NSObject>.FromObjectsAndKeys(values, keys, keys.Length);
                Firebase.Analytics.Analytics.LogEvent(EventNamesConstants.Login, parameters);
            }
            catch
            {
                // Ignore
            }
        }`
    
  • kalkotekedarkalkotekedar USMember ✭✭

    @RaymondKelly Thanks for your reply hope this will work for me

  • WojciechKulikWojciechKulik USMember ✭✭
    edited August 20

    Hi,

    is there any way to use old Google Analytics Api, becasue I don't see this option anymore on web panel - there is only Firebase.

    When I add to Xamarin.iOS project the nuget package with Firebase I get those errors:

  • TedebusTedebus USMember ✭✭

    @RaymondKelly said:
    Yes, it does, but you need to handle the logic in each project. So basically:
    1. Add Firebase Analytics nuget package to each platform project (you don't need it in the Forms project)
    2. Follow the instructions for each platform for initializing Firebase.

    iOS AppDelegate - FinishedLaunching
    Firebase.Analytics.App.Configure();

    Android MainActivity - OnCreate
    firebaseAnalytics = FirebaseAnalytics.GetInstance(this);

    Hi,
    can you tell me because I'm getting this strange error?

    Error CS0234: The type or namespace name 'App' does not exist in the namespace 'Firebase.Analytics' (are you missing an assembly reference?) (CS0234)

    It refers to:
    Firebase.Analytics.App.Configure();

    Here you can see Firebase resources on my project:

    What do you think is going wrong?

    Thank you in advance!

  • TedebusTedebus USMember ✭✭

    Well... I solved after 3 minutes from last post. I'm sorry!
    I don't know why but something changed.
    Actually "Firebase.Analytics." doesn't longer contain the "App" class.
    It's now in "Firebase.Core"! :/
    I downloaded the sample project from GitHub to try to compile and I saw it.
    Taking a look to the documentation I see that (now) it's written:

    Add the following line of code somewhere in your app, typically in your AppDelegate's FinishedLaunching method (don't forget to import Firebase.Core namespace):

    I'm quite sure it was in Analytics in the past because I was able to compile the code some months ago.

  • SabariManoSabariMano USMember

    @Tedebus. Your right, "Firebase.Core" working for me.

    Thank you!

  • batmacibatmaci DEMember ✭✭✭✭
    Is it also possible to use it in uwp application?
Sign In or Register to comment.