Skip to content

us-newsletter-hide-soft-opt-in#15930

Open
georgerichmond wants to merge 12 commits into
mainfrom
us-newsletter-hide-soft-opt-in
Open

us-newsletter-hide-soft-opt-in#15930
georgerichmond wants to merge 12 commits into
mainfrom
us-newsletter-hide-soft-opt-in

Conversation

@georgerichmond
Copy link
Copy Markdown
Contributor

@georgerichmond georgerichmond commented May 20, 2026

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 usSignupHideMarketingToggle switch is enabled.

  • Adds a useHideMarketingToggleForCountry hook that checks the switch and the user's country code via useCountryCode
  • When the switch is on and countryCode === 'US' and the user is signed out, the marketing toggle is hidden and marketing=true is always included in the sign-up payload
  • When the switch is off, or the user is signed in, or the country is anything other than US (including undefined while resolving), existing behaviour is unchanged
  • A marketingOptInHidden: true field is appended to the sign-up request payload in the hidden case so the backend can identify implicit opt-ins
  • marketingOptInType is 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 in
    • similar-guardian-products-optout — toggle visible, user opted out
    • Omitted entirely for signed-in users
  • Applies consistently across all three sign-up surfaces: SecureSignup, NewsletterSignupForm, and ManyNewsletterSignUp
  • Mocks useCountryCode in Storybook preview and adds a USHideMarketingToggle story to NewsletterSignupForm

Why?

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.

Before After
Marketing toggle visible for all signed-out users Marketing toggle hidden for signed-out US users (switch on)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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=true and appends marketingOptInHidden=true to the sign-up payload.
  • Adds marketingOptInType into 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.

Comment thread dotcom-rendering/src/lib/useHideMarketingToggleForCountry.ts Outdated
Comment thread dotcom-rendering/src/lib/useNewsletterSignupForm.ts Outdated
Comment thread dotcom-rendering/src/lib/useNewsletterSignupForm.ts Outdated
Comment thread dotcom-rendering/src/components/SecureSignup.island.tsx Outdated
Comment thread dotcom-rendering/src/components/SecureSignup.island.tsx Outdated
@georgerichmond georgerichmond added the feature Departmental tracking: work on a new feature label May 20, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 false while useCountryCode() 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 force marketing=true afterwards. 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';

Comment thread dotcom-rendering/src/lib/useHideMarketingToggleForCountry.ts Outdated
Comment thread dotcom-rendering/src/components/SecureSignup.island.tsx
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

  • showMarketingToggle and marketingOptInHiddenForCountry both treat isSignedIn === '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,

Comment thread dotcom-rendering/src/lib/newsletter-marketing-opt-in.ts Outdated
Comment thread dotcom-rendering/src/lib/useNewsletterSignupForm.ts
Comment thread dotcom-rendering/src/components/SecureSignup.island.tsx Outdated
Comment thread dotcom-rendering/src/components/ManyNewsletterSignUp.island.tsx Outdated
@georgerichmond georgerichmond force-pushed the us-newsletter-hide-soft-opt-in branch from 48b04f2 to 770c8e8 Compare May 20, 2026 12:39
@georgerichmond georgerichmond marked this pull request as ready for review May 20, 2026 12:42
@georgerichmond georgerichmond requested a review from a team as a code owner May 20, 2026 12:42
@github-actions
Copy link
Copy Markdown

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

@georgerichmond georgerichmond added the run_chromatic Runs chromatic when label is applied label May 20, 2026
@georgerichmond georgerichmond requested a review from Copilot May 20, 2026 12:49
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label May 20, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread dotcom-rendering/src/lib/useNewsletterSignupForm.ts
Comment thread dotcom-rendering/src/lib/useNewsletterSignupForm.ts
Comment thread dotcom-rendering/src/lib/newsletter-marketing-opt-in.ts
Comment thread dotcom-rendering/src/lib/newsletter-sign-up-requests.ts
Comment thread dotcom-rendering/src/components/SecureSignup.island.test.tsx Outdated
Comment thread dotcom-rendering/src/components/SecureSignup.island.test.tsx Outdated
Comment thread dotcom-rendering/src/components/SecureSignup.island.tsx
Comment thread dotcom-rendering/src/components/SecureSignup.island.tsx
Comment thread dotcom-rendering/src/lib/newsletter-marketing-opt-in.ts Outdated
Comment thread dotcom-rendering/src/lib/useNewsletterSignupForm.ts Outdated
@georgerichmond georgerichmond force-pushed the us-newsletter-hide-soft-opt-in branch from 0606e30 to 47874a5 Compare May 21, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove marketing soft opt in for US: Hide toggle and apply removed soft opt in (client-side logic)

3 participants