Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

poumason/GoogleAnalyticsClientDotNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}");

// If you install .NET Standard version, must setting DefaultUserAgent property
service.DefaultUserAgent = "{default user agent}";

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 or .NET Standard, 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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages