Skip to content
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

Analytics: Update without new dependency #550

Merged
merged 1 commit into from
Sep 17, 2024
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: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@mui/lab": "^5.0.0-alpha.170",
"@mui/material": "^5.15.20",
"@mui/material-nextjs": "^5.16.6",
"@next/third-parties": "^14.2.11",
"@openstreetmap/id-tagging-schema": "^6.7.3",
"@sentry/nextjs": "^8",
"@xmldom/xmldom": "^0.8.10",
Expand Down
5 changes: 4 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
import { UserThemeProvider } from '../src/helpers/theme';
import { GlobalStyle } from '../src/helpers/GlobalStyle';
import { doShortenerRedirect } from '../src/services/helpers';
import { PROJECT_NAME } from '../src/services/project';
import { PROJECT_ID, PROJECT_NAME } from '../src/services/project';
import { GoogleAnalytics } from './api/google-analytics';

type Props = AppProps & EmotionCacheProviderProps;

Expand All @@ -27,6 +28,7 @@ export default class MyApp extends App<Props> {
render() {
const { Component, pageProps, emotionCache } = this.props as any;
const { userThemeCookie } = pageProps;
const isOpenClimbing = PROJECT_ID === 'openclimbing';

return (
<>
Expand All @@ -46,6 +48,7 @@ export default class MyApp extends App<Props> {
<GlobalStyle />
</UserThemeProvider>
</AppCacheProvider>
{isOpenClimbing && <GoogleAnalytics />}
</>
);
}
Expand Down
2 changes: 0 additions & 2 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Document, {
Main,
NextScript,
} from 'next/document';
import { GoogleAnalytics } from '@next/third-parties/google';
import type { DocumentContext } from 'next/dist/shared/lib/utils';
import {
DocumentHeadTags,
Expand Down Expand Up @@ -65,7 +64,6 @@ export default class MyDocument extends Document<Props> {
<Main />
<InjectIntl intl={serverIntl} />
<NextScript />
{isOpenClimbing && <GoogleAnalytics gaId="G-XCHYKP28FT" />}
</body>
</Html>
);
Expand Down
23 changes: 23 additions & 0 deletions pages/api/google-analytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import Script from 'next/script';

const OPENCLIMBING_ID = 'G-XCHYKP28FT';

export const GoogleAnalytics = () => (
<>
<Script
strategy="lazyOnload"
src={`https://www.googletagmanager.com/gtag/js?id=${OPENCLIMBING_ID}`}
/>

<Script id="" strategy="lazyOnload">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '${OPENCLIMBING_ID}');
`}
</Script>
</>
);
14 changes: 2 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1184,13 +1184,6 @@
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.6.tgz#6b63a7b4ff3b7b410a038e3ee839c951a3136dc9"
integrity sha512-NANtw+ead1rSDK1jxmzq3TYkl03UNK2KHqUYf1nIhNci6NkeqBD4s1njSzYGIlSHxCK+wSaL8RXZm4v+NF/pMw==

"@next/third-parties@^14.2.11":
version "14.2.11"
resolved "https://registry.yarnpkg.com/@next/third-parties/-/third-parties-14.2.11.tgz#57e8889735182e362b2ea88019ac51318ea300c6"
integrity sha512-KpTrJg05vyi+0NxjuQT9CR4lsiVTciLSupMosR/BtSHek5bqHWP3KvHfFEsOcxBeOZLNhSmBUhkYclQ4eUVu9Q==
dependencies:
third-party-capital "1.0.20"

"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
Expand Down Expand Up @@ -7264,6 +7257,7 @@ string-length@^4.0.1:
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3:
name string-width-cjs
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -7408,6 +7402,7 @@ string_decoder@~1.1.1:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1:
name strip-ansi-cjs
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -7559,11 +7554,6 @@ theming@^3.3.0:
react-display-name "^0.2.4"
tiny-warning "^1.0.2"

third-party-capital@1.0.20:
version "1.0.20"
resolved "https://registry.yarnpkg.com/third-party-capital/-/third-party-capital-1.0.20.tgz#e218a929a35bf4d2245da9addb8ab978d2f41685"
integrity sha512-oB7yIimd8SuGptespDAZnNkzIz+NWaJCu2RMsbs4Wmp9zSDUM8Nhi3s2OOcqYuv3mN4hitXc8DVx+LyUmbUDiA==

through2@~0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/through2/-/through2-0.4.2.tgz#dbf5866031151ec8352bb6c4db64a2292a840b9b"
Expand Down
Loading