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

Add additional properties to WC Analytics events #20812

Merged
merged 18 commits into from
Aug 30, 2021

Conversation

moon0326
Copy link
Contributor

@moon0326 moon0326 commented Aug 24, 2021

Please do not merge this PR yet. Changes in this PR depend on the newly added action in WC Pay. We need to merge these changes after releasing the WC Pay version 2.9. WC Pay version 2.9 has been released and I've updated this PR to work with previous versions of WC Payments in 4e9a4fb

Fixes woocommerce/woocommerce-admin#7301

Changes proposed in this Pull Request:

  • Supports array value to be added as an event property 4f2d1bc - This is needed to add payment_options value.
  • Added additional properties to woocommerceanalytics_product_purchase and woocommerceanalytics_product_checkout_view. The additional properties are listed in the issue.
  • One notable change is that it uses an action.
    from WC Pay when the express checkout methods are enabled.

Jetpack product discussion

Does this pull request change what data or activity we track or use?

We're adding the following properties to woocommerceanalytics_product_purchase and woocommerceanalytics_product_checkout_view events.

woocommerceanalytics_product_purchase

payment_option: the option that was used. Eg Stripe or COD
express_checkout: if the express checkout option was used: Eg: Apple Pay or Null
guest_checkout: if the guest checkout was used
create_account: check if the shopper created an account (Y/N)
device: mobile/desktop

woocommerceanalytics_product_checkout_view

payment_options: an array with the options available. Eg [paypal, stripe, cod, amazon]
express_checkout: an array with the options available. Eg [apple_pay] or [null] if they don’t display them
guest_checkout: Yes/No. Identify if the store allows users to checkout without an account
create_account: Yes/No Identify if the store allows users to create an account on checkout
device: mobile/desktop

Testing instructions:

Please use WC Pay 2.9.0

If you're new to WC Analytic testing, please perform the following steps to enable WC Analytic.

  1. Install and activate WooCommerce.
  2. Finish onboarding wizard and enable Direct bank transfer in WooCommerce -> Settings -> Payments.
  3. Install and activate Jetpack.
  4. Connect your site to Jetpack
  5. WC Analytic doesn't track in test/dev mode. Open this file and add return true to force WC Analytic to track during the testing.
  6. Click on a product on /shop to see the details.
  7. Open your browser inspector -> Network -> search for "t.gif" then refresh.
  8. You should see t.gif request.

If you don't see t.gif request for some reason, make sure WooCommerce Analytics module is activated in /wp-admin/admin.php?page=jetpack_modules

Case 1 -- Without WC Payment installed/activated

  1. Make sure WC Payment plugin is not installed/activated.
  2. Add a product to the cart.
  3. Open browser inspector -> Network and search for t.gif
  4. Continue to the checkout page.
  5. You should see t.gif request.
  6. Click on the request and confirm that the request URL contains all the required properties for woocommerceanalytics_product_checkout_view event.
  7. Click [ Place order ] button with Direct bank transfer selected.
  8. You should see another t.gif request on the Order received page for woocommerceanalytics_product_purchase event. Confirm that the required properties are included in the URL.

Bonus: Add multiple products and confirm you get t.gif request for each product.

Screen Shot 2021-08-25 at 11 46 03 AMth_

You can use tools like https://www.freeformatter.com/url-parser-query-string-splitter.html to parse the URL into a table.

Case 2 -- WC Payment activated + express checkout methods enabled.

  1. Use ngrok to get https and publicly accessible address.
  2. Install, activate, and connect WC Payment
  3. Make sure Express Checkouts are enabled in Payments -> Settings
  4. Repeat steps 2~8 from Case 1.
  5. Confirm both events have express_checkout value.

woocommerceanalytics_product_checkout_view should have either google_pay or apple_pay
woocommerceanalytics_product_purchase should have null

Case 3 -- WC Payment activated and express checkout methods disabled.

  1. Use ngrok to get https and publicly accessible address.
  2. Install, activate, and connect WC Payment
  3. Navigate to Payments -> Settings and disable Express Checkouts
  4. Repeat steps 2~8 from Case 1
  5. Confirm express_checkout value is null in both events.

Case 4 -- WC Payment activated + express checkout methods enabled + checkout using Google/Apple pay.

  1. Use ngrok to get https and publicly accessible address.
  2. Install, activate, and connect WC Payment
  3. Navigate to Payments -> Settings and disable Express Checkouts
  4. Create a new product and set the price to $0.5 (minimum price to use google pay).
  5. Add the product to the cart and contitnue to the checkout page.
  6. Click Google Pay or Apple Pay to checkout.
  7. Confirm express_checkout value.

both events should have google_pay or apple_pay

Case 5 -- WC Payment version lower than 2.9.0.

The action used in this PR was added in WC Payment version 2.9.0. If the user has WC Payment version lower than 2.9.0, then the action should not be used.

  1. Install & activated WC Payment version lower than 2.9.0
  2. Add a product to the cart and continue to the checkout page.
  3. On the checkout page, right-click on the page and click "View Page Source"
  4. Scroll to the bottom of the page and confirm the event JS script is not using wp.hooks.addAction

@moon0326 moon0326 marked this pull request as draft August 24, 2021 23:55
@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Feature] WooCommerce Analytics labels Aug 24, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: September 7, 2021.
  • Scheduled code freeze: August 30, 2021.

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Aug 24, 2021
@moon0326 moon0326 marked this pull request as ready for review August 25, 2021 18:33
@moon0326 moon0326 marked this pull request as draft August 25, 2021 21:10
@moon0326 moon0326 marked this pull request as ready for review August 25, 2021 21:22
@moon0326
Copy link
Contributor Author

moon0326 commented Aug 26, 2021

Hi @haszari ✋, we would love to include this PR in the next release on September 7th. Could you please review this PR when you get a chance? Github is recommending you since you have worked on the files included in this PR 😄

@haszari
Copy link
Contributor

haszari commented Aug 26, 2021

we would love to include this PR in the next release on September 7th. Could you please review this PR when you get a chance? Github is recommending you since you have worked on the files including in this PR

No problem, will take a look! Also pinging in @deltaWhiskey to get some eyes from Woo Data (side note – is there a GitHub team for woo data?)

@moon0326
Copy link
Contributor Author

Hi @kraftbj ✋ we would love to include this PR in the next release on September 7th. Could you please review this PR when you get a chance? 🙇 It looks like you have worked on the WC Analytic module. According to the field guide, I also need one approval from a member of Jetpack team.

@jeherve jeherve added the DO NOT MERGE don't merge it! label Aug 26, 2021
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

Please do not merge this PR yet. Changes in this PR depend on the newly added action in WC Pay. We need to merge these changes after releasing the WC Pay version 2.9.

we would love to include this PR in the next release on September 7th

When do you think this new version of WCPay will be released? Can we merge this PR before next Monday, so it can be included in the next release?

Comment on lines +358 to +382
if ( 'Google Pay (WooCommerce Payments)' === $payment_option_title ) {
$express_checkout = array( 'google_pay' );
} elseif ( 'Apple Pay (WooCommerce Payments)' === $payment_option_title ) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this support sites using a different language?

Copy link
Contributor Author

@moon0326 moon0326 Aug 26, 2021

Choose a reason for hiding this comment

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

Thank you for the catch 👍 This is a test case I missed testing.

I've tested this PR with two different languages and they both worked as expected.

WC Pay uses the exact string to update the post meta table according to this block.

Comment on lines 305 to 306
'guest_checkout' => $guest_checkout,
'create_account' => $create_account,
Copy link
Member

Choose a reason for hiding this comment

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

Since this comes from options, would it be overkill to validate that we have the right letters here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's a good idea 👍 change was also simple enough. Updated in b2505f7

@moon0326
Copy link
Contributor Author

moon0326 commented Aug 26, 2021

Please do not merge this PR yet. Changes in this PR depend on the newly added action in WC Pay. We need to merge these changes after releasing the WC Pay version 2.9.
we would love to include this PR in the next release on September 7th

When do you think this new version of WCPay will be released? Can we merge this PR before next Monday, so it can be included in the next release?

@jeherve Thank you for the review 👍 I've pushed a few changes to address your suggestions.

WC Pay 2.9.0 has been released yesterday and I also pushed a commit to make this PR work with previous versions of WC Pay. I've updated the description accordingly.

I want to merge this before next Monday if everything goes okay.

@moon0326
Copy link
Contributor Author

moon0326 commented Aug 27, 2021

This tested great for me, thank you @moon0326 !

Approving this from a Woo Start + Manage perspective 🚀

I didn't get to test Case 4 as it needed a real credit card set up with Apple Pay. Maybe a sandbox account should be used for this? https://developer.apple.com/apple-pay/sandbox-testing/

