Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Problem with Firebase Analytics (Android) on Xamarin.Forms

$
0
0

Hi,

I am trying to implement Firebase Analytics in my Android project in Xamarin Forms...

My Dependency:

using System;
using Android.Content;
using Xamarin.Forms;
using Firebase.Analytics;
using Firebase.Crash;
using Android.OS;

[assembly: Dependency(typeof(ConvertAny.Droid.FirebaseService))]
namespace ConvertAny.Droid
{
    public class FirebaseService : IFirebaseService
    {
        FirebaseAnalytics firebaseAnalytics;

        public void Track_App_Page(String PageNameToTrack)
        {
            var bundle = new Bundle();
            bundle.PutString(FirebaseAnalytics.Param.ItemId, "1");
            bundle.PutString(FirebaseAnalytics.Param.ItemName, PageNameToTrack);

            firebaseAnalytics.LogEvent(FirebaseAnalytics.Event.SelectContent, bundle);
        }
    }
}

In MainActivity:

FirebaseAnalytics firebaseAnalytics;

protected override void OnCreate(Bundle bundle)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);

    firebaseAnalytics = FirebaseAnalytics.GetInstance(this);
    ...........
    ...........
    ...........

In my Home.xaml.cs:

FirebaseDependencyService.Track_App_Page("Pages - Home");

But I am getting:

Object reference not set to an instance of an object.

On this line:

firebaseAnalytics.LogEvent(FirebaseAnalytics.Event.SelectContent, bundle);

Can anyone help please

Thanks,
Jassim


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>