-
Notifications
You must be signed in to change notification settings - Fork 13
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
Allow opting into analytics #101
Conversation
Though it only has free plugin logic, wiht an action for the Pro plugin (or anything else) to run.
php/Blocks/Loader.php
Outdated
if ( Settings::ANALYTICS_OPTED_IN_VALUE === get_option( Settings::ANALYTICS_OPTION_NAME ) ) { | ||
wp_enqueue_script( | ||
self::ANALYTICS_SCRIPT_SLUG, | ||
'https://www.googletagmanager.com/gtag/js?id=UA-17364082-14', |
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 UA id should probably be unique to GCB
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.
Should be able to get that from the GA dashboard
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.
OK nice, could you Slack me a link to that?
@@ -1 +1 @@ | |||
lts/* | |||
14 |
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.
Node LTS used to be 14
, but now it's 16
. It seems that Gutenberg still uses 14
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.
interesting! I haven't heard of this lts
before.
@@ -0,0 +1 @@ | |||
export { default as GAClient } from './GAClient'; |
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 silly for one file, but it follows the pattern of exporting files in all of the other directories
js/src/common/classes/GAClient.js
Outdated
}; | ||
|
||
// @ts-ignore | ||
this.config = window.genesisAnalyticsConfig || {}; |
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.
Does this value need to be window.gcbAnalyticsConfig
?
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.
Uf, you're right.
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.
Fixed in b45e3a3
js/src/block-editor/index.js
Outdated
registerBlocks( genesisCustomBlocks, gcbBlocks, Edit ); | ||
|
||
domReady( () => { |
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.
domReady
is interesting. Where you coming across any issues that needed this?
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's a good point, I didn't notice that it was needed.
Moving it out of domReady()
now…
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.
Moved out in 87d1f45
js/src/block-editor/index.js
Outdated
|
||
domReady( () => { | ||
// @ts-ignore | ||
window.dataLayer = window.dataLayer || []; |
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.
What was you logic for moving window.dataLayer
our of GAClient
?
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.
Not a functional reason, I just like class files to have only the class, and no logic other than that.
Maybe from too much time in PHP 🤣
But if you'd prefer, I could move it back.
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.
Actually, I'm going to move it back.
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.
Moved it back in 9d8bd80
* | ||
* @return {() => void} A debounced function. | ||
*/ | ||
const debounce = ( func, wait ) => { |
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.
It doesn't follow the same standard as the rest of this plugin, but it is possible to name the export instead of using default
.
export const debounce = () => { ... }
That will prevent the need for export default debounce
at the bottom, and it can be included with
include { debounce } from './debounce';
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.
Yeah, this plugin's setup is a bit outdated, with the index.js
file having all of the exports.
Ideally, I'd modernize the whole js/src
directory.
But it might be strange to not have this debounce
in index.js
, while all of the other helper functions are in it.
@@ -158,6 +166,22 @@ public function editor_assets() { | |||
] | |||
); | |||
|
|||
if ( Settings::ANALYTICS_OPTED_IN_VALUE === get_option( Settings::ANALYTICS_OPTION_NAME ) ) { |
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.
Do you want to factor in any historical opt-in events like we just merged into GB?
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.
Hm, good question.
That might be something for product, but I think for this scope, this might be enough.
There is no genesisAnalyticsConfig in this plugin.
There is no genesisAnalyticsConfig in this plugin.
It's an essential part of the class, so it's strange to not have it in that file.
* @param {boolean | number | string} enable The value to be set. | ||
*/ | ||
enableAnalytics( enable ) { | ||
enable = !! +enable; |
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.
I'm not sure I'm familiar with this syntax. What is happening on this line?
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.
Ah, I stole that from BMO.
I didn't know about +
either.
It's first casting enable
to a Number
with +enable
. For example, converting '0'
to 0
.
Then, it casts it to a Boolean
with !!
.
I think this prevents an enable
value of '0'
from being true
.
Like:
if ( '0' ) {
console.log( 'This is true' );
}
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.
Thanks!
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.
Of course! I just found out about +
Hi @johnstonphilip, |
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.
Great work!
@BMO-tech, thanks so much for your testing and review. |
Changes
Fixes GF-3267
Testing instructions
composer i && npm i && npm run dev
window.GcbAnalytics