From a69318e3ff067cb3883ba7454610984513004a20 Mon Sep 17 00:00:00 2001 From: Qin Guan Date: Sun, 22 Oct 2023 15:22:02 +0800 Subject: [PATCH] feat: add growthbook --- components/app/services/page.vue | 2 +- nuxt.config.ts | 6 ++++++ package.json | 1 + plugins/growthbook.ts | 20 ++++++++++++++++++++ pnpm-lock.yaml | 15 +++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 plugins/growthbook.ts diff --git a/components/app/services/page.vue b/components/app/services/page.vue index 93a635d..ff2bcd9 100644 --- a/components/app/services/page.vue +++ b/components/app/services/page.vue @@ -48,7 +48,7 @@ async function click() { - + SSTAA Registration System (SSTAARS) diff --git a/nuxt.config.ts b/nuxt.config.ts index 2530d30..4765226 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -126,5 +126,11 @@ export default defineNuxtConfig({ firebase: { projectId: 'sstaa-app' || process.env.FIREBASE_PROJECT_ID, }, + + public: { + growthbook: { + clientKey: '' || process.env.GROWTHBOOK_CLIENT_KEY, + }, + }, }, }) diff --git a/package.json b/package.json index b82e24a..02e0b5a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "devDependencies": { "@antfu/eslint-config": "latest", "@cloudflare/workers-types": "^4.20230914.0", + "@growthbook/growthbook": "^0.29.0", "@libsql/client": "^0.3.4", "@nuxt/devtools": "latest", "@nuxt/ui": "^2.8.1", diff --git a/plugins/growthbook.ts b/plugins/growthbook.ts new file mode 100644 index 0000000..92f2374 --- /dev/null +++ b/plugins/growthbook.ts @@ -0,0 +1,20 @@ +import { GrowthBook } from '@growthbook/growthbook' + +export default defineNuxtPlugin(async () => { + const config = useRuntimeConfig() + + const growthbook = new GrowthBook({ + apiHost: 'https://cdn.growthbook.io', + clientKey: config.public.growthbook.clientKey, + enableDevMode: true, + subscribeToChanges: true, + }) + + await growthbook.loadFeatures() + + return { + provide: { + growthbook, + }, + } +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7b3f329..0fbd130 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ devDependencies: '@cloudflare/workers-types': specifier: ^4.20230914.0 version: 4.20230914.0 + '@growthbook/growthbook': + specifier: ^0.29.0 + version: 0.29.0 '@libsql/client': specifier: ^0.3.4 version: 0.3.4 @@ -2393,6 +2396,13 @@ packages: resolution: {integrity: sha512-+ZplYUN3HOpgCfgInqgdDAbkGGVzES1cs32JJpeqoh87SkRobGXElJx+1GZSaDqzFL+bYiX18qEcBK76mYs8uA==} dev: true + /@growthbook/growthbook@0.29.0: + resolution: {integrity: sha512-hRYtBw1cg3fqjBRKRfazkRfCJyFpIxjdEUjmwkFaSBorzVDiX35gcp8x83vytQdx5E9xfQo3x/m9Z1yEMDrN7A==} + engines: {node: '>=10'} + dependencies: + dom-mutator: 0.5.0 + dev: true + /@grpc/grpc-js@1.9.3: resolution: {integrity: sha512-b8iWtdrYIeT5fdZdS4Br/6h/kuk0PW5EVBUGk1amSbrpL8DlktJD43CdcCWwRdd6+jgwHhADSbL9CsNnm6EUPA==} engines: {node: ^8.13.0 || >=10.10.0} @@ -5897,6 +5907,11 @@ packages: esutils: 2.0.3 dev: true + /dom-mutator@0.5.0: + resolution: {integrity: sha512-bbeX8HWE8JGzraFgbVBX4ws2g3heZFuTtrleQBuN7huy+7n2n7etSuVnot3/1z3jdY2MiwuvoS4Ep1UT2rrGBw==} + engines: {node: '>=10'} + dev: true + /dom-serializer@2.0.0: resolution: {integrity: sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==} dependencies: