GoogleAnalytics.App is an unofficial SDK for interacting with Google Analytics. It is compatible with version 2 of the Google Analytics SDK for iOS and Android and uses Google Measurement Protocol to report app- and mobile-specific metrics.
Install-Package GoogleAnalytics.App
The GoogleAnalytics.App API was designed to approximately match that of the official Google Analytics SDKs for iOS and Android. While it currently offers a subset of the features provided by the official SDKs, the hope is that it will grow over time to match the same level of functionality and to grow closer to the APIs offered by the official SDKs.
The tracking functions of the GoogleAnalytics.App API are all performed asynchronously, using the async/await functionality offered by C# 5. The Async Targetting Pack (Microsoft.Bcl.Async) is used to provide this functionality for Windows Phone 7 where async/await are not supported natively.
Tracker is the main object used to report analytics information. Obtain an instance of Tracker, and then call its *Async
methods to track various types of activities.
Initialize a new Tracker instance with the given tracking ID (e.g. "UA-XXXXXX-XX").
Optional. When true, send analytics messages over SSL. The default value for this property is true
.
Optional. When true, send a flag in each analytics message that instructs Google to anonymize the IP address of the sender. The default value for this property is false
.
Optional. When true, the next time a tracking call is made a parameter will be added to indicate that a new session should be started. This flag will then be cleared. When a Tracker is first instantiated, the default value for this property is true
. Set this property to false
before making a tracking call to prevent this default behavior.
Optional. When true, if an error occurs during transmission of an analytics message, throw the exception. When false, if an error occurs during transmission of an analytics message, ignore the exception and return a TrackingResult object. The TrackingResult object will include the originating exception and will have its Success
property set to false
. The default value for this property is false
.
Set the value of a custom dimension for all tracking calls. Each custom dimension has an associated index.
Set the value of a custom metric for all tracking calls. Each custom metric has an associated index.
Track that the specified view or screen was displayed.
async Task<TrackingResult> SendEventAsync(string category, string action, [string label = null], [long? value = null])
Track an event.
Track a transaction.
Transaction is a structure that represents a transaction to report via Tracker's TrackTransactionAsync
method. It contains various properties about the transaction itself, as well as zero or more TransactionItems.
Required. A unique identifier for the transaction.
Optional. Specifies the affiliation or store name.
Optional. Specifies the total revenue associated with the transaction.
Optional. Specifies the total tax of the transaction.
Optional. Specifies the total shipping cost of the transaction.
Optional. A list of items associated with the transaction.
TransactionItem is a structure that represents a single item associated with a transaction.
Optional. Specifies the price for a single item / unit.
Optional. Specifies the number of items purchased.
Optional. Specifies the SKU or item code.
Optional. Specifies the item name.
Optional. Specifies the category that the item belongs to.
TrackingResult is a structure that represents the result of a call to one of Tracker's *Async
tracking methods.
The URL to which the call was made.
The parameters sent during the call.
A flag indicating whether the call was successful.
The exception that occurred during the call, if any. This is only populated when the call fails (Success
is set to false
) and Tracker's ThrowOnErrors
property is also set to false
(the default).
After cloning the repository, run build.bat. You can optionally pass a configuration name (eg. "Release") to build.bat to build a specific configuration, or if not the Debug configuration will be used. When the build completes, the resulting NuGet package and symbol package will be in the build\{configuration name} directory.