matomo-org / matomo-for-wordpress

Get a fully functioning Matomo Analytics for your WordPress. Star us on Github? +1. Matomo is the leading open alternative to Google Analytics that gives you full control over your data. Privacy is built-in. 100% data ownership, no one else can see your data. We love Pull Requests!
https://matomo.org
GNU General Public License v3.0
120 stars 25 forks source link

Woocommerce tracking does not work when admin-ajax.php is used #851

Closed YohannJsl1 closed 1 year ago

YohannJsl1 commented 1 year ago

Hello,

My e-commerce logs are empty even if I know I had orders and I tested several add to cart as an user, everything was tracked on the real team visit report as you can see below Capture d’écran 2023-09-11 à 10 38 02

For the ecommerce logs it's always empty regardless of the period. Capture d’écran 2023-09-11 à 10 39 07

I tried to disable LSCache and disable the tracking code but it's not working. I found nothing answering to this issue.

Here is my system report :

Matomo

Endpoints

Crons

Contrôles obligatoires

Contrôles facultatifs

Matomo Settings

Logs

WordPress

WordPress Plugins

Server

Database

Browser

diosmosis commented 1 year ago

Hi @YohannJsl1, I've started looking into your problem, can you confirm that the "Enable ecommerce" option is set in the Matomo Analytics > Settings > Tracking page? I suspect this isn't the issue, but I want to make sure.

EDIT: and another question, is there a checkout page that's part of your ecommerce workflow and if so what would the URL path of the page be? (eg, if the URL is https://mysite.com/checkout, then /checkout).

YohannJsl1 commented 1 year ago

Hi @diosmosis thank you for your answer.

Yes "Enable ecommerce" option is on Capture d’écran 2023-09-12 à 08 47 38

On the first screenshot of my previous message I was translating with google but the path is /confirmation and not /checkout The thing is if the user is adding to the cart it is just loading a side cart without changing the url and I also want to track theses add to cart.

One other thing : my website is host on a subdirectory site.com/subdirectory so all the urls follow this subdirectory, for example site.com/subdirectory/confirmation . I don't know if it can have any impact.

diosmosis commented 1 year ago

@YohannJsl1 when you view a product on your site, would you be able to check if somewhere in the HTML of the page there is this text: addEcommerceItem or setEcommerceView within a <script> element?

NOTE: if you're comfortable sharing the website, that might help speed things up. This can be done via email if you'd like.

YohannJsl1 commented 1 year ago

Please send me your email I'll send the URL to you

YohannJsl1 commented 1 year ago

Thank you, just sent to you

diosmosis commented 1 year ago

@YohannJsl1 received, I'll look into it and update you when I find something.

diosmosis commented 1 year ago

@YohannJsl1 I've looked into this and it seems it's a bug in Matomo for Wordpress when using AJAX requests to manage ecommerce functionality. Unfortunately there doesn't appear to be an easy fix. There doesn't appear to be a workaround either.

YohannJsl1 commented 1 year ago

@diosmosis do you have any idea of how long it will take to fix it ? Or do you know any alternatives app to use to do so ?

diosmosis commented 1 year ago

@YohannJsl1 If a fix is identified soon, then it might be able to go out in a release in around a month. If I can think of a workaround you can use I'll post it here as well.

If you're asking for alternative wordpress plugins that work like Matomo for Wordpress for ecommerce then I'm not particularly aware of any, apologies.

YohannJsl1 commented 1 year ago

Is there a workaround to at least track when the user is on the confirmation page ? The slug end with /confirmation/

diosmosis commented 1 year ago

@YohannJsl1 actually I may be incorrect about the problem, looking into it again.

Regarding the confirmation page, if the page is marked as the checkout page in Woocommerce. Is this not the case for your site?

YohannJsl1 commented 1 year ago

Yes confirmation and checkout page is the same page.

The problem is I don't have any way to track the add to cart as it's an AJAX add to cart, but maybe I can at least track when the person is on the checkout page (it will not solve the problem but I will still have a better view)

diosmosis commented 1 year ago

The problem is I don't have any way to track the add to cart as it's an AJAX add to cart, but maybe I can at least track when the person is on the checkout page (it will not solve the problem but I will still have a better view)

This should actually already be the case, I misread parts of the existing code. In case of AJAX the ecommerce tracking is done server side, and as far as I can tell it should be working for you.

I do have one possible idea, the "Block Bad Queries" plugin might be blocking those requests. I haven't verified, but you could try temporarily deactivating that plugin and checking if ecommerce actions start getting tracked.

YohannJsl1 commented 1 year ago

I don't know what "Block Bad Queries" plugin is but I tried disabling all security plugin and it didn't change anything.

diosmosis commented 1 year ago

Bugs found from debugging (will create new issues for each):

diosmosis commented 1 year ago
diosmosis commented 1 year ago

Since debugging is complete, I'm going to close this.