Google Analytics Ecommerce Events

Track shopping behavior with precision using GA4 ecommerce events without relying on page views or screen recordings. Learn how to capture key user actions for deeper insight.

Ceyhun Enki Aksan
Ceyhun Enki Aksan Entrepreneur, Maker

A brief reminder: we can track user interactions with content—without relying on web page views or screen recordings—through Google Analytics.

These interactions may include actions such as link clicks, form submissions, file downloads, mobile ad clicks, embedded AJAX elements, and video plays.

note

For e-commerce operations related to Google Analytics 4 (GA4), please refer to the article titled Google Analytics E-Commerce Events and Reports.

In previous posts, I have shared various articles about the Global Site Tag (Global Site Tag / GTAG), which enables us to link our website pages to Google Analytics and Google Ads IDs, and use the data we collect for various purposes. The following list summarizes these posts:

The above articles generally include examples and additional notes regarding event usage[^1]. In this article, I aim to expand on these examples and provide further explanations for potential scenarios that may arise. Let’s first review event usage through a concrete example;

function onclickCallback(e) {
  var e = window.e || e;
  if ( (e.target.tagName !== 'A') || (e.target.host == window.location.host) ) return;
  outboundLinkClick(e.target); // GA event tracker
}
if (document.addEventListener) { document.addEventListener('click', onclickCallback, false); }
else { document.attachEvent('onclick', onclick_); }

jQuery(document).ready(function($) {
  $('a[href^="http"]:not([href*="//' + location.host + '"])').on('click', function(e) {
    outboundLinkClick($(this).attr("href")); return true;
  });
});

document.addEventListener('load', function(){
  Array.from(document.querySelectorAll('a[href^="http"]:not([href*="//' + location.host + '"])')).forEach(function(e) {
    outboundLinkClick(this.attr("href")); return true;
  });
});

var outboundLinkClick = function(url) {
  // UA
  gtag('event', 'click', {
    'event_category': 'outbound',
    'event_label': url,
    'transport_type': 'beacon',
    'event_callback': function(){
      document.location = url;
    }
  });
}

Considering the anatomy of an event, as clearly shown in the above examples, each event contains components such as category, action, label, and value. Each event parameter includes a corresponding value. The label and value components are optional.

warning

As of July 2023, Universal Analytics (UA) is being replaced by Google Analytics 4 (GA4).