Coder Social home page Coder Social logo

Comments (13)

damieng avatar damieng commented on July 19, 2024

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.

ddobrev avatar ddobrev commented on July 19, 2024

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.

damieng avatar damieng commented on July 19, 2024

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.

ddobrev avatar ddobrev commented on July 19, 2024

@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.

damieng avatar damieng commented on July 19, 2024

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.

ddobrev avatar ddobrev commented on July 19, 2024

@damieng are you talking about the implementation of BaseAutoMeasurement or do I have to make other changes as well?

from csharpanalytics.

damieng avatar damieng commented on July 19, 2024

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:

  1. A class to send the requests in background. This is based on BackgroundUriRequester but would use QueueBackgroundWorkItem instead of Task.Run
  2. 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.

ddobrev avatar ddobrev commented on July 19, 2024

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.

damieng avatar damieng commented on July 19, 2024

You can create a URL for an event quite easily.

  1. 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.
  2. Call the BuildUri method on that builder passing in a new EventActivity with the details you want to track.
  3. 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.

ddobrev avatar ddobrev commented on July 19, 2024

@damieng thank you very much, I'll definitely try it.

from csharpanalytics.

ddobrev avatar ddobrev commented on July 19, 2024

I've just seen SessionManager does not have an empty constructor. What SessionState and sample rate do I need to pass?

from csharpanalytics.

damieng avatar damieng commented on July 19, 2024

Just pass null and 100.0m into the constructor

from csharpanalytics.

ddobrev avatar ddobrev commented on July 19, 2024

Thank you.

from csharpanalytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.