Skip to content

Commit 1d9ee15

Browse files
add umami tracking codes via script tags
Signed-off-by: greg pereira <[email protected]>
1 parent 98c56d5 commit 1d9ee15

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/components/AppLayout.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ import UserMenu from './UserMenu/UserMenu';
2626
import { useSession } from 'next-auth/react';
2727
// import { useTheme } from '../context/ThemeContext';
2828
import { useState } from 'react';
29+
import {
30+
PROD_DEPLOYMENT_ENVIRONMENT,
31+
PROD_METRICS_WEBSITE_ID,
32+
QA_DEPLOYMENT_ENVIRONMENT,
33+
QA_METRICS_WEBSITE_ID,
34+
UMAMI_METRICS_SCRIPT_SOURCE
35+
} from '../types/const';
2936

3037
interface IAppLayout {
3138
children: React.ReactNode;
@@ -46,6 +53,31 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
4653
const router = useRouter();
4754
const pathname = usePathname();
4855

56+
React.useEffect(() => {
57+
if (typeof window === 'undefined') return;
58+
59+
const hostname = window.location.hostname;
60+
const isProd = hostname === PROD_DEPLOYMENT_ENVIRONMENT;
61+
const isQA = hostname === QA_DEPLOYMENT_ENVIRONMENT;
62+
63+
const scriptSource = isQA || isProd ? UMAMI_METRICS_SCRIPT_SOURCE : '';
64+
const websiteId = isProd ? PROD_METRICS_WEBSITE_ID : isQA ? QA_METRICS_WEBSITE_ID : null;
65+
66+
if (scriptSource && websiteId) {
67+
const script = document.createElement('script');
68+
script.async = true;
69+
script.defer = true;
70+
script.dataset.websiteId = websiteId;
71+
script.src = scriptSource;
72+
73+
document.head.appendChild(script);
74+
75+
return () => {
76+
document.head.removeChild(script);
77+
};
78+
}
79+
}, []);
80+
4981
React.useEffect(() => {
5082
// Fetch the experimental feature flag
5183
const fetchExperimentalFeature = async () => {

src/types/const.ts

+9
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ export const FORK_CLONE_CHECK_RETRY_TIMEOUT = 5000;
66
export const FORK_CLONE_CHECK_RETRY_COUNT = 10;
77
export const GITHUB_API_URL = 'https://api.github.com';
88
export const BASE_BRANCH = 'main';
9+
10+
// Umami metrics constants
11+
export const PROD_DEPLOYMENT_ENVIRONMENT = 'ui.instructlab.ai';
12+
export const PROD_METRICS_WEBSITE_ID = 'e20a625c-c3aa-487b-81ec-79525ecec36b';
13+
// export const QA_DEPLOYMENT_ENVIRONMENT = 'qa.ui.instructlab.ai';
14+
export const QA_DEPLOYMENT_ENVIRONMENT = 'localhost';
15+
export const QA_METRICS_WEBSITE_ID = '013a7037-2576-4dc9-95e2-a48c234680cb';
16+
export const UMAMI_METRICS_SCRIPT_SOURCE =
17+
'https://umami-umami.ui-instructlab-ai-0e3e0ef4c9c6d831e8aa6fe01f33bfc4-0000.us-south.containers.appdomain.cloud/script.js';

0 commit comments

Comments
 (0)