Skip to content

Commit

Permalink
feat(ACC-643): add posthog config to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
pwilson77 committed Jul 24, 2024
1 parent f36170c commit 3128eb3
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/saas-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ jobs:
run: kubectl set image deployment netmaker-ui netmaker-ui=${{ github.repository_owner }}/netmaker-ui-saas:${{ env.TAG }} -n accounts

- name: Set Intercom vars
run: kubectl set env deployment netmaker-ui INTERCOM_APP_ID=al371us8 -n accounts
run: |
kubectl set env deployment netmaker-ui INTERCOM_APP_ID=al371us8 -n accounts
kubectl set env deployment netmaker-ui PUBLIC_POSTHOG_HOST=${{ secrets.POSTHOG_HOST }} -n accounts
kubectl set env deployment netmaker-ui PUBLIC_POSTHOG_KEY=${{ secrets.POSTHOG_DEV_KEY }} -n accounts
- name: Deploy to k8s cluster
run: kubectl rollout restart deploy netmaker-ui -n accounts
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/saas-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ jobs:
run: kubectl set image deployment netmaker-ui netmaker-ui=${{ github.repository_owner }}/netmaker-ui-saas:${{ env.TAG }} -n accounts

- name: Set Intercom vars
run: kubectl set env deployment netmaker-ui INTERCOM_APP_ID=al371us8 -n accounts

run: |
kubectl set env deployment netmaker-ui INTERCOM_APP_ID=al371us8 -n accounts
kubectl set env deployment netmaker-ui PUBLIC_POSTHOG_HOST=${{ secrets.POSTHOG_HOST }} -n accounts
kubectl set env deployment netmaker-ui PUBLIC_POSTHOG_KEY=${{ secrets.POSTHOG_KEY }} -n accounts
- name: Deploy to k8s cluster
run: kubectl rollout restart deploy netmaker-ui -n accounts

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/saas-deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ jobs:
run: kubectl set image deployment netmaker-ui netmaker-ui=${{ github.repository_owner }}/netmaker-ui-saas:${{ env.TAG }} -n accounts

- name: Set Intercom vars
run: kubectl set env deployment netmaker-ui INTERCOM_APP_ID=al371us8 -n accounts
run: |
kubectl set env deployment netmaker-ui INTERCOM_APP_ID=al371us8 -n accounts
kubectl set env deployment netmaker-ui PUBLIC_POSTHOG_HOST=${{ secrets.POSTHOG_HOST }} -n accounts
kubectl set env deployment netmaker-ui PUBLIC_POSTHOG_KEY=${{ secrets.POSTHOG_DEV_KEY }} -n accounts
- name: Deploy to k8s cluster
run: kubectl rollout restart deploy netmaker-ui -n accounts
Expand Down
14 changes: 14 additions & 0 deletions generate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@ if [ -z "${INTERCOM_APP_ID:-}" ]; then
INTERCOM_APP_ID=""
fi

# ensure it is empty string if not set
if [ -z "${PUBLIC_POSTHOG_HOST:-}" ]; then
PUBLIC_POSTHOG_HOST=""
fi

# ensure it is empty string if not set
if [ -z "${PUBLIC_POSTHOG_KEY:-}" ]; then
PUBLIC_POSTHOG_KEY=""
fi

cat >/usr/share/nginx/html/nmui-config.js <<EOF
window.NMUI_AMUI_URL='$AMUI_URL';
window.NMUI_BACKEND_URL='$BACKEND_URL';
window.NMUI_INTERCOM_APP_ID='$INTERCOM_APP_ID';
window.NMUI_PUBLIC_POSTHOG_HOST='$PUBLIC_POSTHOG_HOST';
window.NMUI_PUBLIC_POSTHOG_KEY='$PUBLIC_POSTHOG_KEY';
EOF

echo ">>>> NMUI_AMUI_URL set to: $AMUI_URL <<<<<"
echo ">>>> NMUI_BACKEND_URL set to: $BACKEND_URL <<<<<"
echo ">>>> NMUI_INTERCOM_APP_ID set to: $INTERCOM_APP_ID <<<<<"
echo ">>>> NMUI_PUBLIC_POSTHOG_HOST set to: $PUBLIC_POSTHOG_HOST <<<<<"
echo ">>>> NMUI_PUBLIC_POSTHOG_KEY set to: ***** <<<<<"
38 changes: 36 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"immer": "^10.1.1",
"lodash": "^4.17.21",
"lucide-react": "^0.408.0",
"posthog-js": "^1.148.1",
"rc-virtual-list": "^3.14.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
37 changes: 30 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,36 @@ import './i18n/i18n';
import { INTERCOM_APP_ID, isSaasBuild, setupTenantConfig } from './services/BaseService';
import { IntercomProvider } from 'react-use-intercom';
import 'animate.css';
import { getPostHogHost, getPostHogPublicApiKey } from './utils/RouteUtils';
import { PostHogProvider } from 'posthog-js/react';

await setupTenantConfig();

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<IntercomProvider appId={INTERCOM_APP_ID} autoBoot={false} shouldInitialize={isSaasBuild} initializeDelay={2000}>
<App />
</IntercomProvider>
</React.StrictMode>,
);
const options = {
api_host: getPostHogHost(),
};

if (isSaasBuild) {
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<PostHogProvider apiKey={getPostHogPublicApiKey()} options={options}>
<IntercomProvider
appId={INTERCOM_APP_ID}
autoBoot={false}
shouldInitialize={isSaasBuild}
initializeDelay={2000}
>
<App />
</IntercomProvider>
</PostHogProvider>
</React.StrictMode>,
);
} else {
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<IntercomProvider appId={INTERCOM_APP_ID} autoBoot={false} shouldInitialize={isSaasBuild} initializeDelay={2000}>
<App />
</IntercomProvider>
</React.StrictMode>,
);
}
10 changes: 10 additions & 0 deletions src/utils/RouteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ export function getNetmakerTrialPeriodDocs() {
return import.meta.env.VITE_NETMAKER_TRIAL_PERIOD_DOCS_URL;
}

// Function to get PostHog public API key
export function getPostHogPublicApiKey() {
return (window as any).NMUI_PUBLIC_POSTHOG_KEY || import.meta.env.VITE_PUBLIC_POSTHOG_KEY;
}

// Function to get PostHog host
export function getPostHogHost() {
return (window as any).NMUI_PUBLIC_POSTHOG_HOST || import.meta.env.VITE_PUBLIC_POSTHOG_HOST;
}

// Function to get netclient download link and filename based on OS, arch and type
export function getNetclientDownloadLink(os: AvailableOses, arch: AvailableArchs): [string, string] {
const fileNamePlaceholder = ':fileName';
Expand Down

0 comments on commit 3128eb3

Please sign in to comment.