GoogleAnalyticsTracker
GoogleAnalyticsTracker copied to clipboard
No documentation for setup on ASP.NET Web API
There is no documentation for how to setup GoogleAnalyticsTracker on ASP.NET Web API.
I'll write down few tips on how to set it up
Thanks, it would nice with information on how to ensure it is properly setup and actually working though.
And if this can be verified in testing environment too or only in production environment.
@vanillajonathan you can create an attribute and decorate all classes you need to track or just create a base class and decorate it.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class GoogleAnalyticsTracking : ActionTrackingAttribute
{
public GoogleAnalyticsTracking() : base("UA-XXXXXXXX-Y")
{ }
}
[GoogleAnalyticsTracking]
public class ApiBase : ApiController { }
Yes, but how and what to do to Startup.cs, Global.asax, etc.
How to register it globally, or on all /api/* routes.
Do you have an example to share of the above GoogleAnalyticsTrackingAttribute combined with a custom IAnalyticsSession to track user sessions? I don't know where to start with creating the custom IAnalyticsSession let alone combine it with the api controller attribute.
Thanks!
@vanillajonathan you can set it globally like MVC does.
http://stackoverflow.com/questions/8786192/asp-net-mvc-register-action-filter-without-modifying-controller
@tmulholl you can invoke its base constructor passing Tracker object which naturally accepts an IAnalyticsSession.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class GoogleAnalyticsTracking : ActionTrackingAttribute
{
public GoogleAnalyticsTracking()
: base(new Tracker("UA-XXXXXXXX-Y", null, new MyCustomAnalyticsSession(), new AspNetWebApiTrackerEnvironment()))
{
}
}
How is this going? Has any documentation been written yet?
What should be inside the "MyCustomAnalyticsSession" class?
I am getting this error also. Looks like it takes string, string, string, string.
The best overloaded method match for 'GoogleAnalyticsTracker.WebApi.ActionTrackingAttribute.ActionTrackingAttribute(string, string, string, string)' has some invalid arguments
This seems like a really cool project... It's just too bad that I have absolutely no idea how to use it, because there is no documentation.
What is an "tracker environment" and how do I create one?
How do I track users?
How do I send a Goal Event?
Tons of potential, just needs documentation!
With GoogleAnalyticsTracker.WebAPI2 I use the following code to setup a global action tracking filter for all controllers in the /api/ path.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.Filters.Add(new ActionTrackingAttribute(
"UA-XXXXXXX-XX", action => action.ControllerContext.Request.RequestUri.AbsolutePath.StartsWith("/api/")));
}
}