us-newsletter-hide-soft-opt-in#15930
Conversation
56853d6 to
dcd9b62
Compare
There was a problem hiding this comment.
Pull request overview
Implements US “soft opt-in” behaviour for newsletter sign-ups by hiding the marketing consent toggle for signed-out users in the US when the us-signup-hide-marketing-toggle switch is enabled, while ensuring the backend and analytics can distinguish implicit opt-ins.
Changes:
- Added
useHideMarketingToggleForCountry(switch + country-code gated) and wired it into all three signup surfaces. - When hidden, forces
marketing=trueand appendsmarketingOptInHidden=trueto the sign-up payload. - Adds
marketingOptInTypeinto tracking payloads and extends unit/story coverage across surfaces.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| dotcom-rendering/src/lib/useNewsletterSignupForm.ts | Adds hidden-toggle support to payload + adds marketingOptInType to tracking details. |
| dotcom-rendering/src/lib/useHideMarketingToggleForCountry.ts | New hook to determine when the marketing toggle should be hidden (US + switch). |
| dotcom-rendering/src/lib/newsletter-sign-up-requests.ts | Extends multi-signup request payload to include marketingOptInHidden. |
| dotcom-rendering/src/components/SecureSignup.island.tsx | Hides marketing checkbox for US signed-out users, forces marketing opt-in, and adds tracking detail. |
| dotcom-rendering/src/components/SecureSignup.island.test.tsx | Adds tests covering US hide-toggle behaviour, payload, and tracking. |
| dotcom-rendering/src/components/NewsletterSignupForm.island.tsx | Passes hide-toggle flag into useNewsletterSignupForm. |
| dotcom-rendering/src/components/NewsletterSignupForm.island.test.tsx | Adds country/switch mocking and assertions for new tracking + hidden-toggle behaviour. |
| dotcom-rendering/src/components/NewsletterSignupForm.island.stories.tsx | Adds Storybook story for US hidden-toggle case and updates mocked state shape. |
| dotcom-rendering/src/components/ManyNewsletterSignUp.island.tsx | Hides checkbox in ManyNewsletter flow, forces marketing opt-in in payload, and tracks opt-in type. |
| dotcom-rendering/src/components/ManyNewsletterSignUp.island.test.tsx | Adds tests for US hide-toggle behaviour and tracking in ManyNewsletter flow. |
| dotcom-rendering/.storybook/preview.ts | Mocks useCountryCode for Storybook to support country-gated scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
dotcom-rendering/src/lib/useHideMarketingToggleForCountry.ts:21
- This hook explicitly returns
falsewhileuseCountryCode()is still resolving (undefined). For US users that means the marketing toggle can render briefly and then disappear once the country code resolves, and the submit logic will forcemarketing=trueafterwards. If the intent is “never show the toggle to US users”, consider defaulting to hidden until the country is known (or using a tri-state return so callers can choose not to render the toggle until resolution) to avoid flicker and inconsistent UX.
export const useHideMarketingToggleForCountry = (): boolean => {
const countryCode = useCountryCode('useHideMarketingToggleForCountry');
const switchEnabled =
window.guardian.config.switches['us-signup-hide-marketing-toggle'] ===
true;
return switchEnabled && countryCode === 'US';
dcd9b62 to
36d9438
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
dotcom-rendering/src/lib/useNewsletterSignupForm.ts:502
showMarketingToggleandmarketingOptInHiddenForCountryboth treatisSignedIn === 'Pending'as signed-out (isSignedIn !== true). This changes pre-existing pending-state behaviour (toggle visibility + payload fields) and can lead to implicit opt-in/tracking before sign-in status is known. Consider handling'Pending'explicitly (e.g. behave like signed-in until resolved).
showMarketingToggle: isSignedIn !== true && !hideMarketingToggle,
marketingOptIn,
marketingOptInHiddenForCountry:
hideMarketingToggle && isSignedIn !== true,
48b04f2 to
770c8e8
Compare
|
Hello 👋! When you're ready to run Chromatic, please apply the You will need to reapply the label each time you want to run Chromatic. |
…state and introduce utility functions for effective opt-in determination
…ut state for hidden toggle
…arify default behavior
…sure consistent behavior for signed-out users
…prove signed-out user behavior
0606e30 to
47874a5
Compare
US newsletter marketing soft opt-in
What does this change?
Implements the UI logic for hiding the marketing consent toggle for signed-out US users when the
usSignupHideMarketingToggleswitch is enabled.useHideMarketingToggleForCountryhook that checks the switch and the user's country code viauseCountryCodecountryCode === 'US'and the user is signed out, the marketing toggle is hidden andmarketing=trueis always included in the sign-up payloadUS(includingundefinedwhile resolving), existing behaviour is unchangedmarketingOptInHidden: truefield is appended to the sign-up request payload in the hidden case so the backend can identify implicit opt-insmarketingOptInTypeis included in Ophan tracking events on all three surfaces:similar-guardian-products-optin-hidden-us— toggle hidden (US soft opt-in)similar-guardian-products-optin— toggle visible, user opted insimilar-guardian-products-optout— toggle visible, user opted outSecureSignup,NewsletterSignupForm, andManyNewsletterSignUpuseCountryCodein Storybook preview and adds aUSHideMarketingTogglestory toNewsletterSignupFormWhy?
US consumer protection regulations mean we should not present a marketing opt-in toggle to US newsletter sign-ups. Instead, users are silently enrolled in
similar_guardian_products— i.e. a soft opt-in. This is gated behind a switch so it can be enabled/disabled independently of a deploy.Parent issue: guardian/email-rendering#930
Screenshots
No visible UI change for non-US users. For US signed-out users, the marketing toggle is hidden — no before/after screenshot is provided as this is switch-gated.