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!

migrated to Paddle

Blue Mouse108feb182dcc
diff --git a/public/index.html b/public/index.html
index 2810c3cac..9aa7437d9 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1,26 +1,31 @@
<!DOCTYPE html>
<html lang="en">
- <head>
- <meta charset="utf-8" />
- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- <meta name="theme-color" content="#818cf8" />
- <meta name="description" content="Powerful web analytics platform that respects user privacy" />
- <meta name="twitter:title" content="Swetrix | Track your website statistics without invading users privacy" />
- <meta name="twitter:description" content="Swetrix is a fully cookie-less privacy-first web analytics service which provides a huge variety of services" />
- <meta name="twitter:card" content="summary_large_image" />
- <meta property="og:title" content="Swetrix Analytics" />
- <meta property="og:description" content="Powerful web analytics platform that respects user privacy" />
- <meta property="og:image" content="https://swetrix.com/assets/og_image.png" />
- <meta property="og:site_name" content="Swetrix Analytics" />
- <meta property="og:url" content="https://swetrix.com">
- <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
- <script src="%PUBLIC_URL%/env.js"></script>
- <title>Swetrix Analytics</title>
- </head>
- <body class="transition-colors duration-300">
- <noscript>You need to enable JavaScript to run this app.</noscript>
- <div id="root"></div>
- </body>
-</html>
+
+<head>
+ <meta charset="utf-8" />
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="theme-color" content="#818cf8" />
+ <meta name="description" content="Powerful web analytics platform that respects user privacy" />
+ <meta name="twitter:title" content="Swetrix | Track your website statistics without invading users privacy" />
+ <meta name="twitter:description"
+ content="Swetrix is a fully cookie-less privacy-first web analytics service which provides a huge variety of services" />
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta property="og:title" content="Swetrix Analytics" />
+ <meta property="og:description" content="Powerful web analytics platform that respects user privacy" />
+ <meta property="og:image" content="https://swetrix.com/assets/og_image.png" />
+ <meta property="og:site_name" content="Swetrix Analytics" />
+ <meta property="og:url" content="https://swetrix.com">
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
+ <script src="%PUBLIC_URL%/env.js"></script>
+ <title>Swetrix Analytics</title>
+</head>
+
+<body class="transition-colors duration-300">
+ <noscript>You need to enable JavaScript to run this app.</noscript>
+ <div id="root"></div>
+ <script src="https://cdn.paddle.com/paddle/paddle.js"></script>
+</body>
+
+</html>
\ No newline at end of file
diff --git a/src/App.js b/src/App.js
index b4bdf3e87..3dd491059 100644
--- a/src/App.js
+++ b/src/App.js
@@ -15,11 +15,13 @@ import Loader from 'ui/Loader'
import ScrollToTop from 'hoc/ScrollToTop'
import Selfhosted from 'hoc/Selfhosted'
+import { isSelfhosted } from 'redux/constants'
import { getAccessToken } from 'utils/accessToken'
import { authMe } from './api'
import { authActions } from 'redux/actions/auth'
import { errorsActions } from 'redux/actions/errors'
import { alertsActions } from 'redux/actions/alerts'
+import UIActions from 'redux/actions/ui'
const MainPage = lazy(() => import('pages/MainPage'))
const SignUp = lazy(() => import('pages/Auth/Signup'))
@@ -68,6 +70,27 @@ const App = () => {
const { message, type } = useSelector(state => state.alerts)
const accessToken = getAccessToken()
+ const paddleCallback = (data) => {
+ dispatch(UIActions.setPaddleLastEvent(data))
+ }
+
+ useEffect(() => {
+ const interval = setInterval(paddleSetup, 200)
+ function paddleSetup() {
+ if (!isSelfhosted) {
+ if (window.Paddle) {
+ window.Paddle.Setup({
+ vendor: 139393,
+ eventCallback: paddleCallback,
+ })
+ clearInterval(interval)
+ }
+ } else {
+ clearInterval(interval)
+ }
+ }
+ }, [])
+
useEffect(() => {
(async () => {
if (accessToken && !authenticated) {
diff --git a/src/pages/Billing/index.jsx b/src/pages/Billing/index.jsx
index 0acb4cc85..51f12ff47 100644
--- a/src/pages/Billing/index.jsx
+++ b/src/pages/Billing/index.jsx
@@ -8,7 +8,7 @@ import { withAuthentication, auth } from 'hoc/protected'
import Title from 'components/Title'
const Features = () => {
- const { t } = useTranslation('common')
+ const { t, i18n: { language } } = useTranslation('common')
return (
<Title title={t('titles.billing')}>
@@ -20,7 +20,7 @@ const Features = () => {
<p className='text-lg text-gray-900 dark:text-gray-50 tracking-tight'>
{t('billing.desc')}
</p>
- <Pricing t={t} />
+ <Pricing t={t} language={language} />
<p className='text-lg text-gray-900 dark:text-gray-50 tracking-tight mt-10'>
<Trans
t={t}
diff --git a/src/pages/MainPage/Pricing.jsx b/src/pages/MainPage/Pricing.jsx
index 83afb46f6..28564e0d0 100644
--- a/src/pages/MainPage/Pricing.jsx
+++ b/src/pages/MainPage/Pricing.jsx
@@ -1,4 +1,4 @@
-import React, { memo, useState } from 'react'
+import React, { memo, useState, useEffect } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { Link } from 'react-router-dom'
import { CheckIcon } from '@heroicons/react/solid'
@@ -40,6 +40,7 @@ const getTiers = (t) => [
t('pricing.tiers.smallBusiSupport'),
t('pricing.tiers.carbonRemoval'),
],
+ pid: 752316,
},
{
name: t('pricing.tiers.startup'),
@@ -50,6 +51,7 @@ const getTiers = (t) => [
t('pricing.tiers.xEvMo', { amount: '500k' }),
// t('pricing.tiers.xMoDataRetention', { amount: 12 }),
],
+ pid: 752317,
},
{
name: t('pricing.tiers.enterprise'),
@@ -61,43 +63,71 @@ const getTiers = (t) => [
t('pricing.tiers.upToXProjects', { amount: 30 }),
// t('pricing.tiers.xMoDataRetention', { amount: 24 }),
],
+ pid: 752318,
},
]
-const Pricing = ({ t }) => {
+const paddleLanguageMapping = {
+ zh: 'zh-Hans',
+ uk: 'ru',
+}
+
+const Pricing = ({ t, language }) => {
const dispatch = useDispatch()
const { authenticated, user } = useSelector(state => state.auth)
+ const { theme } = useSelector(state => state.ui.theme)
+ const { lastEvent } = useSelector(state => state.ui.misc.paddle)
const [planCodeLoading, setPlanCodeLoading] = useState(null)
const tiers = getTiers(t)
- const onPlanChange = async (planCode) => {
- if (planCodeLoading === null && user.planCode !== planCode) {
- setPlanCodeLoading(planCode)
- try {
- const { data: { url, message } } = await upgradePlan(planCode)
+ const lastEventHandler = async (data) => {
+ if (_isNil(data)) {
+ return
+ }
- if (_isString(message)) {
- try {
- const me = await authMe()
+ if (data.event === 'Checkout.Complete') {
+ // giving some time to the API to process tier upgrate via Paddle webhook
+ setTimeout(async () => {
+ try {
+ const me = await authMe()
- dispatch(authActions.loginSuccess(me))
- dispatch(authActions.finishLoading())
- } catch (e) {
- dispatch(authActions.logout())
- }
-
- dispatch(alertsActions.accountUpdated(message))
+ dispatch(authActions.loginSuccess(me))
+ dispatch(authActions.finishLoading())
+ } catch (e) {
+ dispatch(authActions.logout())
}
- if (!_isEmpty(url)) {
- window.location.href = url
- }
- } catch ({ message }) {
- if (_isString(message)) {
- dispatch(errorsActions.genericError(message))
- }
- } finally {
+
+ // @TODO: add 'sub downgraded' message
+ dispatch(alertsActions.accountUpdated('The subscription has been upgraded.'))
+ }, 1000)
+ setPlanCodeLoading(null)
+ } else if (data.event === 'Checkout.Close') {
+ setPlanCodeLoading(null)
+ }
+ }
+
+ useEffect(() => {
+ lastEventHandler(lastEvent)
+ }, [lastEvent])
+
+ const onPlanChange = (tier) => {
+ if (planCodeLoading === null && user.planCode !== tier.planCode) {
+ setPlanCodeLoading(tier.planCode)
+
+ if (!window.Paddle) {
+ dispatch(errorsActions.genericError('Payment script has not yet loaded! Please, try again.'))
setPlanCodeLoading(null)
+ return
}
+
+ window.Paddle.Checkout.open({
+ product: tier.pid,
+ email: user.email,
+ passthrough: `{"uid": ${user.id}}`,
+ locale: paddleLanguageMapping[language] || language,
+ title: tier.name,
+ displayModeTheme: theme,
+ })
}
}
@@ -173,7 +203,7 @@ const Pricing = ({ t }) => {
{_isNil(tier.priceMonthly) ? (
authenticated ? (
<span
- onClick={() => onPlanChange(tier.planCode)}
+ onClick={() => onPlanChange(tier)}
className={cx('inline-flex items-center justify-center mt-8 w-full rounded-md py-2 text-sm font-semibold text-white text-center cursor-pointer select-none', {
'bg-indigo-600 hover:bg-indigo-700': planCodeLoading === null && tier.planCode !== user.planCode,
'bg-indigo-400 cursor-default': planCodeLoading !== null || tier.planCode === user.planCode,
@@ -194,7 +224,7 @@ const Pricing = ({ t }) => {
)
) : authenticated ? (
<span
- onClick={() => onPlanChange(tier.planCode)}
+ onClick={() => onPlanChange(tier)}
className={cx('inline-flex items-center justify-center mt-8 w-full rounded-md py-2 text-sm font-semibold text-white text-center cursor-pointer select-none', {
'bg-indigo-600 hover:bg-indigo-700': planCodeLoading === null && tier.planCode !== user.planCode,
'bg-indigo-400 cursor-default': planCodeLoading !== null || tier.planCode === user.planCode,
diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsx
index 5cf2c1257..fdac8f015 100644
--- a/src/pages/MainPage/index.jsx
+++ b/src/pages/MainPage/index.jsx
@@ -95,7 +95,7 @@ const Features = ({ t }) => (
)
const Main = () => {
- const { t } = useTranslation('common')
+ const { t, i18n: { language } } = useTranslation('common')
const { theme } = useSelector(state => state.ui.theme)
return (
@@ -239,7 +239,7 @@ const Main = () => {
</div>
</div>
</div>
- <Pricing t={t} />
+ <Pricing t={t} language={language} />
<FAQs t={t} />
<div className='bg-white dark:bg-gray-750'>
diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.js
index c06469f6e..8410e850b 100644
--- a/src/redux/actions/ui/index.js
+++ b/src/redux/actions/ui/index.js
@@ -88,6 +88,13 @@ const setGeneralStats = (stats) => ({
}
})
+const setPaddleLastEvent = (event) => ({
+ type: types.SET_PADDLE_LAST_EVENT,
+ payload: {
+ event,
+ }
+})
+
const UIActions = {
loadProjects,
setProjects,
@@ -102,6 +109,7 @@ const UIActions = {
setLiveStats,
setTheme,
setGeneralStats,
+ setPaddleLastEvent,
}
export default UIActions
diff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.js
index e15b3ceb0..50bee0d9f 100644
--- a/src/redux/actions/ui/types.js
+++ b/src/redux/actions/ui/types.js
@@ -12,4 +12,5 @@ export const types = {
SET_PUBLIC_PROJECT: 'UI_SET_PUBLIC_PROJECT',
SET_THEME: 'UI_SET_THEME',
SET_GENERAL_STATS: 'UI_SET_GENERAL_STATS',
+ SET_PADDLE_LAST_EVENT: 'UI_SET_PADDLE_LAST_EVENT',
}
diff --git a/src/redux/reducers/ui/misc.js b/src/redux/reducers/ui/misc.js
index c8db08501..414ecccd6 100644
--- a/src/redux/reducers/ui/misc.js
+++ b/src/redux/reducers/ui/misc.js
@@ -1,16 +1,17 @@
import { types } from 'redux/actions/ui/types'
-const getInitialState = () => {
- return {
- stats: {
- users: 0,
- projects: 0,
- pageviews: 0,
- },
+const initialState = {
+ stats: {
+ users: 0,
+ projects: 0,
+ pageviews: 0,
+ },
+ paddle: {
+ lastEvent: null,
}
}
-const miscReducer = (state = getInitialState(), { type, payload }) => {
+const miscReducer = (state = initialState, { type, payload }) => {
switch (type) {
case types.SET_GENERAL_STATS: {
const { stats } = payload
@@ -20,6 +21,17 @@ const miscReducer = (state = getInitialState(), { type, payload }) => {
}
}
+ case types.SET_PADDLE_LAST_EVENT: {
+ const { event } = payload
+ return {
+ ...state,
+ paddle: {
+ ...state.paddle,
+ lastEvent: event,
+ }
+ }
+ }
+
default:
return state
}