Skip to content

Commit 0a20a3a

Browse files
authored
Merge pull request #140 from dzcode-io/bugfix/139
🐞 fixed analytics bug
2 parents e63637f + 81ef9d7 commit 0a20a3a

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

frontend/src/apps/main/entry/index.pug

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ head(lang=lang)
1010
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
1111
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
1212
ga('create', "#{gaCode}", 'auto');
13-
ga('send', 'pageview');
1413
//- Facebook Pixel Code
1514
script.
1615
!function(f,b,e,v,n,t,s)
@@ -21,7 +20,6 @@ head(lang=lang)
2120
t.src=v;s=b.getElementsByTagName(e)[0];
2221
s.parentNode.insertBefore(t,s)}(window, document,'script','https://connect.facebook.net/en_US/fbevents.js');
2322
fbq('init', "#{fbpCode}");
24-
fbq('track', 'PageView');
2523
//- Facebook Comments plugin
2624
meta(property="fb:app_id" content=fbAppCode)
2725

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import "./style";
22
import "react-toastify/dist/ReactToastify.css";
3-
import { BrowserRouter, Redirect, Route, Switch } from "react-router-dom";
3+
import {
4+
BrowserRouter,
5+
Redirect,
6+
Route,
7+
Switch,
8+
useLocation,
9+
} from "react-router-dom";
410
import React, { Suspense, lazy } from "react";
511
import Container from "@material-ui/core/Container";
612
import CssBaseline from "@material-ui/core/CssBaseline";
@@ -10,6 +16,7 @@ import { Navbar } from "t9/apps/main/components/navbar";
1016
import { Provider } from "react-redux";
1117
import { Theme } from "t9/apps/main/components/theme";
1218
import { ToastContainer } from "react-toastify";
19+
import { getEnv } from "src/common/utils";
1320
import { mainStore } from "t9/apps/main/redux";
1421
import { render } from "react-dom";
1522

@@ -18,38 +25,48 @@ const Articles = lazy(() => import("t9/apps/main/scenes/articles"));
1825
const Projects = lazy(() => import("t9/apps/main/scenes/projects"));
1926
const Learn = lazy(() => import("t9/apps/main/scenes/learn"));
2027
const Faq = lazy(() => import("t9/apps/main/scenes/faq"));
21-
2228
const Contact = lazy(() => import("t9/apps/main/scenes/contact"));
2329

30+
const env = getEnv();
31+
2432
export const App = () => {
33+
const location = useLocation();
34+
React.useEffect(() => {
35+
if (env !== "development") {
36+
window.ga("set", "page", location.pathname);
37+
window.ga("send", "pageview");
38+
window.fbq("track", "PageView");
39+
}
40+
}, [location]);
41+
2542
return (
2643
<Theme>
27-
<BrowserRouter>
28-
<Navbar />
29-
<Container maxWidth="lg">
30-
<ToastContainer />
31-
<Suspense fallback={Loading}>
32-
<Switch>
33-
<Route path="/" exact component={Landing} />
34-
<Route path="/Learn" component={Learn} />
35-
<Route path="/Articles" component={Articles} />
36-
<Route path="/Projects" component={Projects} />
37-
<Route path="/Contact-Us" component={Contact} />
38-
<Route path="/FAQ" component={Faq} />
39-
<Route render={() => <Redirect to="/" />} />
40-
</Switch>
41-
</Suspense>
42-
</Container>
43-
<Footer />
44-
</BrowserRouter>
44+
<Navbar />
45+
<Container maxWidth="lg">
46+
<ToastContainer />
47+
<Suspense fallback={Loading}>
48+
<Switch>
49+
<Route path="/" exact component={Landing} />
50+
<Route path="/Learn" component={Learn} />
51+
<Route path="/Articles" component={Articles} />
52+
<Route path="/Projects" component={Projects} />
53+
<Route path="/Contact-Us" component={Contact} />
54+
<Route path="/FAQ" component={Faq} />
55+
<Route render={() => <Redirect to="/" />} />
56+
</Switch>
57+
</Suspense>
58+
</Container>
59+
<Footer />
4560
<CssBaseline />
4661
</Theme>
4762
);
4863
};
4964

5065
render(
5166
<Provider store={mainStore}>
52-
<App />
67+
<BrowserRouter>
68+
<App />
69+
</BrowserRouter>
5370
</Provider>,
5471
document.getElementById("app-container"),
5572
);

0 commit comments

Comments
 (0)