Skip to content
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

Blocks: add a new Cookie Consent Block #29197

Merged
merged 9 commits into from Mar 2, 2023
Merged

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Feb 28, 2023

Proposed changes:

Replay of #29191 in the Jetpack plugin.

This adds a new Beta block, to be used in block themes, to display a cookie consent banner on the site.

image

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

  • pdDR7T-Ax-p2
  • pdDR7T-Cr-p2

Does this pull request change what data or activity we track or use?

  • Yes, it adds a new cookie (eucookielaw) when you click to accept the banner. That cookie is already in use by the Cookies & Consents Banner widget, but that should still be documented.

Testing instructions:

  1. Start with a site that's connected to WordPress.com and where you have enabled Beta blocks (add_filter( 'jetpack_blocks_variation', function () { return 'beta'; } );).
    • On WordPress.com Simple, you do not need the filter. You will see the block when you are logged in.
  2. Go to Appearance > Themes and enable a block theme; Twenty Twenty Three will work.
  3. Go to Appearance > Site Editor
  4. You should now be able to add and customize the block.
    • Check that you can edit contents and change the settings in the block sidebar.
    • Check that your changes can be saved.
    • Check that your changes are visible on the frontend.
    • When dismissing the banner in the frontend, you will see the eucookielaw cookie be added in your browser. The banner should then be gone.
    • When refreshing the page, the banner should still be gone.

Replay of #29191 in the Jetpack plugin.

This adds a new Beta block, to be used in block themes, to display a cookie consent banner on the site.

