-
Notifications
You must be signed in to change notification settings - Fork 336
Description
Feature Description
Update the email reporting infrastructure to support in email report notices. The initial notices will be:
- Analytics set up (views at the top of the template) This ticket
- Enable Conversion events (views within a section)
Email notices should be flexible for future registered notifications.
Notices should be dismissed if clicked or after being included in two email reports.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Email report templates support pluggable "in email" notices, starting with a header notice slot. Notices can be registered with an ID, placement, display logic, CTA label/URL, and dismissal key/count.
- The "Analytics set up" notice shows at the top of the email report when the recipient does not have Analytics set up (mirroring the existing dashboard "never connected" condition). It should target users who can act on setup (admins/shared owners).
- Clicking the notice CTA routes through the email link proxy, redirects the user to the dashboard Analytics setup flow, and dismisses the notice for that user.
- Notices are suppressed once dismissed and are automatically dismissed after they have appeared in two sent reports (per user). If a notice is excluded (dismissed or exhausted), it does not render in the email.
- Existing email content remains unchanged aside from the new header notice block when present; no notice renders if none are eligible.
Implementation Brief
- Add an email notice registry/resolver in
includes/Core/Email_Reporting/Email_Notices.php:- Define notice entries with:
id,placement(header),should_display( WP_User $user ), andget_payload( WP_User $user )returningtitle,body,cta_label,cta_url. - Implement a
get_header_notices( WP_User $user )method that returns eligible notices and handles impression tracking (see below).
- Define notice entries with:
- Use existing prompt dismissal storage for per‑user counts and expiry (no new options):
- Use
Google\Site_Kit\Core\Prompts\Dismissed_Promptswith a user‑scopedUser_Optionsinstance:new Dismissed_Prompts( new User_Options( $context, $user_id ) ). - Store counts on the prompt slug (e.g.,
email-report-notice-analytics-setup). - Eligibility logic:
- If prompt has a non‑expired
expires> treat as dismissed (don't show). - If
count >= 2> permanently dismiss by callingadd( $slug, 0 )and don't show.
- If prompt has a non‑expired
- When a notice is included in a report, increment count by calling
add( $slug, DAY_IN_SECONDS )so it can appear again once expiry elapses, but only up to 2 total times.
- Use
- Implement the "Analytics set up" notice definition in the registry:
- Use existing "never connected" logic:
Was_Analytics_4_Connectedisfalseand Analytics 4 is not connected.- User must be able to act:
current_user_can( Permissions::MANAGE_OPTIONS )(admins/shared owners).
- Build CTA URL via the Email Link Proxy (from issue Implement Golinks concept for generalisable redirects to SK screens #11849) so clicks dismiss and redirect to Analytics setup. Use the proxy builder (to be added in Implement Golinks concept for generalisable redirects to SK screens #11849) to embed
notice_idand redirect target. - Copy should match AC/Figma; no copy hard‑coding outside of translatable strings.
- Use existing "never connected" logic:
- Wire notice payload into the email template:
- Update
Email_Template_Formatter::build_template_payload()(and its call inEmail_Log_Processor) to accept theWP_User $user, resolve header notices, and add aheader_noticesarray intotemplate_data. - Only include the notice when eligible; keep payload empty otherwise.
- Update
- Render in template:
- Update
header.php(or add a smallnotice.php) to render the header notice block ifheader_noticesis present; omit CTA if no URL/label.
- Update
- CTA dismissal:
- Ensure the proxied CTA URL includes the notice slug so the link proxy can mark it dismissed (dependency on Implement Golinks concept for generalisable redirects to SK screens #11849). This issue only needs to consume that API.
Test Coverage
- Notice resolver returns the "Analytics set up" notice only when GA4 was never connected, Analytics is disconnected, and the user can manage options.
- Prompt dismissal logic: not shown when prompt is unexpired; auto‑dismiss after two appearances.
- Template payload includes
header_noticeswhen eligible, empty otherwise. - Template rendering test: header notice renders with title/body/CTA when present, and no notice markup when absent.
QA Brief
- Setup Site Kit with
proactiveUserEngagementfeature flag enabled- Do not setup Analytics module
- Subscribe to email reporting
- Use tester plugin to trigger the email reporting, and when email arrives, verify that notice is showing at the top with content and design as per figma
- Veridy that clicking CTA from notice lands you on Analytics module setup screen
- Notice should show up 2 times if no action is taken - 3rd time it should not be present
- If CTA is taken from notice in email reporting on the first email, it should not be showing next time
- Notice shows only when Analytics module was never setup - not if GA4 was setup and then disconnected
Note: After 1st email with notice, if sending another email within 24h, notice dismissal will not cooldown yet, update wp_googlesitekitpersistent_dismissed_prompts under "email-report-notice-analytics-setup";a:2:{s:7:"expires";i:1772720046;s:5:"count";i:1;} replace the timestamp eq 1772720046 with the one in the past, you can use 1772323200 (ensure format is correct and pasted without empty space or it will malform the DB value)
Changelog entry
- Add in-email notices support for Email Reporting emails.