Added queue clearing
JavaScript events considered:
- updateCart
- changedCheckoutStep
- updatedProduct
- updateProductList
- clickQuickView
| Questions | Answers |
|---|---|
| Description? | see https://github.com/PrestaShop/PrestaShop/issues/37661 |
| Type? | bug fix |
| BC breaks? | no |
| Deprecations? | no |
| Fixed ticket? | Fixes #37661 |
| Sponsor company | @codencode |
| How to test? | see https://github.com/PrestaShop/PrestaShop/issues/37661 |
@Hlavtox, I have also prepared the code to handle the update of the product list (e.g., on the category page when filtering). I could upload this code to this PR or create another PR, so you can review everything when you have time. What do you think?
awesome, waiting for merge
@Hlavtox, have you had a chance to review this PR?
Also, if it's okay, I could create a second PR with the changes related to updating the product list (e.g., on the category page when filtering).
Thanks, and sorry for bothering you.
@Hlavtox, I noticed the PHPStan test is failing (https://github.com/PrestaShop/ps_googleanalytics/actions/runs/14990171643/job/42111552847?pr=170) because it reports a missing method. This happens because it doesn't recognize the type of the $module attribute.
Initially, I had added the type declaration in the class definition like this (since my IDE suggested it):
/**
* @var Ps_Googleanalytics
*/
public $module;
But you rightly advised me to remove it (https://github.com/PrestaShop/ps_googleanalytics/pull/170#discussion_r1918195529). What do you recommend to fix the test issue? Should I perhaps add the type declaration back?
I'd like to fix these issues since I'm preparing videos to demonstrate the functionality - this way we can work toward closing this PR. Thanks!
@Codencode
Open up this file - https://github.com/PrestaShop/ps_googleanalytics/blob/dev/tests/phpstan/phpstan-8.0.neon
And add this to ignoreErrors:
- '#Call to an undefined method Module::getDataHandler\(\).#'
And probably the same for https://github.com/PrestaShop/ps_googleanalytics/blob/dev/tests/phpstan/phpstan-latest.neon, not sure.
Should work 🎉
@Hlavtox, I also had to modify:
- phpstan-1.7.7.neon
- phpstan-1.7.8.neon
After several attempts, I finally got it working 😄
I think it should be good now.
Thanks a lot!
Below are some videos and screenshots showing how the changes work. Each of the following JavaScript events:
- updateCart
- changedCheckoutStep
- updatedProduct
- updateProductList
- clickQuickView
triggers an AJAX call to the ajax.php file with the parameter action=flushQueue.
Screenshot of adding to cart without the modification
Video of adding to cart without the modification
Add to cart - without fix.webm
Screenshot of adding to cart with the modification
Video of adding to cart with the modification
Video of updateCart and changedCheckoutStep events
updateCart - changedCheckoutStep.webm
Video of updateProductList, clickQuickView, and updatedProduct events
Hi @PrestaShop/qa-functional, Could you check this PR when you have time? Let me know if there are any blockers or if you need anything from my side.
Thanks in advance! 🙏
Hello @paulnoelcholot
The issue is that some Google Analytics events are not tracked at the time the action is performed but are instead tracked when the page is reloaded. Let me give an example: when you add an item to the cart, an addToCart event is sent to Google Analytics. However, this event ends up in a "queue" and is only actually sent when the page is refreshed. The problem arises when a user adds an item to the cart and then closes the browser. My PR ensures that when you add an item to the cart (and, of course, this also applies to other events), the system adds the event to the queue, retrieves the queued events, and sends them to Google Analytics immediately.
To test these events, you need to use Google Tag Assistant: https://tagassistant.google.com/ Below are three videos:
1. Google Tag Assistant setup
2. Using Google Tag Assistant to verify that the event is sent on page refresh and not when clicking "Add to cart"
02 - problem - add to cart.webm
3. Using Google Tag Assistant with the new code to confirm that the event is sent when clicking "Add to cart"
In the videos, the text is in Italian, and the "Add to cart" event is labeled as "Aggiungi al carrello."
Let me know if you need any further clarification.
@Codencode,
Thanks you very much for your help.
I have a problem during the google assistant setup :
How can I install tag?
Thanks for your feedback!
@paulnoelcholot It looks to me like you haven't installed or configured the ps_googleanalytics module.
@paulnoelcholot, were you able to run the tests in the end?
ping @PrestaShop/qa-functional
@Hlavtox @kpodemski, I think testing this change is a bit 'complicated.' I tried my best to explain how to do it and even added some videos. Do you have any suggestions? I'm afraid these changes won't get merged, and that's a shame.