Support » Plugin: GTM4WP » Adding custom variable to product information

  • Hi there,

    First of all I want to thank you very much for this great plugin and the contribution you are offering in this forum. We are using the plugin for quite some time now and are really satsified with it.

    I am currently trying to add a datalayer variable to all product information data (giving out a constant – except from the order confirmation page, but this exception will be added later on), but it simply won’t come out. Could you perhaps have a look?

    Two different filters were used, but neither worked:

    function custom_metric_addition( $dataLayer ) {
      $dataLayer["metric1"] = 0;
      return $dataLayer;
    add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, "custom_metric_addition" );
    add_filter( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, "custom_metric_addition" );

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Thomas Geiger



    Could you just replace the PHP constant to the actual value of the constant? I have seen sometimes weird scoping where those constants did not work as expeced.

    Also the definition of the hook seems to be incorrect: the first parameter is the product data correctly but there is a second parameter which is a string and tells you where the data is being used (detail view, checkout view, purchase, etc)

    add_filter( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, "custom_metric_addition", 10, 2 );


    add_filter( "gtm4wp_eec_product_array", "custom_metric_addition", 10, 2 );

    Thread Starter Christopher Mailänder


    Thank you so much for the quick answer. It is coming out now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding custom variable to product information’ is closed to new replies.