Closed Jericho closed 9 years ago
It's certainly possible although you'd likely want to exclude a bunch of tracking stats such as screen resolution etc.
Background requests could be dispatched to GA with QueueBackgroundWorkItem and you'd have to decide whether you wanted the concept of a user/session. If so you'd need to fake that out - the simplest would be to hash the session id and not worry about returning/new visitors or set your own cookie.
I'd start with what I wanted to see in GA and how it would look and work back from there.
Hello @damieng . I need GA for ASP.NET too but I am afraid I don't really understand your comment. Is it or is it not possible to use CSharpAnalytics in ASP.NET projects (ASP.NET MVC in particular)? I can see there's a BaseAutoMeasurement sub-class per platform but there isn't one for ASP.NET.
What information are you trying to track in GA that you would want to send from the server via MVC?
If you want to track visitor data like screen resolution etc. then putting the GA Javascript code in your page is the best option. The reason for this is that a web server simply doesn't have access to a lot of this information (screen res, flash version, java installed, visitor cookie, etc)
If instead you wanted to track say WebAPI usage and didn't care about visitor specific data like screen res and visitor/new user then all you'd need to do is to create a class that would dispatch the background queue to GA.
@damieng I need to track arbitrary info using GA events (an example at https://developers.google.com/analytics/devguides/collection/android/v4/events).
If all the data you want is server side all you really need is an implementation of the background request sender that uses ASP.NET's QueueBackgroundWorkItem infrastructure and a bit of code to handle starting that up and shutting it down by hooking into the ASP.NET event system.
@damieng are you talking about the implementation of BaseAutoMeasurement or do I have to make other changes as well?
The point of AutoMeasurement is to provide a simple one-stop automatic system for that platform. If there are no events built-in to ASP.NET MVC you want to track (app start, session start, request start etc). then it's not quite what you want.
What you need are two classes:
I think what I need is simpler than either. I only need to construct an event - category, label, action - and manually send it - for example, on a clicked button. Here is a code example (for Android): https://developers.google.com/analytics/devguides/collection/android/v4/events#implementation . Can CSharpAnalytics do it?
You can create a URL for an event quite easily.
e.g.
// Get tracker
var t = new MeasurementUriBuilder(myConfiguration, new SessionManager(), new MyEnvironment());
// Build an Event URI
var uri = t.BuildUri(new EventActivity("Hello", "There"));
// TODO: Make a HTTP request to that Uri without blocking this request
@damieng thank you very much, I'll definitely try it.
I've just seen SessionManager does not have an empty constructor. What SessionState and sample rate do I need to pass?
Just pass null and 100.0m into the constructor
Thank you.
Has anybody considered adding support for ASP.NET projects so we track our server-side C# code in webform and/or MVC applications?