📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
tracking some custom events
Blue Mousef57542208e7b
diff --git a/src/index.js b/src/index.jsindex af51e7602..5b12b128e 100644--- a/src/index.js+++ b/src/index.js@@ -6,29 +6,20 @@ import { Provider } from 'react-redux'import { I18nextProvider } from 'react-i18next'import { HelmetProvider } from 'react-helmet-async'import { transitions, positions, Provider as AlertProvider } from '@blaumaus/react-alert'-import * as Swetrix from 'swetrix'import 'billboard.js/dist/billboard.min.css'import 'prismjs/themes/prism-tomorrow.css'-import { isSelfhosted } from 'redux/constants'import CrashHandler from 'pages/CrashHandler'+import { trackViews } from 'utils/analytics'import AlertTemplate from 'ui/Alert'import App from './App'import i18next from './i18next'import './index.css'-const SWETRIX_PID = 'STEzHcB1rALV'+trackViews()console.log('%cWelcome, hacker, glad you opened your console, you seem serious about your craft and will go a long way!\nP.S. All the bugs, feature requests are welcome to be sent to [email protected]', 'color: #818cf8;background: #1f2937;font-size: 20px;text-shadow: 2px 2px black')-if (!isSelfhosted) {- Swetrix.init(SWETRIX_PID)- Swetrix.trackViews({- ignore: [/^\/projects/i, /^\/verify/i, /^\/password-reset/i],- heartbeatOnBackground: true,- })-}-const options = {position: positions.BOTTOM_RIGHT,timeout: 8000,diff --git a/src/pages/Auth/Signup/BasicSignup.jsx b/src/pages/Auth/Signup/BasicSignup.jsxindex 62af0c391..cdf455b70 100644--- a/src/pages/Auth/Signup/BasicSignup.jsx+++ b/src/pages/Auth/Signup/BasicSignup.jsx@@ -14,6 +14,7 @@ import {isValidEmail, isValidPassword, MIN_PASSWORD_CHARS, MAX_PASSWORD_CHARS,} from 'utils/validator'import { HAVE_I_BEEN_PWNED_URL } from 'redux/constants'+import { trackCustom } from 'utils/analytics'const BasicSignup = () => {const { t } = useTranslation('common')@@ -34,8 +35,12 @@ const BasicSignup = () => {const onSubmit = (data) => {if (!isLoading) {setIsLoading(true)- dispatch(authActions.signupAsync(data, t, () => {- setIsLoading(false)+ dispatch(authActions.signupAsync(data, t, (result) => {+ if (result) {+ trackCustom('SIGNUP_BASIC')+ } else {+ setIsLoading(false)+ }}))}}diff --git a/src/pages/Auth/Signup/Signup.jsx b/src/pages/Auth/Signup/Signup.jsxindex d92fd2760..6b1b19c5f 100644--- a/src/pages/Auth/Signup/Signup.jsx+++ b/src/pages/Auth/Signup/Signup.jsx@@ -17,6 +17,7 @@ import {isValidEmail, isValidPassword, MIN_PASSWORD_CHARS, MAX_PASSWORD_CHARS,} from 'utils/validator'import { HAVE_I_BEEN_PWNED_URL } from 'redux/constants'+import { trackCustom } from 'utils/analytics'const Signup = ({ signup }) => {const { t } = useTranslation('common')@@ -70,7 +71,9 @@ const Signup = ({ signup }) => {if (!isLoading) {setIsLoading(true)signup(data, t, (result) => {- if (!result) {+ if (result) {+ trackCustom('SIGNUP')+ } else {setIsLoading(false)}})diff --git a/src/pages/Project/Settings/ProjectSettings.jsx b/src/pages/Project/Settings/ProjectSettings.jsxindex 890d9e037..33afd0dff 100644--- a/src/pages/Project/Settings/ProjectSettings.jsx+++ b/src/pages/Project/Settings/ProjectSettings.jsx@@ -23,6 +23,7 @@ import Button from 'ui/Button'import Checkbox from 'ui/Checkbox'import Modal from 'ui/Modal'import { nanoid } from 'utils/random'+import { trackCustom } from 'utils/analytics'import routes from 'routes'const MAX_NAME_LENGTH = 50@@ -84,6 +85,7 @@ const ProjectSettings = ({newProject(t('project.settings.updated'))} else {await createProject(formalisedData)+ trackCustom('PROJECT_CREATED')newProject(t('project.settings.created'))}diff --git a/src/pages/UserSettings/UserSettings.container.jsx b/src/pages/UserSettings/UserSettings.container.jsxindex 6165e2d9c..76d5dce87 100644--- a/src/pages/UserSettings/UserSettings.container.jsx+++ b/src/pages/UserSettings/UserSettings.container.jsx@@ -16,6 +16,7 @@ import { errorsActions } from 'redux/actions/errors'import { alertsActions } from 'redux/actions/alerts'import UIActions from 'redux/actions/ui'import { getCookie, setCookie } from 'utils/cookie'+import { trackCustom } from 'utils/analytics'import { confirmEmail, exportUserData } from 'api'import routes from 'routes'import UserSettings from './UserSettings'@@ -33,7 +34,10 @@ const UserSettingsContainer = () => {(error) => dispatch(errorsActions.deleteAccountFailed(error),),- () => history.push(routes.main),+ () => {+ trackCustom('ACCOUNT_DELETED')+ history.push(routes.main)+ },t,),)@@ -47,6 +51,7 @@ const UserSettingsContainer = () => {}await exportUserData()+ trackCustom('GDPR_EXPORT')dispatch(alertsActions.accountUpdated(t('profileSettings.reportSent')))setCookie(GDPR_REQUEST, true, 1209600) // setting cookie for 14 days} catch (e) {diff --git a/src/utils/analytics.js b/src/utils/analytics.jsnew file mode 100644index 000000000..c691836a6--- /dev/null+++ b/src/utils/analytics.js@@ -0,0 +1,27 @@+import * as Swetrix from 'swetrix'+import { isSelfhosted } from 'redux/constants'++const SWETRIX_PID = 'STEzHcB1rALV'++Swetrix.init(SWETRIX_PID)++const trackViews = () => {+ if (!isSelfhosted) {+ Swetrix.trackViews({+ ignore: [/^\/projects/i, /^\/verify/i, /^\/password-reset/i],+ heartbeatOnBackground: true,+ })+ }+}++const trackCustom = (ev, unique = true) => {+ if (!isSelfhosted) {+ Swetrix.track({+ ev, unique,+ })+ }+}++export {+ trackViews, trackCustom,+}