Skip to content

Commit c9afd83

Browse files
google analytics & sitemap generator added
1 parent f6c58fa commit c9afd83

5 files changed

Lines changed: 64 additions & 22 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"jobTitle": "Full-Stack Developer",
4040
"worksFor": {
4141
"@type": "Organization",
42-
"name": "izet e-payments pvt ltd"
42+
"name": "ibacustech solutions pvt ltd"
4343
},
4444
"alumniOf": [
4545
{

sitemap-generator.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import axios from 'axios';
22

3+
declare const console: { warn: (...args: any[]) => void };
4+
35
export default async function getProjectRoutes() {
46
try {
57
const response = await axios.get('https://api.sibisiddharth.me/api/projects?limit=1000');
@@ -12,7 +14,11 @@ export default async function getProjectRoutes() {
1214
// test deploy
1315
return projects.map(project => `/#/projects/${project.id}`);
1416
} catch (error) {
15-
console.warn('Sitemap: Failed to fetch dynamic routes.', error.message);
17+
if (error instanceof Error) {
18+
console.warn('Sitemap: Failed to fetch dynamic routes.', error.message);
19+
} else {
20+
console.warn('Sitemap: Failed to fetch dynamic routes.', String(error));
21+
}
1622
return [];
1723
}
1824
}

src/main.tsx

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
1-
import React from 'react'
2-
import ReactDOM from 'react-dom/client'
3-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
4-
import App from './App.tsx'
5-
import './index.css'
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
4+
import App from './App.tsx';
5+
import './index.css';
66
import clarity from '@microsoft/clarity';
77

8+
const queryClient = new QueryClient();
9+
10+
declare global {
11+
interface Window {
12+
dataLayer: any[];
13+
gtag: (...args: any[]) => void;
14+
}
15+
}
16+
817
if (import.meta.env.PROD) {
18+
// ✅ Initialize Microsoft Clarity
919
clarity.init(import.meta.env.VITE_CLARITY_PROJECT_ID);
10-
}
1120

12-
const queryClient = new QueryClient();
21+
// ✅ Initialize Google Analytics (GA4)
22+
const gaMeasurementId = import.meta.env.VITE_GA_MEASUREMENT_ID;
23+
if (gaMeasurementId) {
24+
// Load GA script
25+
const script = document.createElement('script');
26+
script.async = true;
27+
script.src = `https://www.googletagmanager.com/gtag/js?id=${gaMeasurementId}`;
28+
document.head.appendChild(script);
29+
30+
// Initialize GA dataLayer
31+
window.dataLayer = window.dataLayer || [];
32+
function gtag(...args: any[]) {
33+
window.dataLayer.push(args);
34+
}
35+
gtag('js', new Date());
36+
gtag('config', gaMeasurementId);
37+
}
38+
}
1339

1440
ReactDOM.createRoot(document.getElementById('root')!).render(
15-
<QueryClientProvider client={queryClient}>
16-
<App />
17-
</QueryClientProvider>
18-
)
41+
<QueryClientProvider client={queryClient}>
42+
<App />
43+
</QueryClientProvider>
44+
);

src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
interface ImportMetaEnv {
44
readonly VITE_CLARITY_PROJECT_ID: string;
5+
readonly VITE_GA_MEASUREMENT_ID: string;
56
}
67

78
interface ImportMeta {

vite.config.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import tailwindcss from '@tailwindcss/vite'
4-
// remove these two lines:
5-
// import sitemap from 'vite-plugin-sitemap'
6-
// import getProjectRoutes from './sitemap-generator.js'
4+
import sitemap from 'vite-plugin-sitemap'
5+
import getProjectRoutes from './sitemap-generator.js'
76

8-
export default defineConfig({
9-
base: "/",
10-
plugins: [
11-
react(),
12-
tailwindcss(),
13-
],
7+
export default defineConfig(async ({ command }) => {
8+
9+
const dynamicRoutes = command === 'build' ? await getProjectRoutes() : [];
10+
11+
return {
12+
base: "/",
13+
plugins: [
14+
react(),
15+
tailwindcss(),
16+
sitemap({
17+
hostname: 'https://sibisiddharth.me',
18+
routes: ['/', '/#/projects', '/#/terms'],
19+
dynamicRoutes: dynamicRoutes,
20+
} as any),
21+
],
22+
}
1423
})

0 commit comments

Comments
 (0)