Skip to content

Commit 2c389b6

Browse files
Add sitemap generation and Google Tag Manager
- Installed and configured next-sitemap for automatic sitemap.xml generation - Added robots.txt generation with proper disallow rules for /dev - Integrated Google Tag Manager with environment variable configuration - Added .env.example file for GTM ID configuration - Sitemap includes all pages with proper priorities (homepage: 1.0, tools: 0.8) - GTM will track user interactions when configured with actual ID To use GTM: Set NEXT_PUBLIC_GTM_ID in .env.local or GitHub secrets 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f58fc8c commit 2c389b6

File tree

6 files changed

+121
-2
lines changed

6 files changed

+121
-2
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Google Tag Manager ID
2+
# Get your GTM ID from https://tagmanager.google.com/
3+
NEXT_PUBLIC_GTM_ID=GTM-XXXXXX

app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Metadata } from "next";
22
import { Inter } from "next/font/google";
3+
import { GTM } from "@/components/GoogleTagManager";
34
import "./globals.css";
45

56
const inter = Inter({
@@ -20,6 +21,7 @@ export default function RootLayout({
2021
return (
2122
<html lang="en">
2223
<body className={`${inter.className} antialiased`}>
24+
<GTM />
2325
{children}
2426
</body>
2527
</html>

components/GoogleTagManager.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use client';
2+
3+
import { GoogleTagManager } from '@next/third-parties/google';
4+
5+
export function GTM() {
6+
// You'll need to replace this with your actual GTM ID
7+
const gtmId = process.env.NEXT_PUBLIC_GTM_ID || 'GTM-XXXXXX';
8+
9+
if (!gtmId || gtmId === 'GTM-XXXXXX') {
10+
console.warn('Google Tag Manager ID not configured');
11+
return null;
12+
}
13+
14+
return <GoogleTagManager gtmId={gtmId} />;
15+
}

next-sitemap.config.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/** @type {import('next-sitemap').IConfig} */
2+
module.exports = {
3+
siteUrl: 'https://serptools.github.io',
4+
generateRobotsTxt: true,
5+
generateIndexSitemap: false,
6+
outDir: 'out',
7+
changefreq: 'weekly',
8+
priority: 0.7,
9+
exclude: ['/dev/*'],
10+
robotsTxtOptions: {
11+
policies: [
12+
{
13+
userAgent: '*',
14+
allow: '/',
15+
disallow: ['/dev'],
16+
},
17+
],
18+
},
19+
transform: async (config, path) => {
20+
// Set higher priority for main pages
21+
if (path === '/') {
22+
return {
23+
loc: path,
24+
changefreq: 'daily',
25+
priority: 1.0,
26+
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
27+
};
28+
}
29+
30+
// Set medium-high priority for tool pages
31+
if (path.startsWith('/tools/')) {
32+
return {
33+
loc: path,
34+
changefreq: 'weekly',
35+
priority: 0.8,
36+
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
37+
};
38+
}
39+
40+
// Default transformation
41+
return {
42+
loc: path,
43+
changefreq: config.changefreq,
44+
priority: config.priority,
45+
lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
46+
};
47+
},
48+
};

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
7-
"build": "next build",
7+
"build": "next build && next-sitemap",
88
"start": "next start",
99
"lint": "next lint",
1010
"gen:manifest": "node scripts/gen-manifest.mjs",
11-
"readme:tools": "node scripts/update-readme.mjs"
11+
"readme:tools": "node scripts/update-readme.mjs",
12+
"postbuild": "next-sitemap"
1213
},
1314
"dependencies": {
15+
"@next/third-parties": "^15.4.6",
1416
"@radix-ui/react-label": "^2.0.2",
1517
"@radix-ui/react-progress": "^1.0.3",
1618
"@radix-ui/react-separator": "^1.1.7",
@@ -35,6 +37,7 @@
3537
"autoprefixer": "^10.4.20",
3638
"eslint": "^9",
3739
"eslint-config-next": "15.1.0",
40+
"next-sitemap": "^4.2.3",
3841
"postcss": "^8",
3942
"tailwindcss": "^3.4.1",
4043
"typescript": "^5"

pnpm-lock.yaml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)