diff --git a/.changeset/popular-actors-talk.md b/.changeset/popular-actors-talk.md new file mode 100644 index 0000000000..b6e6df8af8 --- /dev/null +++ b/.changeset/popular-actors-talk.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": patch +--- + +Posthog no longer collect the events from the staging environments. This means we track the data only in production environments. diff --git a/.github/workflows/deploy-cloud.yaml b/.github/workflows/deploy-cloud.yaml index 4a87b84631..c5d2edd4a1 100644 --- a/.github/workflows/deploy-cloud.yaml +++ b/.github/workflows/deploy-cloud.yaml @@ -24,8 +24,6 @@ jobs: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} APPS_MARKETPLACE_API_URL: "https://apps.saleor.io/api/v2/saleor-apps" IS_CLOUD_INSTANCE: true - POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }} - POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }} ONBOARDING_USER_JOINED_DATE_THRESHOLD: ${{ vars.CLOUD_ONBOARDING_USER_JOINED_DATE_THRESHOLD }} steps: - name: Check region diff --git a/.github/workflows/deploy-master-staging.yaml b/.github/workflows/deploy-master-staging.yaml index 7eb95603b0..b171b5e2e5 100644 --- a/.github/workflows/deploy-master-staging.yaml +++ b/.github/workflows/deploy-master-staging.yaml @@ -24,8 +24,6 @@ jobs: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} APPS_MARKETPLACE_API_URL: "https://apps.staging.saleor.io/api/v2/saleor-apps" IS_CLOUD_INSTANCE: true - POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }} - POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }} ONBOARDING_USER_JOINED_DATE_THRESHOLD: ${{ vars.STAGING_ONBOARDING_USER_JOINED_DATE_THRESHOLD }} steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/deploy-staging-and-prepare-release.yaml b/.github/workflows/deploy-staging-and-prepare-release.yaml index c502e53073..6ea0bdd7f7 100644 --- a/.github/workflows/deploy-staging-and-prepare-release.yaml +++ b/.github/workflows/deploy-staging-and-prepare-release.yaml @@ -61,6 +61,7 @@ jobs: IS_CLOUD_INSTANCE: true POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }} POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }} + POSTHOG_EXCLUDED_DOMAINS: ${{ vars.EXCLUDED_DOMAINS }} ONBOARDING_USER_JOINED_DATE_THRESHOLD: ${{ vars.STAGING_ONBOARDING_USER_JOINED_DATE_THRESHOLD }} steps: - uses: actions/checkout@v4 diff --git a/src/components/ProductAnalytics/index.tsx b/src/components/ProductAnalytics/index.tsx index 26e70d5e9a..9a39f02be9 100644 --- a/src/components/ProductAnalytics/index.tsx +++ b/src/components/ProductAnalytics/index.tsx @@ -2,6 +2,18 @@ import { PostHogConfig } from "posthog-js"; import { PostHogProvider } from "posthog-js/react"; import React from "react"; +const isDomainExcluded = () => { + const domainsString = process.env.POSTHOG_EXCLUDED_DOMAINS; + + if (!domainsString) { + return false; + } + + const excludedDomains = domainsString.split(","); + + return excludedDomains.some(domain => window.location.hostname.includes(domain)); +}; + const useConfig = () => { const options = { api_host: process.env.POSTHOG_HOST, @@ -14,11 +26,16 @@ const useConfig = () => { } satisfies Partial; const apiKey = process.env.POSTHOG_KEY; const isCloudInstance = process.env.IS_CLOUD_INSTANCE; + const canRenderAnalytics = () => { if (!isCloudInstance) { return false; } + if (isDomainExcluded()) { + return false; + } + if (!options.api_host || !apiKey) { return false; } diff --git a/vite.config.js b/vite.config.js index 5ffc95b53e..514b90d22e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -51,6 +51,7 @@ export default defineConfig(({ command, mode }) => { FLAGS_SERVICE_ENABLED, LOCALE_CODE, POSTHOG_KEY, + POSTHOG_EXCLUDED_DOMAINS, POSTHOG_HOST, SENTRY_AUTH_TOKEN, SENTRY_ORG, @@ -84,6 +85,7 @@ export default defineConfig(({ command, mode }) => { IS_CLOUD_INSTANCE, LOCALE_CODE, POSTHOG_KEY, + POSTHOG_EXCLUDED_DOMAINS, POSTHOG_HOST, ONBOARDING_USER_JOINED_DATE_THRESHOLD, injectOgTags: @@ -161,6 +163,7 @@ export default defineConfig(({ command, mode }) => { SENTRY_RELEASE, STATIC_URL, POSTHOG_KEY, + POSTHOG_EXCLUDED_DOMAINS, POSTHOG_HOST, ONBOARDING_USER_JOINED_DATE_THRESHOLD, // eslint-disable-next-line camelcase