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 woo analytics event props for block/shortcode use in cart/checkout #15127

Merged
merged 4 commits into from
Mar 30, 2020

Conversation

haszari
Copy link
Contributor

@haszari haszari commented Mar 25, 2020

This PR adds additional props to woocommerceanalytics events so we can filter based on how stores implement their cart & checkout pages.

New cart & checkout blocks are coming soon in the WooCommerce Blocks plugin. We're planning to evaluate these blocks by measuring conversion rates from the existing woocommerceanalytics events, in particular add_to_cart, product_checkout and product_purchase. To compare traditional and block-based UX, we need to add these new props to the events.

The new props are as follows. Values are 0 or 1, consistent with other boolean tracks props.

  • cart_page_contains_cart_block
  • cart_page_contains_cart_shortcode
  • checkout_page_contains_checkout_block
  • checkout_page_contains_checkout_shortcode

Screen Shot 2020-03-26 at 1 02 11 PM

Changes proposed in this Pull Request:

  • Utility functions for determining if a woo site is using shortcodes or blocks on the cart & checkout pages.
  • Include this info as props on all woocommerceanalytics events.
  • Cache this info in a transient (1-day life, jetpack-woocommerce-analytics-cart-checkout-info-cache).

Is this a new feature or does it add/remove features to an existing part of Jetpack?

This adds features to the existing woocommerce-analytics module.

Testing instructions:

  • This requires WooCommerce to be installed and set up on the site, with some products. Recommend setting up Cash on delivery payment method for easy checkout.
  • The events are disabled for development sites. Use an incognito window, or hack this by adding return true; at the start of Jetpack_WooCommerce_Analytics::shouldTrackStore().
  • Open network tab in browser dev tools, search for pixel.wp.com.
  • View a product on the front end of your site. You should see a request for woocommerceanalytics_product_view event. This should have new properties (parameters) as above. Check that the values are correct. You'll probably have 1 for shortcodes and 0 for blocks.

If you install the current master branch of WooCommerce Blocks, you can add the cart & checkout blocks to the cart & checkout pages and retest - the values should show the correct info. If don't have blocks plugin and want to hack some more, you can fake this by adding an html comment that looks like the start of one of the blocks.

You can also test edge cases such as:

  • Add the shortcodes and blocks to the pages, i.e. use both at the same time.
  • Delete all content from the pages, or switch in some alternative cart or checkout solution (e.g. One Page Checkout).
  • Add cart/checkout shortcodes/blocks to other pages (not cart/checkout page).
  • Break your woo setup or skip onboarding so there is no designated cart/checkout page.

Note that this is cached in a transient for a day, so if you change your setup, you'll need to wait a day to retest, or delete the transient:

yarn docker:wp transient delete "jetpack-woocommerce-analytics-cart-checkout-info-cache"

Note: right now, the events are not all consistently firing for block-based cart & checkout (e.g. woocommerce/woocommerce-blocks#2031). For example, product_checkout only works with shortcode checkout. This is a separate issue and will be fixed in a separate PR. Please be aware of this when testing with blocks :)

Proposed changelog entry for your changes:

  • Added props to WooCommerce Analytics events indicating if store is using blocks or shortcodes on cart & checkout pages.

@haszari haszari requested a review from a team as a code owner March 25, 2020 23:16
@haszari haszari self-assigned this Mar 25, 2020
@haszari haszari added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Status] Needs GDPR Review [Status] Needs Tracks Review Added/removed/modified a tracks event. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] WooCommerce Analytics labels Mar 25, 2020
@haszari haszari added this to the 8.4 milestone Mar 25, 2020
@jetpackbot
Copy link

jetpackbot commented Mar 25, 2020

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: April 7, 2020.
Scheduled code freeze: March 31, 2020

Generated by 🚫 dangerJS against 7a6b95b

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 tests well for me. I only have minor remarks.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Mar 26, 2020
Copy link
Member

@deltaWhiskey deltaWhiskey left a comment

Choose a reason for hiding this comment

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

I agree with the other reviewers' comments. Otherwise, looks good to me.

I only reviewed code, and did not test.

I'm concerned how this approach will work a year from now. If many features, such as these blocks, will result in properties being added to every woocommerceanalytics_ event, then the event data could become quite heavy. Especially with the verbose names of the new properties. I do like the self-explanatory names, though.

This is a non-issue if these are the only such properties that will be added in the foreseeable future. But, if more are coming, perhaps the properties should only be added to relevant events. Or a once-per-visit event could be sent with the details for this url.

@haszari haszari force-pushed the update/woo-analytics-cart-checkout-props branch from 5efc95c to 7a6b95b Compare March 26, 2020 22:04
@haszari
Copy link
Contributor Author

haszari commented Mar 26, 2020

I'm concerned how this approach will work a year from now. If many features, such as these blocks, will result in properties being added to every woocommerceanalytics_ event, then the event data could become quite heavy. Especially with the verbose names of the new properties. I do like the self-explanatory names, though.
This is a non-issue if these are the only such properties that will be added in the foreseeable future. But, if more are coming, perhaps the properties should only be added to relevant events. Or a once-per-visit event could be sent with the details for this url.

Good point @deltaWhiskey - I would definitely prefer to log these more "static" props using such an event. Let's keep this in mind as we iterate - I believe there's no standard mechanism for sending a once-per-visit event right now, so we'd need to develop that.

@haszari
Copy link
Contributor Author

haszari commented Mar 26, 2020

Feedback addressed & rebased the branch - please re-review when ready :)

@jeherve Should I address codeclimate issue (below) before merge? I could move post_contains_text() and get_cart_checkout_info() into a utility class perhaps.

File wp-woocommerce-analytics-universal.php has 292 lines of code (exceeds 250 allowed). Consider refactoring.

@haszari haszari added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Mar 26, 2020
@jeherve
Copy link
Member

jeherve commented Mar 27, 2020

Should I address codeclimate issue (below) before merge?

No need, I don't think it's really worth it.

Our CodeClimate configuration is still a work in progress; we need to update its configuration a bit more so it can provide more useful suggestions. Right now it can sometimes be helpful or provide an interesting point of view on how some things could be refactored, but really most of the time it's not super helpful imo. :)

),
);

set_transient( 'jetpack-woocommerce-analytics-cart-checkout-info-cache', $info, DAY_IN_SECONDS );
Copy link
Member

Choose a reason for hiding this comment

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

You'll want to update the transient name here as well, or make it a variable maybe to avoid further issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

D'oh! Fixed here: 6bfc817

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ready for review again @jeherve :)

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Mar 27, 2020
@haszari haszari removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Mar 27, 2020
@haszari haszari added the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Mar 27, 2020
@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 Crew. Label will be renamed soon. labels Mar 30, 2020
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 in my tests. 🚢

@jeherve jeherve merged commit c276917 into master Mar 30, 2020
@jeherve jeherve deleted the update/woo-analytics-cart-checkout-props branch March 30, 2020 14:52
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Mar 30, 2020
jeherve added a commit that referenced this pull request Mar 31, 2020
jeherve added a commit that referenced this pull request Mar 31, 2020
* Initial changelog entry

* Changelog: add #14904

* Changelog: add #14910

* Changelog: add #14913

* Changelog: add #14916

* Changelog: add #14922

* Changelog: add #14924

* Changelog: add #14925

* Changelog: add #14928

* Changelog: add #14840

* Changelog: add #14841

* Changelog: add #14842

* Changelog: add #14826

* Changelog: add #14835

* Changelog: add #14859

* Changelog: add #14884

* Changelog: add #14888

* Changelog: add #14817

* Changelog: add #14814

* Changelog: add #14819

* Changelog;: add #14797

* Changelog: add #14798

* Changelog: add #14802

* Changelog: add #13676

* Changelog: add #13744

* Changelog: add #13777

* Changelog: add #14446

* Changelog: add #14739

* Changelog: add #14770

* Changelog: add #14784

* Changelog: add #14897

* Changelog: add #14898

* Changelog: add #14968

* Changelog: add #14985

* Changelog: add #15044

* Changelog: add #15052

* Update to remove Podcast since it remains in Beta

* Changelog: add #14803

* Changelog: add #15028

* Changelog: add #15065

* Changelog:add #14886

* Changelog: add #15118

* Changelog: add #14990

* Changelog: add #14528

* Changelog: add #15120

* Changelog: add #15126

* Changelog: add #15049

* Chanegelog: add #14852

* Changelog: add #15090

* Changelog: add #15138

* Changelog: add #15124

* Changelog:add #15055

* Changelog: add #15017

* Changelog: add #15109

* Changelog: add #15145

* Changelog:add #15096

* Changelog:add #15153

* Changelog: add #15133

* Changelog: add #14960

* Changelog: add #15127

* Changelog: add #15056

* Copy current changelog to changelog archive.

* Clarify changelog description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WooCommerce Analytics [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.

6 participants