ps_googleanalytics icon indicating copy to clipboard operation
ps_googleanalytics copied to clipboard

Added queue clearing

Open Codencode opened this issue 1 year ago • 14 comments

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

Codencode avatar Dec 17 '24 09:12 Codencode

@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?

Codencode avatar Dec 18 '24 07:12 Codencode

awesome, waiting for merge

kreare avatar Dec 18 '24 09:12 kreare

@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.

Codencode avatar Jan 16 '25 09:01 Codencode

@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 avatar May 13 '25 07:05 Codencode

@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 avatar May 13 '25 07:05 Hlavtox

@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!

Codencode avatar May 13 '25 08:05 Codencode

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

Add to cart - without fix

Video of adding to cart without the modification

Add to cart - without fix.webm

Screenshot of adding to cart with the modification

Add to cart - with fix

Video of adding to cart with the modification

Add to cart - with fix.webm

Video of updateCart and changedCheckoutStep events

updateCart - changedCheckoutStep.webm

Video of updateProductList, clickQuickView, and updatedProduct events

updateProductList - clickQuickView - updatedProduct.webm

Codencode avatar May 13 '25 08:05 Codencode

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! 🙏

Codencode avatar May 21 '25 06:05 Codencode

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

01 - init.webm

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"

03 - fix - add to cart.webm

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 avatar May 21 '25 14:05 Codencode

@Codencode,

Thanks you very much for your help.

I have a problem during the google assistant setup : image

How can I install tag?

Thanks for your feedback!

paulnoelcholot avatar May 23 '25 08:05 paulnoelcholot

@paulnoelcholot It looks to me like you haven't installed or configured the ps_googleanalytics module.

Codencode avatar May 23 '25 12:05 Codencode

@paulnoelcholot, were you able to run the tests in the end?

Codencode avatar Jul 09 '25 14:07 Codencode

ping @PrestaShop/qa-functional

Codencode avatar Jul 18 '25 15:07 Codencode

@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.

Codencode avatar Jul 20 '25 10:07 Codencode