Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

minor improvements

Blue Mouse698ddb16f747
diff --git a/package.json b/package.json
index 2b0627f89..5593f56dc 100644
--- a/package.json
+++ b/package.json
@@ -8,8 +8,10 @@
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.8.3",
"axios": "^0.21.1",
+ "billboard.js": "^3.1.1",
"bootstrap": "^4.6.0",
"bootstrap-icons": "^1.4.1",
+ "debug": "^4.3.2",
"nanoid": "^3.1.22",
"node-sass": "^5.0.0",
"react": "^17.0.1",
@@ -21,7 +23,6 @@
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
- "recharts": "^2.0.9",
"redux": "^4.0.5",
"redux-auth-wrapper": "^3.0.0",
"redux-saga": "^1.1.3",
diff --git a/src/api/index.js b/src/api/index.js
index 0a5a36b16..8fd68e31a 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -1,7 +1,11 @@
import axios from 'axios'
import { store } from 'store'
+import Debug from 'debug'
import { authActions } from 'actions/auth'
-import { getAccessToken, removeAccessToken } from "utils/accessToken"
+
+import { getAccessToken, removeAccessToken } from 'utils/accessToken'
+
+const debug = Debug('analytics:api')
const api = axios.create({
baseURL: process.env.REACT_APP_API_URL,
@@ -36,7 +40,8 @@ export const authMe = () =>
.get('/auth/me')
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const login = (credentials) =>
@@ -44,7 +49,8 @@ export const login = (credentials) =>
.post('/auth/login', credentials)
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const signup = (data) =>
@@ -84,7 +90,8 @@ export const forgotPassword = (email) =>
.post('/auth/reset-password', email)
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const confirmEmail = () =>
@@ -92,7 +99,8 @@ export const confirmEmail = () =>
.post('/user/confirm_email')
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const exportUserData = () =>
@@ -100,7 +108,8 @@ export const exportUserData = () =>
.get('/user/export')
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const createNewPassword = (id, password) =>
@@ -120,7 +129,8 @@ export const verifyEmail = ({ path, id }) =>
.get(`/auth/${path}/${id}`)
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const getProjects = () =>
@@ -128,7 +138,8 @@ export const getProjects = () =>
.get(`/project`)
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const createProject = (data) =>
@@ -136,7 +147,8 @@ export const createProject = (data) =>
.post(`/project`, data)
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const updateProject = (id, data) =>
@@ -144,7 +156,8 @@ export const updateProject = (id, data) =>
.put(`/project/${id}`, data)
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
export const deleteProject = (id) =>
@@ -152,5 +165,6 @@ export const deleteProject = (id) =>
.delete(`/project/${id}`)
.then(response => response.data)
.catch(error => {
- throw new Error(error.response.data.message)
+ debug('%s', error)
+ return error.response.data
})
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index a31c5b494..984d2c025 100644
--- a/src/index.js
+++ b/src/index.js
@@ -18,6 +18,10 @@ const options = {
transition: transitions.SCALE
}
+if (process.env.NODE_ENV !== 'production') {
+ localStorage.debug = 'analytics:*'
+}
+
ReactDOM.render(
<React.StrictMode>
<AlertProvider template={AlertTemplate} {...options}>
diff --git a/src/index.scss b/src/index.scss
index 264f49eca..c997e00b2 100644
--- a/src/index.scss
+++ b/src/index.scss
@@ -1,3 +1,5 @@
+// @import "bootstrap/dist/css/bootstrap.min.css";
+
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index a148d9874..1c6ee5480 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -1,55 +1,9 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'
-import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'
import ProjectSettings from 'pages/Project/Create'
import { Locale } from './Panels'
-const data = [
- {
- name: 'Page A',
- uv: 4000,
- pv: 2400,
- amt: 2400,
- },
- {
- name: 'Page B',
- uv: 3000,
- pv: 1398,
- amt: 2210,
- },
- {
- name: 'Page C',
- uv: 2000,
- pv: 9800,
- amt: 2290,
- },
- {
- name: 'Page D',
- uv: 2780,
- pv: 3908,
- amt: 2000,
- },
- {
- name: 'Page E',
- uv: 1890,
- pv: 4800,
- amt: 2181,
- },
- {
- name: 'Page F',
- uv: 2390,
- pv: 3800,
- amt: 2500,
- },
- {
- name: 'Page G',
- uv: 3490,
- pv: 4300,
- amt: 2100,
- },
-]
-
const ViewProject = (props) => {
const { name } = props
const [settings, setSettings] = useState(false)
@@ -73,25 +27,6 @@ const ViewProject = (props) => {
Settings
</button>
</div>
- <ResponsiveContainer width="100%" minHeight="300px">
- <LineChart
- data={data}
- margin={{
- top: 5,
- right: 30,
- left: 20,
- bottom: 5,
- }}
- >
- <CartesianGrid strokeDasharray="3 3" />
- <XAxis dataKey="name" />
- <YAxis />
- <Tooltip />
- <Legend />
- <Line type="monotone" dataKey="pv" stroke="#8884d8" activeDot={{ r: 8 }} />
- <Line type="monotone" dataKey="uv" stroke="#82ca9d" />
- </LineChart>
- </ResponsiveContainer>
<div className="d-flex flex-wrap">
<Locale />
<Locale />
diff --git a/src/utils/accessToken.js b/src/utils/accessToken.js
index cd747bec1..be78a2856 100644
--- a/src/utils/accessToken.js
+++ b/src/utils/accessToken.js
@@ -1,5 +1,10 @@
+import Debug from 'debug'
+import { getItem, setItem, removeItem } from './localstorage'
+
+const debug = Debug('analytics:utils:at')
+
export const getAccessToken = () => {
- const accessToken = localStorage.getItem('access_token')
+ const accessToken = getItem('access_token')
let token = null
if (!accessToken) {
@@ -9,16 +14,16 @@ export const getAccessToken = () => {
try {
token = JSON.parse(accessToken)
} catch(e) {
- console.error('Error while parsing access token: ' + e)
+ debug('Error while parsing access token: %s', e)
}
return token
}
export const setAccessToken = token => {
- localStorage.setItem('access_token', token)
+ setItem('access_token', token)
}
export const removeAccessToken = () => {
- localStorage.removeItem('access_token')
+ removeItem('access_token')
}
diff --git a/src/utils/cookie.js b/src/utils/cookie.js
index 44dca0e65..8c37e7cf9 100644
--- a/src/utils/cookie.js
+++ b/src/utils/cookie.js
@@ -5,4 +5,4 @@ export const getCookie = key => {
export const setCookie = (key, value, maxAge = 3600) => {
document.cookie = `${key}=${value}; max-age=${maxAge}; path=/`
-}
\ No newline at end of file
+}
diff --git a/src/utils/localstorage.js b/src/utils/localstorage.js
new file mode 100644
index 000000000..49838c53e
--- /dev/null
+++ b/src/utils/localstorage.js
@@ -0,0 +1,31 @@
+/*
+ * a small localStorage proxy for to persist localStorage
+ * contents in runtime memory after first access in order
+ * to save performance on JSON-parsing and instead remember
+ * how any localStorage item was modified after first access
+ */
+const currentLocalStorage = {}
+
+export const setItem = (key, value) => {
+ currentLocalStorage[key] = value
+ localStorage.setItem(key, JSON.stringify(value))
+}
+
+export const getItem = (key) => {
+ if (currentLocalStorage[key]) {
+ return currentLocalStorage[key]
+ }
+
+ const storedValue = localStorage.getItem(key)
+
+ try {
+ return JSON.parse(storedValue)
+ } catch {
+ return storedValue
+ }
+}
+
+export const removeItem = (key) => {
+ delete currentLocalStorage[key]
+ localStorage.removeItem(key)
+}
diff --git a/src/utils/random.js b/src/utils/random.js
index 757b6ed62..a869a4ea3 100644
--- a/src/utils/random.js
+++ b/src/utils/random.js
@@ -2,4 +2,4 @@ import { customAlphabet } from 'nanoid'
const legalCharacters = '1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm-'
-export const nanoid = customAlphabet(legalCharacters, 11)
\ No newline at end of file
+export const nanoid = customAlphabet(legalCharacters, 11)
diff --git a/src/utils/validator.js b/src/utils/validator.js
index f531d0e14..2556cd2f8 100644
--- a/src/utils/validator.js
+++ b/src/utils/validator.js
@@ -1,3 +1,3 @@
export const isValidEmail = text => text.match(/^\w+([.+-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,7})+$/)
-export const isValidPassword = text => text.length >= 8
\ No newline at end of file
+export const isValidPassword = text => text.length >= 8