Skip to content

Commit

Permalink
Exclude pothog traffic (#5342)
Browse files Browse the repository at this point in the history
Co-authored-by: Paweł Chyła <[email protected]>
  • Loading branch information
andrzejewsky and poulch committed Jan 10, 2025
1 parent b44516b commit 0be566e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-actors-talk.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 0 additions & 2 deletions .github/workflows/deploy-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy-master-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-staging-and-prepare-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/components/ProductAnalytics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,11 +26,16 @@ const useConfig = () => {
} satisfies Partial<PostHogConfig>;
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;
}
Expand Down
3 changes: 3 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0be566e

Please sign in to comment.