Event Tracking - Main Image

I was trying to set up Event Tracking (clicks, form submissions etc) through Google Analytics for a website that I was making. I read through Google’s official documentation and found it really hard to understand what they were saying. Finally, after many hours, I realised that the actual process is very simple. So for those out there who just want to quickly set up Event Tracking in your website through Google Analytics, simply follow this. I will explain showing a form submission as an example. But you can use the same process for clicks as well.

To set up Event Tracking in Google Analytics you need to do three things.

  1. Create a Google Analytics Account – I will not explain how to do this. You should already know this. You can set up an account here – https://www.google.co.in/analytics/
  2. Set up a code for your event.
  3. Use this code in your website.

Set up a code for your event

This is the most basic code. You can just copy and paste it and just change the eventCategory and eventAction to whatever you want.

There are many other Field Names you can give based on your needs. But eventCategory and eventAction are mandatory. And remember the names you give for the eventCategory and eventAction can be anything. It’s up to you.

For example, to create an Event Tracking for form submission, you can name the eventCategory as “Form” and the eventAction as “Submission” and your code will be

Use the code in your website for Event Tracking

The next part is what I couldn’t find for a long time. How do I make google know some event has occurred in my site?

Simple – We use JavaScript (Sometimes embedded inside the HTML or PHP code)

I’m going to show you two ways of doing this.

  1. Using onclick event – This is quite straight forward. You add the onclick event (this is a built in event in HTML to execute a JavaScript code when something is clicked). In our case we want to track a form submission event. So to the submit button we just need to add the onclick event with our code. As shown below.

  1. Using PHP – you need to add JavaScript into the PHP to get the event fired. In the code below, when the form submission goes through, the event information is sent to google. The code looks big, but I’ve posted this code to show that the event can happen once the form submission goes through and not at the click event. In the first case, even if the form submission didn’t go through due to errors and only the submit button was clicked the event will be registered.


Simple version to add the code to a “Submit” click event.

If you’re lazy to write the code yourself, you can use the link below to just type in your desired fields and it will generate the code for you.


And below is the official google page that explains Event Tracking. It doesn’t really say how to use the code in your site.


Let me know if this was helpful and also if you need any further help with this.