google-analyticsgoogle-tag-managergoogle-analytics-4web-analytics

How do you send an array of items with an event using Google Tag Manager & GA4, BigQuery


I'd like to record & analyze the "impressions" of items in a list (could be products, stores, etc) and they don't fit easily into the eCommerce fields. I generate the event when the page is loaded, add it to the DataLayer and pass the event to GTM. I've tried several variations but the closest seems to be capturing the items in the event, but as a string of 'Object' references. I know there is some step eCommerce uses to convert items to something more palatable to GTM/GA4 but I can't find any documentation on how to do that with custom events. Any guidance would be awesome.

Thanks!

1.) The output captured in BigQuery enter image description here

2.) The code generating the event

enter image description here

3.) The captured GTM event in a debug extension

enter image description here

4.) The captured GA4 event in the same extension

enter image description here

5.) The Tag in GTM

enter image description here

6.) The Variable in GTM

enter image description here

7.) Custom Dimensions in GA4

enter image description here


Solution

  • Essentially, this would have saved you a lot of time: Google Analytics 4 / Custom dimension with multiple values per event

    See whenever you see the [object Object] thing is a telltale sign that JS tries to do "" + {} at some point. That's how JS casts objects to strings. That implies that you're trying to shove an object where only strings are expected.

    Now you essentially have two options:

    1. Solve your problems via strings rather than objects. This is problematic since GA limits the max length of an event property to the very arbitrary 100 chars. Some people use multiple dimensions to store more chars and maybe some ids instead of full names. Obviously, this method implies using ETL to join the dimensions, then parse them out into multiple rows or something akin to that.

    2. Utilize EEC and have your impressions as product views. Probably the only place where GA allows arrays is the items array within ecommerce events. The default items array. Not a custom dimension that you create. Here's the reference: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm

    I hear you, they don't fit easily in the ecommerce fields. Well, GA4 is quite an MVP analytics, so the short answer is: make them fit. Utilize categories for proper structuring. Hacking around like this when using GA4 is normal. It's a free product. It's not exactly a high-level professional web analytics tool. There are proper tools for better analytics, but they are very costly, so hacking around in GA4 is what most do.

    You can pick a harmless looking ecommerce event like you already do, the view_item_list is a good pick. And then instead of using the custom dimensions, follow the syntax reference from Google's doc. Here's the fields reference for that event: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_item_list Seems like only the item id and name are required, so you don't need to pass value or whatever else that could taint reports. And then if you have a flag in one of the items categories, you could completely separate this data from your normal ecommerce reports if needed, so it's not that bad of a hack.