Skip to content

Commit cb4f8ef

Browse files
Add Google Analytics
Added Google Analytics to latest dev branch
1 parent 4a27e56 commit cb4f8ef

File tree

11 files changed

+81
-38
lines changed

11 files changed

+81
-38
lines changed

app/Http/Requests/Admin/Settings/BaseSettingsFormRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function rules()
1919
'app:name' => 'required|string|max:255',
2020
'pterodactyl:auth:2fa_required' => 'required|integer|in:0,1,2',
2121
'app:locale' => ['required', 'string', Rule::in(array_keys($this->getAvailableLanguages()))],
22+
'app:analytics' => 'nullable|string',
2223
];
2324
}
2425

@@ -31,6 +32,7 @@ public function attributes()
3132
'app:name' => 'Company Name',
3233
'pterodactyl:auth:2fa_required' => 'Require 2-Factor Authentication',
3334
'app:locale' => 'Default Language',
35+
'app:analytics' => 'Google Analytics',
3436
];
3537
}
3638
}

app/Http/ViewComposers/AssetComposer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function compose(View $view)
3737
'enabled' => config('recaptcha.enabled', false),
3838
'siteKey' => config('recaptcha.website_key') ?? '',
3939
],
40+
'analytics' => config('app.analytics') ?? '',
4041
]);
4142
}
4243
}

app/Providers/SettingsServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SettingsServiceProvider extends ServiceProvider
2121
protected $keys = [
2222
'app:name',
2323
'app:locale',
24+
'app:analytics',
2425
'recaptcha:enabled',
2526
'recaptcha:secret_key',
2627
'recaptcha:website_key',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"path": "^0.12.7",
2424
"query-string": "^6.7.0",
2525
"react": "^16.13.1",
26+
"react-ga": "^3.1.2",
2627
"react-dom": "npm:@hot-loader/react-dom",
2728
"react-fast-compare": "^3.2.0",
2829
"react-google-recaptcha": "^2.0.1",

resources/scripts/components/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as React from 'react';
1+
import React, { useEffect } from 'react';
2+
import ReactGA from 'react-ga';
23
import { hot } from 'react-hot-loader/root';
34
import { BrowserRouter, Route, Switch } from 'react-router-dom';
45
import { StoreProvider } from 'easy-peasy';
@@ -48,6 +49,11 @@ const App = () => {
4849
store.getActions().settings.setSettings(SiteConfiguration!);
4950
}
5051

52+
useEffect(() => {
53+
ReactGA.initialize(SiteConfiguration!.analytics);
54+
ReactGA.pageview(location.pathname);
55+
}, []);
56+
5157
return (
5258
<>
5359
<GlobalStylesheet/>
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
2+
import ReactGA from 'react-ga';
23
import { Route, RouteComponentProps, Switch } from 'react-router-dom';
34
import LoginContainer from '@/components/auth/LoginContainer';
45
import ForgotPasswordContainer from '@/components/auth/ForgotPasswordContainer';
56
import ResetPasswordContainer from '@/components/auth/ResetPasswordContainer';
67
import LoginCheckpointContainer from '@/components/auth/LoginCheckpointContainer';
78
import NotFound from '@/components/screens/NotFound';
89

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-
);
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+
};
Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as React from 'react';
1+
import React, { useEffect } from 'react';
2+
import ReactGA from 'react-ga';
23
import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
34
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
45
import NavigationBar from '@/components/NavigationBar';
@@ -8,24 +9,30 @@ import NotFound from '@/components/screens/NotFound';
89
import TransitionRouter from '@/TransitionRouter';
910
import SubNavigation from '@/components/elements/SubNavigation';
1011

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-
);
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+
};

resources/scripts/routers/ServerRouter.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2+
import ReactGA from 'react-ga';
23
import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
34
import NavigationBar from '@/components/NavigationBar';
45
import ServerConsole from '@/components/server/ServerConsole';
@@ -60,6 +61,10 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
6061
};
6162
}, [ match.params.id ]);
6263

64+
useEffect(() => {
65+
ReactGA.pageview(location.pathname);
66+
}, [ location.pathname ]);
67+
6368
return (
6469
<React.Fragment key={'server-router'}>
6570
<NavigationBar/>

resources/scripts/state/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface SiteSettings {
77
enabled: boolean;
88
siteKey: string;
99
};
10+
analytics: string;
1011
}
1112

1213
export interface SettingsStore {

resources/views/admin/settings/index.blade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
<p class="text-muted"><small>This is the name that is used throughout the panel and in emails sent to clients.</small></p>
3232
</div>
3333
</div>
34+
<div class="form-group col-md-4">
35+
<label class="control-label">Google Analytics</label>
36+
<div>
37+
<input type="text" class="form-control" name="app:analytics" value="{{ old('app:analytics', config('app.analytics')) }}" />
38+
<p class="text-muted"><small>This is your Google Analytics Tracking ID, Ex. UA-123723645-2</small></p>
39+
</div>
40+
</div>
3441
<div class="form-group col-md-4">
3542
<label class="control-label">Require 2-Factor Authentication</label>
3643
<div>

0 commit comments

Comments
 (0)