duracelltomi / gtm4wp

Google Tag Manager plugin for WordPress
https://gtm4wp.com/
GNU General Public License v3.0
147 stars 96 forks source link

Clicking a product on the product list ignores the link's target attribute #259

Closed robklo closed 1 year ago

robklo commented 1 year ago

Hi @duracelltomi

Our website was implemented in such a way that when you click a product on the products list it should open in a new tab. We've added the target="_blank" to the products links but it still open in the same tab (ignoring the target). When we disable the gtm4wp plugin, it works as expected.

I've debugged the plugin and found following fragments of the js/gtm4wp-woocommerce-enhanced.js file:

if ( ctrl_key_pressed ) {
    // we need to open the new tab/page here so that popup blocker of the browser doesn't block our code
    window.productpage_window = window.open( 'about:blank', '_blank' );
}

(...)

if ( ctrl_key_pressed && productpage_window ) {
    productpage_window.location.href = dom_productdata.getAttribute( 'data-gtm4wp_product_url' );
} else {
    document.location.href = dom_productdata.getAttribute( 'data-gtm4wp_product_url' );
}

Would it be possible to expand the ctrl_key_pressed condition to also include a check for target value?

I can prepare a code fix if that will help.

duracelltomi commented 1 year ago

Thanks for the fix!

robklo commented 1 year ago

Thanks for merging!