wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Closes #7436 Add tracking of selected options change

Open remyperona opened this issue 6 months ago • 18 comments

Description

Fixes #7436

Send a Mixpanel event when at least one of the selected WP Rocket options value is changed (disabled to enabled or enabled to disabled).

Convert the old WP Rocket optin to the new one from the WP Mixpanel package on update to the next version of the plugin.

Type of change

  • [x] Enhancement (non-breaking change which improves an existing functionality).

Detailed scenario

What was tested

Automated tests have been added.

Tested manually the new optin system, and the option update sending the event to Mixpanel.

How to test

  • On WP Rocket settings page
  • Have analytics enabled
  • Change the value of the preload fonts option
  • Save changes
  • an event WPM Option Changed should be logged in mixpanel

Technical description

Documentation

This PR introduces a new Tracking class and subscriber class to handle Mixpanel tracking in the plugin.

Currently one tracking is implemented on update_option_wp_rocket_settings, specifically for the auto_preload_fonts option.

It also migrate the Optin analytics from the old WP Rocket way (as a value in the settings array) to the WP Mixpanel package way (a separate option). It handles the display of the optin field in a separate template, and a new AJAX handling.

New dependencies

wp-media/wp-mixpanel

Mandatory Checklist

Code validation

  • [x] I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • [x] I triggered all changed lines of code at least once without new errors/warnings/notices.
  • [x] I implemented built-in tests to cover the new/changed code.

Code style

  • [x] I wrote a self-explanatory code about what it does.
  • [x] I protected entry points against unexpected inputs.
  • [x] I did not introduce unnecessary complexity.

remyperona avatar Jun 04 '25 19:06 remyperona

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
:white_check_mark: -0.03% (target: -0.10%) :white_check_mark: 55.68% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3a1f32bb4a9b8cd40e32c682a86d888a71ec4825) 39725 17535 44.14%
Head commit (a86c8a695b97dc95f956952d534e7ddad2dc8729) 39755 (+30) 17538 (+3) 44.12% (-0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7441) 88 49 55.68%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

codacy-production[bot] avatar Jun 04 '25 19:06 codacy-production[bot]

To add to the PR: change the MixPanel token

MathieuLamiot avatar Jun 11 '25 15:06 MathieuLamiot

@wp-media/qa-team The Mixpanel account to see the event being tracked is the one for Group one, using your group email. If you don't have access, you can check with Mathieu.

The event should be logged in the production events.

Also, this PR introduces an automatic migration to the new mixpanel library optin tracking during update to 3.19.1. If you can't simulate that, you should be able to switch on the optin on the WP Rocket settings dashboard.

remyperona avatar Jun 12 '25 15:06 remyperona

QA team should have access here: https://eu.mixpanel.com/login/ (as well as all devs)

MathieuLamiot avatar Jun 12 '25 19:06 MathieuLamiot

Ummm not sure if I am dumb, but I can't see the JS event fired which kinda make sense as @remyperona used the php library, and on mixpanel, I can't see any related event. Or maybe I'm getting lost in all group.one events ...

Miraeld avatar Jun 13 '25 00:06 Miraeld

@remyperona Thanks for the PR. Please notice that we have the following regression while exploring.

  • enable analytics isnot working 1- fresh install and activate PR after merging dev to it 2- enable analytics => console error is there 3- refresh admin => analytics gets disabled automatically (working fine on 3.19.0.1) screen-capture - 2025-06-13T110241.383.webm Screenshot from 2025-06-13 11-07-11

Mai-Saad avatar Jun 13 '25 08:06 Mai-Saad

@Miraeld To easily find the events in MixPanel, you can use the "Events" tab and search. Indeed, I don't see any "WPM Option Changed event".

image

MathieuLamiot avatar Jun 13 '25 09:06 MathieuLamiot

Thanks for the confirmation @MathieuLamiot , i saw that category and couldn't find any event related to options changed, that's why I was wondering if I was looking at the right spot.

@remyperona could you confirm if on your side it is working as it isn't for us.

Miraeld avatar Jun 13 '25 09:06 Miraeld

I can see the event

mixpanel

remyperona avatar Jun 13 '25 16:06 remyperona

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
:white_check_mark: -0.03% (target: -0.10%) :white_check_mark: 51.65% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3a1f32bb4a9b8cd40e32c682a86d888a71ec4825) 39725 17535 44.14%
Head commit (af3245c1b19c80b05d192bdb06f5bf4632c67d15) 39757 (+32) 17536 (+1) 44.11% (-0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7441) 91 47 51.65%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

codacy-production[bot] avatar Jun 13 '25 16:06 codacy-production[bot]

@remyperona WDYT about @Mai-Saad's finding? @Miraeld Can you share what steps you took, that did not fire the event, so that we can reproduce & investigate? Thanks

MathieuLamiot avatar Jun 13 '25 16:06 MathieuLamiot

Well, the step are pretty simple and in the description of the issue: Enable WPR, consent to share data, change preload font status (enabled/disabled)

Miraeld avatar Jun 13 '25 16:06 Miraeld

I think the issue reported by Mai was caused by the fact the JS min file was not updated, so it was calling the old AJAX action. I pushed it now.

remyperona avatar Jun 13 '25 17:06 remyperona

@Miraeld With those steps, it is working on my local. Are you able to provide more details?

https://github.com/user-attachments/assets/e25556f2-9ee6-4dfe-80cd-4f411abca619

I also validated updating from 3.18.3 keeps the Data consent setting (tested both with on & off)

MathieuLamiot avatar Jun 13 '25 19:06 MathieuLamiot

enable analytics isnot working 1- fresh install and activate PR after merging dev to it 2- enable analytics => console error is there 3- refresh admin => analytics gets disabled automatically (working fine on 3.19.0.1)

Enable/disable analytics is working after the latest commit. I will let @Miraeld validate the Metabase part (AC).

Mai-Saad avatar Jun 16 '25 12:06 Mai-Saad

Hello hello, First point: I figured out what was my problem: composer.lock I forgot to delete it. Second point: It is working fine now, I can see the event in mixpanel. For info @Mai-Saad you don't see the request sent to mixpanel in the dev tool anymore, it's managed by PHP so server to server.

Third point: Are we ok it's only working with auto_preload_fonts and for example self hosted google font doesn't trigger any event on mixpanel ? @MathieuLamiot

Miraeld avatar Jun 17 '25 07:06 Miraeld

@Miraeld Thank you for the update. About the 3rd point, yes this is the expected behavior (see the original issue). Moving to QA Done

MathieuLamiot avatar Jun 17 '25 07:06 MathieuLamiot

Yea I saw that point on the original issue, but asked because the PR mentioned "Add tracking to selected options change". So wasn't sure.

Miraeld avatar Jun 17 '25 07:06 Miraeld