Skip to content

Commit 16ba68b

Browse files
authored
patch: Adjusting google events
patch: Adjusting google events
2 parents 946ff60 + 71e181e commit 16ba68b

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

public/index.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4+
<!-- Global site tag (gtag.js) - Google Analytics -->
5+
<script
6+
async
7+
src="https://www.googletagmanager.com/gtag/js?id=G-JF1788P5N0"
8+
></script>
9+
<script>
10+
window.dataLayer = window.dataLayer || [];
11+
function gtag() {
12+
dataLayer.push(arguments);
13+
}
14+
gtag("js", new Date());
15+
16+
gtag("config", "G-JF1788P5N0");
17+
</script>
418
<meta charset="utf-8" />
519
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
620
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -19,7 +33,7 @@
1933
<title>Todo list</title>
2034
</head>
2135
<body>
22-
<noscript>You need to enable JavaScript to run this app.</noscript>
36+
<noscript>You need to enable JavaScript to run this app.</noscript>
2337
<div id="root"></div>
2438
</body>
2539
</html>

src/components/Modal/modalTag.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ const ModalTag = ({ hideModal, showModal }) => {
7676
setTagList(auxArr);
7777

7878
ReactGA.event({
79-
category: 'Button',
80-
action: 'Creating a new tag item'
79+
category: "Create",
80+
action: "Creating a new tag",
81+
label: "Tag Creation",
8182
});
8283

8384
setSelectorError(false);

src/components/Modal/modalTodo.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ const ModalTodo = ({ hideModal, showModal }) => {
8888
setTodoList(todoArr);
8989

9090
ReactGA.event({
91-
category: 'Button',
92-
action: 'Creating a new todo item'
91+
category: "Create",
92+
action: "Creating a new todo",
93+
label: "Todo Creation",
9394
});
9495

9596
setSelectorError(false);

src/components/SideBar/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useContext } from "react";
2-
2+
import ReactGA from "react-ga";
33
//Context
44
import { dataContext } from "../../context/dataContext.js";
55

@@ -26,6 +26,15 @@ const SideBar = () => {
2626
const [showModal, setShowModal] = useState(false);
2727
const [searchValue, setSearchValue] = useState("");
2828

29+
function handleClickAdd() {
30+
ReactGA.event({
31+
category: "Open",
32+
action: "Openned tag creation modal",
33+
label: "Tag Modal",
34+
});
35+
setShowModal(true);
36+
}
37+
2938
return (
3039
<>
3140
<Container>
@@ -62,7 +71,11 @@ const SideBar = () => {
6271
/>
6372
)}
6473
<Foot>
65-
<AddIcon onClick={() => setShowModal(true)} />
74+
<AddIcon
75+
onClick={() => {
76+
handleClickAdd();
77+
}}
78+
/>
6679
<span onClick={() => setShowModal(true)}>Add a new tag</span>
6780
</Foot>
6881
</div>

src/pages/Main/app.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import ModalTodo from "../../components/Modal/modalTodo";
2323

2424
import { ToastContainer } from "react-toastify";
2525

26+
ReactGA.initialize('G-JF1788P5N0');
27+
2628
const App = () => {
2729
const [showModal, setShowModal] = useState(false);
2830
const { todoFilter, setTodoFilter, tagList, setTagList } = useContext(dataContext);
@@ -40,16 +42,16 @@ const App = () => {
4042
}, [])
4143

4244
useEffect(() => {
43-
ReactGA.initialize('G-JF1788P5N0');
4445

4546
//to report page view
46-
ReactGA.pageview("/");
47+
ReactGA.pageview(window.location.pathname + window.location.search);
4748
}, [])
4849

4950
function handleClickAdd() {
5051
ReactGA.event({
51-
category: 'Button',
52-
action: 'Click the button that open todo modal'
52+
category: 'Open',
53+
action: 'Openned todo creation modal',
54+
label: 'Todo Modal'
5355
});
5456
setShowModal(true);
5557
}

0 commit comments

Comments
 (0)