[![How to Add Event Tracking in Google Analytics 1](https://coma.lv/wp-content/uploads/2025/09/Gemini_Generated_Image_6emha56emha56emh.webp)](https://coma.lv/wp-content/uploads/2025/09/Gemini_Generated_Image_6emha56emha56emh.webp)

# How to Add Event Tracking in Google Analytics

Sep 1, 2025/by [Vadim Pavlovich](https://coma.lv/en/author/djcoma/)

Would you like to track user activity while they are still on your site? You can track page views, referral sources, the time a user spends on a page and much more simply by installing Google Analytics, but for deeper results you will need event tracking. In this article we will show you how to add Google Analytics event tracking in WordPress.

## What Is Event Tracking

Event tracking lets you measure user actions on your site. These actions can be clicks on buttons, video plays, file downloads, form submissions and so on. Say you added a video to a product page and want to find out how effective it is in terms of conversion. Event tracking lets you find out how many users played the video. Another example is AJAX-based form submissions. If you use Gravity Forms or another contact plugin, submitting a form does not turn into a new page view. Using event tracking, you can see how users interacted with the form. The same applies to file downloads: you can track how many users downloaded a file using event tracking, and even which button on the page was clicked most often. Event tracking differs from link tracking in Google Analytics. All of this lets you see how people behave on your site. This in turn lets you choose the right strategy for sales and conversions based on user preferences.

## Getting Started

Before you start, you will need to set up and install Google Analytics on your site.

**Important:** In 2023 Google fully shut down **Universal Analytics** and moved all users to **Google Analytics 4 (GA4)**. The old analytics.js code no longer works.

If your site’s code still contains something like:

<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview'); </script>   — this is **outdated Universal Analytics code**, and it no longer collects data.

Instead, **Google Analytics 4** is now used on all sites. You can install the code directly or through Google Tag Manager.

Example of the basic GA4 code:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX'); </script>

## Creating Your Own Event in Google Analytics

Go to your GA4 profile and click the **Admin** link at the bottom of the left panel. If you have several sites, make sure you are viewing the dashboard of the site you need.

![WordPress](https://coma.lv/wp-content/uploads/2016/12/Ekranuznemums-2025-09-17-052319.png)

In the **Data display** section choose **Events**. Here you can create your own events or edit existing ones.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-17-053017.jpg)

Click the **Create Event** button and set the conditions for the new event. For example, if you want to track a form submission, enter the event name *form_submit* and specify the parameters that will be used to track this action on the site.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-17-055502.jpg)

After the event is created and has been recorded at least once, it will appear in the **Events** section on the **Recent events** tab. Here you can mark it as a **Key Event** (this is what used to be called a *conversion*). After that the event will be shown on a separate **Key events** tab. If necessary, you can also mark the event as **NPA (Non-Personalized Ads)** so that it is not used for ad personalization.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-18-000326.jpg)

## Adding onClick Event Tracking

The simplest and perhaps fastest way to add Google Analytics event tracking is to use the onClick attribute. This method simply sends an event to Google Analytics when a user clicks an element. In this example we will track users who click a book download link. We will add an onClick parameter to the download link using this format.

onClick="gtag('event', 'download', { content_type: 'ebook', content_title: 'Free Ebook' });"

You will need to replace the type, name and label with those that match the conditions of your event. In the end the book download link will look like this:

<a onClick="gtag('event', 'download', { content_type: 'ebook', content_title: 'Free Marketing Ebook' });" href="http://example.com/wp-content/uploads/2025/01/free-ebook.pdf"> Download Free Ebook </a>

When a user clicks the link, an event will be sent to Google Analytics.

**Important:** in WordPress, some themes, plugins or security settings may block inline onClick. To reliably track such clicks and avoid problems with blocking of inline onClick, you can use**Google Tag Manager**, which we will cover next.

## Adding Event Tracking with Google Tag Manager

[Google Tag Manager](https://tagmanager.google.com/) is an online tool that lets you add various tracking codes as tags. You can use it to create tags for tracking events in your Google Analytics profile. The main advantage of using Google Tag Manager is that you will not need to add code to your site manually and you can manage all your tags from one place.

*If your site already has the GA4 tracking code inserted, you do not have to remove it, but keep in mind that the same events may be duplicated.

Once you have successfully added the Google Analytics tag to the tag manager, the next step is to create a new trigger. In this article we will use form submission tracking as the event. Click **Triggers** in the tag manager and then click the **New** button.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-011235.jpg)

You will land in the setup wizard, where you need to choose the event type — for example, **Form Submission**.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-011523.jpg)

In the trigger settings you can choose whether to fire it for all forms or only for some. If you have more than one form on the page and want to track a specific one, set up a filter by form ID or class. To do this, in the **Variables** section click **Configure** and enable the built-in variables **Form ID**and/or **Form Classes**(and, if necessary, other form variables). In the trigger condition use, for example, *Form ID equals contact_form_1* or *Form Classes contains newsletter-form*, so that the tag fires only for the form you need.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-012919.jpg)

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-013001.jpg)

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-013123.jpg)

*Note:* for forms that use AJAX, the standard Form Submission trigger often does not fire. In such cases you can use **Custom Event** for accurate tracking of a specific form. For ordinary forms, you can select a specific form by the ID or class of the <form>, specifying the corresponding condition in the trigger. For Contact Form 7 and other forms whose <form> has no ID or unique class, it is more reliable to use the form’s **action** attribute. In GTM add a condition using the **Form Element** variable with a **matches CSS selector** check and specify a value such as form[action="/contacts/#wpcf7-f42-p43-o1"].

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-050004.jpg)

You can find out the form’s ID, class or action through the browser inspector by looking at the id, class or action attribute of the <form> tag.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-040743.jpg)

After that, create a new tag. In the tag manager click **Tags** and then the **New** button.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-015207.jpg)

Choose **Google Analytics: GA4 Event** as the tag type.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-015921.jpg)

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-020004.jpg)

If you have already inserted the Google tag on your site directly, you do not need to create a separate Google tag in GTM at this step. It is enough to create only the **GA4 Event**for the event you need.

Specify the Google Analytics tracking ID (G-XXXXXXX). You can get it from your Google Analytics profile (go to **Admin → Data collection and modification → Data Streams**, choose your web stream and copy the **Measurement ID** in the upper right corner of the page).

Then set the event name and parameters: specify the **Event Name**, and add the event parameters one at a time via **Add parameter**, entering values such as form_type = contact, form_name = contact_form_1, submitted = true.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-024718.jpg)

For a form submission it will look like this:

**Event Name:** form_submit

**Event Parameters:**

- form_type = contact
- form_name = contact_form_1
- submitted = true

*If the tag configuration shows the message “No Google tag found in this container”, this is normal if you have already installed the Google tag directly on the site. In this case the GA4 Event tag will work without a separate Configuration tag in GTM.

In the next step, choose the trigger you created earlier.

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-024918.jpg)

![WordPress](https://coma.lv/wp-content/uploads/2025/09/Ekranuznemums-2025-09-19-024935.jpg)

Finally, click the **Save** button to save the tag. In the window that appears, enter a name for the tag and click **Save** again. The tag will appear in the workspace. For the changes to take effect on the site, click **Submit** in the upper right corner, enter a version name (optionally add a description) and confirm the publication.

That’s it. Now go to your site and submit the form, then go to **Reports → Engagement → Events** in your Analytics profile, and you will see your event recorded and tracked.

Using the tag manager, you can create different types of events and manage them centrally. It will also save you from editing your WordPress templates or adding code manually.

---

*Our specialization is WordPress website development and maintenance. Contact us for a free consultation — [vadim@coma.lv](mailto:vadim@coma.lv), [+371 29394520](tel:+37129394520)*

---
