Beautiful Open-Source Form Builder
Enhance application with Clarity integration (#896)
Chirag Chhatrala26da2256359a
diff --git a/client/.env.example b/client/.env.exampleindex 30d9dc1db..fa62f31de 100644--- a/client/.env.example+++ b/client/.env.example@@ -8,4 +8,5 @@ NUXT_PUBLIC_GOOGLE_ANALYTICS_CODE=NUXT_PUBLIC_H_CAPTCHA_SITE_KEY=NUXT_PUBLIC_RE_CAPTCHA_SITE_KEY=NUXT_API_SECRET=secret-NUXT_PUBLIC_ROOT_REDIRECT_URL=\ No newline at end of file+NUXT_PUBLIC_ROOT_REDIRECT_URL=+NUXT_PUBLIC_CLARITY_PROJECT_ID=\ No newline at end of filediff --git a/client/app.vue b/client/app.vueindex fa7b5c116..2d6c91834 100644--- a/client/app.vue+++ b/client/app.vue@@ -20,6 +20,7 @@</ClientOnly><ClientOnly>+ <Clarity /><FeatureBase /><SubscriptionModal /><QuickRegister />@@ -30,6 +31,7 @@<script setup>import FeatureBase from "~/components/vendor/FeatureBase.vue"+import Clarity from "~/components/vendor/Clarity.vue"const config = useRuntimeConfig()diff --git a/client/components/pages/admin/ClarityLink.vue b/client/components/pages/admin/ClarityLink.vuenew file mode 100644index 000000000..d7c761722--- /dev/null+++ b/client/components/pages/admin/ClarityLink.vue@@ -0,0 +1,22 @@+<template>+ <UButton+ variant="outline"+ icon="i-heroicons-arrow-top-right-on-square"+ :to="clarityLink"+ target="_blank"+ label="Open in Clarity"+ />+</template>++<script setup>+const props = defineProps({+ user: { type: Object, required: true }+})++const runtimeConfig = useRuntimeConfig()+const clarityProjectId = computed(() => runtimeConfig.public.clarityProjectId || null)++const clarityLink = computed(() => {+ return `https://clarity.microsoft.com/projects/view/${clarityProjectId.value}/impressions?CustomUserId=is%3B${props.user.email}`+})+</script>\ No newline at end of filediff --git a/client/components/vendor/Clarity.vue b/client/components/vendor/Clarity.vuenew file mode 100644index 000000000..039916a6e--- /dev/null+++ b/client/components/vendor/Clarity.vue@@ -0,0 +1,51 @@+<template />++<script setup>+import Clarity from '@microsoft/clarity'++const authStore = useAuthStore()+const authenticated = computed(() => authStore.check)+const user = computed(() => authStore.user)+const isIframe = useIsIframe()+const loaded = ref(false)+const runtimeConfig = useRuntimeConfig()+const clarityProjectId = computed(() => runtimeConfig.public.clarityProjectId || null)++async function loadClarity() {+ const projectId = clarityProjectId.value+ if (!projectId || !authenticated.value || isIframe || loaded.value) return++ try {+ Clarity.init(projectId)+ if (user.value?.id) {+ Clarity.identify(String(user.value.id), null, null, user.value.email)+ }+ loaded.value = true+ } catch (error) {+ console.error('[Clarity] Failed to init', error)+ }+}++watch(authenticated, (val) => {+ if (val) loadClarity()+})++watch(user, (val) => {+ if (import.meta.server) return+ if (!loaded.value || !authenticated.value || isIframe) return+ if (val?.id) {+ try {+ Clarity.identify(String(val.id), null, null, val.email)+ } catch (error) {+ console.error('[Clarity] Failed to identify user', error)+ }+ }+})++onMounted(() => {+ if (import.meta.server) return+ loadClarity()+})+</script>++diff --git a/client/package-lock.json b/client/package-lock.jsonindex f54def8a7..ac0d11d91 100644--- a/client/package-lock.json+++ b/client/package-lock.json@@ -9,6 +9,7 @@"dependencies": {"@codemirror/lang-html": "^6.4.9","@iconify-json/material-symbols": "^1.2.4",+ "@microsoft/clarity": "^1.0.0","@nuxt/ui": "^3.2.0","@pinia/nuxt": "^0.11.0","@popperjs/core": "^2.11.8",@@ -2337,6 +2338,11 @@"integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==","license": "MIT"},+ "node_modules/@microsoft/clarity": {+ "version": "1.0.0",+ "resolved": "https://registry.npmjs.org/@microsoft/clarity/-/clarity-1.0.0.tgz",+ "integrity": "sha512-2QY6SmXnqRj6dWhNY8NYCN3e53j4zCFebH4wGnNhdGV1mqAsQwql2fT0w8TISxCvwwfVp8idsWLIdrRHOms1PQ=="+ },"node_modules/@miyaneee/rollup-plugin-json5": {"version": "1.2.0","resolved": "https://registry.npmjs.org/@miyaneee/rollup-plugin-json5/-/rollup-plugin-json5-1.2.0.tgz",diff --git a/client/package.json b/client/package.jsonindex 643337cdf..0088ba446 100644--- a/client/package.json+++ b/client/package.json@@ -38,6 +38,7 @@"dependencies": {"@codemirror/lang-html": "^6.4.9","@iconify-json/material-symbols": "^1.2.4",+ "@microsoft/clarity": "^1.0.0","@nuxt/ui": "^3.2.0","@pinia/nuxt": "^0.11.0","@popperjs/core": "^2.11.8",diff --git a/client/pages/admin.vue b/client/pages/admin.vueindex bb74461fd..dd5140d27 100644--- a/client/pages/admin.vue+++ b/client/pages/admin.vue@@ -108,6 +108,7 @@><ImpersonateUser :user="userInfo" /><SendPasswordResetEmail :user="userInfo" />+ <ClarityLink :user="userInfo" /></div><divclass="w-full grid gap-2 grid-cols-1 lg:grid-cols-2"diff --git a/client/runtimeConfig.js b/client/runtimeConfig.jsindex 209072943..23ae4b573 100644--- a/client/runtimeConfig.js+++ b/client/runtimeConfig.js@@ -26,6 +26,8 @@ export default {SENTRY_TRACES_SAMPLE_RATE: parseNumber(process.env.SENTRY_TRACES_SAMPLE_RATE),SENTRY_REPLAY_SAMPLE_RATE: parseNumber(process.env.SENTRY_REPLAY_SAMPLE_RATE),SENTRY_ERROR_REPLAY_SAMPLE_RATE: parseNumber(process.env.SENTRY_ERROR_REPLAY_SAMPLE_RATE),++ clarityProjectId: process.env.NUXT_PUBLIC_CLARITY_PROJECT_ID || null,},/**