The only possible issue I found was in case 3, on the checkout screen I got an empty value instead of null. i.e express_checkout=&.... I was using Safari for my testing.

Thank you 👍 for the review and for catching the bug. I've pushed 9bcef13 to fix the null issue.

@haszari
Copy link
Contributor

haszari commented Aug 30, 2021

WC Analytic doesn't track in test/dev mode. Open this file and add return true to force WC Analytic to track during the testing.

@moon0326 FYI you can also test without hacking the code – just use a different browser session to purchase as a guest or non-admin user.

@moon0326
Copy link
Contributor Author

moon0326 commented Aug 30, 2021

WC Analytic doesn't track in test/dev mode. Open this file and add return true to force WC Analytic to track during the testing.

@moon0326 FYI you can also test without hacking the code – just use a different browser session to purchase as a guest or non-admin user.

@haszari Thank you! Looking at the code, that should work as well.

Could you take a look at the comments I left to your comments? 🙇 I want to ship the current changes tomorrow (code freeze) then follow up with Stripe plugin and JS code inclusion changes in the next release.

haszari
haszari previously approved these changes Aug 30, 2021
Copy link
Contributor

@haszari haszari left a comment

Choose a reason for hiding this comment

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

I gave this a really quick test – there are lots of combinations to test, and they are all somewhat complex to set up!

Here's what I tested:

  • Checkout event shows correct store options (create account, allow guest, available payment options).
  • When an express option available, it's included in checkout event. Google Pay is the only one I can get going: express_checkout: google_pay.
  • Purchase with wcpay shows correct gateway woocommerce_payments.
  • Only tested with core payment options (COD and Cheque), and WooCommerce Payments.
  • WooCommerce Payments was in test mode.

I didn't test the following:

  • If these events and props all work correctly with checkout or cart blocks from WooCommerce Blocks.
  • Create account on purchase flow.
  • Any express payments – Google pay fails for me (Billing Street address is a required field. Billing Town / City is a required field. Billing Postcode is a required field.).

Feedback on events and props

There's a lot of new info getting tracked here. That's great if we need it all - though I'm curious if some of this info might be redundant or not essential. Store settings are also tracked in WooCommerce Tracker.

After we ship new events and props it's harder to remove things or adjust naming, especially if the intention and use is not clearly defined.

Let's follow this up – @pmcpinto could you P2 the question(s) you want to answer with this info>

Regarding the actual naming of the new props, here are some suggestions. The goal here is to make each prop as clear and unambiguous as possible.

  • woocommerceanalytics_product_checkout
    • payment_options available_payment_options or available_regular_payment_options (to distinguish from express)
    • express_checkout available_express_payment_options
    • guest_checkout store_allows_guest_checkout
    • create_account store_allows_create_account_at_checkout
    • device tbc - let's clarify what we are tracking here; if we stick with wp_is_mobile perhaps we can name is_mobile or useragent_is_mobile
  • woocommerceanalytics_product_purchase
    • payment_option user_payment_option or user_regular_payment_option if this is empty/null for express
    • express_checkout user_express_payment_option
    • Or - would user_payment_option and is_user_payment_option_express work better?
    • guest_checkout is_guest_checkout
    • create_account is_checkout_create_account or similar
    • otherwise use same props as checkout event

For all these properties, please use standard types and formats as recommended by data team (e.g. boolean props).

Blocks and other express checkout

Noting a couple of places that I haven't tested:

  • Express payment on product page.
  • Express payment on cart page.
  • Checkout page using block.

If we want to track checkout/purchase anywhere they happen on a site, we should test those flows too (and follow up if needed).

Next steps

I've approved this PR – if it's urgent to get this shipped in next Jetpack, so we can start run funnels, I don't want to hold it up.

At the same time, I'd love to find out more about what questions this tracking will answer so we can ensure we're collecting the right info (and no more). If it's not urgent, maybe it's better to have that discussion before shipping. cc @pmcpinto

$wcpay_version = get_option( 'woocommerce_woocommerce_payments_version' );
$has_required_wcpay_version = version_compare( $wcpay_version, '2.9.0', '>=' );
// Check express payment availablity only if WC Pay is enabled and express checkout (payment request) is enabled.
if ( in_array( 'woocommerce_payments', $enabled_payment_options, true ) && $has_required_wcpay_version ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious if Woo has an API for express payment methods. Ideally we could call a standard API to determine what express options are available, and avoid tight coupling to specific gateway plugins.

WooCommerce Blocks checkout block has some support/APIs for express payment options, so might be worth discussing with that team for advice.

$create_account = 'N';
}

