-
Notifications
You must be signed in to change notification settings - Fork 805
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
WooCommerce Analytics: Queue add_to_cart
Events
#9052
Conversation
* @param $cart_item_data | ||
*/ | ||
public function capture_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) { | ||
if ( ! is_single() ) { |
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.
add_to_cart
Events
4793a0f
to
dacc670
Compare
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.
Some quick comments, will run some further tests shortly and report back.
); | ||
// check for previous add-to-cart cart events | ||
$data = WC()->session->get( 'wca_session_data' ); | ||
if ( !empty( $data ) ) { |
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.
minor but space between ! empty
@@ -325,4 +303,89 @@ public function get_user_id() { | |||
return 'null'; | |||
} | |||
|
|||
/** | |||
* @param $cart_item_key |
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.
Indentation is a little wonky right here.
public function capture_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) { | ||
$referer_postid = isset( $_SERVER['HTTP_REFERER'] ) ? url_to_postid( $_SERVER['HTTP_REFERER'] ) : 0; | ||
// if the referring post is not a product OR the product being added is not the same as post | ||
// (eg. related product list on single product page) then include a product view event |
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.
Also noting from our convo today - how will this bit of logic respond to a quick add event from a product listing page?
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.
Good point. It captures the add_to_cart
action properly -- but it does also fire off a view which might not be accurate in this case.
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.
yes, adding a product from the product page results in 2 product_view
s and one add-to-cart
if the referring post is not a product OR the product being added is not the same as post
(eg. related product list on single product page) then include a product view event
This is correct, and when I step through the code, this portion behaves as expected. Digging further, the extra page view is from the page refresh, and you can see that working in the master branch.
@greenafrican Since we are utilizing session
, in capture_product_view
we can check to see if a product_view
is about to be dropped. This may depend on timing. Is it worth exploring?
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.
Digging further, the extra page view is from the page refresh
Yes, I had an extra check to prevent these but removed it yesterday as it can cause other issues down the line. For example, if the user continues to add_to_cart
we log all the additional add_to_cart
events but no further product_views
. It is not ideal/perfect as is but I'd rather there were a few extra product_views
than have a situation where there can be more add_to_carts
than product_views
. The more I think about this the more I wonder if we don't need to move to reporting on uniques rather than simple counts.
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.
how will this bit of logic respond to a quick add event from a product listing page?
@timmyc It will add both a product_view
and an add_to_cart
event, which is what we want.
It captures the add_to_cart action properly -- but it does also fire off a view which might not be accurate in this case.
@justinshreve My thoughts are that we do want the product_view
here for 2 reasons: 1) we don't want a situation where we have more add_to_cart
events than product_views
in a funnel, 2) I feel as though, by clicking add_to_cart
, the user has 'looked' at the product.
|
||
/** | ||
* @param $product_id | ||
* @param $qty |
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.
s/qty/quantity ?
|
||
// extract new event data | ||
$new_data = array( | ||
'event' => $event, |
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.
spacing a bit off here too.
/cc @justinshreve - would be keen to have you 👀 this PR if you have some time. |
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.
A few comments. Events seem to be firing correctly.
$product_id, | ||
$quantity, | ||
$event, | ||
$cart_item_key = '' ) { |
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.
Minor: I'm not a fan of having each argument on it's own line here.
|
||
// check for existing data | ||
$data = WC()->session->get( 'wca_session_data' ); | ||
if ( empty( $data ) || !is_array( $data ) ) { |
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.
Space between !
and is_array
/** | ||
* Gets product categories or varation attributes as a formatted concatenated string | ||
* | ||
* @param array $product WC_Product. |
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.
$product
is an object, not an array.
public function capture_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) { | ||
$referer_postid = isset( $_SERVER['HTTP_REFERER'] ) ? url_to_postid( $_SERVER['HTTP_REFERER'] ) : 0; | ||
// if the referring post is not a product OR the product being added is not the same as post | ||
// (eg. related product list on single product page) then include a product view event |
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.
Good point. It captures the add_to_cart
action properly -- but it does also fire off a view which might not be accurate in this case.
$product_id, | ||
$quantity, | ||
$event, | ||
$cart_item_key = '' ) { |
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.
$cart_item_key
is unused in this function
send product view events for products added to cart from any list or non-product detail page
…non-product detail page
eefb048
to
4ec0832
Compare
Any ideas why 88e8644 broke the build for this branch? |
It probably just needs a restart - I restarted two failed jobs, let's see what happens. |
Thanks @zinigor |
Thanks for the reviews @timmyc @psealock @justinshreve Fixes included in the latest squashed commit:
|
@jeherve Would you mind reviewing this PR, to be included in v5.9.1 if possible? |
@psealock @timmyc @justinshreve would you mind doing another review of this? |
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.
Gave this another run through. Works as expected, didn't find anything odd.
* Changelog 6.0: create base for changelog. * Add #8938 to changelog * Add #8962 to changelog * Add #8974 to changelog * Add #8975 to changelog * Add #8978 to changelog * Add #8867 to changelog * Add #8937 to changelog * Add #8961 to changelog * Add #8855 to changelog * Add #8944 to changelog * Add #8973 to changelog * Add #8977 to changelog * Add #8979 to changelog * Add #8980 to changelog * Add #8982 to changelog * Add #8983 to changelog * Add #8984 to changelog * Add #8986 to changelog * Add #9005 to changelog * Add #9010 to changelog * Add #9012 to changelog * Add #9021 to changelog * Add #9022 to changelog * Add #9056 to changelog * Add #9061 to changelog * Add #9079 to changelog * Add #9080 to changelog * Add #9088 to changelog * Add #9096 to changelog * Add #9097 to changelog * Add #9100 to changelog * Add #9107 to changelog * Add #8969 to changelog * Add #8993 to changelog * Add #9003 to changelog * Add #9031 to changelog * Add #8945 to changelog * Add #9052 to changelog * Add #9058 to changelog * Add #9066 to changelog * Add #9076 to changelog * Add #9053 to changelog * Add #9108 to changelog * Add #9135 to changelog * Add #9148 to changelog * Add #9125 to changelog * Add #9137 to changelog * Added testing instructions for 6.0. * Added IS testing instructions, huge props to @tiagonoronha. * Added #8498 to changelog. * Added #8954 to changelog. * Added #8985 to changelog. * add #9027 * add #9112 to changelog * add #9136 to changelog * add #9102 to changelog * add #9093 to changelog * add #9062 to changelog * add #9172 to changelog
Fixes #9049
Changes proposed in this Pull Request:
add_to_cart
events and logging on the next pageproduct_view
events from product pageTesting instructions:
http://exampleshop.com/?add-to-cart=${product_id}
Proposed changelog entry for your changes:
WooCommerce Analytics: Start tracking all possible ways to add a product to a cart