Showing posts with label google-tag-manager. Show all posts
Showing posts with label google-tag-manager. Show all posts

Feb 12, 2024

Understanding the gcd parameter in GA4 network requests

I have a problem: I don't remember things :) That's why my Google Calendar is full of memos even for personal stuff I'm supposed to remember. 

Given this premise, you can probably imagine how much I hate the new gcd parameter, the parameter associated with Consent Mode v2 - populated with consent for the new signals ad_user_data and ad_personalization

The gcd parameter in GA4 network requests

For those who don't know what I'm talking about, I strongly recommend having a look at this guide on the Simo Ahava's blog authored by Markus Baersch, to get a deeper understanding of Consent Mode v2 and the gcd parameter. 

For the sake of this post, I will summarize here the main components of this parameter. The value passed in the gcd parameter consists of: 

  • first two integers, e.g. 11
  • followed by a letter to represent the status of the ad_storage consent signal, for instance p
  • followed by another integer separating the above consent signal from the next one, e.g. 1
  • a letter to represent the status of the analytics_storage consent signal, e.g. another p
  • integer, e.g. 1
  • letter - e.g. p - for the ad_user_data consent signal
  • integer, 1
  • letter - p - for the ad_personalization consent signal
  • finally, another integer to close the string, for instance 5.

Taking the above example, the value passed in the gcd parameter would be 11p1p1p1p5

I don't know what people think about this parameter but I find it a bit confusing and the meaning of the letters representing consent signals is hard to remember since they are not limited to the p I 've used in my example: There are 9 of them!

How beautiful is the gcs parameter instead

The good old gcs parameter is instead straightforward in my opinion since it uses binary numbers to represent the two main consent signals ad_storage and analytics_storageIt's dead simple:
  • G1 is always there, thus can be ignored
  • then there's the ad_storage consent signal, either 1 if it's been granted or 0 if not
  • finally there's the analytics_storage consent signal, again 1 or 0 wheter consent has been given or not.
How simple is that? I immediately read that, for instance, G101 means analytics_storage is granted while ad_storage is not, and so on for any other possible combination.

The trick I found to remember how to read the gcd parameter 

Serendipity, as usual, has shown me the way again this time. I was playing with a table taken from the guide I mentioned on Simo's blog, when sorting the rows on Google Sheets I realized there was a pattern.

The table taken from Simo's blog (credits)

A simple alphabetical sorting in the Letter column unveils there are 3 letter groups: 

  1. the 1st letter group (l, m, n) represents consent signals where the default command is not recorded altogether
  2. the 2nd one (p, q, r) represents consent signals where the default command sets to denied
  3. the 3rd one (t, u, v) represents consent signals where the default command sets to granted.
