Giter Club home page Giter Club logo

googleanalyticstracker's Introduction

GoogleAnalyticsTracker

GoogleAnalyticsTracker - A C# library for tracking Google Analytics

Like this project?

via PayPal.

What can it be used for?

GoogleAnalyticsTracker was created to have a means of tracking specific URL's directly from C#. For example, when creating an API using the ASP.NET MVC framework, GoogleAnalyticsTracker enables you to track usage of the API by calling directly into Google Analytics.

Get it on NuGet!

Install-Package GoogleAnalyticsTracker

Example usage

Using GoogleAnalyticsTracker is very straightforward. In your code, add the following structure wherever you want to track page views:

using (Tracker tracker = new Tracker("UA-XXXXXX-XX", "www.example.org"))
{
    tracker.TrackPageView("My API - Create", "api/create");
    tracker.TrackPageView("MY API - List", "api/list");
}

Or without a using block:

Tracker tracker = new Tracker("UA-XXXXXX-XX", "www.example.org");
tracker.TrackPageView("My API - Create", "api/create");

A number of extension methods are available which use the provided HttpContext as the source for URL and user propertires:

Tracker tracker = new Tracker("UA-XXXXXX-XX", "www.example.org");
tracker.TrackPageView(HttpContext, "My API - Create");

Finally, an ActionFilter for use with ASP.NET MVC is available:

[ActionTracking("UA-XXXXXX-XX", "www.example.org")]
public class ApiController
    : Controller
{
    public JsonResult Create()
    {
        return Json(true);
    }
}

This filter can also be applied as a global action filter, optionally filtering the requests to log:

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
        filters.Add(new ActionTrackingAttribute(
            "UA-XXXXXX-XX", "www.example.org",
            action => action.ControllerDescriptor.ControllerName == "Api")
        );
    }
}

License

MS-PL License

Building the source

After cloning the repository, run build.cmd. A folder named "Build" will be created and populated with:

  • Assemblies
  • PDB files
  • NuGet package

Who uses GoogleAnalyticsTracker?

googleanalyticstracker's People

Contributors

joelmartinez avatar maartenba avatar pmarflee avatar

Stargazers

 avatar

Watchers

 avatar

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.