Skip to content

1731 add analytics tag for judge (#1662) #1663

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

Merged
merged 1 commit into from
Jul 14, 2025
Merged
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
1 change: 1 addition & 0 deletions Servers/UI/OJS.Servers.Ui/ClientApp/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ VITE_UI_SERVER_URL = 'https://alpha.judge.softuni.org'
VITE_ADMINISTRATION_URL = 'https://admin.alpha.judge.softuni.org'
VITE_PLATFORM_URL = 'https://platform.softuni.bg'
VITE_YOUTUBE_VIDEO_ID = 'EjQlqgTbvsE'
VITE_GA_ID=G-19F5E0RPNK
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useEffect } from 'react';
import { Outlet, ScrollRestoration } from 'react-router-dom';
import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
import usePageViewTracking from 'src/hooks/use-page-view-tracking';

import MuiUiThemeProvider from '../../../hooks/use-mui-ui-theme';
import useTheme from '../../../hooks/use-theme';
Expand Down Expand Up @@ -47,6 +48,8 @@ const ClientPortal = () => {
};
}, [ isDarkMode ]);

usePageViewTracking();

useEffect(() => {
toggleGlobalStyles();
}, [ isDarkMode, toggleGlobalStyles ]);
Expand Down
3 changes: 2 additions & 1 deletion Servers/UI/OJS.Servers.Ui/ClientApp/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/naming-convention */

/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_UI_SERVER_URL: string;
readonly VITE_ADMINISTRATION_URL: string;
readonly VITE_PLATFORM_URL: string;
readonly VITE_YOUTUBE_VIDEO_ID: string;
readonly VITE_GA_ID: string;
}

declare module '*.css';
Expand Down
9 changes: 9 additions & 0 deletions Servers/UI/OJS.Servers.Ui/ClientApp/src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */

declare global {
interface Window {
gtag?: (...args: any[]) => void;
}
}

export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

const usePageViewTracking = () => {
const location = useLocation();
const GA_ID = import.meta.env.VITE_GA_ID;

useEffect(() => {
if (!GA_ID || import.meta.env.DEV) {
return;
}

if (window.gtag) {
window.gtag(
'config', GA_ID,
{ page_path: location.pathname + location.search },
);
}
}, [ GA_ID, location ]);
};

export default usePageViewTracking;
7 changes: 4 additions & 3 deletions Servers/UI/OJS.Servers.Ui/ClientApp/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@


import { Suspense } from 'react';
import { createRoot } from 'react-dom/client';
import initAnalytics from 'src/utils/initAnalytics';

import SpinningLoader from './components/guidelines/spinning-loader/SpinningLoader';
import { flexCenterObjectStyles } from './utils/object-utils';
import App from './App';

import './styles/global.scss';

initAnalytics();

const container = document.getElementById('root');
const root = createRoot(container!);

const comp =
const comp =
<Suspense fallback={<div style={{ ...flexCenterObjectStyles }}><SpinningLoader /></div>}>
<App />
</Suspense>
Expand Down
20 changes: 20 additions & 0 deletions Servers/UI/OJS.Servers.Ui/ClientApp/src/utils/initAnalytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const initAnalytics = () => {
const GA_ID = import.meta.env.VITE_GA_ID;
if (!GA_ID || import.meta.env.DEV) {return;}

const script = document.createElement('script');
script.setAttribute('async', '');
script.src = `https://www.googletagmanager.com/gtag/js?id=${GA_ID}`;
document.head.appendChild(script);

const inlineScript = document.createElement('script');
inlineScript.innerHTML = `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_ID}');
`;
document.head.appendChild(inlineScript);
};

export default initAnalytics;
Loading