Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a pull request onto an ongoing pull request #8123
cc @greenafrican
Main Change
Instead of placing information in a javascript object on the page for the Analytics repo to read, call the Analytics methods directly. Reasons for this include:
add-to-cart
events that use an AJAX request to fire an analytics event without a page refreshOther Changes
add-to-cart
event.add_action( 'woocommerce_add_to_cart' ...)
to capture a product added via a product page.handle_purchase_event
function. (Currently needs work)track
topush
so it can happen before or after initialization ofs.js
Issues
The ajax call to add a product to the cart can come from a cached page. This means any cart information coming from PHP can't be reliable. A cart hash and session id are available via cookies, but information on the contents of the cart aren't not. I see three possible solutions:
add-to-cart
events from PHP and keep track of cart details in session storage. The problem here is cookies such astk_rl
,tk_ro
,tk_ai
won't be available.