Product Category for the Analytics Purposes


Now that I have a custom Shop page build with the Layout editor, the next step is to enable Enhanced Ecommerce Analytics on it (In Universal Analytics), and also to feed Google Analytics 4 with Ecommerce data.

For that, I need to push stuff to the Data Layer first using custom Attributes. I don’t have a problem to push stuff like price, product name, etc. Those are all coming from Dynamic data.

However, Custom Attribute data-product_cat="" Needs a value, and that value does not exist in the Dynamic data list. We have to turn on the Looper provider for the terms to get them. That does not work with Analytics.

I have checked the Storefront theme which is kind of the default WC theme with correct semantics: it has no issue pulling the Product category as a value for the custom attribute.

Honestly I don’t see any other way to push the Product category into Google Analytics, from the Custom Product page.

In Google Analytics 4, that would be the item_list_name parameter.

My questions are;

Will it ever be possible to query at least the primary product category and get it as dynamic data? If not, that could become an issue in building professional solutions.

On the Shop Index page and also anywhere where product lists are outputted, there is another piece of data that is often used in Analytics, but I haven’t found a way to get it dynamically: data-product_listposition="". This is the position of the product in the list. If it is first on the list, the value is 1, and so on. Would it be possible to retrieve this data dynamically?

Thank you!

PS: When adding a product to cart using the Product form element, the category is being read. The issue is when adding it using the Ajax Add to cart button element.

I have noticed that you have added the class single_add_to_cart_button to this button. However, according to Woocommerce specs, that class is only for the Archive Add to cart buttons. On a Single product page, the class should be single_add_to_cart_button. When I change the class to this, the Ajax animation is not working, despite the other classes ajax_add_to_cart productherobtn are still present.

Hey @Misho,

This is best answered by our core developer, Alex. I’ll forward this to him.

Please stay tuned.


1 Like