• Hey all,

    I have only variable products in my store. I have choose a default variation for all products to trigger the event “gtm4wp.changeDetailViewEEC” everytime a product page is loaded.

    Now I want to track this event with facebook:

    fbq('track', 'ViewContent', {
        content_type: 'product_group',
        content_ids: ['1234'],
    });

    The problem I have is that I cant get the parent product ID, which in my case is the product_group Id from the datalayer. Everytime the Details View Events fires I got the ID of the product variant.

    Does anybody can help me with that?

    • This topic was modified 3 years, 9 months ago by betzebu.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    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.

    Thread Starter betzebu

    (@betzebu)

    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?

    Plugin Author Thomas Geiger

    (@duracelltomi)

    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’

    Thread Starter betzebu

    (@betzebu)

    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!

    Plugin Author Thomas Geiger

    (@duracelltomi)

    Could you post the URL of the site where you added this hook?

    Thread Starter betzebu

    (@betzebu)

    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.

    Thread Starter betzebu

    (@betzebu)

    Hey Thomas,

    do you have an idea for that?

    greets 🙂

    Plugin Author Thomas Geiger

    (@duracelltomi)

    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

    Thread Starter betzebu

    (@betzebu)

    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?

    Thread Starter betzebu

    (@betzebu)

    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 🙁

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Parent Product ID in DataLayer’ is closed to new replies.