$guest_checkout = $order->get_user() ? 'N' : 'Y';
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's standardise the format of boolean props (1 0, Y N, yes no etc).

Note that elsewhere in this file, 1 0 is used for boolean props (e.g. cart_page_contains_cart_block). This is compact and unambiguous; I'd recommend sticking with this, or whatever data team recommends.

$express_checkout = 'null';
// When the payment option is woocommerce_payment
// See if Google Pay or Apple Pay was used.
if ( 'woocommerce_payments' === $payment_option ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This block of code is tightly coupled to WooCommerce payments. Perhaps it could be factored out into a function so it's clear it depends on another plugin.

Or perhaps use a hook/filter to provide a standard interface to any plugin that might need to supply this info (e.g. other gateway plugins).

Also see above comment – if there's a Woo API for express payment methods, we should use that. If there isn't an API - should we add one?

'pq' => $order_item->get_quantity(),
'oi' => $order->get_order_number(),
'pq' => $order_item->get_quantity(),
'device' => wp_is_mobile() ? 'mobile' : 'desktop',
Copy link
Contributor

Choose a reason for hiding this comment

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

Best to check in with data team about how we plan to segment data / analyse by device (mobile, screen size, etc) before adding a new prop. Tracks events may already have a generic mechanism for this; User Agent is sent with all tracks requests.

$session->set( 'wc_checkout_createaccount_used', true );
$session->save_data();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the best way to detect that a new account was requested? Maybe there's another hook fired when the account is created.

@moon0326 moon0326 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Team Review labels Aug 30, 2021
jeherve
jeherve previously approved these changes Aug 30, 2021
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

this looks good to me. 🚢

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 30, 2021
@moon0326
Copy link
Contributor Author

moon0326 commented Aug 30, 2021

this looks good to me. 🚢

Thank you @jeherve 👍 I'll give one last test (just in case) shortly and merge it before the end of today.

@moon0326 moon0326 dismissed stale reviews from jeherve and haszari via bc0a9ef August 30, 2021 17:57
@moon0326 moon0326 requested a review from a team as a code owner August 30, 2021 17:57
@moon0326 moon0326 force-pushed the update/7301-add-new-wc-analytic-events branch from bc0a9ef to 9bcef13 Compare August 30, 2021 17:58
@moon0326 moon0326 force-pushed the update/7301-add-new-wc-analytic-events branch 2 times, most recently from 3236fe6 to 9bcef13 Compare August 30, 2021 18:00
@sdixon194 sdixon194 added the [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account label Aug 30, 2021
@moon0326 moon0326 merged commit da047f0 into master Aug 30, 2021
@moon0326 moon0326 deleted the update/7301-add-new-wc-analytic-events branch August 30, 2021 19:34
davidlonjon added a commit that referenced this pull request Aug 31, 2021
* master: (34 commits)
  Fix issue templates (#20880)
  Social Icon Widget: Fix Icons Not Saving (#20862)
  Dashboard: Add a specific message for a site that is too new to have a rewind status (#20863)
  Add additional properties to WC Analytics events (#20812)
  Connection: add spinner for the "Connect" button (#20872)
  Update storybook monorepo to v6.3.7 (#20877)
  Lightweight PHPCS (#20876)
  Recommendations: Add Jetpack Product Suggestions step (#20814)
  Update babel monorepo (#20875)
  Update wordpress monorepo (#20873)
  cli: Check subprocess exit statuses in docker commands (#20861)
  Facebook Widget: Fix URL error when adding widget (#20864)
  Stats: make nudges collapsible (#20765)
  Remove temporary Newspack block override css (#20868)
  Allow ZIP uploads via Calypso (#20860)
  Sync Package Release v1.26.0 (#20870)
  Connection: remove in-place in secondary flows (#20739)
  BUILD_DIR -> BUILD_BASE in initial checks (#20857)
  E2E tests: Fix missing action for atomic workflow (#20866)
  Boost: Fix skip proxy origins to load css during critical CSS generation (#20793)
  ...
@kraftbj kraftbj removed the [Status] Ready to Merge Go ahead, you can push that green button! label Sep 29, 2021
@coder-karen coder-karen removed the [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account label Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WooCommerce Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new events to the Analytics module
8 participants