Skip to content
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

Order attribution - avoid attributing AJAX-checkouts to Web Admin #44219

Merged
merged 4 commits into from Feb 15, 2024

Conversation

layoutd
Copy link
Contributor

@layoutd layoutd commented Jan 31, 2024

Changes proposed in this Pull Request:

This prevents orders created through AJAX checkout requests from getting an extra source_type meta value as "Web admin" incorrectly. Ref p1706574180153889-slack-C7U3Y3VMY
image

How to test the changes in this Pull Request:

Ensure that orders created in the Web Admin are still classified as Web Admin:

  1. Create an order using the Add Order button (/wp-admin/post-new.php?post_type=shop_order).
  2. Confirm that its origin in the Orders Table is "Web admin":
    image

Ensure that orders created via AJAX requests aren't classified as Web Admin

  1. Configure the shop:

    • Classic checkout
    • Cash on delivery enabled
    • Flat rate shipping to Europe
  2. Add some products to the cart.

  3. Go to the checkout page, confirm there's a woocommerce-process-checkout-nonce:
    image

  4. Execute the following snippet in the browser dev console (it will attempt to build the URL automatically assuming shop.dom/checkout/ is the URL; otherwise, set the URL manually):

    JavaScript block ```javascript var nonce_val = jQuery('#woocommerce-process-checkout-nonce').val(); var ajax_url =window.location.href .replace( '/checkout/', '/wp-admin/admin-ajax.php?action=woocommerce_checkout&woocommerce-process-checkout-nonce=' + nonce_val );

    jQuery.post(
    ajax_url,
    {
    billing_first_name: "PR44219",
    billing_last_name: "Test",
    billing_company: "",
    billing_country: "UA",
    billing_address_1: "Test",
    billing_address_2: "Test",
    billing_city: "Test",
    billing_state: "UA07",
    billing_postcode: "44219",
    billing_phone: "44219",
    billing_email: "admin@example.com",
    shipping_first_name: "PR44219",
    shipping_last_name: "Test",
    shipping_company: "",
    shipping_country: "UA",
    shipping_address_1: "Test",
    shipping_address_2: "Test",
    shipping_city: "Test",
    shipping_state: "UA07",
    shipping_postcode: "44219",
    order_comments: "",
    shipping_method: ["flat_rate:3"],
    payment_method: "cod",
    wc_order_attribution_source_type: 'utm',
    wc_order_attribution_referrer: '(none)',
    wc_order_attribution_utm_campaign: 'sale',
    wc_order_attribution_utm_source: 'NEWSOURCE',
    wc_order_attribution_utm_medium: 'social',
    wc_order_attribution_utm_content: '(none)',
    wc_order_attribution_utm_id: '20231121',
    wc_order_attribution_utm_term: 'testing',
    wc_order_attribution_session_entry: 'https://fakestore.com/shop',
    wc_order_attribution_session_start_time: '2024-01-31 11:30:13',
    wc_order_attribution_session_pages: '8',
    wc_order_attribution_session_count: '2',
    wc_order_attribution_user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ 120.0.0.0 Safari/537.36',
    })
    .done(function(data, textStatus, jqXHR) {
    console.log('Status Code:', jqXHR.status);
    console.log('Status Text:', jqXHR.statusText);
    console.log('WooCommerce Response:', data.result);
    if(data.order_id) {
    console.log('WooCommerce Order ID:', data.order_id);
    }
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
    console.error('Status Code:', jqXHR.status);
    console.error('Status Text:', jqXHR.statusText);
    });

    </details>
    
    
  5. Confirm in the dev console that the console show Status Code: 200 and Status Text: success.

  6. Note that without these changes, the "Origin" in the Orders Table will be Web Admin, and with it, it will show the Source:
    image
    (In the page edit form the correct Source value will always be displayed):
    image

Ensure that regular orders are still attributed correctly

  1. In a new incognito tab, visit the shop with UTM params: web.com/shop/?utm_source=GOODTEST&utm_medium=test&utm_campaign=pr-test
  2. add items to the cart and go through the checkout.
  3. Confirm the Orders table and Order Edit metaboxes show the expected values:
    image

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

@layoutd layoutd added team: Ventures focus: order attribution Issues related to the order attribution feature labels Jan 31, 2024
@layoutd layoutd self-assigned this Jan 31, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jan 31, 2024
Copy link
Contributor

github-actions bot commented Jan 31, 2024

Test Results Summary

Commit SHA: a0354fb

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 38s
E2E Tests291003003216m 25s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@layoutd layoutd requested a review from a team January 31, 2024 11:48
Copy link
Contributor

github-actions bot commented Jan 31, 2024

Hi @budzanowski,

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

@budzanowski
Copy link
Contributor

StackOverflow suggests that it is possible to check if we have the admin doing Ajax: https://wordpress.stackexchange.com/a/286299

Would this approach improve precision or this does not cover the scenarios that we want to target?

@layoutd
Copy link
Contributor Author

layoutd commented Jan 31, 2024

That might be more precise, is it common for orders to be created via ajax in the admin panel?

@layoutd
Copy link
Contributor Author

layoutd commented Jan 31, 2024

I added a more detailed check that will allow the possibility for Web Admin orders to be created via AJAX calls.

@budzanowski
Copy link
Contributor

That might be more precise, is it common for orders to be created via ajax in the admin panel?

I don't know, sorry :/

Copy link
Contributor

@budzanowski budzanowski left a comment

Choose a reason for hiding this comment

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

Looks good.

@layoutd
Copy link
Contributor Author

layoutd commented Feb 13, 2024

I made one more small change to clarify the logic, would you mind doing a quick sanity check, @budzanowski?

@budzanowski
Copy link
Contributor

@layoutd done.

@layoutd layoutd force-pushed the fix/better-order-attribution-web-adming-attribution branch from aabe50f to a0354fb Compare February 13, 2024 15:13
@layoutd layoutd merged commit 406dcac into trunk Feb 15, 2024
34 checks passed
@layoutd layoutd deleted the fix/better-order-attribution-web-adming-attribution branch February 15, 2024 11:38
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 15, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 15, 2024
@Stojdza Stojdza added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: order attribution Issues related to the order attribution feature needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Ventures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants