From 8a90d8730d1afef253fcdfb4bb41f6c6e2193d87 Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Fri, 4 Oct 2024 17:48:40 +0300 Subject: [PATCH 1/4] Newsletters: allow skipping modals with URL query param --- .../subscribe-modal/subscribe-modal.js | 15 ++++++++++++++- .../subscribe-overlay/subscribe-overlay.js | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js b/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js index 1360693915fa8..173ce1ee2bf66 100644 --- a/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js +++ b/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js @@ -9,7 +9,20 @@ domReady( () => { return lastDismissed ? Date.now() - lastDismissed > Jetpack_Subscriptions.modalInterval : true; } - if ( ! modal || ! hasEnoughTimePassed() ) { + // Subscriber ended up here e.g. from emails: + // we won't show the modal to them in future since they most likely are already a subscriber. + function skipModal() { + const urlParams = new URLSearchParams( window.location.search ); + const skip = urlParams.get( 'jetpack_skip_subscription_popup' ); + if ( skip ) { + storeCloseTimestamp(); + return true; + } + + return false; + } + + if ( ! modal || ! hasEnoughTimePassed() || skipModal() ) { return; } diff --git a/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js b/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js index 936b5840c80fb..bb20609480439 100644 --- a/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js +++ b/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js @@ -6,7 +6,20 @@ domReady( function () { const hasOverlayDismissedCookie = document.cookie && document.cookie.indexOf( overlayDismissedCookie ) > -1; - if ( ! overlay || hasOverlayDismissedCookie ) { + // Subscriber ended up here e.g. from emails: + // we won't show the overlay to them in future since they most likely are already a subscriber. + function skipOverlay() { + const urlParams = new URLSearchParams( window.location.search ); + const skip = urlParams.get( 'jetpack_skip_subscription_popup' ); + if ( skip ) { + setOverlayDismissedCookie(); + return true; + } + + return false; + } + + if ( ! overlay || hasOverlayDismissedCookie || skipOverlay() ) { return; } From 004c37183b72e49ff8e2c1f5b95a054b0eab5a0c Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Fri, 4 Oct 2024 17:54:33 +0300 Subject: [PATCH 2/4] changelog --- .../plugins/jetpack/changelog/update-subscriptions-skip-modal | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/update-subscriptions-skip-modal diff --git a/projects/plugins/jetpack/changelog/update-subscriptions-skip-modal b/projects/plugins/jetpack/changelog/update-subscriptions-skip-modal new file mode 100644 index 0000000000000..2e357ea143d80 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-subscriptions-skip-modal @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Newsletters: allow skipping modals with URL query param From 278436ec496bdfcaf7c86b2baaba79a6715e12c1 Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Fri, 4 Oct 2024 18:14:37 +0300 Subject: [PATCH 3/4] More elegant by cleaning up the URL param --- .../subscriptions/subscribe-modal/subscribe-modal.js | 8 +++++--- .../subscriptions/subscribe-overlay/subscribe-overlay.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js b/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js index 173ce1ee2bf66..ff6c22fdb4f89 100644 --- a/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js +++ b/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js @@ -3,6 +3,7 @@ const { domReady } = wp; domReady( () => { const modal = document.querySelector( '.jetpack-subscribe-modal' ); const modalDismissedCookie = 'jetpack_post_subscribe_modal_dismissed'; + const skipUrlParam = 'jetpack_skip_subscription_popup'; function hasEnoughTimePassed() { const lastDismissed = localStorage.getItem( modalDismissedCookie ); @@ -12,9 +13,10 @@ domReady( () => { // Subscriber ended up here e.g. from emails: // we won't show the modal to them in future since they most likely are already a subscriber. function skipModal() { - const urlParams = new URLSearchParams( window.location.search ); - const skip = urlParams.get( 'jetpack_skip_subscription_popup' ); - if ( skip ) { + const url = new URL( window.location.href ); + if ( url.searchParams.has( skipUrlParam ) ) { + url.searchParams.delete( skipUrlParam ); + window.history.pushState( {}, '', url ); storeCloseTimestamp(); return true; } diff --git a/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js b/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js index bb20609480439..69f508753843a 100644 --- a/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js +++ b/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js @@ -3,15 +3,17 @@ const { domReady } = wp; domReady( function () { const overlay = document.querySelector( '.jetpack-subscribe-overlay' ); const overlayDismissedCookie = 'jetpack_post_subscribe_overlay_dismissed'; + const skipUrlParam = 'jetpack_skip_subscription_popup'; const hasOverlayDismissedCookie = document.cookie && document.cookie.indexOf( overlayDismissedCookie ) > -1; // Subscriber ended up here e.g. from emails: // we won't show the overlay to them in future since they most likely are already a subscriber. function skipOverlay() { - const urlParams = new URLSearchParams( window.location.search ); - const skip = urlParams.get( 'jetpack_skip_subscription_popup' ); - if ( skip ) { + const url = new URL( window.location.href ); + if ( url.searchParams.has( skipUrlParam ) ) { + url.searchParams.delete( skipUrlParam ); + window.history.pushState( {}, '', url ); setOverlayDismissedCookie(); return true; } From 3036a3ae2dcd53e6560ec7779600cfd9be9d749a Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Tue, 15 Oct 2024 15:02:17 +0300 Subject: [PATCH 4/4] Use replaceState instead of pushState to avoid leaving history --- .../modules/subscriptions/subscribe-modal/subscribe-modal.js | 2 +- .../subscriptions/subscribe-overlay/subscribe-overlay.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js b/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js index ff6c22fdb4f89..e2b084cda60bc 100644 --- a/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js +++ b/projects/plugins/jetpack/modules/subscriptions/subscribe-modal/subscribe-modal.js @@ -16,7 +16,7 @@ domReady( () => { const url = new URL( window.location.href ); if ( url.searchParams.has( skipUrlParam ) ) { url.searchParams.delete( skipUrlParam ); - window.history.pushState( {}, '', url ); + window.history.replaceState( {}, '', url ); storeCloseTimestamp(); return true; } diff --git a/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js b/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js index 69f508753843a..83eae23686338 100644 --- a/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js +++ b/projects/plugins/jetpack/modules/subscriptions/subscribe-overlay/subscribe-overlay.js @@ -13,7 +13,7 @@ domReady( function () { const url = new URL( window.location.href ); if ( url.searchParams.has( skipUrlParam ) ) { url.searchParams.delete( skipUrlParam ); - window.history.pushState( {}, '', url ); + window.history.replaceState( {}, '', url ); setOverlayDismissedCookie(); return true; }