Repository navigation
Conversation
The product page swaps a few blocks over AJAX and pushes a new URL instead of reloading, so displayFooterProduct never runs again: Google Analytics keeps reporting the combination the page was opened with, whatever the shopper switches to afterwards. displayProductAdditionalInfo is one of the blocks that refresh returns, so view_item is now sent from there for the newly selected combination. It is emitted only for that refresh - a normal render still reports once, from displayFooterProduct - and never for quickview, which has never reported. ga_tag.tpl defers to DOMContentLoaded, which cannot fire again in an already-loaded page, so the refreshed block uses a template without it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
displayFooterProduct, which carriesview_item, is not one of those blocks, so Google Analytics keeps reporting the combination the page was opened with for the whole visit.view_itemis now also sent fromdisplayProductAdditionalInfo, which is one of the blocks that refresh returns - only for that refresh, so a normal render still reports exactly once.ga_tag.tplwraps its code inDOMContentLoaded, which cannot fire again in an already-loaded page, so the refreshed block uses a template without that wrapper.view_itemis sent for the default combination. Pick another size or colour: before, nothing is sent and GA still shows the first combination; after, a secondview_itemarrives withitem_id<product>-<combination>and the matchingitem_variant. Opening a quickview still sends nothing, and switching combinations inside a quickview still sends nothing.Measured
PrestaShop 9.2.0, product 1 of the demo catalogue (8 combinations). The shopper switches to combination 3,
M / White, which is what the theme posts asgroup[1]=2&group[2]=8to the product refresh:The page-load count staying at 1 is the point: the new hook returns nothing unless the request is the product refresh, so nothing is double-counted.
Notes for review
page_viewtoo. GA4's enhanced measurement already reports page changes from browser history events, and the theme's combination switch goes throughhistory.pushState(themes/_core/js/product.js). Sending our ownpage_viewwould double-count it. The e-commerce event is the part GA4 cannot infer, which is why onlyview_itemis sent.displayProductAdditionalInfo.ProductControllerreturns a fixed set of rendered partials foraction=refresh, andcatalog/_partials/product-additional-info.tpl- which both default themes render as{hook h='displayProductAdditionalInfo' product=$product}- is one of them. The theme replaces that block with the response, so a<script>inside it runs, with$productalready presented for the newly selected combination. No new endpoint and no extra request.ga_tag.tplisdocument.addEventListener('DOMContentLoaded', ...). That event has long fired by the time the block is injected, so the code would never run.ga_tag_immediate.tplis the same file without the wrapper. Adding a flag toga_tag.tplinstead would silently drop the wrapper for every event on any theme that overrides that template, so it is left untouched.action=refreshwithajax, neverquickview, and only on the product controller. Classic'squickview.tplinlines the same hook, hence the explicit quickview check.is_array() || ArrayAccesscheck on theproducttemplate variable is the same guard as Prevent fatal error when product template variable is a Product object #181 on the sibling hook; if that PR lands first the two sites should share it.upgrade-6.0.0.phpwould not run on shops already on it - the hook would never be registered and the fix would be inert. Hence 6.1.0 plusupgrade/upgrade-6.1.0.php. If you would rather batch the bump separately, the upgrade script has to be renamed to whatever the next version is.Checks
php-cs-fixer reports no diff, with a positive control returning 8 on an injected violation.
php -lpasses on PHP 7.2, the lowest leg of the syntax matrix, for all five touched PHP files. The before/after above is the substitute for a test: this module's suite is PHPStan only.