Ga Dot Net

GaDotNet is an open source library designed to make it easy to log page views, events and transactions, through code, without using JavaScript or even needing to have a browser.

Index:

  1. Download
  2. Built in tracking image handler
  3. API usage
  4. Single page view usage
  5. Single page view with image usage
  6. Event tracking
  7. Setup

Introduction

As this project is still in beta, i am only going to support page views for this release, but events and transactions are coming very soon. Additionally, it is lacking any testing, so this will come very soon too.

Potential scenarios where this library can come in handy:

  • When you want to log page views for things that normally' can’t – like web service calls, win forms application usage etc.
  • When you replace page views with Ajax calls, but still want to log the Ajax action as a second page view
  • If you want to use Google analytics to log non-website information, such as offline transactions, product catalogue statistics or store purchases.

Download Version 1.2

Download library from GitHub

Download using NuGet (coming soon)

Built in tracking image handler

If you are looking to track your FaceBook fan pages, or any other place you want to track a page view but only have the ability to link an image, but not insert the Google Analytics JavaScript.

<img src="/tracker.asmx?domain=mydomain.com&pagetitle=My%20Page%20Title&url=/my-page.aspx" />

Easy to use, simple API

To log a page view is very simple

Simple page view usage: 

If you simply want to log a page view, create a page view object and track it.

GooglePageView pageView = new GooglePageView("My page title",
                                "www.mydomain.com",
                                "/my-page-url.html");
TrackingRequest request = new RequestFactory().BuildRequest(pageView);
GoogleTracking.FireTrackingEvent(request);

 

Page view tracking with image usage (log with GA and stream /spacer.gif)

If you want to track a page view and then stream an spacer gif.

GooglePageView pageView = new GooglePageView("My page title",
                                "www.mydomain.com",
                                "/my-page-url.html");
GoogleTracking.TrackPageViewWithImage(HttpContext.Current, pageView);

Event tracking

Logging events is just as easy

int? eventValue = 100;
GoogleEvent googleEvent = new GoogleEvent("mydomain.com",
    "Event Category", 
    "Event Action",
    "Event Label",
    eventValue);

TrackingRequest request = 
    new RequestFactory().BuildRequest(googleEvent, HttpContext.Current);

GoogleTracking.FireTrackingEvent(request);

Setup

Simply download the library, reference the DLL GaDotNet.Common in your application, set your Google Analytics Account code in the app settings of your web.config or app.config and you’re done.

    <appSettings>
        
        <!-- Google Analytics Account code (in format UA-XXXXXX-X) -->
        <add key="GoogleAnalyticsAccountCode" value="UA-599999-9"/>
        
    </appSettings>