Hi,
This is currently not possible with GTM4WP since it does not include the parent ID in the data layer.
Do you have experience with JavaScript codes? With some JS “magic” you could get the parent product ID from the HTML code of your site.
Hey Thomas,
thanks for your response. I would rather solve this via a PHP Filter.
Do you offer a filter which I can use to get the parent product ID and then write it into the data layer?
Sure, you can use the gtm4wp_eec_product_array
hook. It has two parameters:
#1 is an array with the product data directly
#2 is the context, like ‘purchase’, ‘cart’, ‘productdetail’, ‘addtocartsingle’, ‘widgetproduct’ or ‘productlist’
Hi Thomas,
Thats my current try, which does not work:
add_filter( 'gtm4wp_eec_product_array', 'add_parent_product_id_datalayer', 10, 2 );
function add_parent_product_id_datalayer($dataLayer, $context){
$dataLayer['parent_product_id'] = '9999';
return $dataLayer;
}
Im testing the datalayer with GTM, but there is no “parent_product_id”.
Thank you so much!
Could you post the URL of the site where you added this hook?
Sure: Son Juliana
I found the ID 9999 in the source code of the page – that worked. But I want to have it into the ecommerce data layer to use with GTM.
Hey Thomas,
do you have an idea for that?
greets 🙂
I can not see this data layer variable 🙁
Why don’t you just override the id variable?
$dataLayer['id'] = '9999';
… though that would impact GA tracking as well
Hey Thomas,
thanks for your idea. I tried to overwrite [‘id’]. But 9999 is now set as the product id of the products impressions.
Not within the detail: { products: [
or items: [
here the normal id is still set. 🙁
From my point of view the best solution would be to add a data layer entry within the “detail: { products:” or “items:” array. So if have the child id ( variant id) and the parent.
The problem I got is that, the new variabel is not written into the data layer, but is added to the source code:
<input type="hidden" name="gtm4wp_parent_id" value="9999">
But thats not helping me 🙁 ..
It seems that the action does not work correctly, do you have an idea?
Hey Thomas,
is their a way to achieve my problem? Can I do something to test it on my own? Actually my hands are tied 🙁