UA-SOME_ANALYTICS_ID-1 = 先ほどのAnalytics ID (2)GAイベントを発火させる関数を作成する ・src/hooks/usePageView.ts ・src/lib/gtag.ts ・src/types/googleAnalytics/event.ts 作成 usePageView.ts import { useEffect } from 'react' import { useRouter } from 'next/router' import * as gtag from '../lib/gtag' export default function usePageView() { const router = useRouter() console.log(gtag.GA_ID) useEffect(() => { if (!gtag.existsGaI
![Next.jsのサイトにGoogle Analyticsを導入する](https://cdn-ak-scissors.b.st-hatena.com/image/square/2b08edddb98afae2e01ad090851afd72f11ec5f3/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--hjM3RNSq--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3ANext.js%2525E3%252581%2525AE%2525E3%252582%2525B5%2525E3%252582%2525A4%2525E3%252583%252588%2525E3%252581%2525ABGoogle%252520Analytics%2525E3%252582%252592%2525E5%2525B0%25258E%2525E5%252585%2525A5%2525E3%252581%252599%2525E3%252582%25258B%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3ARen%252520Shimosawa%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EtL0FPaDE0R2ptcmlXRGR5UjRXLUdpUHd4eUZHbGphX1Q0cUVRS3hqcXhNU1NPPXM5Ni1j%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)