Skip to content

Commit 2ffbc2c

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

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/components/AppLayout.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ 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 { PROD_DEPLOYMENT_ENVIRONMENT, PROD_METRICS_WEBSITE_ID, QA_DEPLOYMENT_ENVIRONMENT, QA_METRICS_WEBSITE_ID, UMAMI_METRICS_SCRIPT_SOURCE } from '../types/const'
2930

3031
interface IAppLayout {
3132
children: React.ReactNode;
@@ -46,6 +47,35 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
4647
const router = useRouter();
4748
const pathname = usePathname();
4849

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

src/types/const.ts

Lines changed: 9 additions & 0 deletions
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)