Solution for GTM4WP - add_to_cart not send dataLayer

If somone use GTM4WP plugin to send data layer.
And add_to_cart not send datalayer on product page.

wp-content\plugins\duracelltomi-google-tag-manager\integration\woocommerce.php

Change from:

wp_enqueue_script( 'gtm4wp-woocommerce', $gtp4wp_script_path . 'gtm4wp-woocommerce.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );

to:

wp_enqueue_script( 'gtm4wp-woocommerce', str_replace( '/dist/', '/', $gtp4wp_script_path ) . 'gtm4wp-woocommerce.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );

wp-content/plugins/duracelltomi-google-tag-manager/js/gtm4wp-woocommerce.js

// track add to cart events for products on product detail pages (line 250)

Change this line from:

if ( event_target_element.closest( '.single_add_to_cart_button:not(.disabled)' ) ) {

to:

if ( event_target_element.closest( '.single_add_to_cart_button' ) ) {

remove :not(.disabled)

And you have to add CSS:

body.single-product button.single_add_to_cart_button span {
   pointer-events: none;
}

Please vote for this on gtm4wp plugin page:

2 Likes

Hello @MarekKmiecik there is no line of code like

wp_enqueue_script( 'gtm4wp-woocommerce', $gtp4wp_script_path . 'gtm4wp-woocommerce.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );

Did you updated to latest version ? Because I'm looking file and search it but there is'nt


This is latest version.

1 Like

Thank you Marek.
I suggest you to use GTM Kit.

I contacted plugin developer and he made plugin compatiable with bricks.

Regards

1 Like