Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include parent category names to the GA product data. #198

Open
WillBrubaker opened this issue Sep 2, 2021 · 3 comments
Open

Include parent category names to the GA product data. #198

WillBrubaker opened this issue Sep 2, 2021 · 3 comments
Labels
type: enhancement The issue is a request for an enhancement.

Comments

@WillBrubaker
Copy link

4260824-zen

categories being sent to Google are just alphabetized and do not reflect any parent/child structure.

p1630554442116900/1630509117.102700-slack-C7U3Y3VMY

@WillBrubaker WillBrubaker added the type: enhancement The issue is a request for an enhancement. label Sep 2, 2021
@jconroy jconroy added needs investigation The issue/PR needs further investigation. needs discussion The issue/PR requires further discussion. labels Sep 2, 2021
@jconroy
Copy link
Member

jconroy commented Sep 2, 2021

Adding tag for discussion - It's not clear to me whether the hierarchy is needed or what the implications are - might need to do some diving into their docs.

@layoutd layoutd self-assigned this Sep 8, 2021
@layoutd
Copy link
Contributor

layoutd commented Sep 14, 2021

This is confirmed, the categories are retrieved (alphabetically) on Line 168 with get_the_terms():

protected static function product_get_category_line( $_product ) {
$out = array();
$variation_data = version_compare( WC_VERSION, '3.0', '<' ) ? $_product->variation_data : ( $_product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $_product->get_id() ) : '' );
$categories = get_the_terms( $_product->get_id(), 'product_cat' );
if ( is_array( $variation_data ) && ! empty( $variation_data ) ) {
$parent_product = wc_get_product( version_compare( WC_VERSION, '3.0', '<' ) ? $_product->parent->id : $_product->get_parent_id() );
$categories = get_the_terms( $parent_product->get_id(), 'product_cat' );
}
if ( $categories ) {
foreach ( $categories as $category ) {
$out[] = $category->name;
}
}
return "'" . esc_js( join( "/", $out ) ) . "',";
}

They're then displayed in a / separated list (Line 181). So for a product with category Clothing > Hoodies, the script shows 'category': 'Clothing/Hoodies', but if the category is Sportswear > Hoodies, the script shows 'category': 'Hoodies/Sportswear'.

According to the Universal Analytics Enhanced Ecommerce documentation, the categories can and should be shown in hierarchical order:

The category to which the product belongs (e.g. Apparel). Use / as a delimiter to specify up to 5-levels of hierarchy (e.g. Apparel/Men/T-Shirts).

However, in WooCommerce products can have multiple categories. For example, the hoodie could have the categories Clothing > Hoodies, as well as Fan Gear > Real Madrid, in which case the plugin shows Clothing/Fan Gear/Hoodie/Real Madrid, which doesn't give Google Analytics an accurate representation of the category hierarchy.

Conclusion

Reordering the categories by hierarchy would be an improvement, but only for products that are in one category "tree". However, there doesn't seem to be a way to reconcile WooCommerce's multi-category support with the single hierarchical category supported by Google Analytics, so making the changes necessary wouldn't fix the problem for all stores. Is it better for the feature to be consistent (but broken) for all cases, or to work sometimes (but not reliably)?

(For reference, Google Analytics 4 still has a hierarchical design, but with a different syntax that isn't currently supported by the plugin AFAICS: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce#view_item)

@layoutd layoutd removed the needs investigation The issue/PR needs further investigation. label Sep 14, 2021
@jconroy
Copy link
Member

jconroy commented Sep 15, 2021

Thanks for the investigation @layoutd and clear information. Leaving as an enhancement for product to prioritize at a later point.

@WillBrubaker feel free to add to the ideas board to help us gather an idea of customer need.

@layoutd layoutd removed the needs discussion The issue/PR requires further discussion. label Sep 17, 2021
@layoutd layoutd removed their assignment Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants