-
Notifications
You must be signed in to change notification settings - Fork 221
Track checkout and cart page info (blocks in use or shortcode in use) #10815
Track checkout and cart page info (blocks in use or shortcode in use) #10815
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThe
This comment was automatically generated by the TypeScript Errors Report
assets/js/base/context/hooks/cart/test/use-store-cart.js
assets/js/base/context/hooks/collections/test/use-collection.js assets/js/base/context/hooks/test/use-query-state.js assets/js/base/hocs/test/with-reviews.js assets/js/base/hooks/test/use-previous.js assets/js/base/hooks/test/use-shallow-equal.js assets/js/blocks/classic-template/index.tsx assets/js/blocks/price-filter/test/use-price-constraints.js assets/js/blocks/reviews/frontend-container-block.js assets/js/blocks/reviews/frontend.js assets/js/data/checkout/thunks.ts assets/js/data/payment/thunks.ts assets/js/editor-components/template-notice/index.tsx assets/js/extensions/jetpack/woocommerce-analytics/index.ts assets/js/hocs/test/with-categories.js assets/js/hocs/test/with-category.js assets/js/hocs/test/with-product-variations.js assets/js/hocs/test/with-product.js assets/js/hocs/test/with-searched-products.js assets/js/templates/revert-button/index.tsx node_modules/@wordpress/core-data/src/entities.ts |
Size Change: +1.26 kB (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
1108658
to
d28368a
Compare
927e49c
to
8a299f4
Compare
d5b5301
to
78d2e12
Compare
a2d069d
to
f50666b
Compare
This PR has been marked as If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing fine for me, but I'm seeing cart and checkout page views being triggred on both Cart and Checkout, so an extra event for both?
- In Cart, I see both Cart and Checkout.
- In Checkout, I see both Cart and Checkout.
return typeof wca.push === 'function'; | ||
}; | ||
|
||
const registerActions = (): void => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a placeholder for when we added shipping/payment method change events. If you like we can remove it from this PR or keep it so we have the code in place when it comes to adding them? Happy either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to keep it as long as we're not merging to trunk until we add said tracking.
Are you using Blocks/Shortcodes for this? I'm going to test later today but if you can share this info it will make it quicker for me! |
const registerActions = (): void => { | ||
if ( ! isValidWCA( window._wca ) ) { | ||
// eslint-disable-next-line no-useless-return | ||
return; | ||
} | ||
|
||
// We will register actions here in a later PR. | ||
}; | ||
|
||
document.addEventListener( 'DOMContentLoaded', () => { | ||
registerActions(); | ||
} ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const registerActions = (): void => { | |
if ( ! isValidWCA( window._wca ) ) { | |
// eslint-disable-next-line no-useless-return | |
return; | |
} | |
// We will register actions here in a later PR. | |
}; | |
document.addEventListener( 'DOMContentLoaded', () => { | |
registerActions(); | |
} ); |
@senadir if you'd like to remove this code from this PR quickly, feel free to apply this suggestion.
Hey @senadir I tested this again on my end and I don't see the duplicated events. I don't see how that could be possible, unless the Cart/Checkout URLs in |
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
I had ugly permalink, that could be it, I will test again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing fine for me but I feel like it introduced a regression, when adding a product from the empty cart view, I'm seeing 2 add_to_cart events instead of 1.
I can't see that in trunk.
…#10815) Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
…#10815) Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
…#10815) Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
…#10815) Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
What
This PR adds tracking for cart and checkout pageview events when using Jetpack WooCommerce Analytics.
Summary of changes:
wc-blocks-jetpack-woocommerce-analytics
which is only loaded when on Cart/Checkout or order received pages.JetpackWooCommerceAnalytics
class to handle loading of the above script when on the cart/checkout page.Why we are using
DOMContentLoaded
We added an event listener for
DOMContentLoaded
in the above mentionedwc-blocks-jetpack-woocommerce-analytics
script that would run themaybeTrack...PageView
functions. While relying onDOMContentLoaded
doesn't feel great, it's probably the only way we can reliably send the tracking events when_wca.push
is ready, below is a list of issues we faced trying to get this working:wc/store/cart
data store, and send the tracking event as soon as the cart was loaded. Unfortunately, it seemed that the cart data store finished initialising and had received all of its actions before the_wca.push
function was ready.wc/store/cart
data store to send the event. This is because the store would receive an action (SELECT_SHIPPING_RATE
) after page load which caused our subscribe function to run and send the event, however if the cart did not have any shippable items this would not have fired.Order Received event
This event is a little different to the cart/checkout pageview events because at the point of recording those events we have access to the
wc/store/cart
data store and therefore we are able to get the cart items easily to fill the event properties. In the order received page, we don't have this data store, and no way to access the data on the front end.The approach taken here was to collect all of the data relating to an order on the
woocommerce_thankyou
hook in PHP, and add it to the WooCommerce Blocks asset data registry. Since this hook only fires on the order received page, that key in the asset data registry would only be set on that page. On the front end we can check for the presence of data in that key and therefore determine reliably if we are on the order received page.The page would load and this key that contains the event properties would be used to populate a
_wca.push
call.Why
To enable pageview tracking when using the WooCommerce Analytics module in Jetpack.
Testing Instructions
Please consider any edge cases this change may have, and also other areas of the product this may impact.
cart_page_contains_cart_block
,cart_page_contains_cart_shortcode
,checkout_page_contains_checkout_block
, andcheckout_page_contains_checkout_shortcode
are correct.woocommerceanalytics_order_confirmation_view
event is being sent and the correct properties are sent with it.Screenshots or screencast
WooCommerce Visibility
Required:
Checklist
Required:
[type]
label or a[skip-changelog]
label.Conditional:
[skip-changelog]
label is not present).Changelog