Skip to content

Commit 7cf6b4b

Browse files
committed
Only load GA when valid key is provided; closes pterodactyl#2678
1 parent de943ea commit 7cf6b4b

File tree

5 files changed

+57
-64
lines changed

5 files changed

+57
-64
lines changed

resources/scripts/api/server/getServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Allocation {
1313

1414
export interface Server {
1515
id: string;
16-
internalId: number;
16+
internalId: number | string;
1717
uuid: string;
1818
name: string;
1919
node: string;

resources/scripts/components/App.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect } from 'react';
22
import ReactGA from 'react-ga';
33
import { hot } from 'react-hot-loader/root';
4-
import { BrowserRouter, Route, Switch } from 'react-router-dom';
4+
import { BrowserRouter, Route, Switch, useLocation } from 'react-router-dom';
55
import { StoreProvider } from 'easy-peasy';
66
import { store } from '@/state';
77
import DashboardRouter from '@/routers/DashboardRouter';
@@ -30,6 +30,16 @@ interface ExtendedWindow extends Window {
3030
};
3131
}
3232

33+
const Pageview = () => {
34+
const { pathname } = useLocation();
35+
36+
useEffect(() => {
37+
ReactGA.pageview(pathname);
38+
}, [ pathname ]);
39+
40+
return null;
41+
};
42+
3343
const App = () => {
3444
const { PterodactylUser, SiteConfiguration } = (window as ExtendedWindow);
3545
if (PterodactylUser && !store.getState().user.data) {
@@ -50,8 +60,9 @@ const App = () => {
5060
}
5161

5262
useEffect(() => {
53-
ReactGA.initialize(SiteConfiguration!.analytics);
54-
ReactGA.pageview(location.pathname);
63+
if (SiteConfiguration?.analytics) {
64+
ReactGA.initialize(SiteConfiguration!.analytics);
65+
}
5566
}, []);
5667

5768
return (
@@ -62,6 +73,7 @@ const App = () => {
6273
<ProgressBar/>
6374
<div css={tw`mx-auto w-auto`}>
6475
<BrowserRouter basename={'/'} key={'root-router'}>
76+
{SiteConfiguration?.analytics && <Pageview/>}
6577
<Switch>
6678
<Route path="/server/:id" component={ServerRouter}/>
6779
<Route path="/auth" component={AuthenticationRouter}/>
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
import React, { useEffect } from 'react';
2-
import ReactGA from 'react-ga';
1+
import React from 'react';
32
import { Route, RouteComponentProps, Switch } from 'react-router-dom';
43
import LoginContainer from '@/components/auth/LoginContainer';
54
import ForgotPasswordContainer from '@/components/auth/ForgotPasswordContainer';
65
import ResetPasswordContainer from '@/components/auth/ResetPasswordContainer';
76
import LoginCheckpointContainer from '@/components/auth/LoginCheckpointContainer';
87
import NotFound from '@/components/screens/NotFound';
98

10-
export default ({ location, history, match }: RouteComponentProps) => {
11-
useEffect(() => {
12-
ReactGA.pageview(location.pathname);
13-
}, [ location.pathname ]);
14-
15-
return (
16-
<div className={'pt-8 xl:pt-32'}>
17-
<Switch location={location}>
18-
<Route path={`${match.path}/login`} component={LoginContainer} exact/>
19-
<Route path={`${match.path}/login/checkpoint`} component={LoginCheckpointContainer}/>
20-
<Route path={`${match.path}/password`} component={ForgotPasswordContainer} exact/>
21-
<Route path={`${match.path}/password/reset/:token`} component={ResetPasswordContainer}/>
22-
<Route path={`${match.path}/checkpoint`} />
23-
<Route path={'*'}>
24-
<NotFound onBack={() => history.push('/auth/login')} />
25-
</Route>
26-
</Switch>
27-
</div>
28-
);
29-
};
9+
export default ({ location, history, match }: RouteComponentProps) => (
10+
<div className={'pt-8 xl:pt-32'}>
11+
<Switch location={location}>
12+
<Route path={`${match.path}/login`} component={LoginContainer} exact/>
13+
<Route path={`${match.path}/login/checkpoint`} component={LoginCheckpointContainer}/>
14+
<Route path={`${match.path}/password`} component={ForgotPasswordContainer} exact/>
15+
<Route path={`${match.path}/password/reset/:token`} component={ResetPasswordContainer}/>
16+
<Route path={`${match.path}/checkpoint`}/>
17+
<Route path={'*'}>
18+
<NotFound onBack={() => history.push('/auth/login')}/>
19+
</Route>
20+
</Switch>
21+
</div>
22+
);
Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { useEffect } from 'react';
2-
import ReactGA from 'react-ga';
1+
import React from 'react';
32
import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
43
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
54
import NavigationBar from '@/components/NavigationBar';
@@ -9,30 +8,24 @@ import NotFound from '@/components/screens/NotFound';
98
import TransitionRouter from '@/TransitionRouter';
109
import SubNavigation from '@/components/elements/SubNavigation';
1110

12-
export default ({ location }: RouteComponentProps) => {
13-
useEffect(() => {
14-
ReactGA.pageview(location.pathname);
15-
}, [ location.pathname ]);
16-
17-
return (
18-
<>
19-
<NavigationBar />
20-
{location.pathname.startsWith('/account') &&
21-
<SubNavigation>
22-
<div>
23-
<NavLink to={'/account'} exact>Settings</NavLink>
24-
<NavLink to={'/account/api'}>API Credentials</NavLink>
25-
</div>
26-
</SubNavigation>
27-
}
28-
<TransitionRouter>
29-
<Switch location={location}>
30-
<Route path={'/'} component={DashboardContainer} exact />
31-
<Route path={'/account'} component={AccountOverviewContainer} exact/>
32-
<Route path={'/account/api'} component={AccountApiContainer} exact/>
33-
<Route path={'*'} component={NotFound} />
34-
</Switch>
35-
</TransitionRouter>
36-
</>
37-
);
38-
};
11+
export default ({ location }: RouteComponentProps) => (
12+
<>
13+
<NavigationBar/>
14+
{location.pathname.startsWith('/account') &&
15+
<SubNavigation>
16+
<div>
17+
<NavLink to={'/account'} exact>Settings</NavLink>
18+
<NavLink to={'/account/api'}>API Credentials</NavLink>
19+
</div>
20+
</SubNavigation>
21+
}
22+
<TransitionRouter>
23+
<Switch location={location}>
24+
<Route path={'/'} component={DashboardContainer} exact/>
25+
<Route path={'/account'} component={AccountOverviewContainer} exact/>
26+
<Route path={'/account/api'} component={AccountApiContainer} exact/>
27+
<Route path={'*'} component={NotFound}/>
28+
</Switch>
29+
</TransitionRouter>
30+
</>
31+
);

resources/scripts/routers/ServerRouter.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect, useState } from 'react';
2-
import ReactGA from 'react-ga';
32
import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
43
import NavigationBar from '@/components/NavigationBar';
54
import ServerConsole from '@/components/server/ServerConsole';
@@ -40,9 +39,9 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
4039
const id = ServerContext.useStoreState(state => state.server.data?.id);
4140
const uuid = ServerContext.useStoreState(state => state.server.data?.uuid);
4241
const isInstalling = ServerContext.useStoreState(state => state.server.data?.isInstalling);
42+
const serverId = ServerContext.useStoreState(state => state.server.data?.internalId);
4343
const getServer = ServerContext.useStoreActions(actions => actions.server.getServer);
4444
const clearServerState = ServerContext.useStoreActions(actions => actions.clearServerState);
45-
const serverId = ServerContext.useStoreState(state => state.server.data?.internalId);
4645

4746
useEffect(() => () => {
4847
clearServerState();
@@ -70,10 +69,6 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
7069
};
7170
}, [ match.params.id ]);
7271

73-
useEffect(() => {
74-
ReactGA.pageview(location.pathname);
75-
}, [ location.pathname ]);
76-
7772
return (
7873
<React.Fragment key={'server-router'}>
7974
<NavigationBar/>
@@ -113,9 +108,9 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
113108
<NavLink to={`${match.url}/settings`}>Settings</NavLink>
114109
</Can>
115110
{rootAdmin &&
116-
<a href={'/admin/servers/view/' + serverId} rel="noreferrer" target={'_blank'}>
117-
<FontAwesomeIcon icon={faExternalLinkAlt}/>
118-
</a>
111+
<a href={'/admin/servers/view/' + serverId} rel="noreferrer" target={'_blank'}>
112+
<FontAwesomeIcon icon={faExternalLinkAlt}/>
113+
</a>
119114
}
120115
</div>
121116
</SubNavigation>

0 commit comments

Comments
 (0)