When I developed my Minimal Google Analytics 4 snippet, I thought about preventing it from being blocked by various AdBlockers.
Along with AdBlock Plus, I am also using the DuckDuckGo Privacy Protection extension in Safari. I am using the DuckDuckGo browser on its own as well.
DuckDuckGo, along with restrictive ad blockers, tends to block requests heading to the google-analytics.com
domain. This is done on purpose, and I fully understand that.
This is why I described mitigation techniques (Minimal Analytics 4 - masking (hiding) requests).
This technique allows you to utilize Redirect 200 to mask requests to external domains under your domain.
By implementing a redirect as follows:
/g/collect https://www.google-analytics.com/g/collect 200
Instead of calling the address below in a script
https://www.google-analytics.com/g/collect
I am calling this
https://www.example.com/g/collect
Behind the scenes, thanks to Redirect 200, I am sending requests to Google Analytics that are not blocked by either AdBlock Plus or DuckDuckGo.
This solution, however, has 2 major flaws.
When Google announced that they would force us to move away from Universal Analytics to Google Analytics 4 I wasn’t happy. Due to a lack of alternatives in minimal analytics, loading official (bloated) tracking code that weighs 171kB (in my instance), which is liable for blocking by various AdBlockers, wasn’t something that I had been looking forward to.
I started searching for a solution. Due to the lack of it, I decided, by hit-and-miss approach, to create my own, and I think I did it. It currently weighs 3kB minified (version 1.10). Its main purpose is to track page views (page_view
, session_start
and first_visit
) on our website in Google Analytics 4 property. Since version 1.06 it detects and tracks site searches (view_search_results
), from 1.07 search query (search_term
), from 1.09 scrolls (scroll
) capturing scroll events each time when a visitor gets to the bottom of a page (90% and below) and from 1.10 it got ability to track <a href
links to files with specified extensions (see below) and all these links where there is a download
attribute specified independently of the extension of the file.
My site use cookies 🍪. Read more about it on: Cookies Policy.