Skip to content

Instantly share code, notes, and snippets.

@kakobotasso
Created May 14, 2019 04:09
Show Gist options
  • Save kakobotasso/f42f6db384850d9251c2259fdc237417 to your computer and use it in GitHub Desktop.
Save kakobotasso/f42f6db384850d9251c2259fdc237417 to your computer and use it in GitHub Desktop.
IEventTracker implementation FireEvents
using System;
using System.Collections.Generic;
using Android.OS;
using Firebase.Analytics;
using FireEvents;
using FireEvents.Droid;
using Xamarin.Forms;
[assembly: Dependency(typeof(EventTrackerDroid))]
namespace FireEvents.Droid
{
public class EventTrackerDroid : IEventTracker
{
public void SendEvent(string eventId)
{
SendEvent(eventId, null);
}
public void SendEvent(string eventId, string paramName, string value)
{
SendEvent(eventId, new Dictionary<string, string>
{
{paramName, value}
});
}
public void SendEvent(string eventId, IDictionary<string, string> parameters)
{
var firebaseAnalytics = FirebaseAnalytics.GetInstance(Forms.Context);
if(parameters == null)
{
firebaseAnalytics.LogEvent(eventId, null);
return;
}
var bundle = new Bundle();
foreach(var param in parameters)
{
bundle.PutString(param.Key, param.Value);
}
firebaseAnalytics.LogEvent(eventId, bundle);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment