-
Notifications
You must be signed in to change notification settings - Fork 800
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
New module for WooCommerce analytics #8296
Conversation
'id': productSku ? productSku : '#' + productID, | ||
'quantity': $( this ).data( 'quantity' ), | ||
}; | ||
_wca.track( { |
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.
Include a page view in here as well.
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.
Was thinking of commenting on the GA code too for this.
@allendav @dereksmart - We have previously looked at manually sending a product view event when an add-to-cart event is triggered from a list (eg. shop) page so that you can never have a 0 view -> 1 cart -> 1 purchase funnel. What do you think?
Do you think its worth it to integrate this code into the existing GA module? We could rename it, of course. |
|
||
wc_enqueue_js( | ||
"window._wca = window._wca || []; | ||
$( '" . esc_js( $selector ) . "' ).click( function() { |
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.
$
will need to be jQuery
*/ | ||
private function __construct() { | ||
$analytics = new Jetpack_WooCommerce_Analytics_Universal(); | ||
} |
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.
Seems like this would be the ideal place to do all the checks for isActiveStore
or WooCommerce is indeed installed.
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 idea, I also noted the repeated checks to WooCommerce
above.
I pulled this branch down and the code doesn't seem to be included when I hit the page. Any tips? EDIT: I threw this in a random place to get it to work:
|
return ''; | ||
} | ||
|
||
return $product->get_sku() ? $product->get_sku() : '#' . $product->get_id(); |
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.
Since this is an internal tool, lets drop the #
from the id and remove references to sku
, which won't be needed
$selector = ".add_to_cart_button:not(.product_type_variable, .product_type_grouped)"; | ||
|
||
wc_enqueue_js( | ||
"$( '" . esc_js( $selector ) . "' ).click( function() { |
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.
By listening to the added_to_cart
Woo event, we can fire our added to cart event when the server returns without errors on the callback.
jQuery('body').on('added_to_cart',function(){
// call track event here
}
Is there an advantage to sending the event as soon as the user clicks the button?
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.
The same situation for "remove from cart"
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.
Except that event isn't fired for the non-async add-to-cart, is it?
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.
That right. The add_to_cart
function above still has to handle non-async
Should we also track |
Thought about this a lot. Very happy to do that but I am concerned that GA is only available to premium users and we want to activate our module for all connected sites. Perhaps we can make some of the code usable for both modules? |
I'm not 100% clear on how to properly set up the module across Jetpack. I did get it to work by reading this - https://jetpack.com/support/control-jetpacks-modules-on-one-page/ Although the WooCommerce Analytics module appears and then disappears and then has a blank name once the page loads. |
Yes, eventually. My initial thought is let's get the basic cart tracking working so we can look at the back end analysis and then we can catch up on the front end edge cases. We should add it to our backlog. I guess we are interested in firing a remove from cart event when the quantity is updated to 0? We don't really care if it goes from 6 to 5, right? |
64acc65
to
eb2a1af
Compare
a5ec9d3
to
fa80140
Compare
Is this using our analytics, or GA? If it is ours, why not just add this to the existing stats module? |
Ours
This is what we had originally, but the idea is to allow the user to turn it off, should they choose. |
Checkout Process UpdateGA uses add_action( 'woocommerce_after_checkout_form', array( $this, 'checkout_process' ) ); This appears to be a bug because the code is run on the checkout screen, but before the user clicks on "Place Order". @allendav, am I reading this correctly? It seems these jetpack/modules/google-analytics/classes/wp-google-analytics-universal.php Lines 374 to 394 in eb3c3e3
We could use this opportunity to place a click event on the "Place Order" button, but if form validation fails its not really a placed order. Alternatively, we can use @greenafrican, this is where I'm at and I've run out of time for today, so I pushed my progress even though its not complete. |
Thanks @psealock I managed to do a bit of testing on this yesterday too.
I see they are tracking a I've wondered whether or not we should track We could use the |
7a03dc2
to
16352e5
Compare
I've updated the branch @psealock take a look and let me know what you think. |
Do you think I could have missed something? I eventually toggled everything in calypso for the advanced analytics for ecommerce |
Sounds like your setup should have worked just fine. I've tested the code in a variety of formats - stand-alone plugin, bundled with |
Thank you! |
Maybe it would be great to rebase this against latest master. The code is not conflicting, but a few releases have been out since this PR was opened. Relabeling as in need of author reply. When we're set please move to needs review again. |
@oskosk The behaviour you describe is the desired result. At the time of writing the testing instructions in the original comment,
Thats correct, we're only tracking users' users
Yup, thats right
You should be able to see events in the Network tab. I will update the test instructions and rebase from master now. Thanks again and sorry for the confusion. |
… analytics enhancements
2b8c138
to
0a25c99
Compare
awesome, thank you @psealock ! |
I'm merging this and opening an issue about it if I get to reproduce the problem 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.
LGTM!
* update changelog.txt * Update readme.txt with scaffolding for 5.9 changelog and release draft shortlink * Add changelog entry for #8243 * Add changelog entry for #8296 * Add changelog entry for #8367 * Add changelog entry for #8686 * Add changelog entry for #8707 * Add changelog entry for #8709 and #8714 * Add changelog entry for #8729 * Add changelog entry for #8777 * Add changelog entry for #8780 * Add changelog entry for #8786 * Add changelog entry for #8787 * Add changelog entry for #8801 #8805 #8832 #8865 and #8804 * Add changelog entry for #8817 * Add changelog entry for #8822 * Add changelog entry for #8823 * Add changelog entry for #8829 * Add changelog entry for #8834 * move some items to major enhancements * Add changelog entry for #8836 * Add changelog entry for #8839 * Add changelog entry for #8861 * Add changelog entry for #8862 * Add changelog entry for #8863 * Add changelog entry for #8866 * Add changelog entry for #8870 * Add changelog entry for #8874 * Add changelog entry for #8875 * Add changelog entry for #8881 * Add changelog entry for #8890 * Add changelog entry for #8911 * Add changelog entry for #8927 * Add changelog entry for #8931 * Add changelog entry for #8933 * Add changelog entry for #8930 * fix wording * typo * minor fixes * replace partner scripts for Jetpack Start in changelog entry * Update to-test.md * Update to-test.md * minor style fixes to to-test.md * minor style fixes to to-test.md * minor fixes on to-test.md * Add changelog entry for #8868 * Add changelog entry for #8844 * Add changelog entry for #8664 * Add changelog entry for #8935 * Add changelog entry for #8425 * Add changelog entry for #8625
New module with WooCommerce analytics ported from the recent Google Analytics enhancements.
Changes proposed in this Pull Request:
Testing instructions:
https://stats.wp.com/s-20180821.js
on public facing pages. The20180821
is dynamic and will change based on datehttps://stats.wp.com/s-20180821.js
is not requested onwp-admin
pages because this code should not run on admin facing pages. The same for logged in admin users._wca
global exists and is anarrayobject.Product Page View
t.gif
Add to Cart via a list
t.gif
Add to Cart via a Product Page
t.gif
Remove from Cart via click on the "X"
t.gif
Remove from Cart via updating the quantity
t.gif
Order Received
Legend
_en
: event namepi
: product idpn
: product namepq
: product quantitypc
: product categorypp
: product priceoi
: order idChangelog entry