From 64810edab8b05bfc88efc35a7958d718ee50362e Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Wed, 24 May 2023 10:29:27 +0200 Subject: [PATCH 1/4] feat: use Git version for analytics Resolves: kubeshop/testkube#3881 --- .github/workflows/docker-build-beta-tag.yml | 1 + .github/workflows/docker-build-develop.yml | 1 + .github/workflows/docker-build-release.yml | 1 + .github/workflows/docker-build-tag.yml | 1 + Dockerfile | 2 ++ src/AppRoot.tsx | 4 +--- src/env.ts | 2 ++ 7 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build-beta-tag.yml b/.github/workflows/docker-build-beta-tag.yml index 71d7ab0bc..df3fd2154 100644 --- a/.github/workflows/docker-build-beta-tag.yml +++ b/.github/workflows/docker-build-beta-tag.yml @@ -47,6 +47,7 @@ jobs: push: true build-args: | TARGET=${{ matrix.path }} + REACT_APP_VERSION=${{ steps.tag.outputs.tag }} REACT_APP_GOOGLE_ANALYTICS_ID=${{ secrets.REACT_APP_GOOGLE_ANALYTICS_ID }} REACT_APP_SEGMENT_KEY=${{ secrets.REACT_APP_SEGMENT_WRITE_KEY }} REACT_APP_POSTHOG_KEY=${{ secrets.REACT_APP_POSTHOG_KEY }} diff --git a/.github/workflows/docker-build-develop.yml b/.github/workflows/docker-build-develop.yml index 1954b540f..53344075f 100644 --- a/.github/workflows/docker-build-develop.yml +++ b/.github/workflows/docker-build-develop.yml @@ -34,6 +34,7 @@ jobs: with: push: true build-args: | + REACT_APP_VERSION=${{ steps.github_sha.outputs.sha_short }} REACT_APP_GOOGLE_ANALYTICS_ID=${{ secrets.REACT_APP_GOOGLE_ANALYTICS_ID }} REACT_APP_SEGMENT_KEY=${{ secrets.REACT_APP_SEGMENT_WRITE_KEY }} REACT_APP_POSTHOG_KEY=${{ secrets.REACT_APP_POSTHOG_KEY }} diff --git a/.github/workflows/docker-build-release.yml b/.github/workflows/docker-build-release.yml index 7212be3fd..71efe049c 100644 --- a/.github/workflows/docker-build-release.yml +++ b/.github/workflows/docker-build-release.yml @@ -34,6 +34,7 @@ jobs: with: push: true build-args: | + REACT_APP_VERSION=${{ steps.github_sha.outputs.sha_short }} REACT_APP_GOOGLE_ANALYTICS_ID=${{ secrets.REACT_APP_GOOGLE_ANALYTICS_ID }} REACT_APP_SEGMENT_KEY=${{ secrets.REACT_APP_SEGMENT_WRITE_KEY }} REACT_APP_POSTHOG_KEY=${{ secrets.REACT_APP_POSTHOG_KEY }} diff --git a/.github/workflows/docker-build-tag.yml b/.github/workflows/docker-build-tag.yml index 9f615e2fb..c9b6018b0 100644 --- a/.github/workflows/docker-build-tag.yml +++ b/.github/workflows/docker-build-tag.yml @@ -47,6 +47,7 @@ jobs: push: true build-args: | TARGET=${{ matrix.path }} + REACT_APP_VERSION=${{ steps.tag.outputs.tag }} REACT_APP_GOOGLE_ANALYTICS_ID=${{ secrets.REACT_APP_GOOGLE_ANALYTICS_ID }} REACT_APP_SEGMENT_KEY=${{ secrets.REACT_APP_SEGMENT_WRITE_KEY }} REACT_APP_POSTHOG_KEY=${{ secrets.REACT_APP_POSTHOG_KEY }} diff --git a/Dockerfile b/Dockerfile index 97e654da6..bbc64297d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,8 @@ ARG REACT_APP_POSTHOG_KEY ENV REACT_APP_POSTHOG_KEY=$REACT_APP_POSTHOG_KEY ARG REACT_APP_GOOGLE_ANALYTICS_ID ENV REACT_APP_GOOGLE_ANALYTICS_ID=$REACT_APP_GOOGLE_ANALYTICS_ID +ARG REACT_APP_VERSION +ENV REACT_APP_VERSION=$REACT_APP_VERSION ENV PATH /app/node_modules/.bin:$PATH COPY ./package.json /app/ diff --git a/src/AppRoot.tsx b/src/AppRoot.tsx index b6f25fed2..02b3e3a21 100644 --- a/src/AppRoot.tsx +++ b/src/AppRoot.tsx @@ -34,8 +34,6 @@ import {externalLinks} from './utils/externalLinks'; import env from './env'; -const pjson = require('../package.json'); - const AppRoot: React.FC = () => { useAxiosInterceptors(); @@ -156,7 +154,7 @@ const AppRoot: React.FC = () => { .append(AnalyticsProvider, { disabled: !isTelemetryEnabled, writeKey: env.segmentKey, - appVersion: pjson.version, + appVersion: env.version, featureFlags, }) .append(MainContext.Provider, {value: mainContextValue}) diff --git a/src/env.ts b/src/env.ts index 12e2c628e..99d52c595 100644 --- a/src/env.ts +++ b/src/env.ts @@ -5,6 +5,7 @@ const build: BuildTimeEnvironment = { posthogKey: process.env.REACT_APP_POSTHOG_KEY, segmentKey: process.env.REACT_APP_SEGMENT_KEY, ga4Key: process.env.REACT_APP_GOOGLE_ANALYTICS_ID, + version: process.env.REACT_APP_VERSION || 'dev', }; // Dynamic variables @@ -17,6 +18,7 @@ type BuildTimeEnvironment = { posthogKey?: string; segmentKey?: string; ga4Key?: string; + version: string; } type DynamicEnvironment = { From f762079e7138a1edd7aca7b891a23cad47511b3d Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Wed, 24 May 2023 10:29:52 +0200 Subject: [PATCH 2/4] feat: expose app version in meta[app-version] --- public/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/public/index.html b/public/index.html index 4950ce64f..5e374034d 100644 --- a/public/index.html +++ b/public/index.html @@ -6,6 +6,7 @@ + Date: Wed, 24 May 2023 13:16:55 +0200 Subject: [PATCH 3/4] feat: send app version to PostHog too Resolves: kubeshop/testkube#3887 --- src/AppRoot.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/AppRoot.tsx b/src/AppRoot.tsx index 02b3e3a21..aa91430da 100644 --- a/src/AppRoot.tsx +++ b/src/AppRoot.tsx @@ -85,6 +85,9 @@ const AppRoot: React.FC = () => { }); }, }); + posthog.register({ + version: env.version, + }); } if (posthog.__loaded) { posthog.opt_in_capturing(); From 13b9d8a5493e3af454f2d1c900e647ff5e079cff Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Wed, 24 May 2023 13:17:31 +0200 Subject: [PATCH 4/4] feat: avoid processing IP in PostHog --- src/AppRoot.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AppRoot.tsx b/src/AppRoot.tsx index aa91430da..3ff9e908f 100644 --- a/src/AppRoot.tsx +++ b/src/AppRoot.tsx @@ -79,6 +79,7 @@ const AppRoot: React.FC = () => { mask_all_text: true, persistence: 'localStorage', property_blacklist: ['$current_url', '$host', '$referrer', '$referring_domain'], + ip: false, loaded: instance => { instance.onFeatureFlags(flags => { setFeatureFlags(flags);