Skip to content

Commit c95f113

Browse files
authored
Enable Mixpanel additional features (#2915)
Fixes #2872
1 parent f2c4c76 commit c95f113

File tree

8 files changed

+122
-8
lines changed

8 files changed

+122
-8
lines changed

configs/app/features/mixpanel.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1+
import type { Config } from 'mixpanel-browser';
2+
13
import type { Feature } from './types';
24

3-
import { getEnvValue } from '../utils';
5+
import { getEnvValue, parseEnvJson } from '../utils';
46

57
const projectToken = getEnvValue('NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN');
8+
const configOverrides = (() => {
9+
const value = getEnvValue('NEXT_PUBLIC_MIXPANEL_CONFIG_OVERRIDES');
10+
if (!value) {
11+
return;
12+
}
13+
14+
return parseEnvJson<Partial<Config>>(value) || undefined;
15+
})();
616

717
const title = 'Mixpanel analytics';
818

9-
const config: Feature<{ projectToken: string }> = (() => {
19+
const config: Feature<{ projectToken: string; configOverrides?: Partial<Config> }> = (() => {
1020
if (projectToken) {
1121
return Object.freeze({
1222
title,
1323
isEnabled: true,
1424
projectToken,
25+
configOverrides,
1526
});
1627
}
1728

configs/envs/.env.main

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ NEXT_PUBLIC_APP_PORT=3000
99
NEXT_PUBLIC_APP_ENV=development
1010
NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws
1111

12+
NEXT_PUBLIC_MIXPANEL_CONFIG_OVERRIDES='{"record_sessions_percent": 0.5, "record_heatmap_data": true}'
13+
1214
# Instance ENVs
1315
NEXT_PUBLIC_ADMIN_SERVICE_API_HOST=https://admin-rs-test.k8s-dev.blockscout.com
1416
NEXT_PUBLIC_API_BASE_PATH=/

deploy/tools/envs-validator/schema.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,25 @@ const userOpsSchema = yup
395395
}),
396396
});
397397

398+
const mixpanelSchema = yup
399+
.object()
400+
.shape({
401+
NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN: yup.string(),
402+
NEXT_PUBLIC_MIXPANEL_CONFIG_OVERRIDES: yup
403+
.object()
404+
.transform(replaceQuotes)
405+
.json()
406+
.when('NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN', {
407+
is: (value: string) => Boolean(value),
408+
then: (schema) => schema,
409+
otherwise: (schema) => schema.test(
410+
'not-exist',
411+
'NEXT_PUBLIC_MIXPANEL_CONFIG_OVERRIDES can only be used if NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN is set to a non-empty string',
412+
value => value === undefined,
413+
),
414+
}),
415+
});
416+
398417
const adButlerConfigSchema = yup
399418
.object<AdButlerConfig>()
400419
.transform(replaceQuotes)
@@ -1103,7 +1122,6 @@ const schema = yup
11031122
NEXT_PUBLIC_RE_CAPTCHA_APP_SITE_KEY: yup.string(),
11041123
NEXT_PUBLIC_RE_CAPTCHA_V3_APP_SITE_KEY: yup.string(), // DEPRECATED
11051124
NEXT_PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID: yup.string(),
1106-
NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN: yup.string(),
11071125
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY: yup.string(),
11081126
NEXT_PUBLIC_ROLLBAR_CLIENT_TOKEN: yup.string(),
11091127

@@ -1119,6 +1137,7 @@ const schema = yup
11191137
.concat(bridgedTokensSchema)
11201138
.concat(sentrySchema)
11211139
.concat(apiDocsScheme)
1140+
.concat(mixpanelSchema)
11221141
.concat(tacSchema)
11231142
.concat(address3rdPartyWidgetsConfigSchema)
11241143
.concat(addressMetadataSchema)

deploy/tools/envs-validator/test/.env.base

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=xxx
66
NEXT_PUBLIC_RE_CAPTCHA_APP_SITE_KEY=xxx
77
NEXT_PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID=UA-XXXXXX-X
88
NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN=xxx
9+
NEXT_PUBLIC_MIXPANEL_CONFIG_OVERRIDES='{"record_sessions_percent": 0.5,"record_heatmap_data": true}'
910
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
1011
NEXT_PUBLIC_AUTH0_CLIENT_ID=xxx
1112
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx

docs/ENVS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ Ads are enabled by default on all self-hosted instances. If you would like to di
544544
| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
545545
| --- | --- | --- | --- | --- | --- | --- |
546546
| NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN | `string` | Project token for [Mixpanel](https://mixpanel.com/) analytics service | true | - | `<your-secret>` | v1.1.0+ |
547+
| NEXT_PUBLIC_MIXPANEL_CONFIG_OVERRIDES | `string` | Pass a JSON-like string that represents a subset of the [Mixpanel SDK configuration](https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#library-configuration) to override the project's default properties. | - | - | `{"record_sessions_percent": 0.5}` | v2.3.0+ |
547548

548549
&nbsp;
549550

lib/mixpanel/useInit.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function useMixpanelInit() {
2828
const mixpanelConfig: Partial<Config> = {
2929
debug: Boolean(debugFlagQuery.current || debugFlagCookie),
3030
persistence: 'localStorage',
31+
...feature.configOverrides,
3132
};
3233
const isAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN));
3334

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"graphql-ws": "^5.11.3",
9595
"js-cookie": "^3.0.1",
9696
"magic-bytes.js": "1.8.0",
97-
"mixpanel-browser": "^2.47.0",
97+
"mixpanel-browser": "2.67.0",
9898
"monaco-editor": "^0.34.1",
9999
"next": "15.2.3",
100100
"next-themes": "0.4.4",

yarn.lock

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6187,6 +6187,16 @@
61876187
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.22.4.tgz#3dd5d53e900df2a40841882c02e56f866c04d202"
61886188
integrity sha512-j8pPKp53/lq9lMXN57S8cFz0MynJk8OWNuUnXct/9KCpKU7DgU3bYMJhwWmcqC0UU29p8Lr0/7KEVcaM6bf47Q==
61896189

6190+
"@rrweb/types@^2.0.0-alpha.18":
6191+
version "2.0.0-alpha.18"
6192+
resolved "https://registry.yarnpkg.com/@rrweb/types/-/types-2.0.0-alpha.18.tgz#e1d9af844cebbf30a2be8808f6cf64f5df3e7f50"
6193+
integrity sha512-iMH3amHthJZ9x3gGmBPmdfim7wLGygC2GciIkw2A6SO8giSn8PHYtRT8OKNH4V+k3SZ6RSnYHcTQxBA7pSWZ3Q==
6194+
6195+
"@rrweb/utils@^2.0.0-alpha.18":
6196+
version "2.0.0-alpha.18"
6197+
resolved "https://registry.yarnpkg.com/@rrweb/utils/-/utils-2.0.0-alpha.18.tgz#7440b425461cf92b8ad9a229db40fa58d456159a"
6198+
integrity sha512-qV8azQYo9RuwW4NGRtOiQfTBdHNL1B0Q//uRLMbCSjbaKqJYd88Js17Bdskj65a0Vgp2dwTLPIZ0gK47dfjfaA==
6199+
61906200
"@rtsao/scc@^1.1.0":
61916201
version "1.1.0"
61926202
resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8"
@@ -7335,6 +7345,11 @@
73357345
resolved "https://registry.yarnpkg.com/@types/csp-dev/-/csp-dev-1.0.0.tgz#59e2fd69f276988b349765c2f6a39ea0a4a1a161"
73367346
integrity sha512-OTHJTGqXvgFu1AE4Eo8cu+jgkQChpzTOHpMDrVkxAmNORVz7/11Zjj2NXZyWQcxibf18C966bU1JWtANrR8uJQ==
73377347

7348+
"@types/css-font-loading-module@0.0.7":
7349+
version "0.0.7"
7350+
resolved "https://registry.yarnpkg.com/@types/css-font-loading-module/-/css-font-loading-module-0.0.7.tgz#2f98ede46acc0975de85c0b7b0ebe06041d24601"
7351+
integrity sha512-nl09VhutdjINdWyXxHWN/w9zlNCfr60JUqJbd24YXUuCwgeL0TpFSdElCwb6cxfB6ybE19Gjj4g0jsgkXxKv1Q==
7352+
73387353
"@types/d3-array@*":
73397354
version "3.0.3"
73407355
resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-3.0.3.tgz#87d990bf504d14ad6b16766979d04e943c046dac"
@@ -8749,6 +8764,11 @@
87498764
"@walletconnect/window-getters" "^1.0.1"
87508765
tslib "1.14.1"
87518766

8767+
"@xstate/fsm@^1.4.0":
8768+
version "1.6.5"
8769+
resolved "https://registry.yarnpkg.com/@xstate/fsm/-/fsm-1.6.5.tgz#f599e301997ad7e3c572a0b1ff0696898081bea5"
8770+
integrity sha512-b5o1I6aLNeYlU/3CPlj/Z91ybk1gUsKT+5NAJI+2W4UjvS5KLG28K9v5UvNoFVjHV8PajVZ00RH3vnjyQO7ZAw==
8771+
87528772
"@zag-js/accordion@1.7.0":
87538773
version "1.7.0"
87548774
resolved "https://registry.yarnpkg.com/@zag-js/accordion/-/accordion-1.7.0.tgz#3bc7d35d3e120561c75da3bd36bfa3f9d4e19f5f"
@@ -10018,6 +10038,11 @@ base-x@^5.0.0:
1001810038
resolved "https://registry.yarnpkg.com/base-x/-/base-x-5.0.1.tgz#16bf35254be1df8aca15e36b7c1dda74b2aa6b03"
1001910039
integrity sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg==
1002010040

10041+
base64-arraybuffer@^1.0.1:
10042+
version "1.0.2"
10043+
resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz#1c37589a7c4b0746e34bd1feb951da2df01c1bdc"
10044+
integrity sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==
10045+
1002110046
base64-js@1.5.1, base64-js@^1.3.1, base64-js@^1.5.1:
1002210047
version "1.5.1"
1002310048
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
@@ -15644,10 +15669,17 @@ mipd@0.0.7:
1564415669
resolved "https://registry.yarnpkg.com/mipd/-/mipd-0.0.7.tgz#bb5559e21fa18dc3d9fe1c08902ef14b7ce32fd9"
1564515670
integrity sha512-aAPZPNDQ3uMTdKbuO2YmAw2TxLHO0moa4YKAyETM/DTj5FloZo+a+8tU+iv4GmW+sOxKLSRwcSFuczk+Cpt6fg==
1564615671

15647-
mixpanel-browser@^2.47.0:
15648-
version "2.47.0"
15649-
resolved "https://registry.yarnpkg.com/mixpanel-browser/-/mixpanel-browser-2.47.0.tgz#4e7fd3bb660c6f63443efbd169d1cd327db71ed4"
15650-
integrity sha512-Ldrva0fRBEIFWmEibBQO1PulfpJVF3pf28Guk09lDirDaSQqqU/xs9zQLwN2rL5VwVtsP1aD3JaCgaa98EjojQ==
15672+
mitt@^3.0.0:
15673+
version "3.0.1"
15674+
resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1"
15675+
integrity sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==
15676+
15677+
mixpanel-browser@2.67.0:
15678+
version "2.67.0"
15679+
resolved "https://registry.yarnpkg.com/mixpanel-browser/-/mixpanel-browser-2.67.0.tgz#74ac41eedec4ca3bdc63c22a91271584b17057f0"
15680+
integrity sha512-LudY4eRIkvjEpAlIAg10i2T2mbtiKZ4XlMGbTyF1kcAhEqMa9JhEEdEcjxYPwiKhuMVSBM3RVkNCZaNqcnE4ww==
15681+
dependencies:
15682+
rrweb "2.0.0-alpha.18"
1565115683

1565215684
mkdirp-classic@^0.5.2, mkdirp-classic@^0.5.3:
1565315685
version "0.5.3"
@@ -15774,6 +15806,11 @@ mz@^2.7.0:
1577415806
object-assign "^4.0.1"
1577515807
thenify-all "^1.0.0"
1577615808

15809+
nanoid@^3.3.11:
15810+
version "3.3.11"
15811+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.11.tgz#4f4f112cefbe303202f2199838128936266d185b"
15812+
integrity sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==
15813+
1577715814
nanoid@^3.3.6, nanoid@^3.3.7:
1577815815
version "3.3.8"
1577915816
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf"
@@ -16525,6 +16562,11 @@ picocolors@^1.0.0, picocolors@^1.0.1, picocolors@^1.1.0:
1652516562
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.0.tgz#5358b76a78cde483ba5cef6a9dc9671440b27d59"
1652616563
integrity sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==
1652716564

16565+
picocolors@^1.1.1:
16566+
version "1.1.1"
16567+
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
16568+
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==
16569+
1652816570
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3, picomatch@^2.3.1:
1652916571
version "2.3.1"
1653016572
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
@@ -16755,6 +16797,15 @@ postcss@^8.4.19, postcss@^8.4.43:
1675516797
picocolors "^1.1.0"
1675616798
source-map-js "^1.2.1"
1675716799

16800+
postcss@^8.4.38:
16801+
version "8.5.6"
16802+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.5.6.tgz#2825006615a619b4f62a9e7426cc120b349a8f3c"
16803+
integrity sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==
16804+
dependencies:
16805+
nanoid "^3.3.11"
16806+
picocolors "^1.1.1"
16807+
source-map-js "^1.2.1"
16808+
1675816809
postgres-array@~2.0.0:
1675916810
version "2.0.0"
1676016811
resolved "https://registry.yarnpkg.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e"
@@ -17782,6 +17833,34 @@ rollup@^4.20.0:
1778217833
"@rollup/rollup-win32-x64-msvc" "4.22.4"
1778317834
fsevents "~2.3.2"
1778417835

17836+
rrdom@^2.0.0-alpha.18:
17837+
version "2.0.0-alpha.18"
17838+
resolved "https://registry.yarnpkg.com/rrdom/-/rrdom-2.0.0-alpha.18.tgz#54726a87053c420ef67b7597a31fef515e372e85"
17839+
integrity sha512-fSFzFFxbqAViITyYVA4Z0o5G6p1nEqEr/N8vdgSKie9Rn0FJxDSNJgjV0yiCIzcDs0QR+hpvgFhpbdZ6JIr5Nw==
17840+
dependencies:
17841+
rrweb-snapshot "^2.0.0-alpha.18"
17842+
17843+
rrweb-snapshot@^2.0.0-alpha.18:
17844+
version "2.0.0-alpha.18"
17845+
resolved "https://registry.yarnpkg.com/rrweb-snapshot/-/rrweb-snapshot-2.0.0-alpha.18.tgz#b242d079cb07acadd389a56674465a466b111e20"
17846+
integrity sha512-hBHZL/NfgQX6wO1D9mpwqFu1NJPpim+moIcKhFEjVTZVRUfCln+LOugRc4teVTCISYHN8Cw5e2iNTWCSm+SkoA==
17847+
dependencies:
17848+
postcss "^8.4.38"
17849+
17850+
rrweb@2.0.0-alpha.18:
17851+
version "2.0.0-alpha.18"
17852+
resolved "https://registry.yarnpkg.com/rrweb/-/rrweb-2.0.0-alpha.18.tgz#19d96bccba44dc1ee37d0b77b9ca1952682e62b5"
17853+
integrity sha512-1mjZcB+LVoGSx1+i9E2ZdAP90fS3MghYVix2wvGlZvrgRuLCbTCCOZMztFCkKpgp7/EeCdYM4nIHJkKX5J1Nmg==
17854+
dependencies:
17855+
"@rrweb/types" "^2.0.0-alpha.18"
17856+
"@rrweb/utils" "^2.0.0-alpha.18"
17857+
"@types/css-font-loading-module" "0.0.7"
17858+
"@xstate/fsm" "^1.4.0"
17859+
base64-arraybuffer "^1.0.1"
17860+
mitt "^3.0.0"
17861+
rrdom "^2.0.0-alpha.18"
17862+
rrweb-snapshot "^2.0.0-alpha.18"
17863+
1778517864
run-parallel@^1.1.9:
1778617865
version "1.2.0"
1778717866
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"

0 commit comments

Comments
 (0)