Skip to content

Commit

Permalink
refactor: change google analytics loading
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbericTrancart committed Oct 26, 2023
1 parent 1a2185c commit bd77377
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
17 changes: 2 additions & 15 deletions app/(main)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Script from 'next/script';
import { IBM_Plex_Sans } from 'next/font/google';
import type { Metadata } from 'next';
import { Header } from 'components/Header';
Expand All @@ -7,6 +6,7 @@ import './global.scss';
import 'prismjs/themes/prism-solarizedlight.css';
import { generateTitleMetadata, PAGES } from 'services/pages';
import styles from './MainLayout.module.scss';
import { Analytics } from './Analytics';

Check failure on line 9 in app/(main)/layout.tsx

View workflow job for this annotation

GitHub Actions / tests

Cannot find module './Analytics' or its corresponding type declarations.

export const ibmPlexSans = IBM_Plex_Sans({
subsets: ['latin'],
Expand All @@ -33,8 +33,6 @@ interface Props {
children: React.ReactNode;
}

const ANALYTICS_ID = process.env.NEXT_PUBLIC_ANALYTICS_ID;

const Layout = ({ children }: Props) => (
<html lang="en" className={ibmPlexSans.variable}>
<body>
Expand All @@ -44,18 +42,7 @@ const Layout = ({ children }: Props) => (

<Footer />

{ANALYTICS_ID !== undefined && ANALYTICS_ID !== '' && (
<>
<Script id="google-analytics">
{`
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '${ANALYTICS_ID}', 'auto');
ga('send', 'pageview');
`}
</Script>
<Script src="https://www.google-analytics.com/analytics.js" />
</>
)}
<Analytics />
</body>
</html>
);
Expand Down
3 changes: 3 additions & 0 deletions components/Skill/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { event } from 'nextjs-google-analytics';
import { useEffect, useState } from 'react';
import { Link } from 'components/Link';
import { Checkbox } from 'components/Checkbox';
Expand Down Expand Up @@ -42,6 +43,8 @@ export const Skill = ({ className, skillId, showKataLink }: Props) => {
} catch {
console.warn('There was an issue with local storage!');
}

event('toggle_skill', { checked });
};

const skill = SKILLS[skillId];
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"copy-text-to-clipboard": "^3.0.0",
"lodash": "^4.17.19",
"next": "^13.5.4",
"nextjs-google-analytics": "^2.3.3",
"prismjs": "^1.21.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,7 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@~2.3.2:
fsevents@^2.3.2, fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
Expand Down Expand Up @@ -3638,6 +3638,13 @@ next@^13.5.4:
"@next/swc-win32-ia32-msvc" "13.5.4"
"@next/swc-win32-x64-msvc" "13.5.4"

nextjs-google-analytics@^2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/nextjs-google-analytics/-/nextjs-google-analytics-2.3.3.tgz#8393804b89915b22d94e0fabb786bdd4012cb888"
integrity sha512-Y6sI6A7wt5dji8hYBnVkOh9LTyImSLFZXx3FpyQgVW7W4b4qEFHjH2u3fhDJsrRZeLlUGM8/RuHD/mhHc2Axfg==
optionalDependencies:
fsevents "^2.3.2"

no-case@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/no-case/-/no-case-3.0.4.tgz#d361fd5c9800f558551a8369fc0dcd4662b6124d"
Expand Down

0 comments on commit bd77377

Please sign in to comment.