Skip to main content
Posts with Tag

Engagement

When Google announced that they would force us to move away from Universal Analytics to Google Analytics 4, I wasn’t happy. The official tracking code is notoriously bloated — weighing in at around 171kB in some instances—and is frequently blocked by various ad-blockers. Given the lack of lightweight alternatives, I wasn’t looking forward to compromising my site’s performance.

I started searching for a solution, but finding nothing that met my needs, I decided to take a “hit-and-miss” approach and build my own. What began as a simple snippet has now evolved into a highly refined, professional-grade tool. With the release of version 1.11 (the “Gold Master”), the script is more robust than ever, while remaining incredibly lean.

The Evolution of the Script

While the primary purpose remains tracking essential metrics like page views (page_view), session starts (session_start), and returning users (first_visit), each iteration has added powerful capabilities:

  • Version 1.06 - 1.07: Introduced site search detection (view_search_results) and search query capturing (search_term).
  • Version 1.09: Added scroll tracking (scroll), firing an event when a visitor reaches 90% of the page depth.
  • Version 1.10: Implemented file download tracking for specified extensions and any links containing the download attribute.
  • Version 1.11 (The “Gold Master”): This latest update represents a total architectural overhaul. It introduces UTM persistence to fix attribution gaps, accurate Average Engagement Time via the Visibility API, and Outbound Link Tracking.

By moving to a dedicated GitHub repository, I’ve also implemented a modern Event Delegation model and Storage Safety Checks to ensure the script runs flawlessly even in strict private browsing modes.

Categories