Skip to content

Bug: Analytics scripts are executed on deploy previews and send unwanted data #1405

@yuriassuncx

Description

@yuriassuncx

Problem

The Analytics component in website/components/Analytics.tsx is currently loading Google Analytics and Google Tag Manager scripts even in deploy preview environments (e.g., *.deno.dev or deco-sites-*.deno.dev).

This happens because of the following check:

const isDeploy = !!context.isDeploy;

On Deno, this value is true not only for production, but also for deploy previews. As a result, analytics scripts are executed in previews, sending data to GA/GTM from non-production domains. These preview domains get marked as monitored domains in Google Tag diagnostics, which triggers errors and pollutes production analytics.

Impact

  • Unwanted data: Preview/staging events are mixed with production analytics.
  • Errors/warnings: Google Tag Manager flags preview domains as unauthorized/monitored, leading to console errors.
  • Harder QA: Makes testing/debugging more difficult, since preview data pollutes real reports.

Suggested Solution

Improve the environment detection so analytics only runs in production. Possible approaches:

  • Use a stricter environment flag (e.g., context.isProduction or an explicit DECO_ENV === 'production').
  • Exclude preview domains explicitly (*.deno.dev, deco-sites-*.deno.dev).
  • Introduce a new config/prop (e.g., enableAnalytics) that defaults to false for previews and true only in production.

Example change:

- const isDeploy = !!context.isDeploy;
+ const isProduction = context.env?.DECO_ENV === "production" || context.isProduction;

- {isDeploy && ( ...analytics scripts... )}
+ {isProduction && ( ...analytics scripts... )}

Expected Outcome

Analytics scripts (GTM/GA) should only run in true production environments.
No data should be sent from deploy previews, ensuring:

  • Clean analytics data.
  • No Google Tag Manager errors from preview domains.
  • A more reliable debugging and testing experience.

Suggested label: analytics

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions