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!

added currency localisation functionality

Blue Mouseeb3b2effb72e
diff --git a/src/api/index.ts b/src/api/index.ts
index 93b2877f1..fe55f173d 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -948,3 +948,14 @@ export const getUserFlow = (
? error.response.data
: error.response.data.message
})
+
+export const getPaymentMetainfo = () =>
+ api
+ .get('user/metainfo')
+ .then((response) => response.data)
+ .catch((error) => {
+ debug('%s', error)
+ throw _isEmpty(error.response.data?.message)
+ ? error.response.data
+ : error.response.data.message
+ })
diff --git a/src/pages/Billing/index.tsx b/src/pages/Billing/index.tsx
index 0a4f759ae..063a349fd 100644
--- a/src/pages/Billing/index.tsx
+++ b/src/pages/Billing/index.tsx
@@ -20,6 +20,7 @@ dayjs.extend(duration)
const Billing = (): JSX.Element => {
const [isCancelSubModalOpened, setIsCancelSubModalOpened] = useState<boolean>(false)
+ const { metainfo } = useSelector((state: StateType) => state.ui.misc)
const { user }: {
user: IUser
} = useSelector((state: StateType) => state.auth)
@@ -95,6 +96,7 @@ const Billing = (): JSX.Element => {
frameStyle: 'width:100%; min-width:312px; background-color: #f9fafb; border: none; border-radius: 10px; margin-top: 10px;',
locale: paddleLanguageMapping[language] || language,
displayModeTheme: theme,
+ country: metainfo.country,
})
setTimeout(() => {
// @ts-ignore
@@ -118,6 +120,7 @@ const Billing = (): JSX.Element => {
frameStyle: 'width:100%; min-width:312px; background-color: #f9fafb; border: none; border-radius: 10px; margin-top: 10px;',
locale: paddleLanguageMapping[language] || language,
displayModeTheme: theme,
+ country: metainfo.country,
})
setTimeout(() => {
// @ts-ignore
diff --git a/src/pages/MainPage/Pricing.tsx b/src/pages/MainPage/Pricing.tsx
index ac2bde431..0fd9f8615 100644
--- a/src/pages/MainPage/Pricing.tsx
+++ b/src/pages/MainPage/Pricing.tsx
@@ -12,7 +12,9 @@ import cx from 'clsx'
import Modal from 'ui/Modal'
import Spin from 'ui/icons/Spin'
-import { CONTACT_EMAIL, paddleLanguageMapping, PLAN_LIMITS } from 'redux/constants'
+import {
+ CONTACT_EMAIL, paddleLanguageMapping, PLAN_LIMITS, CURRENCIES,
+} from 'redux/constants'
import { errorsActions } from 'redux/reducers/errors'
import { alertsActions } from 'redux/reducers/alerts'
import { authActions } from 'redux/reducers/auth'
@@ -22,14 +24,16 @@ import routes from 'routes'
import { IUser } from 'redux/models/IUser'
import { AppDispatch, StateType } from 'redux/store'
+type CurrencyCode = 'USD' | 'EUR' | 'GBP'
+
const getNonStandardTiers = (t: (key: string, options?: {
[key: string]: any
-}) => string) => ({
+}) => string, currencyCode: CurrencyCode) => ({
free: {
name: t('pricing.free'),
planCode: 'free',
- priceMonthly: PLAN_LIMITS.free.priceMonthly,
- priceYearly: PLAN_LIMITS.free.priceYearly,
+ priceMonthly: PLAN_LIMITS.free.price[currencyCode].monthly,
+ priceYearly: PLAN_LIMITS.free.price[currencyCode].yearly,
legacy: PLAN_LIMITS.free.legacy,
includedFeatures: [
t('pricing.tiers.upToXVMo', { amount: PLAN_LIMITS.free.monthlyUsageLimit.toLocaleString() }),
@@ -47,8 +51,8 @@ const getNonStandardTiers = (t: (key: string, options?: {
trial: {
name: t('pricing.tiers.trial'),
planCode: 'trial',
- priceMonthly: PLAN_LIMITS.trial.priceMonthly,
- priceYearly: PLAN_LIMITS.trial.priceYearly,
+ priceMonthly: PLAN_LIMITS.trial.price[currencyCode].monthly,
+ priceYearly: PLAN_LIMITS.trial.price[currencyCode].yearly,
legacy: PLAN_LIMITS.trial.legacy,
includedFeatures: [
t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.freelancer') }),
@@ -58,12 +62,12 @@ const getNonStandardTiers = (t: (key: string, options?: {
const getTiers = (t: (key: string, options?: {
[key: string]: any
-}) => string) => [
+}) => string, currencyCode: CurrencyCode) => [
{
name: t('pricing.tiers.hobby'),
planCode: 'hobby',
- priceMonthly: PLAN_LIMITS.hobby.priceMonthly,
- priceYearly: PLAN_LIMITS.hobby.priceYearly,
+ priceMonthly: PLAN_LIMITS.hobby.price[currencyCode].monthly,
+ priceYearly: PLAN_LIMITS.hobby.price[currencyCode].yearly,
includedFeatures: [
t('pricing.tiers.upToXVMo', { amount: PLAN_LIMITS.hobby.monthlyUsageLimit.toLocaleString() }),
t('pricing.tiers.upToXWebsites', { amount: PLAN_LIMITS.hobby.maxProjects }),
@@ -82,8 +86,8 @@ const getTiers = (t: (key: string, options?: {
{
name: t('pricing.tiers.freelancer'),
planCode: 'freelancer',
- priceMonthly: PLAN_LIMITS.freelancer.priceMonthly,
- priceYearly: PLAN_LIMITS.freelancer.priceYearly,
+ priceMonthly: PLAN_LIMITS.freelancer.price[currencyCode].monthly,
+ priceYearly: PLAN_LIMITS.freelancer.price[currencyCode].yearly,
includedFeatures: [
t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.hobby') }),
t('pricing.tiers.xVMo', { amount: PLAN_LIMITS.freelancer.monthlyUsageLimit.toLocaleString() }),
@@ -98,8 +102,8 @@ const getTiers = (t: (key: string, options?: {
{
name: t('pricing.tiers.startup'),
planCode: 'startup',
- priceMonthly: PLAN_LIMITS.startup.priceMonthly,
- priceYearly: PLAN_LIMITS.startup.priceYearly,
+ priceMonthly: PLAN_LIMITS.startup.price[currencyCode].monthly,
+ priceYearly: PLAN_LIMITS.startup.price[currencyCode].yearly,
includedFeatures: [
t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.freelancer') }),
t('pricing.tiers.xVMo', { amount: PLAN_LIMITS.startup.monthlyUsageLimit.toLocaleString() }),
@@ -113,8 +117,8 @@ const getTiers = (t: (key: string, options?: {
{
name: t('pricing.tiers.enterprise'),
planCode: 'enterprise',
- priceMonthly: PLAN_LIMITS.enterprise.priceMonthly,
- priceYearly: PLAN_LIMITS.enterprise.priceYearly,
+ priceMonthly: PLAN_LIMITS.enterprise.price[currencyCode].monthly,
+ priceYearly: PLAN_LIMITS.enterprise.price[currencyCode].yearly,
includedFeatures: [
t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.startup') }),
t('pricing.tiers.xVMo', { amount: PLAN_LIMITS.enterprise.monthlyUsageLimit.toLocaleString() }),
@@ -132,10 +136,7 @@ const BillingFrequency = {
yearly: 'yearly',
}
-const PricingItem = ({
- tier, user, t, authenticated, billingFrequency, onPlanChange, downgradeHandler, downgrade,
- planCodeLoading, planCodeID, userPlancodeID,
-}: {
+interface IPricingItem {
tier: any
user: IUser
t: (key: string, options?: {
@@ -154,9 +155,17 @@ const PricingItem = ({
planCodeLoading: boolean | string | null
planCodeID: string | number
userPlancodeID: string | number
-}) => {
+ currencyCode: CurrencyCode
+}
+
+const PricingItem = ({
+ tier, user, t, authenticated, billingFrequency, onPlanChange, downgradeHandler, downgrade,
+ planCodeLoading, planCodeID, userPlancodeID, currencyCode,
+}: IPricingItem) => {
let action
+ const currency = CURRENCIES[currencyCode]
+
if (planCodeID > userPlancodeID) {
action = t('pricing.upgrade')
} else if (downgrade) {
@@ -200,7 +209,7 @@ const PricingItem = ({
)}
<p className='mt-4 text-center'>
<span className='text-4xl font-bold text-[#4D4D4D] dark:text-gray-50'>
- $
+ {currency.symbol}
{billingFrequency === BillingFrequency.monthly ? tier.priceMonthly : tier.priceYearly}
</span>
&nbsp;
@@ -252,14 +261,19 @@ const PricingItem = ({
)
}
-const Pricing = ({ t, language }: {
+interface IPricing {
t: (key: string) => string,
language: string,
-}) => {
+}
+
+const Pricing = ({ t, language }: IPricing) => {
const dispatch: AppDispatch = useDispatch()
const { authenticated, user } = useSelector((state: StateType) => state.auth)
const { theme } = useSelector((state: StateType) => state.ui.theme)
- const { lastEvent } = useSelector((state: StateType) => state.ui.misc.paddle)
+ const { paddle, metainfo } = useSelector((state: StateType) => state.ui.misc)
+ const { lastEvent } = paddle
+ const currencyCode = user?.tierCurrency || metainfo.code
+
const [planCodeLoading, setPlanCodeLoading] = useState<string | null>(null)
const [downgradeTo, setDowngradeTo] = useState<{
planCode: string,
@@ -269,12 +283,12 @@ const Pricing = ({ t, language }: {
} | null>(null)
const [showDowngradeModal, setShowDowngradeModal] = useState<boolean>(false)
const [billingFrequency, setBillingFrequency] = useState(user?.billingFrequency || BillingFrequency.monthly)
- const tiers = getTiers(t)
+ const tiers = getTiers(t, currencyCode)
const nonStandardTiers: {
[key: string]: {
[key: string]: any,
},
- } = getNonStandardTiers(t)
+ } = getNonStandardTiers(t, currencyCode)
const isNonStandardTier = authenticated && !_isEmpty(nonStandardTiers[user.planCode])
useEffect(() => {
@@ -341,6 +355,7 @@ const Pricing = ({ t, language }: {
frameStyle: 'width:100%; min-width:312px; background-color: #f9fafb; border: none; border-radius: 10px; margin-top: 10px;',
locale: paddleLanguageMapping[language] || language,
displayModeTheme: theme,
+ country: metainfo.country,
})
setTimeout(() => {
// @ts-ignore
@@ -359,6 +374,7 @@ const Pricing = ({ t, language }: {
locale: paddleLanguageMapping[language] || language,
title: tier.name,
displayModeTheme: theme,
+ country: metainfo.country,
})
}
}
@@ -430,6 +446,7 @@ const Pricing = ({ t, language }: {
authenticated={authenticated}
planCodeID={user.planCode}
userPlancodeID={user.planCode}
+ currencyCode={currencyCode}
/>
)}
{_map(tiers, (tier) => {
@@ -450,6 +467,7 @@ const Pricing = ({ t, language }: {
authenticated={authenticated}
planCodeID={planCodeID}
userPlancodeID={userPlancodeID}
+ currencyCode={currencyCode}
/>
)
})}
diff --git a/src/redux/constants/index.ts b/src/redux/constants/index.ts
index 746eb22be..204b68fc7 100644
--- a/src/redux/constants/index.ts
+++ b/src/redux/constants/index.ts
@@ -374,64 +374,153 @@ export const THEME_TYPE: IStringObject = {
export const DEFAULT_ALERTS_TAKE: number = 100
-// TODO: Eventually this should be fetched from the API, e.g. GET /config route
-export const PLAN_LIMITS: {
- [key: string]: {
- monthlyUsageLimit: number
- maxProjects: number
- maxAlerts: number
- legacy: boolean
- priceMonthly: number
- priceYearly: number
+const EUR = {
+ symbol: '€',
+ code: 'EUR',
+}
+
+const USD = {
+ symbol: '$',
+ code: 'USD',
+}
+
+const GBP = {
+ symbol: '£',
+ code: 'GBP',
+}
+
+type ICurrencies = {
+ [key in 'EUR' | 'USD' | 'GBP']: {
+ symbol: string
+ code: string
}
-} = {
+}
+
+export const CURRENCIES: ICurrencies = {
+ EUR, USD, GBP,
+}
+
+// TODO: Eventually this should be fetched from the API, e.g. GET /config route
+export const PLAN_LIMITS = {
free: {
- priceMonthly: 0,
- priceYearly: 0,
monthlyUsageLimit: 5000,
maxProjects: 10,
maxAlerts: 1,
legacy: true,
+ price: {
+ USD: {
+ monthly: 0,
+ yearly: 0,
+ },
+ EUR: {
+ monthly: 0,
+ yearly: 0,
+ },
+ GBP: {
+ monthly: 0,
+ yearly: 0,
+ },
+ },
},
trial: {
monthlyUsageLimit: 100000,
maxProjects: 20,
maxAlerts: 20,
legacy: false,
- priceMonthly: 0,
- priceYearly: 0,
+ price: {
+ USD: {
+ monthly: 0,
+ yearly: 0,
+ },
+ EUR: {
+ monthly: 0,
+ yearly: 0,
+ },
+ GBP: {
+ monthly: 0,
+ yearly: 0,
+ },
+ },
},
hobby: {
monthlyUsageLimit: 10000,
maxProjects: 20,
maxAlerts: 10,
legacy: false,
- priceMonthly: 5,
- priceYearly: 50,
+ price: {
+ USD: {
+ monthly: 5,
+ yearly: 50,
+ },
+ EUR: {
+ monthly: 5,
+ yearly: 50,
+ },
+ GBP: {
+ monthly: 4,
+ yearly: 40,
+ },
+ },
},
freelancer: {
monthlyUsageLimit: 100000,
maxProjects: 20,
maxAlerts: 20,
legacy: false,
- priceMonthly: 15,
- priceYearly: 150,
+ price: {
+ USD: {
+ monthly: 15,
+ yearly: 150,
+ },
+ EUR: {
+ monthly: 15,
+ yearly: 150,
+ },
+ GBP: {
+ monthly: 14,
+ yearly: 140,
+ },
+ },
},
startup: {
monthlyUsageLimit: 1000000,
maxProjects: 30,
maxAlerts: 50,
legacy: false,
- priceMonthly: 59,
- priceYearly: 590,
+ price: {
+ USD: {
+ monthly: 59,
+ yearly: 590,
+ },
+ EUR: {
+ monthly: 57,
+ yearly: 570,
+ },
+ GBP: {
+ monthly: 49,
+ yearly: 490,
+ },
+ },
},
enterprise: {
monthlyUsageLimit: 5000000,
maxProjects: 50,
maxAlerts: 100,
legacy: false,
- priceMonthly: 110,
- priceYearly: 1100,
+ price: {
+ USD: {
+ monthly: 110,
+ yearly: 1100,
+ },
+ EUR: {
+ monthly: 110,
+ yearly: 1100,
+ },
+ GBP: {
+ monthly: 95,
+ yearly: 950,
+ },
+ },
},
}
diff --git a/src/redux/models/IMetainfo.ts b/src/redux/models/IMetainfo.ts
new file mode 100644
index 000000000..f79f52a1b
--- /dev/null
+++ b/src/redux/models/IMetainfo.ts
@@ -0,0 +1,5 @@
+export interface IMetainfo {
+ country: string | null
+ symbol: string
+ code: 'USD' | 'EUR' | 'GBP'
+}
diff --git a/src/redux/models/IUser.ts b/src/redux/models/IUser.ts
index e0b7dbee7..0f6ead34a 100644
--- a/src/redux/models/IUser.ts
+++ b/src/redux/models/IUser.ts
@@ -33,4 +33,5 @@ export interface IUser {
googleId: string | null
githubId: number | null
registeredWithGithub: boolean
+ tierCurrency: 'USD' | 'EUR' | 'GBP' | null
}
diff --git a/src/redux/reducers/ui/misc.ts b/src/redux/reducers/ui/misc.ts
index d59743135..d6b863d88 100644
--- a/src/redux/reducers/ui/misc.ts
+++ b/src/redux/reducers/ui/misc.ts
@@ -3,9 +3,11 @@ import { LOW_EVENTS_WARNING } from 'redux/constants'
import { setCookie } from 'utils/cookie'
import { secondsTillNextMonth } from 'utils/generic'
import { IStats } from 'redux/models/IStats'
+import { IMetainfo } from 'redux/models/IMetainfo'
interface IInitialState {
stats: IStats
+ metainfo: IMetainfo
paddleLoaded: boolean
paddle: any
showNoEventsLeftBanner: boolean
@@ -19,6 +21,11 @@ const initialState: IInitialState = {
projects: 0,
events: 0,
},
+ metainfo: {
+ country: null,
+ symbol: '$',
+ code: 'USD',
+ },
paddleLoaded: false,
paddle: {},
showNoEventsLeftBanner: false,
@@ -47,6 +54,9 @@ const miscSlice = createSlice({
setExtensions(state, { payload }: PayloadAction<any[]>) {
state.extensions = payload
},
+ setMetainfo(state, { payload }: PayloadAction<IMetainfo>) {
+ state.metainfo = payload
+ },
setLastBlogPost(state, { payload }: PayloadAction<any>) {
state.lastBlogPost = payload
},
diff --git a/src/redux/sagas/actions/index.ts b/src/redux/sagas/actions/index.ts
index 6e8c8a995..2841474c1 100644
--- a/src/redux/sagas/actions/index.ts
+++ b/src/redux/sagas/actions/index.ts
@@ -12,6 +12,10 @@ const loadProjects = (take?: number, skip?: number) => ({
payload: { take, skip },
})
+const loadMetainfo = () => ({
+ type: types.LOAD_METAINFO,
+})
+
const loadSharedProjects = (take?: number, skip?: number) => ({
type: types.LOAD_SHARED_PROJECTS,
payload: { take, skip },
@@ -138,6 +142,7 @@ const sagaActions = {
shareVerifyAsync,
linkSSO,
unlinkSSO,
+ loadMetainfo,
}
export default sagaActions
diff --git a/src/redux/sagas/actions/types.ts b/src/redux/sagas/actions/types.ts
index c631fe86c..6bd321ba1 100644
--- a/src/redux/sagas/actions/types.ts
+++ b/src/redux/sagas/actions/types.ts
@@ -1,6 +1,7 @@
const sagaTypes = Object.freeze({
LOAD_EXTENSIONS: 'LOAD_EXTENSIONS',
LOAD_PROJECTS: 'LOAD_PROJECTS',
+ LOAD_METAINFO: 'LOAD_METAINFO',
LOAD_SHARED_PROJECTS: 'LOAD_SHARED_PROJECTS',
LOAD_PROJECT_ALERTS: 'LOAD_PROJECT_ALERTS',
LOGIN_ASYNC: 'LOGIN_ASYNC',
diff --git a/src/redux/sagas/ui/index.ts b/src/redux/sagas/ui/index.ts
index 082fd521b..2a5ddeffc 100644
--- a/src/redux/sagas/ui/index.ts
+++ b/src/redux/sagas/ui/index.ts
@@ -8,6 +8,7 @@ import generalStats from './worker_general_stats'
import isEventsAvailable from './worker_is_events_available'
import shareVerify from './share_verify'
import loadExtensions from './load_extensions'
+import loadMetainfo from './load_metainfo'
import logout from './logout'
import loadSharedProjects from './load_shared_projects'
import loadProjectAlerts from './load_alerts'
@@ -19,6 +20,8 @@ function* mainUISaga() {
yield fork(generalStats)
// @ts-ignore
yield takeEvery(sagaTypes.LOAD_PROJECTS, loadProjects)
+ // @is-ignore
+ yield takeEvery(sagaTypes.LOAD_METAINFO, loadMetainfo)
// @ts-ignore
yield takeEvery(sagaTypes.LOAD_SHARED_PROJECTS, loadSharedProjects)
yield takeEvery(sagaTypes.LOAD_EXTENSIONS, loadExtensions)
diff --git a/src/redux/sagas/ui/load_metainfo.ts b/src/redux/sagas/ui/load_metainfo.ts
new file mode 100644
index 000000000..2910c7c3f
--- /dev/null
+++ b/src/redux/sagas/ui/load_metainfo.ts
@@ -0,0 +1,29 @@
+import { put, call } from 'redux-saga/effects'
+import Debug from 'debug'
+
+import UIActions from 'redux/reducers/ui'
+import { isSelfhosted } from 'redux/constants'
+import { IMetainfo } from 'redux/models/IMetainfo'
+import {
+ getPaymentMetainfo,
+} from '../../../api'
+
+const debug = Debug('swetrix:rx:s:load-extensions')
+
+export default function* loadMetainfo() {
+ if (isSelfhosted) {
+ return
+ }
+
+ try {
+ const metainfo: IMetainfo = yield call(getPaymentMetainfo)
+
+ yield put(UIActions.setMetainfo(metainfo))
+ } catch (e: unknown) {
+ const { message } = e as { message: string }
+ // if (_isString(message)) {
+ // yield put(UIActions.setProjectsError(message))
+ // }
+ debug('failed to load metainfo: %s', message)
+ }
+}