-
Notifications
You must be signed in to change notification settings - Fork 801
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
Fix - No GA code when Enable Enhanced eCommerce
option is active but WooCommerce is not active
#10092
Conversation
That's a great PR description, thank you so much for your effort! Generated by 🚫 dangerJS |
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.
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.
Small suggested change, but not a blocker.
if ( Jetpack_Google_Analytics_Options::enhanced_ecommerce_tracking_is_enabled() ) { | ||
// At this time, we only leverage universal analytics when enhanced ecommerce is selected and WooCommerce is active. | ||
// Otherwise, don't bother emitting the tracking ID or fetching analytics.js | ||
if ( Jetpack_Google_Analytics_Options::enhanced_ecommerce_tracking_is_enabled() && class_exists( 'WooCommerce' ) ) { |
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.
This is extremely nitpicky, but sharing to help frame something to keep in mind. With an &&
operation, it checks left-to-right and fails on the first failed condition—so the enhanced_ecommerce_tracking_is_enabled
, then the class_exists
check. The class_exists
check is pretty cheap, but enhanced_ecommerce_tracking_is_enabled
eventually calls get_option
, which may or may not be a db hit (didn't look to see if the option is autoloaded or not).
In this case, it probably isn't a huge thing, but for the sake of performance, thinking about the order things are checked can help you out.
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 makes sense to me! Thanks Kraft 👍
I've pushed a new commit to reorder the condition positions
That would help the performance a bit.
Hi @htdat - what's the use case that this addresses? Thx! |
@allendav The use case I'm testing for is someone who had a WooCommerce site and started tracking with enhanced eCommerce, then stopped using WooCommerce (for whatever reason). Before the PR, it would disable all Google Analytics code since WooCommerce wasn't active. |
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.
Works as described.
@@ -49,12 +49,6 @@ public function wp_head() { | |||
return; | |||
} | |||
|
|||
// At this time, we only leverage universal analytics for enhanced ecommerce. If WooCommerce is not | |||
// present, don't bother emitting the tracking ID or fetching analytics.js | |||
if ( ! class_exists( 'WooCommerce' ) ) { |
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.
Why remove this? Although the other change you made will prevent this class from being instantiated unless WooCommerce is active, this is a nice extra layer of protection that avoids this class becoming dependent on another class for sanity.
@@ -50,7 +50,9 @@ class Jetpack_Google_Analytics { | |||
* @return void | |||
*/ | |||
private function __construct() { | |||
if ( Jetpack_Google_Analytics_Options::enhanced_ecommerce_tracking_is_enabled() ) { | |||
// At this time, we only leverage universal analytics when enhanced ecommerce is selected and WooCommerce is active. | |||
// Otherwise, don't bother emitting the tracking ID or fetching analytics.js |
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.
Maybe reword or even completely remove this comment because it is a little confusing since the else condition will emit a tracking ID ala legacy.
@kraftbj wrote
OK, fair enough. So we want to "fall back" to legacy analytics if WooCommerce is deactivated while this "enhanced eCommerce" option is active - that's cool. |
* Readme: add boilerplate for next release, 6.6 * Add 6.5 to the changelog.txt file * Set boilerplate testing list for 6.6 * Readme: update stable tag to 6.5 * Add bullets to 6.5 changelog items * Readme: add link to previous changelogs This will help folks who want to know more about past releases, while keeping the readme.txt short so as to not overwhelm translators and site owners only looking for information about the last release. * Changelog: add information at the top of the changelog file. * Changelog: add #10054 * Changelog: add #10078 * Changelog: add #10079 * Changelog: add #10064 * Changelog: add #10094 * Changelog: add #10096 * Testing list: add more information based on #10087 * Changelog: add #9847 * Changelog: add #10084 * Changelog: add #9918 * Changelog: add #7614 * Changelog: add #10116 * Changelog: add #10108 * Changelog: add #10041 * Changelog: add #10121 * Changelog: add #10134 * Changelog: add #10130 * Changelog: add #10109 * changelog: add #10137 * changelog: add #9952 * changelog: add #10120 * changelog: add #10162 * Changelog: add #10163 * Changelog: add #10092 * changelog: add #10156 * Changelog: add #10154 * changelog: add #10122 * Changelog: add #10101 * changelog: add #10105 * changelog: add #10190 * Changelog: add #10196 * changelog: add #10152 * Changelog: add #10153 * Testing list: add more details to Site Verification testing steps. @see #10143 (comment) * changelog: add #10194 * Changelog: add #10193
👋from a HE. My first PR. Thanks for the feedback in advance :)
Fixes #10091
Changes proposed in this Pull Request:
Currently, Jetpack does not output the GA tracking code in a specific case, which can be replicated as you see on #10091 :
Enable Enhanced eCommerce
option is activeTesting instructions:
Jetpack Google Analytics
.Proposed changelog entry for your changes:
Fix Bug - Do not output the Google Analytics code when
Enable Enhanced eCommerce
option is active but WooCommerce is not active