Google Analytics

Tag Manager: Fire Tag Only if CSS Class is Absent

I finally stepped away from Google Analytics and implemented Plausible's cookie-free tracking on the blog. Ironically, to implement Plausible's code, I used Google's Tag Manager (this doesn't compromise Plausible's code in any way; I just think it's sad that Google is still a crutch for my dev-ops). Since Plausible doesn't gather Personally Identifiable Information (PII), though, excluding my own usage on the site becomes a slight challenge; Google Analytics let's you exclude data based on IP--but, that's not an option with Plausible. With the help of Tag Manager, however, I can prevent Plausible's code from loading based on whether a CSS class is present on a DOM Element. When logged into Drupal, there are any number of CSS classes that are unique in the DOM. This provides a simple solution to excluding my own usage from Plausible's analytic data. Here's how to do that.

Step 1: Finding Unique Classes in the DOM

This technique isn't limited to excluding analytics tags. By finding unique classes in the DOM, you can setup both exclusion and inclusion rules for Tag Manager to fire a tag of any type. This is actually a pretty powerful ability. In my case, though, I need to find a CSS class (or classes) in the DOM that only appears when I'm logged into the blog. Drupal adds these kinds of classes throughout the DOM, but the most logical candidate, for me, is a class in the <body> tag.

Obtaining Cookie Consent with Tag Manager

Here's a simple way to ensure users opt into your site cookies; you won't even break a sweat!

The European Union is ahead of us when it comes to protecting your data on the web. I have a feeling we'll eventually see legislation here in the US, as well, mandating that we be a little more forthcoming with how readily we invade consumer privacy. The General Data Protection Regulation (GDPR) employed in the EU, however, has meant that sites there are now required to obtain free consent from their users in regard to cookies.

WTF is a Macro? Passing Variables to Tracking Code

A marketing company says they want to pass a "macro" to their tracking script, and that only I can do it. Tag Manager and JavaScript are the answer.

I've never pretended Analytics was my forte; I can handle it, but it's not where most of my energy winds up directed. Like all developers, though, I'm a pro at leveraging Google and StackOverflow to fill in the gaps. Still, every now and then, these vast fonts of wisdom fail to deliver and I come that much closer to developing chronic ulcers.