Then, each letter of each letter group represents the consent signal after the update command has been executed. Therefore:
  1. letters in the 1st position (l, p, t) represent consent signals where the update command is missing 
  2. letters in the 2nd position (m, q, u) represent consent signals where the update command sets to denied
  3. letters in the 3rd position (n, r, vrepresent consent signals where the update command sets to granted.

I know this can still be a bit confusing so the table below is worth a thousand words.

The table that helped me understand how to read the gcd parameter

Conclusions

I guess there are other people who already found that pattern and are using it to read the gcd parameter. Some other people are instead ignoring this topic altogether. 

However, I hope there's someone else who will find this tip useful for the day by day debugging.

Nov 5, 2023

Custom Event named as an Automatic Event will duplicate events in GA4

Some days ago I found a question on Reddit asking what happens when Custom Event and GTM GA4 Event have the same event_name? To be honest I wasn’t sure - as I wanted to be - about the answer so I decided to do a pretty simple test I will show in the next lines.

The most complete guide I’ve found about duplicate events in Google Analytics 4 is of course someone by Julius: https://www.analyticsmania.com/post/duplicate-events-in-google-analytics-4-and-how-to-fix-them/.

Unfortunately, that wasn’t enough for what I wanted to prove, so I hope I can help someone sharing how I tested it, precisely tackling the question.

How I set GTM to duplicate an automatic event

First things first, I set a GA4 event tag on Google Tag Manager replicating an automatic event. I’ve chosen the GA4 event page_view, but it could have been anything else.

Triggers were exactly the same to be sure they fired at the same time (see snapshot below).

The Google Tag - sending a page_view - and the parallel custom GA4 page_view event I set](https://prod-files-secure.s3.us-west-2.amazonaws.com/32360bfe-b1bd-4ec9-9e24-4f0ea3b3f0f2/5c18cac9-ef46-49c7-99f7-d7b7d47f0fdf/Screenshot_2023-11-04_11.28.18.png)  The Google Tag - sending a page_view - and the parallel custom GA4 page_view event I set
The Google Tag - sending a page_view - and the parallel custom GA4 page_view event I set

The GA4 event tag was set by adding just a custom parameter to let me easily recognize what I was looking at in the DebugView.

The GA4 event tag is set with a custom parameter foo with value bar
The GA4 event tag is set with a custom parameter foo with value bar

Results: Will both automatic and custom GA4 events fire?

I haven’t published my new version of the GTM container but simply used the Google Tag Assistant to test the results in the GA4 DebugView.

The results were straightforward. Both the automatic page_view and the custom page_view were fired. The first page_view event was the automatic one while the second contained the custom parameter foo.

page_view automatic event automatically created by GA4
page_view automatic event automatically created by GA4

page_view custom event with custom parameter foo
page_view custom event with custom parameter foo

Here we go, a complete test to successfully prove what happens when automatic events get duplicated with custom ones. There’s no deduplication on Google’s side, so look out!

Aug 4, 2023

How to convert the Google Tag Manager JSON to a spreadsheet overcoming Excel limits with KNIME

Most of the time you can easily convert a Google Tag Manager JSON file to an Excel one with some free tools.

The best tool of this kind is probably the Google Sheets extension “GTM Tools” by the almighty Simo Ahava.

Unfortunately, the free superpowers of this add-on can encounter some bitter moments where things go wrong, as well as any other tool.

The issue with Google Sheets characters limit in a single cell

I was trying to wrap my head around a GTM setup so I decided to use GTM Tools to simplify the overview of tags and triggers.

During the processing phase of the GTM container assessed, I got a strange error message breaking the workflow.

The error message raised by GTM Tools Google Sheets extension

The issue is that one of the tags was more than 50k characters long - I know that sounds crazy - which is the maximum limit of chars available in Google Sheets!

KNIME to the rescue… maybe

I’ve used KNIME in the past to automate some tasks. One of the most interesting stuff I published in KNIME Hub was a simple workflow taking a GTM JSON file and converting it to an Excel one.

I must be honest, I’ve usually preferred GTM Tools since it’s a bit more hassle-free, a couple of clicks and you’re there. In this case, I thought my little KNIME application using Excel instead of Google Sheets could have made my day.

Unfortunately that was not the case since Microsoft Excel has got its own limit of 32k characters which is even less than the Google Sheets one!

The error message raised by the KNIME Excel Writer node 😟

How I made it work

The easiest way I found to make it work, was to edit the KNIME application looking for a way to split into multiple columns the cell content related to the infamous tag, before the Excel Writer node was run.

Here below is how the workflow appears after adding a couple more KNIME nodes: The Cell Splitter By Position node - in charge of splitting the content - and the Column Filter node - used to remove the original column with the extra large content to split.

The final KNIME workflow with the Cell Splitter By Position and the Column Filter nodes in the 3rd branch

In particular, to make it work, I set 4 split indices to split the content when it reaches 30k, 60k, 90k or 120k characters.

For each split the node will create a new column. The original column coming from the GTM JSON was named Details so I decided to just name them Details1, Details2 and so on, Details5 being the last one at the 4th split.

Configuration of the Cell Splitter By Position node

The table previews generated by KNIME are quite straightforward about the results of the node.

The table preview before applying the Cell Splitter By Position node
The table preview after applying the Cell Splitter By Position node (we will remove the original Details column with the next node)

And that worked like a charm. Now my GTM JSON file perfectly fits a simple Excel file!