-
Notifications
You must be signed in to change notification settings - Fork 833
WooCommerce Analytics: Prevent server-side track event rejections due to array event properties #45544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
…d strings and URL-encode for pixel URL compatibility. Serialize non-indexed arrays to JSON strings
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
Partially fixes WOOA7S-568
Proposed changes:
This PR addresses a bug where server-side events, such as
product_purchase
, are being rejected due to invalid event prop names when there are additional blocks present on the cart or checkout page.While the ideal solution would be to address these issues directly in WooCommerce core, the core release schedule means we have to implement this fix here first and subsequently submit a PR to WooCommerce core.
Root cause:
Event prop names are required to match the pattern
^[a-z_][a-z0-9_]*$
. However, when arrays are passed as event properties (for example, an array likeadditional_blocks_on_checkout_page
), the serialization performed byhttp_build_query
turns them into query parameters with keys such asadditional_blocks_on_checkout_page[0]
,additional_blocks_on_checkout_page[1]
, etc. These prop names contain brackets ([0]
), which violates the required event prop naming convention and results in events getting rejected.Example:
Here is the method used by
s.js
to construct the query string:How this PR fixes it:
This update encodes event property values when they are arrays, preventing the creation of invalid property names.
Other information:
Jetpack product discussion
n/a
Does this pull request change what data or activity we track or use?
no, this doesn't add/change any data or activity we track or use but just fixes a bug where server-side events are rejected due to invalid event prop names when there are additional blocks present on the cart or checkout page.
Testing instructions:
Prerequisites:
set_transient( 'jetpack_woocommerce_analytics_additional_blocks_on_checkout_page', array( 'core/group', 'core/heading' ), DAY_IN_SECONDS );
in any file that gets loaded before the cart or checkout page is loaded.woocommerceanalytics_add_to_cart
event is logged inwp-content/debug.log
andadditional_blocks_on_checkout_page
prop value is encoded as a single string with the values separated by commas. Confirm that theadditional_blocks_on_cart_page
prop value is empty string (additional_blocks_on_cart_page=&additional_blocks_on_checkout_page=core%252Fgroup%252Ccore%252Fheading&
).woocommerceanalytics_product_purchase
event is logged inwp-content/debug.log
andadditional_blocks_on_checkout_page
prop value is encoded as a single string with the values separated by commas. Confirm that theadditional_blocks_on_cart_page
prop value is empty string (additional_blocks_on_cart_page=&additional_blocks_on_checkout_page=core%252Fgroup%252Ccore%252Fheading&
).You can also search the events via the Tracks Live View to confirm that the events are logged correctly.