Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Add w.js when wc_tracker is enabled. #369

Merged
merged 1 commit into from
Sep 7, 2018
Merged

Add w.js when wc_tracker is enabled. #369

merged 1 commit into from
Sep 7, 2018

Conversation

timmyc
Copy link
Contributor

@timmyc timmyc commented Sep 7, 2018

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 for w.js to be loaded onto wc-admin pages when the option to woocommerce_allow_tracking is set to yes. 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 from loadScript 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

  • Not entirely certain if tracks will record properly for sites that are not WooPack ( /cc @greenafrican and @psealock for any ideas here )
  • In other projects when loading 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 of wcSettings.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

  • Enable tracking on your site by updating via update_option( 'woocommerce_allow_tracking', 'yes' );
  • Open up a wc-admin page, and in the js console, verify that _tkq is present
  • Disable the wc tracker update_option( 'woocommerce_allow_tracking', 'no' );
  • Refresh the wc-admin page and verify _tkq is not present on the window

@timmyc timmyc requested a review from a team September 7, 2018 00:26
@psealock
Copy link
Collaborator

psealock commented Sep 7, 2018

Not entirely certain if tracks will record properly for sites that are not WooPack

Events will be recorded correctly, but users will be tracked by a cookie-based anonymous id. In terms of measuring usage, I think this will be sufficient.

Copy link
Collaborator

@psealock psealock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working as described. w.js loads and records initial event

@timmyc
Copy link
Contributor Author

timmyc commented Sep 7, 2018

Thank you kindly for the feedback and confirmation on the non-Jetpack sites @psealock. I'm hoping we don't need to worry about cache busting too often. Did that ever get improved from a systems side with an etag or some sort of automated expiry?

@timmyc timmyc merged commit 83e7753 into master Sep 7, 2018
@timmyc timmyc deleted the add/w-js branch September 7, 2018 14:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants