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

Push Notifications #417

Closed
wants to merge 23 commits into from
Closed

Push Notifications #417

wants to merge 23 commits into from

Conversation

jeffersonrabb
Copy link
Contributor

@jeffersonrabb jeffersonrabb commented Jan 31, 2020

All Submissions:

Changes proposed in this Pull Request:

Implements basic support for AMP-compatible Push Notifications using One Signal. This PR still has some rough edges but is ready for review/discussion.

Video demo of subscribing: https://cloudup.com/cyyfKRs0tG7

How to test the changes in this Pull Request:

  1. Navigate to Newspack Engagement Wizard, click on "Push" tab.
  2. Click toggle to install One Signal plugin.
  3. Go to https://onesignal.com/ create a free account, then create an App for "Web Push."
  4. In Settings->Keys/IDs find your APP ID and REST API KEY. Copy paste these into the corresponding fields in the engagement wizard.
  5. Edit a widget area. Add the Newspack Push Notifications widget to a an area.
  6. Try testing in an AMP request. You should see a Subscribe button. Clicking the button opens a popup browser window, and in the window you will be prompted to subscribe.
  7. After subscribing you should see the number of subscribers increment in the One Signal dashboard.
  8. If you don't, you may be blocking notifications. On advice of @adekbadek I usually would create a new Chrome profile (click your Avatar in the upper right, choose ADD+), and subscribe with that user.
  9. After successfully subscribing, try creating and publishing a post and you should receive a push notification.

Open Questions

  1. For now it appears the pop-up window is required. I'll be opening an AMP issue seeking improvement but for now it seems we're stuck with it. How should we style to make it a more palatable experience? cc: @thomasguillot
  2. How can we make the widget UI better?
  3. Should we add a block as well? If so, it would presumably live in Newspack Blocks.
  4. Should we guide users through acquiring and configuring their One Signal account? There is some information about doing this in the One Signal plugin — we could just send new users over there.
  5. I believe the implementation will not currently work in non-AMP. This should be addressed.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

layout="nodisplay"
helper-iframe-url="<?php echo esc_url( $base ); ?>/helper-iframe.html?appId=<?php echo esc_attr( $one_signal_api_key ); ?>"
permission-dialog-url="<?php echo esc_url( $base ); ?>/permission-dialog.html?appId=<?php echo esc_attr( $one_signal_api_key ); ?>"
service-worker-url="<?php echo esc_url( $base ); ?>/service-worker.js?appId=<?php echo esc_attr( $one_signal_api_key ); ?>"

Choose a reason for hiding this comment

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

Suggested change
service-worker-url="<?php echo esc_url( $base ); ?>/service-worker.js?appId=<?php echo esc_attr( $one_signal_api_key ); ?>"
service-worker-url="<?php echo esc_url( $base ); ?>/service-worker.js?appId=<?php echo esc_attr( $one_signal_api_key ); ?>"
service-worker-scope="<?php echo esc_url( trailingslashit( $base ) ); ?>"

@westonruter
Copy link

westonruter commented Feb 4, 2020

I wonder if this PR should end up being merged if it works? Perhaps it should rather be upstreamed as part of OneSignal/OneSignal-WordPress-Plugin#187?

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

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

Works as advertised, there're just some nitpicky linting errors. Also, Weston's suggestion to add service-worker-scope seems reasonable.

@adekbadek adekbadek added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 20, 2020
Copy link
Contributor

@thomasguillot thomasguillot left a comment

Choose a reason for hiding this comment

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

Screenshot 2020-02-21 at 09 49 44

On this screen:

  • I've just clicked on the toggle button to enable the push notifications and I get a [object Object] in both inputs.
  • It needs some sort of help text to explain how to get the App ID and API key with a link to One Signal (or in the future to the documentation page of this feature on our website)

Screenshot 2020-02-21 at 10 01 47

  • It would be nice to have the option to change the copy of both buttons.
  • Why do we display both buttons but use visibility: hidden to hide one of the two? Visually it creates a massive gap. If we have to "display" both, can we at least use display: none?
  • I'd definitely suggest a block to make this feature a bit more flexible within the content.

Screenshot 2020-02-21 at 10 12 51

How should we style to make it a more palatable experience?

Quite frankly I'm not sure. This looks terrible 😂 Can we reduce the window size? Also if you click on the x to close the pop-up, the window doesn't close... it's just so bad.

Screenshot 2020-02-21 at 10 16 36

When AMP is set to Transitional or Reader, we get this pop-up at the top of the screen. Looks like it's coming from One Signal. Can we style it so it doesn't look so out-of-place? Right now, all I can think is a fake spam advert with the big ugly icon.

Copy link

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

Overall this PR looks great, just a few nits and questions! Thanks for taking the time to integrate OneSignal directly in this plugin.

includes/class-pwa.php Outdated Show resolved Hide resolved
$path = null;

if ( substr( $raw_uri, 0, strlen( '/helper-iframe.html' ) ) === '/helper-iframe.html' ) {
$path = dirname( NEWSPACK_PLUGIN_FILE ) . '/assets/raw/amp-web-push-helper-frame.html';

Choose a reason for hiding this comment

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

Interested to know why not use /assets/raw/amp-web-push-helper-frame.html directly with the <amp-web-push> tag? Instead of going through /helper-iframe.html then mapping it.

if ( ! $this->is_configured() ) {
return $this->unconfigured_error();
}
$settings = \OneSignal::get_onesignal_settings();

Choose a reason for hiding this comment

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

Since you are using OneSignal::save_onesignal_settings() and OneSignal::get_onesignal_settings() we will make a note that these are public interfaces should not change in the OneSignal-WordPress-Plugin repo.

@@ -16,6 +16,13 @@
*/
class PWA {

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rgomezp this commit adds the service worker scope you recommended.

Choose a reason for hiding this comment

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

@jeffersonrabb Looks good to me!

@adekbadek
Copy link
Member

Closing for now in favour of #1076

@adekbadek adekbadek closed this Aug 17, 2021
@thomasguillot thomasguillot deleted the add/push-notifications branch October 15, 2021 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants