Comments (13)
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.
from csharpanalytics.
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.
from csharpanalytics.
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.
from csharpanalytics.
@damieng I need to track arbitrary info using GA events (an example at https://developers.google.com/analytics/devguides/collection/android/v4/events).
from csharpanalytics.
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.
from csharpanalytics.
@damieng are you talking about the implementation of BaseAutoMeasurement or do I have to make other changes as well?
from csharpanalytics.
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:
- A class to send the requests in background. This is based on BackgroundUriRequester but would use QueueBackgroundWorkItem instead of Task.Run
- A class to stop and start that queue as well as provide a global entry point in. This could be based on one of the AutoMeasurement classes but without the auto-event stuff or the offline storage of unsent requests.
from csharpanalytics.
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?
from csharpanalytics.
You can create a URL for an event quite easily.
- Create an instance of MeasurementUriBuilder with configuration, session manager and fake/dummy IEnvironment implementation. You can keep this around on a static if you like to make it easier to use.
- Call the BuildUri method on that builder passing in a new EventActivity with the details you want to track.
- Make a http request with that Url.
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
from csharpanalytics.
@damieng thank you very much, I'll definitely try it.
from csharpanalytics.
I've just seen SessionManager does not have an empty constructor. What SessionState and sample rate do I need to pass?
from csharpanalytics.
Just pass null and 100.0m into the constructor
from csharpanalytics.
Thank you.
from csharpanalytics.
Related Issues (20)
- GetEntryAssembly vs GetExecutingAssembly HOT 2
- Build break because of requestUri.ShouldUsePostForRequest() HOT 1
- Exception HOT 6
- Assembly.GetEntryAssembly can be null and causes crashes. HOT 3
- Windows Phone 8.1 Support HOT 1
- Prior requests cause null exception in BaseAutoMeasurement::Request HOT 1
- Exception on Start() HOT 8
- Starting multiple instances of a WPF application at same time throws Exception in Start()
- Add a flag AutoMeasurement.Initialized HOT 6
- Make internal classes public HOT 1
- TrackEvent exchange parameters action and category HOT 1
- Allow to use GA debug URL
- MeasurementAnalyticsClient.AdjustUriBeforeRequest cuts strings with special chars HOT 2
- Setting SetOptOut before Start causes crash
- Support WPF .NET 4.0 Client Profile applications HOT 5
- At one of my testing machines I get an deserializing error
- Session start and session end time stamps registered at GA are very often too late relative to other events HOT 3
- proxy support HOT 1
- Unhandled Exception HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csharpanalytics.