Skip to content

Enable analytics by default with preserved opt-outs - #13

Merged
lifeodyssey merged 1 commit into
mainfrom
codex/default-on-analytics
Sep 25, 2026
Merged

lifeodyssey merged 1 commit into
mainfrom
codex/default-on-analytics

Conversation

@lifeodyssey

@lifeodyssey lifeodyssey commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Visitors previously generated no browser or Google Analytics events until they clicked the analytics prompt. Enable sanitized analytics by default for visitors without a saved preference, while preserving existing opt-outs and browser DNT/GPC signals. The footer shows the current setting and lets visitors turn collection off or back on. Opting out takes effect even if saving the preference fails.

Share routes remain excluded from Google, and the existing content/key/URL sanitization is unchanged. Document this as a collection-coverage change, not evidence of user growth.

Validation: 581 tests across 23 files passed, production build and TypeScript checks passed, Worker deployment dry run passed, independent review found no blocking issues. Released to production on 2026-09-25 at 17:13:08 UTC (September 26 at 01:13:08 Asia/Taipei), initial Worker version c9b3853d-5ade-494a-81d1-eff067339dca; merged commit 7b0668b73c554541d4716e795a42e4a6bd7cb3f3.

A fresh Chrome Incognito session loaded the production bundle index-D2dTX9YF.js without clicking any analytics consent control. Google tag loading returned 200 and the GA collect request for G-8B4LL2C8L7 returned 204. First-party page_view and webmcp_available were verified in production storage with the internal validation campaign default_on_0926; these checks must not be counted as customer growth.

The production preferences control was then switched off and the page reloaded. The off state persisted, and the Network panel showed no Google tag/collect requests and no /api/analytics/events requests. Existing independent Cloudflare service measurement was unchanged.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @lifeodyssey, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c3bf22c5-4220-407b-878f-ad8319a92d25

📥 Commits

Reviewing files that changed from the base of the PR and between f5b2748 and 62b86d0.

📒 Files selected for processing (8)
  • README.md
  • docs/analytics/measurement-contract.md
  • docs/analytics/operations.md
  • src/client/AnalyticsNotice.tsx
  • src/client/analytics.ts
  • tests/client/analytics-notice.test.tsx
  • tests/client/analytics.test.ts
  • tests/client/webmcp.test.ts
 _____________________________________________________________________________________________________________________________________
< Prototype to learn. Prototyping is a learning experience. Its value lies not in the code you produce, but in the lessons you learn. >
 -------------------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR enables sanitized browser, Google, and eligible WebMCP analytics by default for visitors without a saved preference, while preserving opt-outs and privacy signals, making opt-out robust to storage failures, exposing the setting in the footer, and documenting the resulting measurement-coverage change.

Sequence diagram for analytics preference changes

sequenceDiagram
    actor Visitor
    participant Footer as AnalyticsNotice
    participant Analytics as analytics.ts
    participant Storage as localStorage
    participant Collectors as Browser/WebMCP/GA

    Visitor->>Footer: Click Analytics preferences
    Footer->>Analytics: readAnalyticsConsent()
    Analytics->>Storage: getItem(CONSENT_KEY)
    Storage-->>Analytics: saved preference or unavailable
    Analytics-->>Footer: current setting
    Visitor->>Footer: choose(denied)
    Footer->>Analytics: setAnalyticsConsent(denied)
    Analytics->>Storage: setItem(CONSENT_KEY, denied)
    Analytics->>Collectors: clear tab context and suppress collection
    Collectors-->>Visitor: Analytics off

    Visitor->>Footer: choose(granted)
    Footer->>Analytics: setAnalyticsConsent(granted)
    Analytics->>Storage: setItem(CONSENT_KEY, granted)
    Analytics->>Collectors: allow eligible sanitized events
    Collectors-->>Visitor: Analytics on
Loading

Flow diagram for default-on analytics eligibility

flowchart TD
    A[Visitor opens site] --> B{Analytics service enabled?}
    B -- No --> Z[No browser analytics]
    B -- Yes --> C{DNT or GPC active?}
    C -- Yes --> Z
    C -- No --> D{Preference storage readable?}
    D -- No --> Z
    D -- Yes --> E{Saved opt-out?}
    E -- Yes --> Z
    E -- No --> F[Analytics enabled by default]
    F --> G[Sanitized browser and eligible WebMCP events]
    G --> H[Optional Google Analytics events]
Loading

Flow diagram for failed opt-out persistence

flowchart TD
    A[Visitor selects turn off analytics] --> B["setAnalyticsConsent(denied)"]
    B --> C{localStorage write succeeds?}
    C -- Yes --> D[Persist denied preference]
    C -- No --> E[Keep denied in memory]
    D --> F[Clear session/acquisition context]
    E --> F
    F --> G[Suppress collection for current page]
Loading

File-Level Changes

Change Details Files
Changed browser analytics from affirmative opt-in to default-on while preserving privacy and preference-based exclusions.
  • Treat an unset preference as enabled when service analytics is active.
  • Continue honoring stored opt-outs, DNT/GPC, and unreadable preference storage.
  • Add in-memory fallback so an opt-out takes effect when localStorage writes fail.
  • Update analytics eligibility checks for browser, Google Analytics, and WebMCP events.
src/client/analytics.ts
tests/client/analytics.test.ts
tests/client/webmcp.test.ts
Updated the analytics preference UI to expose the active setting and support toggling collection.
  • Keep the notice closed by default and show the current on/off state in the footer.
  • Replace consent-oriented actions with explicit turn-on/turn-off controls.
  • Display privacy-signal messaging and disable re-enablement when required.
src/client/AnalyticsNotice.tsx
tests/client/analytics-notice.test.tsx
Revised analytics documentation to describe the new coverage boundary and interpretation rules.
  • Document default-on behavior, preserved opt-outs, privacy signals, and storage failures.
  • Clarify that browser, WebMCP, and GA count changes across deployment are coverage changes, not product growth.
  • Retain sanitization, rate limits, GA separation, and private/share-route exclusions.
README.md
docs/analytics/measurement-contract.md
docs/analytics/operations.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@lifeodyssey
lifeodyssey merged commit 7b0668b into main Sep 25, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant