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

Google Analytics関連コードを削除した #25

Merged
merged 2 commits into from
Apr 21, 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
49 changes: 0 additions & 49 deletions app/modules/gtags.client.ts

This file was deleted.

47 changes: 0 additions & 47 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ import {
Scripts,
ScrollRestoration,
isRouteErrorResponse,
json,
useLoaderData,
useLocation,
useRouteError,
} from "@remix-run/react";

import type { LinksFunction } from "@remix-run/node";
import stylesheet from "~/tailwind.css?url";
import { SpeedInsights } from "@vercel/speed-insights/remix"

import * as gtag from "~/modules/gtags.client"
import { useEffect } from "react";
import { PageTransitionProgressBar } from "./components/PageTransitionProgressBar";

export const links: LinksFunction = () => [
Expand All @@ -30,25 +23,8 @@ export const links: LinksFunction = () => [
},
];

export async function loader() {
const gaTrackingId = process.env.NODE_ENV !== "development" ? process.env.GA_TRACKING_ID : null;
return json({
gaTrackingId : gaTrackingId ?? ""
});
}



export function Layout({ children }: { children: React.ReactNode }) {
const { gaTrackingId } = useLoaderData<typeof loader>();
const location = useLocation();

useEffect(() => {
if (gaTrackingId?.length) {
gtag.pageview(location.pathname, gaTrackingId);
}
}, [location, gaTrackingId]);

return (
<html lang="ja">
<head>
Expand All @@ -63,29 +39,6 @@ export function Layout({ children }: { children: React.ReactNode }) {
{children}
<ScrollRestoration />
<Scripts />
<SpeedInsights />
{!gaTrackingId ? null : (
<>
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${gaTrackingId}`}
/>
<script
async
id="gtag-init"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaTrackingId}', {
page_path: window.location.pathname,
});
`,
}}
/>
</>
)}
</body>
</html>
);
Expand Down
Loading