Co-authored-by: Omar Alshaker <omar@omaralshaker.com>
@jeherve jeherve added [Feature] Extra Sidebar Widgets [Status] In Progress [Pri] Normal [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Feb 28, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 28, 2023

Are you an Automattician? You can now test your Pull Request on WordPress.com. On your sandbox, run

bin/jetpack-downloader test jetpack add/cookie-consent-block

to get started. More details: p9dueE-5Nn-p2

@github-actions
Copy link
Contributor

github-actions bot commented Feb 28, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: March 7, 2023.
  • Scheduled code freeze: February 28, 2023.

* @return bool
*/
function should_register_block() {
return true;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is there for development, it should be removed before we merge this PR.

attributes,
example: {
attributes: {
// @TODO: Add default values for block attributes, for generating the block preview.
Copy link
Member Author

Choose a reason for hiding this comment

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

We'd need to address that.

Copy link
Member

Choose a reason for hiding this comment

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

Do we have to add anything here if the block as a default value for every attribute?

source: 'html',
selector: 'p',
default: __(
'Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. To find out more, including how to control cookies, see here: <a href=https://automattic.com/cookies/>Cookie Policy</a>.',
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect that self-hosted sites would need a different link here. Maybe Atomic too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, for the widget we allow custom links in there, and also take into account the page you can set as your privacy policy page in WordPress:

'default-policy-url' => 'https://automattic.com/cookies/',
'custom-policy-url' => get_option( 'wp_page_for_privacy_policy' ) ? get_permalink( (int) get_option( 'wp_page_for_privacy_policy' ) ) : '',

This is something we could improve on in a follow-up PR I think.

Copy link
Member

Choose a reason for hiding this comment

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

It would be a nice improvement for the default value, but the block is entirely customizable and users can change the URL.

@alshakero
Copy link
Member

Thank you so much @jeherve and @anomiex! I addressed all your feedback.

  • Added a nice MIT licensed icon.
  • Removed the exclusion for sites with ads, took inspiration from the widget. I took this condition from wpcom/wp-content/mu-plugins/widgets/eu-cookie-law/eu-cookie-law.php but it doesn't seem to translate well in Jetpack (at least locally). And removing it is fairly harmless since the block is opt-in.
  • Made the description plain text. Hence, removed the learn more link.

Copy link
Member Author

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

I gave it a try. I think this first iteration is ready to merge; we can iterate in follow-up PRs.

I cannot approve it though since I opened the PR, so I'll let someone else from Crew take care of that.

I left some more comments below.


I wonder if some folks will be tempted to do something like this:

image

And if so, should we support having 2 buttons, one accept, one reject? That's probably something for a v2.

},
],
] }
templateLock="all"
Copy link
Member Author

Choose a reason for hiding this comment

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

It would be nice if I had more flexibility over the button, such as alignment within the block. Maybe we could give more options by not locking the button?

Since the button has to be there for the block to work, we could maybe take an approach similar to #24838?

Copy link
Member

Choose a reason for hiding this comment

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

We actually started with a much more flexible block, we had the whole thing as a template (see: pdDR7T-Cr-p2) but the flexibility makes it a great tool to abuse and show one-time ads on your site.

The only reason I see InnerBlocks here is that I couldn't figure hard-coding a customizable button. RichText only allowed us to hard-code a p but I was unable to find a way for a button.

allowedBlocks={ [ 'core/button' ] }
template={ [
[
'core/button',
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we would get more options by switching to using jetpack/button, like we do in most of our other blocks that use buttons?

Comment on lines +17 to +19
text: 'var(--wp--preset--color--contrast)',
background: 'var(--wp--preset--color--tertiary)',
link: 'var(--wp--preset--color--contrast)',
Copy link
Member Author

Choose a reason for hiding this comment

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

Something seems off with this. It grabs the colors just fine, but when I go to edit them, I see this:

image

Copy link
Member

Choose a reason for hiding this comment

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

I couldn't come up with a way to make this work. Undocumented and I tried everything I can come up with!

Comment on lines +43 to +57
{
label: isRTL() ? __( 'Right', 'jetpack' ) : __( 'Left', 'jetpack' ),
value: 'left',
},
{
label: __( 'Full', 'jetpack' ),
value: 'full',
},
{
label: __( 'Wide', 'jetpack' ),
value: 'wide',
},
{
label: isRTL() ? __( 'Left', 'jetpack' ) : __( 'Right', 'jetpack' ),
value: 'right',
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we offer a center option here as well?

Copy link
Member

Choose a reason for hiding this comment

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

It took us so much work to get this running in more than one theme.

onChange={ textValue => setAttributes( { text: textValue } ) }
/>
<InnerBlocks
allowedBlocks={ [ 'core/button' ] }
Copy link
Member Author

Choose a reason for hiding this comment

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

Could we allow headings here as well, for folks who want to add a bigger title before the explanation?

Copy link
Member

Choose a reason for hiding this comment

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

These InnerBlocks are only around the button. They're not meant to give control to the user. They're just a way to make the button customizable. I wish I could lock it down further.

@jeherve jeherve added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Status] Needs Team Review and removed [Status] In Progress labels Feb 28, 2023
Copy link
Member

@alshakero alshakero left a comment

Choose a reason for hiding this comment

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

Pushed some improvements and it looks great now!

attributes,
example: {
attributes: {
// @TODO: Add default values for block attributes, for generating the block preview.
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to add anything here if the block as a default value for every attribute?

source: 'html',
selector: 'p',
default: __(
'Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. To find out more, including how to control cookies, see here: <a href=https://automattic.com/cookies/>Cookie Policy</a>.',
Copy link
Member

Choose a reason for hiding this comment

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

It would be a nice improvement for the default value, but the block is entirely customizable and users can change the URL.

},
],
] }
templateLock="all"
Copy link
Member

Choose a reason for hiding this comment

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

We actually started with a much more flexible block, we had the whole thing as a template (see: pdDR7T-Cr-p2) but the flexibility makes it a great tool to abuse and show one-time ads on your site.

The only reason I see InnerBlocks here is that I couldn't figure hard-coding a customizable button. RichText only allowed us to hard-code a p but I was unable to find a way for a button.

Comment on lines +17 to +19
text: 'var(--wp--preset--color--contrast)',
background: 'var(--wp--preset--color--tertiary)',
link: 'var(--wp--preset--color--contrast)',
Copy link
Member

Choose a reason for hiding this comment

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

I couldn't come up with a way to make this work. Undocumented and I tried everything I can come up with!

Comment on lines +43 to +57
{
label: isRTL() ? __( 'Right', 'jetpack' ) : __( 'Left', 'jetpack' ),
value: 'left',
},
{
label: __( 'Full', 'jetpack' ),
value: 'full',
},
{
label: __( 'Wide', 'jetpack' ),
value: 'wide',
},
{
label: isRTL() ? __( 'Left', 'jetpack' ) : __( 'Right', 'jetpack' ),
value: 'right',
Copy link
Member

Choose a reason for hiding this comment

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

It took us so much work to get this running in more than one theme.

onChange={ textValue => setAttributes( { text: textValue } ) }
/>
<InnerBlocks
allowedBlocks={ [ 'core/button' ] }
Copy link
Member

Choose a reason for hiding this comment

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

These InnerBlocks are only around the button. They're not meant to give control to the user. They're just a way to make the button customizable. I wish I could lock it down further.

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

I'll go with Jeremy saying it's good enough to merge and iterate on.

@jeherve jeherve merged commit b8fd51f into trunk Mar 2, 2023
@jeherve jeherve deleted the add/cookie-consent-block branch March 2, 2023 09:18
@github-actions github-actions bot removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Status] Needs Team Review labels Mar 2, 2023
@github-actions github-actions bot added this to the jetpack/11.9 milestone Mar 2, 2023
@jeherve jeherve modified the milestones: jetpack/11.9, jetpack/12.0 Mar 2, 2023
@samiff samiff added the [Status] Needs Testing We need to add this change to the testing call for this month's release label Mar 8, 2023
@anomiex anomiex removed the [Status] Needs Testing We need to add this change to the testing call for this month's release label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Cookie Consent [Feature] Extra Sidebar Widgets [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants