Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No documentation for setup on ASP.NET Web API #104

Open
vanillajonathan opened this issue Apr 21, 2016 · 11 comments
Open

No documentation for setup on ASP.NET Web API #104

vanillajonathan opened this issue Apr 21, 2016 · 11 comments

Comments

@vanillajonathan
Copy link
Contributor

There is no documentation for how to setup GoogleAnalyticsTracker on ASP.NET Web API.

@gandarez
Copy link
Collaborator

I'll write down few tips on how to set it up

@vanillajonathan
Copy link
Contributor Author

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.

@gandarez
Copy link
Collaborator

@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 { }

@vanillajonathan
Copy link
Contributor Author

Yes, but how and what to do to Startup.cs, Global.asax, etc.

How to register it globally, or on all /api/* routes.

@tmulholl
Copy link

tmulholl commented Jun 2, 2016

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!

@gandarez
Copy link
Collaborator

gandarez commented Jun 2, 2016

@gandarez
Copy link
Collaborator

gandarez commented Jun 2, 2016

@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()))
    {
    }
}

@vanillajonathan
Copy link
Contributor Author

How is this going? Has any documentation been written yet?

@mikemike396
Copy link

mikemike396 commented Nov 7, 2016

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

@CyberBill
Copy link

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!

@vanillajonathan
Copy link
Contributor Author

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/")));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants