.Net library for sending Google Analytics Measurement Protocol requests. This library provides support for creating any type of Measurement Protocol request by using any of the existing Measurement Protocol request parameters. It implements basic validation of the requests and parameters, but before using this library please read Measurement Protocol Developer Guide and Measurement Protocol Parameter Reference for being able to create correct requests.
You can add this library to your project by using NuGet, you just have to type in your Package Manager Console:
Install-Package GoogleMeasurementProtocol
- Create a Page View request
//Create a factory based on your tracking id
var factory = new GoogleAnalyticsRequestFactory("UA-xxxxxxx-x");
//Create a PageView request by specifying request type
var request = factory.CreateRequest(HitTypes.PageView);
//Add parameters to your request, each parameter has a corresponding class which has name = parameter name from google reference docs
request.Parameters.Add(new DocumentHostName("test.com"));
request.Parameters.Add(new DocumentPath("/test/testPath2"));
request.Parameters.Add(new DocumentTitle("test title2"));
var clientId = Guid.NewGuid();
//Make a get request which will contain all informations from above
request.Get(clientId);
//Make a Post request which will contain all informations from above
request.Post(clientId);
- Connection configuration
var webProxy = new WebProxy("http://localhost:8888");
//Create a factory which will create requests that will use https connection through the given proxy
var factory = new GoogleAnalyticsRequestFactory("UA-xxxxxxx-x",true, webProxy);
- Set Agent and Ip info
request.Parameters.Add(new UserAgentOverride("Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14"));
request.Parameters.Add(new IpOverride("1.2.3.4"));
##Exceptions
All exceptions that occur in library will be propagated to the calling thread.
MIT