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

DataLayer BUG in variable product #339

Open
micmaf opened this issue Mar 22, 2024 · 7 comments
Open

DataLayer BUG in variable product #339

micmaf opened this issue Mar 22, 2024 · 7 comments

Comments

@micmaf
Copy link

micmaf commented Mar 22, 2024

Hi everyone,

For variable products there is a big problem in the latest versions of this plugin (1.20.0 and 1.20.1). Version 1.19.1 works.

When we have the variable product, the plugin do a strange merge of the fields and send principally the fields of the product root/parent.

This is the current DataLayer (wrong):

{
    "internal_id": 4269,  // this is the ID Parent - The position is wrong
    "item_id": 4269, // this is the ID Parent - The position is wrong
    "item_name": "Product Name",
    "sku": "ParentSKU", - The position is wrong
    "price": "22.90", 
    "stocklevel": 8,  // This is the stock of the Parent Product...  I leaved this info when it was a single product - It's wrong
    "stockstatus": "instock",
    "google_business_vertical": "retail",
    "item_category": "Product Category",
    "id": 9255, // this is the variation ID - The position is wrong
    "variant": "quantita-250-ml" // It's correct
}

My correct data are:
The ID variation: 9255
The ID parent: 4269
The variant: "quantita-250-ml"

This bug has already been reported several times, but has not been fixed. It has been present for about a month.

@micmaf
Copy link
Author

micmaf commented Mar 22, 2024

I think I've fixed the issue. File: /plugins/duracelltomi-google-tag-manager/dist/js/gtm4wp-woocommerce.js

`
o.price = gtm4wp_make_sure_is_float(o.price),
o.item_id = e.variation_id,

`

I have changed from o.id to o.item_id. Now the js script works. Please can you do to check if this solution is valid?

@duracelltomi
Copy link
Owner

Thanks for the report and for the suggestion.
I added the fix: 2acafeb

I will do my best to release this tomorrow

@micmaf
Copy link
Author

micmaf commented Mar 27, 2024

Great! Thank you

@micmaf
Copy link
Author

micmaf commented Mar 27, 2024

I have a question: what is "internal_id"?

If this field is the product ID (example if we choose to use the SKU value as item_id) we need to fix this field too, because now we send the parent ID when we have a variable product.

@StSaens
Copy link

StSaens commented Mar 29, 2024

The SKU that is currently being reported is also the wrong one. It picks the parent's SKU, while it should pick the variant's SKU.

I think it's best to stay with Google's standards: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtag#view_item_details

item_id: "SKU_12345"
item_variant: "green",

Google does not mention an 'id' or 'internal id'. So I guess @duracelltomi can make a definition for those?

What are the definitions as currently intended?
id = parent or variant?
item_id = parent or variant? (i'd say variant sku, per google)
item_variant = variant (id or sku)?
internal_id = ?

In woocommerce a variable product (=(parent)product with variants, https://woo.com/document/variable-product/?aff=56839) has:
parent product:
id: 25 (usually the wordpress post id)
sku: abc (although on parent level you generally can't buy the parent, so the sku is a bit of a dummy)

variant/variation product:
id: 35 (usually the wordpress post id)
parent_id: 25
sku: abcdef2
atrributes: color, size, etc

@duracelltomi
Copy link
Owner

Google documentation does not say you can not add extra keys into the ecommerce items array. In fact, this is how you can define item scoped custom dimensions: https://support.google.com/analytics/answer/14239695

internal_id is needed in some setups to always see the product ID even if you decide to report the SKU in the item_id field.

id is there because of a possible miscommunication within Google as in Google Ads they decided to use almost the same event structure as with GA4 but instead of item_id, they are using id to store the product ID: https://support.google.com/google-ads/answer/7305793

So if you want to use the items array to fill both GA4 and Google Ads with product data, both item_id and id needs to be there. If you are not registering the "id' parameter in GA4 as an items scoped custom dimension, it will not harm anything however Google Ads will be able to read the same data and provide dynamic remarketing functionality.

I am looking at the SKU issue and reviewing how GTM4WP processes variable and grouped products.

@duracelltomi
Copy link
Owner

This should fix all issues: cae6a76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants