Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude posthog traffic #5342

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 }}
NyanKiyoshi marked this conversation as resolved.
Show resolved Hide resolved
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
Loading