Skip to content

Conversation

@Codencode
Copy link

@Codencode Codencode commented Dec 17, 2024

JavaScript events considered:

  • updateCart
  • changedCheckoutStep
  • updatedProduct
  • updateProductList
  • clickQuickView
Questions Answers
Description? see PrestaShop/PrestaShop#37661
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #37661
Sponsor company @Codencode
How to test? see PrestaShop/PrestaShop#37661

JavaScript events considered:
- updateCart
- changedCheckoutStep
- updatedProduct
- updateProductList
/**
* @var Ps_Googleanalytics
*/
public $module;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? I think it should be automatic when you are extending ModuleFrontController.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not necessary; I added it to make the type explicit, i.e., "Ps_Googleanalytics", so that there are no warnings in the editor.
However, if you consider it "redundant", I can remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove this please, your IDE complains because it lacks the context of a parent class. :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it.
Thanks!

Co-authored-by: Nicolas Lœuillet <nicolas@loeuillet.org>
@Codencode Codencode requested a review from nicosomb December 17, 2024 15:35
Copy link
Contributor

@Hlavtox Hlavtox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block to prevent accidental merge, I want to check and test it. 👍

@Codencode
Copy link
Author

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

@kreare
Copy link

kreare commented Dec 18, 2024

awesome, waiting for merge

@Codencode
Copy link
Author

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

Copy link
Contributor

@Hlavtox Hlavtox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment but I think its good.

ping @kpodemski for check

/**
* @var Ps_Googleanalytics
*/
public $module;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove this please, your IDE complains because it lacks the context of a parent class. :-)

@Codencode Codencode closed this May 13, 2025
@github-project-automation github-project-automation bot moved this from Ready for review to Closed in PR Dashboard May 13, 2025
@Codencode Codencode reopened this May 13, 2025
@github-project-automation github-project-automation bot moved this from Closed to Reopened in PR Dashboard May 13, 2025
@Codencode
Copy link
Author

@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 (#170 (comment)).
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!

@Hlavtox
Copy link
Contributor

Hlavtox commented May 13, 2025

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

@Codencode Codencode force-pushed the fix-37661-add_to_cart-event-in-realtime branch 7 times, most recently from cf51d26 to 55b954c Compare May 13, 2025 08:40
@Codencode Codencode force-pushed the fix-37661-add_to_cart-event-in-realtime branch from 55b954c to 07dd3d0 Compare May 13, 2025 08:44
@Codencode
Copy link
Author

@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
Copy link
Author

Codencode commented May 13, 2025

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
Copy link
Author

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

Copy link

@paulnoelcholot paulnoelcholot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Codencode,

Thank you for your suggestion. We indeed lack competent resources on the subject of Google Analytics. Could you provide us with a clear and precise step-to-reproduce to test the issue, then the PR?

Thanks you very much!

@Codencode
Copy link
Author

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.

@paulnoelcholot
Copy link

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

@Codencode
Copy link
Author

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

@Codencode
Copy link
Author

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

@paulnoelcholot paulnoelcholot removed their assignment Jul 16, 2025
@Codencode
Copy link
Author

ping @PrestaShop/qa-functional

@Codencode
Copy link
Author

@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 Codencode mentioned this pull request Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Reopened

Development

Successfully merging this pull request may close these issues.

[ps_googleanalytics]: add_to_cart event in realtime

7 participants