This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
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.
For #8
In preparation for releasing
wc-admin
to the .org repository, we should begin to add in tracking to aspects of the project so we can get a better idea of how users are interacting with the new designs. To enable us to do so, this PR adds a script tag forw.js
to be loaded onto wc-admin pages when the option towoocommerce_allow_tracking
is set toyes
.w.js
will give us the necessary pipeline to record tracks events.My first inclination was to use
wp_enqueue_script
but it appears there is no way to easily defer/async load the stats asset this route, so instead I took some inspiration fromloadScript
in Calypso to arrive at this solution. Since I can't think of an immediate need to load other external scripts like this, I figured doing a quick one-off implementation would be good for now, but would absolutely be open to ways to improve this interesting code 😄 .Questions
w.js
a cache buster string is added to force a download of a new version. I have omitted that here, but we will likely need to add that in 😢After this is merged in, I anticipate doing another PR to create a simple
lib/analytics
wrapper that can key off ofwcSettings.trackingEnabled
that will allow components to record tracks. At this layer we can also add in logic to try and filter out our test envs from being tracked too.To Test
update_option( 'woocommerce_allow_tracking', 'yes' );
_tkq
is presentupdate_option( 'woocommerce_allow_tracking', 'no' );
_tkq
is not present on the window