/GoogleAnalyticsClientDotNet

Integration Google Analytics track event for Windows Universal Apps and WPF.

Primary LanguageC#Apache License 2.0Apache-2.0

GoogleAnalyticsClientDotNet

This project provides basic API integration for using Google Analytics track event from .NET applications.

Supported Platform : UWP, .NET(4.5.1)

Current Features:

Usage:

Step 1. install nuget:

Step 2. new the AnalyticsService instance.

AnalyticsService service = new AnalyticsService();
service.Initialize("{tracking id}", "{appName}", "{appId}", "{appVersion}");

Step 3. new the EventParameter, and set properties.

EventParameter eventData = new EventParameter();
eventData.Category = "";
eventData.Action = "";
eventData.Label = "";
eventData.ScreenName = "";
eventData.ClientId = "";
eventData.UserAgent = deviceService.ModelName;
            
service.TrackEvent(eventData);

Step 4. For WPF, need call method: SaveTempEventsData() to keep not upload events.

private async void MainWindow_Closed(object sender, EventArgs e)
{
    await service?.SaveTempEventsData();
}

Step 5. For Universal Windows Platform. User need to add SaveTempEventsData method in the Suspened event.

/// <summary>
/// Invoked when application execution is being suspended.  Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();

    await service.SaveTempEventsData();

    deferral.Complete();
}

Licence

Licenced under the Apache 2.0 licence

Reference

Google Analytics SDK for Windows and Windows Phone