Skip to content

add umami tracking codes via script tags #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/components/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import {
import { BarsIcon } from '@patternfly/react-icons';
import ThemePreference from '@/components/ThemePreference/ThemePreference';
import '../styles/globals.scss';
PROD_DEPLOYMENT_ENVIRONMENT,
PROD_METRICS_WEBSITE_ID,
QA_DEPLOYMENT_ENVIRONMENT,
QA_METRICS_WEBSITE_ID,
UMAMI_METRICS_SCRIPT_SOURCE
} from '../types/const';

interface IAppLayout {
children: React.ReactNode;
Expand All @@ -50,6 +56,31 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
const router = useRouter();
const pathname = usePathname();

React.useEffect(() => {
if (typeof window === 'undefined') return;

const hostname = window.location.hostname;
const isProd = hostname === PROD_DEPLOYMENT_ENVIRONMENT;
const isQA = hostname === QA_DEPLOYMENT_ENVIRONMENT;

const scriptSource = isQA || isProd ? UMAMI_METRICS_SCRIPT_SOURCE : '';
const websiteId = isProd ? PROD_METRICS_WEBSITE_ID : isQA ? QA_METRICS_WEBSITE_ID : null;

if (scriptSource && websiteId) {
const script = document.createElement('script');
script.async = true;
script.defer = true;
script.dataset.websiteId = websiteId;
script.src = scriptSource;

document.head.appendChild(script);

return () => {
document.head.removeChild(script);
};
}
}, []);

React.useEffect(() => {
// Fetch the experimental feature flag
const fetchExperimentalFeature = async () => {
Expand Down
8 changes: 8 additions & 0 deletions src/types/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ export const FORK_CLONE_CHECK_RETRY_TIMEOUT = 5000;
export const FORK_CLONE_CHECK_RETRY_COUNT = 10;
export const GITHUB_API_URL = 'https://api.github.com';
export const BASE_BRANCH = 'main';

// Umami metrics constants
export const PROD_DEPLOYMENT_ENVIRONMENT = 'ui.instructlab.ai';
export const PROD_METRICS_WEBSITE_ID = 'e20a625c-c3aa-487b-81ec-79525ecec36b';
export const QA_DEPLOYMENT_ENVIRONMENT = 'qa.ui.instructlab.ai';
export const QA_METRICS_WEBSITE_ID = '013a7037-2576-4dc9-95e2-a48c234680cb';
export const UMAMI_METRICS_SCRIPT_SOURCE =
'https://umami-umami.ui-instructlab-ai-0e3e0ef4c9c6d831e8aa6fe01f33bfc4-0000.us-south.containers.appdomain.cloud/script.js';
Loading