Does anyone have any experience with event tracking? (specifically on click)

This tutorial for 'on click' goal setting is confusing to me:

I think this is the tutorial I need, but I don't have a lot of experience with Java Script, is this what I'm looking for?

Dani AI

Generated

A short practical follow‑up to the confusion in the original post from and the helpful context from , and : the usual reason click events (especially outbound links or downloads) “don’t register” is that the browser leaves the page before the tracking hit is sent. Modern approaches solve that either by sending the hit reliably before navigation or by using a background transport so navigation doesn’t block the send.

For manual fixes, two common patterns are:

  • Universal Analytics (analytics.js): use a hitCallback so navigation happens after the event is sent.
  • gtag/GA4: use event_callback and prefer transport_type: 'beacon' so the browser sends the hit reliably.

Example patterns (replace href with the clicked URL):

ga('send', 'event', 'Outbound', 'click', href, {
  hitCallback: function() { document.location = href; }
});
gtag('event', 'click', {
  'event_category': 'outbound',
  'event_label': href,
  'transport_type': 'beacon',
  'event_callback': function() { document.location = href; }
});

For less code and fewer mistakes, use Google Tag Manager to fire click/download tags and let GTM handle timing and retries. GA4 also has different event semantics (name + params vs. category/action/label) so avoid mixing conventions when migrating.

Troubleshooting checklist: confirm the correct tracking/measurement ID is present; check Real‑Time in Analytics; use DevTools network to watch hits to collect or the GA4 endpoint; ensure no JavaScript errors; avoid double-tagging; use navigator.sendBeacon as a graceful fallback for very short navigations (see browser support). Useful references: analytics.js events and GA4 events docs and the MDN page on navigator.sendBeacon for transport details.

References:

Recommended Answers

All 4 Replies

Does anyone have any experience with event tracking? (specifically on click)

This tutorial for 'on click' goal setting is confusing to me:

I think this is the tutorial I need, but I don't have a lot of experience with Java Script, is this what I'm looking for?

Event Tracking is a feature of Google Analytics you use to track different actions visitors take on your website, such as clicking a button or downloading a file. It is useful for tracking actions on your website that don't take the user to a new page (such as clicking play on a video player).

Have you ever set a goal in GA for clicking an outbound link?
I am having trouble following the above tutorial and I'm not sure where I am going wrong.

I think it has something to do with the javascript.

It should be simple!

Event Tracking is a method available in the tracking code that you can use to record user interaction with website elements, such as a Flash-driven menu system. This is accomplished by attaching the method call to the particular UI element you want to track. When used this way, all user activity on such elements is calculated and displayed as Events in the Analytics reporting interface. Additionally, pageview calculations are unaffected by user activity tracked using the Event Tracking method. Finally, Event Tracking employs an object-oriented model that you can use to collect and classify different types of interaction with your web page objects.

By contrast, tracking web page objects using the tracking code requires virtual URL creation and provides no object hierarchy. With the legacy code, user interaction with page objects is calculated and displayed as part of total page views to your site, and no distinction is made between actual and virtual pageviews.

With , you would commonly apply Event Tracking to:

* Any Flash-driven element, like a Flash website, or a Flash Movie player
* Embedded AJAX page elements
* Page gadgets
* File downloads
* Load times for data

This document assumes familiarity with Google Analytics Tracking Code (GATC) configuration. Additionally, you must have the tracking code installed on those pages where you configure Event Tracking as described here. For more information on tracking your site using the GATC, see the Tracking Sites guide as well as the documentation in the Analytics Concepts section of this site.

I have it available on a few of my sites and it works like a charm. I use it mainly to track PDF downloads and Email links.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.