How to solve compatibility issues - Google Tag Manager Enhanced eCommerce and Google Analytics 4

Follow

Comments

10 comments

  • Avatar
    Andrei Leev

    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! 

    1
    Comment actions Permalink
  • Avatar
    MrPaulsky

    @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 

    <a <?php href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">

    To

    <a <?php echo $this->helper('WeltPixel\GoogleTagManager\Helper\Data')->addProductClick($_product, $iterator-1); ?> href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">
    0
    Comment actions Permalink
  • Avatar
    SRG Group

    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?

    0
    Comment actions Permalink
  • Avatar
    Support

    Adam,

    Good point. Already added an option for it starting with version 1.7.3 - August 23, 2018. 

    0
    Comment actions Permalink
  • Avatar
    Vincent Teyssier

    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 ?

    0
    Comment actions Permalink
  • Avatar
    Shaun

    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

    if ($this->isProductClickTrackingOnlyForGtmEnabled())

    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

    <action method="setTemplate" ifconfig="weltpixel_googletagmanager/general/product_click_tracking_layout_update">

    and then the admin user can be explicit about the functionality required and the addProductClick function can stay as is?

    0
    Comment actions Permalink
  • Avatar
    Ian

    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:

    <a href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">

    to

    <a <?php echo $this->helper('WeltPixel\GA4\Helper\Data')->addProductClick($_product, $iterator-1); ?> href="<?php echo $_product->getProductUrl() ?>" tabindex="-1">

    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

    0
    Comment actions Permalink
  • Avatar
    Carr Liang

    Hi Ian,

    Coincidentally, the theme I use is the same as yours, you can try to adjust WeltPixel/GA4/view/frontend/layout/weltpixel_ga4_serverside_select_item.xml instead of what the article says. In my case this works. Hope it helps you!
    Alas... the product is good, but the customer service is not satisfactory.

    0
    Comment actions Permalink
  • Avatar
    Ian

    Thank you Carr, that worked for me! I will see over the coming days whether we get full tracking with the module now.

    Regards

    Ian

    0
    Comment actions Permalink
  • Avatar
    Support

    Hey everyone! Thanks for your interactions with this article! We're glad to see it's helped provide some guidance in overcoming some of the compatibility problems you're facing with 3rd party themes. 

    We've updated the article a bit for increased clarity and have also added some recommendations for overcoming problems that appear when using tracking Product Clicks via the Measurement Protocol functionality in the PRO version of the module. Let us know if you have any other suggestions!

    0
    Comment actions Permalink

Please sign in to leave a comment.