Skip to content

Commit

Permalink
feat: report Git version in telemetry (#693)
Browse files Browse the repository at this point in the history
* feat: use Git version for analytics

Resolves: kubeshop/testkube#3881

* feat: expose app version in meta[app-version]

* feat: send app version to PostHog too

Resolves: kubeshop/testkube#3887

* feat: avoid processing IP in PostHog
  • Loading branch information
rangoo94 authored May 24, 2023
1 parent 2dfaa14 commit c13e8be
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-build-beta-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker-build-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker-build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker-build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="TestKube dashboard" />
<meta name="referrer" content="no-referrer" />
<meta name="app-version" content="%REACT_APP_VERSION%" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
Expand Down
8 changes: 5 additions & 3 deletions src/AppRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import {externalLinks} from './utils/externalLinks';

import env from './env';

const pjson = require('../package.json');

const AppRoot: React.FC = () => {
useAxiosInterceptors();

Expand Down Expand Up @@ -82,12 +80,16 @@ 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);
});
},
});
posthog.register({
version: env.version,
});
}
if (posthog.__loaded) {
posthog.opt_in_capturing();
Expand Down Expand Up @@ -157,7 +159,7 @@ const AppRoot: React.FC = () => {
.append(AnalyticsProvider, {
disabled: !isTelemetryEnabled,
writeKey: env.segmentKey,
appVersion: pjson.version,
appVersion: env.version,
featureFlags,
})
.append(MainContext.Provider, {value: mainContextValue})
Expand Down
2 changes: 2 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +19,7 @@ type BuildTimeEnvironment = {
posthogKey?: string;
segmentKey?: string;
ga4Key?: string;
version: string;
}

type DynamicEnvironment = {
Expand Down

0 comments on commit c13e8be

Please sign in to comment.