Skip to content

Commit

Permalink
add google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmathidayatullah committed Jun 9, 2024
1 parent 2602ae8 commit 6afe910
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_API_URL=https://i-mader.tech
NEXT_PUBLIC_MEASUREMENT_ID=G-3FNP2LS55J
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@ant-design/nextjs-registry": "^1.0.0",
"antd": "^5.17.4",
"axios": "^1.7.2",
"next": "14.2.3",
"pm2": "^5.4.0",
"react": "^18",
Expand Down
26 changes: 26 additions & 0 deletions src/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import Script from 'next/script';

const GoogleAnalytics = () => {
return (
<>
<Script
strategy='lazyOnload'
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_MEASUREMENT_ID}`}
/>

<Script id='' strategy='lazyOnload'>
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_MEASUREMENT_ID}', {
page_path: window.location.pathname,
});
`}
</Script>
</>
);
};

export default GoogleAnalytics;
4 changes: 3 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Inter } from "next/font/google";
import "./globals.css";
import { AntdRegistry } from "@ant-design/nextjs-registry";
import LayoutHome from "@/components/wrapper/layout-home";
import GoogleAnalytics from "@/GoogleAnalytics";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -29,7 +30,8 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>
<body>
<GoogleAnalytics />
<AntdRegistry>
<LayoutHome>{children}</LayoutHome>
</AntdRegistry>
Expand Down
1 change: 1 addition & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Script from 'next/script'
import Hero from "./ui/section/hero";
import WhyChooseUs from "./ui/section/why-choose-us";
import Blog from "./ui/section/blog";
Expand Down
52 changes: 52 additions & 0 deletions src/hooks/useContact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import axios from 'axios';
import useSWR from 'swr';
// import { Task } from '../types/task';

export const useTasks = (callback?: Function) => {
const api = axios.create({
baseURL: process.env.REACT_APP_API_URL,
});

const fetcher = (url: string) => api.get(url).then((res) => res.data);

// const { data, error, mutate } = useSWR<Task[], Error>('/tasks', fetcher, {
// onSuccess: (data, key) => {
// if (callback) callback();
// },
// });

// const createTask = async (task: Task) => {
// if (!data) {
// return false;
// }
// const result = await api.post<Task>('//api/v1/contact-us/add', task);
// mutate([...data, result.data]);
// };

// const updateTask = async (task: Task) => {
// if (!data) {
// return false;
// }
// const { data: updatedTask } = await api.patch<Task>(
// `/tasks/${task.id}`,
// task
// );
// mutate(
// data.map(
// (task) => (task.id === updatedTask.id ? updatedTask : task),
// false
// )
// );
// };

// const removeTask = async (task: Task) => {
// if (!data) {
// return false;
// }
// await api.delete<Task>(`/tasks/${task.id}`);
// mutate(data.filter((item) => item.id === task.id, false));
// };

// return { data, error, createTask, updateTask, removeTask };
// return { data, error, createTask };
};
Empty file added src/types/contact-us.ts
Empty file.

0 comments on commit 6afe910

Please sign in to comment.