Software Architect / Microsoft MVP (AI) and Technical Author

Analytics and Big Data, General Development, Tooling

Tracking website events with Google Analytics


Sometimes you want to track specific events that occur in your website and report over these metrics. Whether it be form signups, button clicks or page views, Google Analytics can do this for you.

With a little bit of coding you can easily leverage the reporting power of the Google Analytics dashboards and drill down into how your website visitors are behaving.

In this post, I’ll show you how to implement Event Tracking in your web site and view these in the Google Analytics admin console.  It assumes you have your analytics tracking code from the Analytics Admin dashboard embedded in your site.


Straight from the Google developers site:

“Events are user interactions with content that can be tracked independently from a web page or a screen load. Downloads, mobile ad clicks, gadgets, Flash elements, AJAX embedded elements, and video plays are all examples of actions you might want to track as Events”

How to implement

The code is simple and can be implemented in one call in your ASP.NET web app.


The following table summarises what each parameter means:


With the above in mind, you inject this call to relevant areas of your application that you want to report on.

For example, in my crime mapping prototype, I may want to track Events when a user has switched the heatmap on or off.  The following GA code would let me do this:

function toggleHeatmap() {
            ga('send', 'event', 'Button', 'click', 'heatmap');
            heatmap.setMap(heatmap.getMap() ? null : map);

You can see that that I’ve added a hierarchy Button->-Click->Heatmap.

This makes it easier at the Google Analytics end to drill down into the Events. With this code in place we can move onto the reporting aspect.


To me, Google Analytics is like a space shuttle control panel at times.  There are so many options and endless segments to pick from. To see our new Events being tracked in the GA admin console, you browse to the Behaviour menu and select Events.


Select Overview to show you the following screen which displays the new Events that we’re tracking from the button click.  This report doesn’t update in real time so you’ll need to give it a few moments to refresh with data.



That’s it’s for now.  In part 2 of this post, I’ll show you how you how to connect your Google Analytics reporting data to Microsoft Power BI.  This allows you to quickly create rich visual dashboards which contain all your analytics data.

Get the latest content and code from the blog posts!
I respect your privacy. No spam. Ever.


  1. Hello there,

    My name is Aly and I would like to know if you would have any interest to have your website here at promoted as a resource on our blog ?

    We are in the midst of updating our broken link resources to include current and up to date resources for our readers. Our resource links are manually approved allowing us to mark a link as a do-follow link as well
    If you may be interested please in being included as a resource on our blog, please let me know.


  2. Geraldine Summerville

    Good day!

    You Need Leads, Sales, Conversions, Traffic for ? Will Findet…


    Don’t believe me? Since you’re reading this message then you’re living proof that contact form advertising works!
    We can send your ad to people via their Website Contact Form.

    IF YOU ARE INTERESTED, Contact us =>


Leave a Reply