1

We are trying to find the Measurement Protocol library for .NET in NuGet. We see that there are several third party ones, but find it strange that there isn't an official one from google similar to their Reporting API which they have for .NET.

Does anyone know if an official one exists for the Measurement Protocol for .NET

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
user2981411
  • 859
  • 12
  • 34

2 Answers2

2

While it is true that the Google Analytics Measurement Protocol allows developers to make HTTP requests to send raw user interaction data directly to Google Analytics servers. It could be argued how easy this protocol is to use for the novice Google analytics user.

An easier option for many is to use a library.

Google Analytics SDK for .Net

The closest thing that you will find for a measurement protocol library is the one that I created Google Analytics SDK for .Net after Microsoft deprecated theirs Windows SDK for Google Analytics they are now directing users to use mine.

I suspect that the main reason there isn't an official one is this is google we are talking about and they don't often pick up .net projects on the fly. That and they have me as a GDE and I am a .net developer so it was easier for me to create one.

// Create Web tracker
var tracker = Tracker.BuildWebTracker("UA-9183475-1");
// Create new Page view hit.
var hit = new PageViewHit(tracker, "location", "hostname", "path", "title");

// Build hit request.
var request = (Hitrequest)tracker.CreateHitRequest(hit);

// Debug hit request.
var debugRequest = Task.Run(() => request.ExecuteDebugAsync());
debugRequest.Wait();
Console.Write(debugRequest.Result.RawResponse);
        
// Execute hit request.        
var collectRequest = Task.Run(() => request.ExecuteCollectAsync());
collectRequest.Wait();
Console.Write(collectRequest.Result.RawResponse);

Disclaimer this is an opensource project that I created. I am a google developer expert for Google analytics and I have been a .net developer for 15 years. I do not work for Google or Microsoft.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • @DalmTo. Thanks for your response. But I think as Michele Pisani pointed out above, the best way is to just use the HttpClient and make the request. – user2981411 Aug 17 '20 at 15:46
  • As you wish the client library is there if you need it has been stable for several years now. I have been using it in production myself for four years. – Linda Lawton - DaImTo Aug 17 '20 at 15:54
0

The Google Analytics Measurement Protocol allows you to make HTTP requests to send data directly to Google Analytics servers. So it is a simple URL with parameters to call from your system, you don't need a library.

https://developers.google.com/analytics/devguides/collection/protocol/v1

Michele Pisani
  • 13,567
  • 3
  • 25
  • 42
  • OP asked for a library linking to the measurement protocol http reference isnt exactly a library. – Linda Lawton - DaImTo Aug 17 '20 at 09:28
  • He asked for a library but that's probably not what he needs, as it's a trivial HTTP call. If he had asked for a Google Analytics sdk library it would have been something else. There is often a gulf between what someone asks and what they really need, especially if they are not in the industry :) – Michele Pisani Aug 17 '20 at 10:37
  • I am glad to hear that at least one person finds the measurement protocol a trivial HTTP call. – Linda Lawton - DaImTo Aug 17 '20 at 10:53