If you successfully followed all installation instructions but notice that extension is breaking your product grid or some user actions are not tracked correctly (ex: product view, add to cart, checkout, ..) most probably issues come from compatibility with the custom theme or 3rd party extensions that are installed on your store and probably alters default Magento functionality for that particular sections. We only guarantee full compatibility of our extensions with default Magento behaviour and our magento 2 Theme Pearl as it's impossible to know how each vendor change default Magento code in their products and the quality of their code.
Solution:
Yes, we have a solution for you. If you are using a custom template and experiencing a conflict, most probably (95% of the cases) the fix presented below will solve your problem.
If you have a customized theme, not our Pearl theme or the default Magento theme, you might need to do the following adjustments if the product listing is customized in your theme, in order to not break your product listing pages and to fully benefit of our GTM and/or GA4 tracking implementation.
As in the displayed screenshot comment out the highlighted area ( this contains the changed product listing from our GTM module, located in
WeltPixel/GoogleTagManager/view/frontend/layout/default.xml
and for GA4 located in
WeltPixel/GA4/view/frontend/layout/default.xml
After this, in your custom listing template (list.phtml) add or replace the following line inside the <a> tag for the displayed image in order to obtain as follows:
a. if you are using GTM:
<?php echo $this->helper('WeltPixel\GoogleTagManager\Helper\Data')->addProductClick($_product, $iterator-1); ?>
So, instead of original Magento code:
<?php // Product Image ?>
<a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
<?php echo $productImage->toHtml(); ?>
</a>
you should now have something similar to this on your list.phtml:
<?php // Product Image ?>
<a <?php echo $this->helper('WeltPixel\GoogleTagManager\Helper\Data')->addProductClick($_product, $iterator-1); ?> href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
<?php echo $productImage->toHtml(); ?>
</a>
b. if you are using GA4 you should obtain something similar to the below section instead of your original product image section:
<?php $ga4Helper = $this->helper('WeltPixel\GA4\Helper\Data'); ?>
<?php // Product Image ?>
<a <?php if ($ga4Helper->isProductClickTrackingEnabled()) :
echo $this->helper('WeltPixel\GA4\Helper\Data')->addProductClick($_product, $iterator-1);
endif; ?>
href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
<?php echo $productImage->toHtml(); ?>
</a>
If the fix doesn't work or you don't manage to implement it properly we advise looking into this issue with a Magento developer in order to identify necessary compatibility adjustments.
----------------
If you are not too advanced with your current project, you can take a look at our integrated solution. It may be more cost / time efficient to use it instead of working on compatibility issues:
Take a look at Pearl Theme that already includes Google Tag Manager , Quick View, Banner Slider, Instagram Widget and 10 other extensions that are already provided with the theme and fully compatible. We created this starting point solution for Magento 2 projects in order for the users to be able to focus on store development instead of compatibility issues. Maybe it's a good alternative for the project you are working on. https://www.weltpixel.com/magento-2-theme-pearl
----------------
Example of category page conflict solving:
Issue:
" I recently downloaded and installed your GTM extension for M2. I have noticed, since installing it, its make over-rides to my product grid look. Can you help fixing this conflict?"
Solution:
"These 2 files were modified:
/mnt/data/home/master/applications/magento/public_html/app/code/WeltPixel/GoogleTagManager/view/frontend/layout/default.xml
/mnt/data/home/master/applications/magento/public_html/app/design/frontend/Infortis/ultimo/Magento_Catalog/templates/product/list.phtml
In default.xml we removed the category product listing template rewrite, our GoogleTagManager module also rewrites the default the listing template
In list.phtml, which is used for the current product listing template, we added the product click GTM tracking code snippet, which was originally introduced in our rewritten template."
Note: At this moment we do not have a conflict free "out of the box" solution for the themes that customize category layout. We are investigating potential solutions, any suggestions from you guys are welcomed.
Comments
7 comments
First of all i would like to thank WeltPixel team for taking time and documenting this issue.
Unluckily I am within those whose theme "product category grid screws up"
By the way, i use "Porto Magento Theme"
In my case product grid when Google Tag Manager is enabled product grid went from 4 rows ended up with 2 rows ( & reconfiguring theme settings didn't help)
So i found this tutorial & managed to comment out code in app/code/WeltPixel/GoogleTagManager/view/frontend/layout/default.xml
By commenting out the code in default.xml (this solved issue with grid)
I'm not a developer but as I understand by commenting out part of a code from module I limited some of its features?
Would appreciate a lot if you could leave a comment on that...
Also i found app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/list.phtml
In my case, it was different from what I saw here, again not a developer but changed it..
From
<?php // Product Image ?>
<div class="product photo product-item-photo">
<a href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">
<?php
if($_category_config['aspect_ratio'])
$productImage = $_imagehelper->init($_product, $image)->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($image_width);
else
$productImage = $_imagehelper->init($_product, $image)->resize($image_width, $image_height);
$productImageUrl = $productImage->getUrl();
?>
<img class="product-image-photo default_image" src="<?php echo $productImageUrl; ?>" alt="<?php echo $productImage->getLabel(); ?>"/>
<?php if($_category_config['alternative_image']): ?>
<?php
if($_category_config['aspect_ratio'])
$productHoverImage = $_imagehelper->init($_product, $hover_image)->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($image_width);
else
$productHoverImage = $_imagehelper->init($_product, $hover_image)->resize($image_width, $image_height);
$productHoverImageUrl = $productHoverImage->getUrl();
?>
<?php if($productImageUrl != str_replace("/thumbnail/","/small_image/",$productHoverImageUrl)): ?>
<img class="product-image-photo hover_image" src="<?php echo $productHoverImageUrl; ?>" alt="<?php echo $productHoverImage->getLabel(); ?>"/>
<?php endif; ?>
<?php endif; ?>
</a>
TO
<?php // Product Image ?>
<div class="product photo product-item-photo">
<a href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">
<a <?php echo $this->helper('WeltPixel\GoogleTagManager\Helper\Data')>getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
<?php echo $productImage->toHtml(); ?>
</a>
Now everything seems to be working fine, but again im not sure if i could messed up some of the modules features whitch i dont see yet. So would appreciate WeltPixels comment alot!
@Andrei Leev Thank you, we had the same problem with Porto theme. So you comment out the part in app/code/WeltPixel/GoogleTageManager/view/frontend/layout/default.xml
And edit the file app/design/frontend/Smartwave/THEME/Magento_Catalog/template/product/list.phtml this way (I'm using a child theme, so I copied the file from the porto parent theme.):
(Around line 70 Porto 3.0.6):
Edit
Is this real, that the official documentation recommends to change the core code of the module? This is not a real solution, only an ugly hack. A composer update, or any plugin update will overwrite the modification...
Why don't you add a switch under config, which can turn on/off these overrides?
Adam,
Good point. Already added an option for it starting with version 1.7.3 - August 23, 2018.
Awesome, I confirm that this is solving the issue for the product click event.
I have Porto as well and I use their filtered product view instead of the regular list, hence you need to apply the fix to the following file:
app/design/frontend/Smartwave/porto/Smartwave_Filteredproducts/templates/grid.phtml (or whatever list you use, ie masonry, side ...)
However that does not solve the issue for the product impression.... any idea which tag I should search for to apply a similar fix ?
I guess you have good reason for cookie purposes to add this conditional to helper addProductClick function, but now those with custom templates can no longer use this method to add product clicks?
WeltPixel\GoogleTagManager\Helper\Data.php line 931 - v 1.10.5
I removed it for now to restore product clicks since cookies aren't an issue for me. If others with custom templates have GPDR requirements they could change this check to isEnabled since that also includes the cookie check.
But I think, cleaner solution for everyone moving forward might be to split the product click functionality by adding a second switch in config -
1. Turn on product click tracking - yes / no?
current - weltpixel_googletagmanager/general/product_click_tracking
2. update templates - automatically (yes) or customise yourself manually (no)?
new - weltpixel_googletagmanager/general/product_click_tracking_layout_update
and update default.xml layout to
and then the admin user can be explicit about the functionality required and the addProductClick function can stay as is?
I'm hoping someone can advise how to solve this issue. I've read all of the above, thanks to all the posters by the way. I'm using Porto theme, v4.0.4 and GA4 Pro.
Using what has been posted above, I have changed:
to
In files:
app/design/frontend/Smartwave/porto_child/Magento_Catalog/templates/product/list.phtml
app/design/frontend/Smartwave/porto_child/Smartwave_Filteredproducts/templates/flex_grid.phtml
app/design/frontend/Smartwave/porto_child/Smartwave_Filteredproducts/templates/grid.phtml
app/design/frontend/Smartwave/porto_child/Smartwave_Filteredproducts/templates/masonry_grid.phtml
app/design/frontend/Smartwave/porto_child/Smartwave_Filteredproducts/templates/owl_list.phtml
app/design/frontend/Smartwave/porto_child/Smartwave_Filteredproducts/templates/side_list.phtml
app/design/frontend/Smartwave/porto_child/Smartwave_Filteredproducts/templates/small_list.phtml
This has restored category pages to how they should appear with setting Measure Product Clicks set to YES. However, if I turn on Enable Measurement Protocol Tracking Configuration, this breaks them again. Can anyone advise?
Thanks
Please sign in to leave a comment.