Skip to content

Commit 91caa20

Browse files
committed
adds google analytics
1 parent eee29d0 commit 91caa20

File tree

7 files changed

+66
-3
lines changed

7 files changed

+66
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"react-circular-progressbar": "^2.0.4",
2020
"react-codemirror2": "^7.2.1",
2121
"react-dom": "^17.0.2",
22+
"react-ga": "^3.3.0",
2223
"react-router": "^5.2.0",
2324
"react-router-dom": "^5.2.0",
2425
"react-scripts": "4.0.3",

src/App.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useAuth0 } from '@auth0/auth0-react'
55
import { Icon } from '@iconify/react';
66
import axios from 'axios';
77
import { v4 as uuidV4 } from 'uuid';
8+
import ReactGA from 'react-ga';
89
import runIcon from './images/icons/run.svg';
910
import whiteboard24Regular from '@iconify/icons-fluent/whiteboard-24-regular';
1011
import Preview from './components/Preview';
@@ -33,12 +34,27 @@ function App() {
3334
setDocId(window.location.pathname.split('/')[1])
3435
setIsDocId(true);
3536
}
37+
if (isAuthenticated) {
38+
ReactGA.event({
39+
category: `user.logged`,
40+
action: `Login`,
41+
label: `${user.email}`
42+
});
43+
}
44+
// eslint-disable-next-line
3645
}, []);
3746

3847

3948
let statusLoop = null;
4049

4150
const runCode = () => {
51+
52+
ReactGA.event({
53+
category: `button.clicked`,
54+
action: `Run Code`,
55+
lang: `${selected}`
56+
});
57+
4258
setOutput('')
4359
setTextEditor('output');
4460
setProcessing(true);
@@ -131,6 +147,10 @@ function App() {
131147
}
132148

133149
const toggleModal = () => {
150+
ReactGA.event({
151+
category: `button.clicked`,
152+
action: `Whiteboard ${modal ? "Opened" : "Closed"}`,
153+
});
134154
setModal(!modal);
135155
}
136156

src/components/IDE.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect, useState, useRef, useCallback } from 'react';
22
import { io } from 'socket.io-client';
33
import { Controlled as CodeMirror } from 'react-codemirror2';
4+
import ReactGA from 'react-ga';
45
import 'codemirror/lib/codemirror.css';
56
import 'codemirror/theme/material.css';
67
import 'codemirror/mode/htmlmixed/htmlmixed';
@@ -40,6 +41,7 @@ export default function IDE({ docId, modal, toggleModal, python, setpython, inpu
4041

4142

4243
useEffect(() => {
44+
ReactGA.pageview('IDE-screen');
4345
var TempSocket = io(process.env.REACT_APP_BACKEND_ENDPOINT_URL);
4446
setSocket(TempSocket);
4547
const peer = new Peer(undefined, {

src/components/Preview.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import React from 'react'
1+
import React, { useEffect } from 'react';
2+
import ReactGA from 'react-ga';
23

34
export default function Preview({ docId }) {
5+
useEffect(() => {
6+
ReactGA.pageview('preview-screen');
7+
}, [])
48

59
const joinRoomViaRoomId = () => {
610
const roomId = document.getElementById("roomIdInput");
@@ -9,9 +13,19 @@ export default function Preview({ docId }) {
913
if (roomIdValue.includes("http") || roomIdValue.includes("https")) {
1014
const url = new URL(roomIdValue);
1115
const path = url.pathname;
16+
ReactGA.event({
17+
category: `button.clicked`,
18+
action: `Join Room`,
19+
label: `from copied url`
20+
});
1221
window.location.href = `${path}`;
1322
}
1423
else {
24+
ReactGA.event({
25+
category: `button.clicked`,
26+
action: `Join Room`,
27+
label: `from input url`
28+
});
1529
window.location.href = `/${roomIdValue}`;
1630
}
1731
}
@@ -24,6 +38,10 @@ export default function Preview({ docId }) {
2438
</div>
2539
<div className="flex flex-col mt-20 justify-center text-white">
2640
<button onClick={() => {
41+
ReactGA.event({
42+
category: `button.clicked`,
43+
action: `Create Room`
44+
});
2745
window.location.href = `/${docId}`
2846
}} className=" hover:shadow-md duration-150 px-4 py-2 rounded-lg shadow text-blue-500 bg-white border border-blue-600 font-semibold">Create Room</button>
2947
{/* <button className=" hover:shadow-md duration-300 px-4 mx-2 py-2 rounded-lg shadow bg-blue-600 font-medium">Sign Up</button> */}

src/components/auth/Auth0.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import React from 'react'
22
import { useAuth0 } from '@auth0/auth0-react';
3+
import ReactGA from 'react-ga';
34

45
export function Login() {
56
const { loginWithRedirect } = useAuth0();
67
return (
78
<div className=" text-white mx-1">
8-
<button onClick={() => { loginWithRedirect() }}>Login</button>
9+
<button onClick={() => {
10+
ReactGA.event({
11+
category: `button.clicked`,
12+
action: `Login`,
13+
});
14+
loginWithRedirect()
15+
}}>Login</button>
916
</div>
1017
)
1118
}
@@ -14,7 +21,13 @@ export function Logout() {
1421
const { logout } = useAuth0();
1522
return (
1623
<div className=" text-white mx-1">
17-
<button onClick={() => { logout() }}>Logout</button>
24+
<button onClick={() => {
25+
ReactGA.event({
26+
category: `button.clicked`,
27+
action: `Logout`,
28+
});
29+
logout()
30+
}}>Logout</button>
1831
</div>
1932
)
2033
}

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import './index.css';
44
import App from './App';
55
import reportWebVitals from './reportWebVitals';
66
import { Auth0Provider } from '@auth0/auth0-react';
7+
import ReactGA from 'react-ga';
78

9+
const trackingId = process.env.REACT_APP_TRACKING_ID
810
const domain = process.env.REACT_APP_AUTH0_DOMAIN;
911
const clientId = process.env.REACT_APP_AUTH0_CLIENT_ID;
1012

13+
ReactGA.initialize(trackingId);
14+
1115
ReactDOM.render(
1216
<React.StrictMode>
1317
<Auth0Provider

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9519,6 +9519,11 @@ react-error-overlay@^6.0.9:
95199519
resolved "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz"
95209520
integrity sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew==
95219521

9522+
react-ga@^3.3.0:
9523+
version "3.3.0"
9524+
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.3.0.tgz#c91f407198adcb3b49e2bc5c12b3fe460039b3ca"
9525+
integrity sha512-o8RScHj6Lb8cwy3GMrVH6NJvL+y0zpJvKtc0+wmH7Bt23rszJmnqEQxRbyrqUzk9DTJIHoP42bfO5rswC9SWBQ==
9526+
95229527
react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1:
95239528
version "16.13.1"
95249529
resolved "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz"

0 commit comments

Comments
 (0)