Simple Google Analytics Plugin for Xamarin Forms.
This is my first plugin, it's a very basic Google Analytics utility for Xamarin Android, iOS and Forms. If you have any comments or suggestions, please let me know.
- Available on NuGet: https://www.nuget.org/packages/Xamarin.Plugins.GoogleAnalytics/
- Install into your PCL project and Client projects.
- Please see the additional setup for each platforms permissions.
Platform Support
Platform | Supported | Version |
---|---|---|
Xamarin.iOS | Yes | iOS 8+ |
Xamarin.Android | Yes | API 15+ |
Windows Phone Silverlight | No | |
Windows Phone RT | No | |
Windows Store RT | No | |
Windows 10 UWP | No | |
Xamarin.Mac | No |
Call CrossGoogleAnalytics.Current from any project or PCL to gain access to APIs.
public interface IGoogleAnalytics
{
bool EnableAdvertisingTracking {get;set;}
void Report (string message, bool isFatal = false);
void Report (Exception exception, bool isFatal = false);
void Report (Exception exception, IDictionary<string, string> extraData, bool isFatal = false);
void TrackEvent (string category, string action, string label, long value);
void TrackPage (string pageName);
}
You must first initialize plugin
On Android, in your main Activity's OnCreate (..) implementation, call:
GoogleAnalyticsImplementation.Init("UA-XXXXXXX-X", this);
In your AppDelegate's FinishedLaunching (..) implementation, call:
GoogleAnalyticsImplementation.Init("trackerName", "UA-XXXXXXX-X");
Simpliest way to report an exception:
CrossGoogleAnalytics.Current.Report(ex);
Track a page:
CrossGoogleAnalytics.Current.TrackPage("PageName");
Track an event:
CrossGoogleAnalytics.Current.TrackEvent("category", "action", "label", 0);