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!

unsubscribe from reports by url

Blue Mouse278e4fc288af
diff --git a/app/api/index.ts b/app/api/index.ts
index cf11b2c88..b331360ed 100644
--- a/app/api/index.ts
+++ b/app/api/index.ts
@@ -1284,3 +1284,21 @@ export const getLastPost = () =>
debug('%s', error)
throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message
})
+
+export const unsubscribeFromEmailReports = (token: string) =>
+ api
+ .get(`user/unsubscribe/${token}`)
+ .then((response) => response.data)
+ .catch((error) => {
+ debug('%s', error)
+ throw error
+ })
+
+export const unsubscribeFromEmailReports3rdParty = (token: string) =>
+ api
+ .get(`project/unsubscribe/${token}`)
+ .then((response) => response.data)
+ .catch((error) => {
+ debug('%s', error)
+ throw error
+ })
diff --git a/app/pages/Unsubscribe/index.tsx b/app/pages/Unsubscribe/index.tsx
new file mode 100644
index 000000000..5b10191cf
--- /dev/null
+++ b/app/pages/Unsubscribe/index.tsx
@@ -0,0 +1,145 @@
+import React, { useState, useEffect, memo } from 'react'
+import { useParams, Link } from '@remix-run/react'
+import { useTranslation } from 'react-i18next'
+import { CheckCircleIcon, XCircleIcon } from '@heroicons/react/24/solid'
+import _isString from 'lodash/isString'
+import { useSelector } from 'react-redux'
+
+import { StateType } from 'redux/store'
+import { unsubscribeFromEmailReports, unsubscribeFromEmailReports3rdParty } from 'api'
+import Loader from 'ui/Loader'
+import routes from 'routesPath'
+
+interface IUnsubscribe {
+ type: 'user-reports' | '3rdparty'
+}
+
+const Unsubscribe = ({ type }: IUnsubscribe): JSX.Element => {
+ const { t } = useTranslation('common')
+ const { token } = useParams()
+ const { authenticated } = useSelector((state: StateType) => state.auth)
+ const [loading, setLoading] = useState<boolean>(true)
+ const [error, setError] = useState<string>('')
+
+ useEffect(() => {
+ setLoading(true)
+
+ if (!_isString(token)) {
+ setError(t('apiNotifications.invalidToken'))
+ setLoading(false)
+ return
+ }
+
+ if (type === 'user-reports') {
+ unsubscribeFromEmailReports(token)
+ .then(() => {
+ setLoading(false)
+ })
+ .catch((reason) => {
+ setError(_isString(reason) ? reason : reason?.response?.data?.message || reason.message)
+ })
+ .finally(() => {
+ setLoading(false)
+ })
+ }
+
+ if (type === '3rdparty') {
+ unsubscribeFromEmailReports3rdParty(token)
+ .then(() => {
+ setLoading(false)
+ })
+ .catch((reason) => {
+ setError(_isString(reason) ? reason : reason?.response?.data?.message || reason.message)
+ })
+ .finally(() => {
+ setLoading(false)
+ })
+ }
+ }, [token, type]) // eslint-disable-line
+
+ if (loading) {
+ return (
+ <div className='min-h-page bg-gray-50 dark:bg-slate-900'>
+ <Loader />
+ </div>
+ )
+ }
+
+ if (error) {
+ return (
+ <div className='bg-gray-50 dark:bg-slate-900 min-h-page px-4 py-16 sm:px-6 sm:py-24 md:grid md:place-items-center lg:px-8'>
+ <div className='max-w-max mx-auto'>
+ <main className='sm:flex'>
+ <XCircleIcon className='h-12 w-12 text-red-400' aria-hidden='true' />
+ <div className='sm:ml-6'>
+ <div className='sm:border-l max-w-prose sm:border-gray-200 sm:pl-6'>
+ <h1 className='text-4xl font-extrabold text-gray-900 dark:text-gray-50 tracking-tight sm:text-5xl'>
+ {error}
+ </h1>
+ </div>
+ <div className='mt-8 flex space-x-3 sm:border-l sm:border-transparent sm:pl-6'>
+ {authenticated ? (
+ <Link
+ to={routes.dashboard}
+ className='inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500'
+ >
+ {t('common.dashboard')}
+ </Link>
+ ) : (
+ <Link
+ to={routes.signin}
+ className='inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500'
+ >
+ {t('auth.signin.button')}
+ </Link>
+ )}
+ <Link
+ to={routes.contact}
+ className='inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-indigo-700 bg-indigo-100 hover:bg-indigo-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:text-gray-50 dark:bg-slate-800 dark:hover:bg-slate-700 dark:focus:ring-gray-50'
+ >
+ {t('notFoundPage.support')}
+ </Link>
+ </div>
+ </div>
+ </main>
+ </div>
+ </div>
+ )
+ }
+
+ return (
+ <div className='bg-gray-50 dark:bg-slate-900 min-h-page px-4 py-16 sm:px-6 sm:py-24 md:grid md:place-items-center lg:px-8'>
+ <div className='max-w-max mx-auto'>
+ <main className='sm:flex'>
+ <CheckCircleIcon className='h-12 w-12 text-green-500 dark:text-green-400' aria-hidden='true' />
+ <div className='sm:ml-6'>
+ <div className='sm:border-l max-w-prose sm:border-gray-200 sm:pl-6'>
+ <h1 className='text-4xl font-extrabold text-gray-900 dark:text-gray-50 tracking-tight sm:text-5xl'>
+ {t('unsubscribe.success')}
+ </h1>
+ </div>
+ <div className='mt-8 flex space-x-3 sm:border-l sm:border-transparent sm:pl-6'>
+ {authenticated ? (
+ <Link
+ to={routes.dashboard}
+ className='inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500'
+ >
+ {t('common.dashboard')}
+ </Link>
+ ) : (
+ <Link
+ to={routes.signin}
+ className='inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500'
+ >
+ {t('auth.signin.button')}
+ </Link>
+ )}
+ </div>
+ </div>
+ </main>
+ </div>
+ </div>
+ )
+}
+
+export default memo(Unsubscribe)
diff --git a/app/routes/3rd-party-unsubscribe.$token.tsx b/app/routes/3rd-party-unsubscribe.$token.tsx
new file mode 100644
index 000000000..ef01a6f4b
--- /dev/null
+++ b/app/routes/3rd-party-unsubscribe.$token.tsx
@@ -0,0 +1,20 @@
+import type { SitemapFunction } from 'remix-sitemap'
+import { redirect } from '@remix-run/node'
+import { isSelfhosted } from 'redux/constants'
+import Unsubscribe from 'pages/Unsubscribe'
+
+export const sitemap: SitemapFunction = () => ({
+ exclude: true,
+})
+
+export async function loader() {
+ if (isSelfhosted) {
+ return redirect('/login', 302)
+ }
+
+ return null
+}
+
+export default function Index() {
+ return <Unsubscribe type='3rdparty' />
+}
diff --git a/app/routes/reports-unsubscribe.$token.tsx b/app/routes/reports-unsubscribe.$token.tsx
new file mode 100644
index 000000000..a7c3759bf
--- /dev/null
+++ b/app/routes/reports-unsubscribe.$token.tsx
@@ -0,0 +1,20 @@
+import type { SitemapFunction } from 'remix-sitemap'
+import { redirect } from '@remix-run/node'
+import { isSelfhosted } from 'redux/constants'
+import Unsubscribe from 'pages/Unsubscribe'
+
+export const sitemap: SitemapFunction = () => ({
+ exclude: true,
+})
+
+export async function loader() {
+ if (isSelfhosted) {
+ return redirect('/login', 302)
+ }
+
+ return null
+}
+
+export default function Index() {
+ return <Unsubscribe type='user-reports' />
+}
diff --git a/public/locales/en.json b/public/locales/en.json
index 110de98ce..dbc3abf9c 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -297,6 +297,9 @@
"cookieDetails": "If you click on the buttons above, a cookie will be stored for {{days}} days to reward the person who referred you and give you {{discount}}% off your first bill.",
"buttons": "Click on these buttons to receive {{discount}}% off your first bill!"
},
+ "unsubscribe": {
+ "success": "You've unsubscribed from analytics email reports"
+ },
"auth": {
"recovery": {
"title": "Account recovery",