Skip to content

Add support for in email notices - Analytics set up (views at the top of the template) #11843

@benbowler

Description

@benbowler

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 ), and get_payload( WP_User $user ) returning title, body, cta_label, cta_url.
    • Implement a get_header_notices( WP_User $user ) method that returns eligible notices and handles impression tracking (see below).
  • Use existing prompt dismissal storage for per‑user counts and expiry (no new options):
    • Use Google\Site_Kit\Core\Prompts\Dismissed_Prompts with a user‑scoped User_Options instance: 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 calling add( $slug, 0 ) and don't show.
    • 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.
  • Implement the "Analytics set up" notice definition in the registry:
  • Wire notice payload into the email template:
    • Update Email_Template_Formatter::build_template_payload() (and its call in Email_Log_Processor) to accept the WP_User $user, resolve header notices, and add a header_notices array into template_data.
    • Only include the notice when eligible; keep payload empty otherwise.
  • Render in template:
    • Update header.php (or add a small notice.php) to render the header notice block if header_notices is present; omit CTA if no URL/label.
  • CTA dismissal:

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_notices when 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 proactiveUserEngagement feature 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityTeam SIssues for Squad 1Type: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions