From 45743a4059987a92b4bb84de396522b14d15c19b Mon Sep 17 00:00:00 2001 From: less Date: Sun, 29 Oct 2023 21:34:36 +0700 Subject: [PATCH] feat: add Mixpanel --- .env | 3 ++- .eslintrc-auto-import.json | 3 ++- package.json | 1 + src/composables/useMixpanel.ts | 7 +++++++ src/router.ts | 10 ++++++++++ yarn.lock | 5 +++++ 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/composables/useMixpanel.ts diff --git a/.env b/.env index b760ccbbbc3d..685b32e31135 100644 --- a/.env +++ b/.env @@ -8,4 +8,5 @@ VITE_IPFS_GATEWAY=snapshot.mypinata.cloud VITE_DEFAULT_NETWORK=1 VITE_PUSHER_BEAMS_INSTANCE_ID=2e080021-d495-456d-b2cf-84f9fd718442 VITE_SHUTTER_EON_PUBKEY=0x0e6493bbb4ee8b19aa9b70367685049ff01dc9382c46aed83f8bc07d2a5ba3e6030bd83b942c1fd3dff5b79bef3b40bf6b666e51e7f0be14ed62daaffad47435265f5c9403b1a801921981f7d8659a9bd91fe92fb1cf9afdb16178a532adfaf51a237103874bb03afafe9cab2118dae1be5f08a0a28bf488c1581e9db4bc23ca -VITE_ENV=develop \ No newline at end of file +VITE_ENV=develop +VITE_MIXPANEL_TOKEN=2ec6cd1b19e790f45cc9a9bb83980c8d diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index 4237cc3451dc..42c32f20b3ec 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -118,6 +118,7 @@ "useFlaggedMessageStatus": true, "useEmailSubscription": true, "useEmailFetchClient": true, - "useStatement": true + "useStatement": true, + "useMixpanel": true } } diff --git a/package.json b/package.json index 2aad3534a8ba..9eff1491a5e1 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "js-sha256": "^0.9.0", "jsonexport": "^3.2.0", "lodash": "^4.17.21", + "mixpanel-browser": "^2.47.0", "readable-stream": "3.6.0", "remarkable": "^2.0.1", "remove-markdown": "^0.5.0", diff --git a/src/composables/useMixpanel.ts b/src/composables/useMixpanel.ts new file mode 100644 index 000000000000..41abaa25fdea --- /dev/null +++ b/src/composables/useMixpanel.ts @@ -0,0 +1,7 @@ +import mixpanel from 'mixpanel-browser'; + +export function useMixpanel() { + mixpanel.init(import.meta.env.VITE_MIXPANEL_TOKEN, { ip: false }); + + return { mixpanel }; +} diff --git a/src/router.ts b/src/router.ts index 0cac4d7b0d17..0f33d7dfc318 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,4 +1,5 @@ import { createRouter, createWebHashHistory, RouteLocation } from 'vue-router'; +import { useMixpanel } from '@/composables/useMixpanel'; import DelegateView from '@/views/DelegateView.vue'; import ExploreView from '@/views/ExploreView.vue'; @@ -25,6 +26,8 @@ import SpaceDelegate from './views/SpaceDelegate.vue'; // The frontend shows all spaces or just a single one, when being accessed // through that space's custom domain. const { domain, domainAlias } = useApp(); +const { mixpanel } = useMixpanel(); + const routes: any[] = []; // These routes get prefixed with the respective space's ENS domain (/:key) @@ -173,6 +176,13 @@ const router = createRouter({ } }); +router.afterEach(to => { + mixpanel.track_pageview({ + page_name: to.name, + page_path: to.path + }); +}); + export { routes }; export default router; diff --git a/yarn.lock b/yarn.lock index ad06a69b474e..41421b1af05c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5594,6 +5594,11 @@ minisearch@^6.0.1: resolved "https://registry.yarnpkg.com/minisearch/-/minisearch-6.1.0.tgz#6e74e743dbd0e88fa5ca52fef2391e0aa7055252" integrity sha512-PNxA/X8pWk+TiqPbsoIYH0GQ5Di7m6326/lwU/S4mlo4wGQddIcf/V//1f9TB0V4j59b57b+HZxt8h3iMROGvg== +mixpanel-browser@^2.47.0: + version "2.47.0" + resolved "https://registry.yarnpkg.com/mixpanel-browser/-/mixpanel-browser-2.47.0.tgz#4e7fd3bb660c6f63443efbd169d1cd327db71ed4" + integrity sha512-Ldrva0fRBEIFWmEibBQO1PulfpJVF3pf28Guk09lDirDaSQqqU/xs9zQLwN2rL5VwVtsP1aD3JaCgaa98EjojQ== + mlly@^1.1.1, mlly@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/mlly/-/mlly-1.2.0.tgz#f0f6c2fc8d2d12ea6907cd869066689b5031b613"