Add filter to apply Base64 encoding to order attribution cookies
Changes proposed in this Pull Request:
In the continuing effort to make the order attribution functionality available for stores on any servers, and in light of several recent mentions of different web application firewalls and rulesets that are still being incorrectly triggered, this PR:
- Bumps the Sourcebuster version to the new v1.2.0 which, among other things, adds a configuration parameter to enable Base64 encoding of the cookie values.
- Adds a new
wc_order_attribution_use_base64_cookiesfilter flag to enable Base64 encoding for Sourcebuster cookies. Merchants who have been blocked from updating to a newer version of WooCommerce due to WAFs falsely flagging the Sourcebuster cookies should hopefully be able to get around this by enabling this encoding.
Related to #43681 and #43413.
Notes:
- When enabled, all new and updated cookie values are Base64 encoded. Existing cookies will remain unencoded, but are still readable and, since cookie lifetime is just the session, they will be recreated in the correct format on the next visit.
- The new Sourcebuster version also enables several new UTM parameters, but capturing those during checkout will be implemented in an accompanying PR.
How to test the changes in this Pull Request:
👉🏻 Prerequisites: store with products and configured to allow checkouts and with order attribution enabled.
Test1: Order attribution works as normal with the new Sourcebuster version (no filter enabled)
- Visit the shop in a new browser session (incognito, for example)
- In the dev console, execute the snippet
wc_order_attribution.getAttributionData()and see that source data is retrieved (probablysource_type:'typein') - Confirm that the
sbjs_*cookies are in the original format (URL encoded,param=value|||param=value|||…): - Add items to the cart and check out.
- Confirm in the order edit page that order attribution data is available
**Test 2: Order attribution works with new filter **
- Add the filter to enable Base64:
add_filter( 'wc_order_attribution_use_base64_cookies', '__return_true' ); - In a new browser session without existing cookeis (incongnito), visit the shop with UTM params
site.com/shop/?utm_source=test_source_base64&utm_campaign=Éürøpãp🅰️&utm_medium=test_medium - Check in the cookies to see that the cookie values are Base64 (just alphanumeric, no
%or=). - In the dev console, execute the snippet
wc_order_attribution.getAttributionData()and see that source data is retrieved - Run the JavaScript snippet to confirm data is accurate
wc_order_attribution.getAttributionData() - Complete the checkout and confirm that order attribution data was captured.
**Test 3: Order attribution works with for users who have cookies in the old format **
- Disable the filter.
- Visit the shop in a new browser session, UTM params:
site.com/shop/?utm_source=test_source_base64&utm_campaign=Éürøpãp🅰️&utm_medium=test_medium - Confirm that all the cookies are in the original format (see test 1, step 3).
- Enable the filter.
- Navigate to another page.
- Confirm that SOME cookies have been updated to Base64 encoding (see explanation in this comment on Sourcebuster PR: https://github.com/woocommerce/sourcebuster-js/pull/6#issuecomment-2108942374)
- In the dev console, execute the snippet
wc_order_attribution.getAttributionData()and see that source data is retrieved - Add items to the cart and check out.
- Confirm in the order edit page that order attribution data is available
Test 4: Order attribution works with for users who have cookies in the new format if the filter is disabled
- Enable the filter.
- Visit the shop in a new browser session, UTM params:
site.com/shop/?utm_source=test_source_base64&utm_campaign=Éürøpãp🅰️&utm_medium=test_medium - Confirm that all the cookies are Base64 encoded (see test 2, step 3).
- Disable the filter.
- Navigate to another page.
- Confirm that SOME cookies have been updated to the old format (see explanation in this comment on Sourcebuster PR: https://github.com/woocommerce/sourcebuster-js/pull/6#issuecomment-2108942374)
- In the dev console, execute the snippet
wc_order_attribution.getAttributionData()and see that source data is retrieved - Add items to the cart and check out.
- Confirm in the order edit page that order attribution data is available
Test 5: Order attribution works with filter enabled using other checkout type
- Change the store checkout type (from Classic to Block, or viceversa).
- Repeat steps from Test 2.
Changelog entry
- [ ] Automatically create a changelog entry from the details below.
Significance
- [ ] Patch
- [ ] Minor
- [ ] Major
Type
- [ ] Fix - Fixes an existing bug
- [ ] Add - Adds functionality
- [ ] Update - Update existing functionality
- [ ] Dev - Development related task
- [ ] Tweak - A minor adjustment to the codebase
- [ ] Performance - Address performance issues
- [ ] Enhancement - Improvement to existing functionality
Message
Comment
Test using WordPress Playground
The changes in this pull request can be previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.
Test this pull request with WordPress Playground.
Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.
Hi , @woocommerce/ventures
Apart from reviewing the code changes, please make sure to review the testing instructions as well.
You can follow this guide to find out what good testing instructions should look like: https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions
Thanks @ecgan! I added another note to the PR description.