Erik Zaadi

The tales of a developer with passion for dad jokes

Google Analytics.NET

Prelude [skip]

I’ve been using Google Analytics for a while now, both for this blog and my projects site, and as many others I think the service is great.

While creating my project site, I wanted to make sure that the site had graceful degradation, especially that the site would be accessible without javascript.
This introduced a new problem for me, even though visitors with javascript disabled where able to see the site rendered, their visits where not tracked in Google Analytics.

I stumbled upon a solution by Remy Sharp (see here), in the form of a plugin written in PHP for the popular WordPress blog engine, and with his permission I ported it to a .NET solution.

So what does this project do?

It generates a snippet that includes not only the regular Google Analytics script, but also a small <NOSCRIPT> tag with an image loaded from Google’s servers, with parameters about the current request.

The result:


The visitor with a javascript disabled browser is tracked, and appended with “[NOSCRIPT]” for easy identification in the dashboard.

Project Components

The project includes three basic components:

  1. Core Engine
    Generates the snippets, either separately (for the NOSCRIPT, and the script), or the entire snippet

  2. ASP.NET MVC Html Helpers

<%= Html.GoogleAnalytics("UA-xxxxxx-x"/* Google Analytics Account ID */)%>  
  1. ASP.NET Web Forms
<GoogleAnalytics:GAControl ID="GAControlID" runat="server" GoogleAnalyticsID="UA-xxxxxx-x" />  

There’s also a small sample site, with both ASP.NET MVC and ASP.NET Web forms samples.

Where can I get it?

Visit the project page for more details.



Share on: