Tracking Events in Google Analytics

Custom Variables in Google Analytics

Based on our previous post, “How to begin with Google Analytics”, you now have the power to install Google Analytics and track your users’ interactions with your website. Our next tutorial is all about how to set up tracking events in Google Analytics.

What are Events?

According to the developer’s guide, Event Tracking in Google Analytics 4 allows you to measure a specific interaction or occurrence on your website or app. The content tracks independently from a web page or a screen load. Types of user interactions include:

  • Downloads
  • Mobile Ad Clicks
  • AJAX embedded elements
  • Video Plays
  • and much more


So how do we track our custom events? Here we go…

Implementing Event Tracking in Google Analytics

Let’s start with an example: You want to track any file that is downloaded from your website.

First, go to the Google Analytics dashboard and ensure that the option to track “File Downloads” is active. That can be found under Admin > Data Streams > Web. In the Web Stream options, click on the settings icon & ensure “File downloads” is active. If it is not active, toggle it active and click the blue “Save” button.

What if you only want to track when a specific file is downloaded?

In this case, we will use Google Tag Manager to track only the specific file(s) that we are interested in. Navigate to the Google Tag Manage dashboard and follow Google’s instructions on creating and installing a GTM tag on your website.

When the GTM tag is configured on your site, return to the GTM dashboard and choose “Triggers” in the left sidebar to setup your custom trigger. Near the top-right corner of the screen, click the “New” button. For the trigger type, select “Just Links”.

Set the trigger to fire on “Some Link Clicks”. In the conditional options, select Click URL > contains > your-file-name.pdf
NOTE: When changing the file name, ensure that the extension also matches your file’s extension. For example, if your link is to a .txt file, then the value should be your-file-name.txt

If the “Click URL” option is not available, you may need to activate it by going to Variables > Configure and choosing it as an option. Finally, when you click save, it will ask you to name your custom trigger.

Next, we need to create a tag that the trigger will fire. Navigate to Tags > New, then select Tag Configuration > Google Analytics > GA4 Event. Add your GA4 Measurement ID in the Measurement ID field. Add file_download under the Event Name field. You can also send additional information under the Event Parameters field, such as the file_extension, file_name, and URL.

Under the Triggers section, select the trigger you created in the previous steps. When you save your tag, it will prompt you to give the tag a unique name.

We are finally ready to test our tag! Near the top-right of the GTM dashboard, click the Preview button. In the preview screen, enter the URL of the page that contains your download link and click the Connect button. This should open up the page URL you provided in a new browser tab. 

On the previous tab, ensure that you have a successful “Connected!” message and click the Continue button. As you navigate the site in the tab GTM opened, you will see realtime information generated in the GTM dashboard. When you click your download link, you will see a File Download event file that include the custom tag you created.

Once you are satisfied that the tag is firing, click the blue Submit button in the top-right corner of the GTM dashboard. This will publish all of the changes and start collecting live data.

Tracking Social Interactions

You can track social interactions in this same way. Instead of tracking a download, let’s say that you want to track the number of times your users click on the Facebook “Like” button.

To do so, you can create a Trigger that listens for a button to be clicked that contains “” in the URL. Within the Tag’s Event Name field, you can create a custom event named facebook_likes. Once this trigger & tag are in place, GA4 will begin logging each time a user clicks the Facebook like button and the data will be usable with GA4 reports.

Would you like additional help with Google Analytics? 
Contact AndiSites to see how we can assist you!

You might also like to read all our blog posts about Google Tools.

Share and follow us on social media:
Visit Us
Follow Me

Subscribe now for useful information from AndiSites:

* indicates required

You might also enjoy

How Can We Help You?

We listen. We're different. You'll see.