Reputation: 1994
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
2.) The code generating the event
3.) The captured GTM event in a debug extension
4.) The captured GA4 event in the same extension
5.) The Tag in GTM
6.) The Variable in GTM
7.) Custom Dimensions in GA4
Upvotes: 0
Views: 2491
Reputation: 1
GA4 is like a canned product still in the process of being more mature for custom tracking requirements. While it meets most of the needs, for some requirements it would need some amount of repurposing the events that GA4 provides. Your option would be to find the closest match of GA4 defined events and keep the syntax as specified in its developer documentations.
Looking at your requirement, I believe it can be met with the Recommended Event "view_item_list". Check this documentation link - https://developers.google.com/analytics/devguides/collection/ga4/reference/events?sjid=17580754313119131924-EU&client_type=gtag#view_item_list
The data layer you have defined would need to be modified to have it exactly in the format required for this event.
You will have to rework the list_items into items array with corresponding parameters for each item. Note that the item parameters will need to be exactly as specified in the documentation.
It might also help to note that GA4 does not support array values in any custom defined events so far. If you want to pass array values, you would need to use one of the Recommended events in the specified syntax. Hopefully, GA4 will have the option in future updates.
Let me know if this works out.
Upvotes: 0
Reputation: 8111
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:
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.
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.
Upvotes: 1