billdogeng-vue
v1.0.0-beta.1
Published
BilldogEng SDK for Vue 3 — SSR-safe, idiomatic Vue/TS wrapper over the BillDog engagement suite (analytics, surveys, in-app messaging, remote feature flags).
Downloads
165
Maintainers
Readme
billdogeng-vue
The BillDog engagement suite for Vue 3 — a thin, idiomatic, SSR-safe wrapper
over the existing browser SDKs (@billdog.io/web, @billdog.io/analytics,
@billdog.io/survey-core).
It surfaces, the Vue way (a plugin + composables + a component):
- init —
createBilldog()plugin (or<BilldogProvider>/useProvideBilldog) - analytics —
capture/identify/groupviauseBilldog() - surveys — fetch / list / submit + a render component (
useSurvey,<Survey/>) - in-app messaging —
useBilldog().showInAppMessages() - feature flags — remote / server-authoritative via
useFeatureFlag()
Feature flags are remote. All targeting is evaluated on the BillDog backend. This package performs no local bucketing and contains no murmurhash — that is forbidden by the BillDog architecture.
useFeatureFlagsimply reads the value the backend already decided and cached.
Install
npm install billdogeng-vue @billdog.io/web @billdog.io/analytics @billdog.io/survey-coreThe three @billdog.io/* packages are optional peer dependencies — install the
ones whose features you use. vue (>=3.3) is a required peer.
Quick start (plugin)
import { createApp } from 'vue';
import { createBilldog } from 'billdogeng-vue';
import App from './App.vue';
const app = createApp(App);
app.use(
createBilldog({
apiKey: 'bd_live_xxx',
projectId: 'proj_123',
// customerId?, anonymousId?, autoloadFeatureFlags? (default true)
}),
);
app.mount('#app');Scoped alternative — <BilldogProvider>
<script setup lang="ts">
import { BilldogProvider } from 'billdogeng-vue';
const config = { apiKey: 'bd_live_xxx', projectId: 'proj_123' };
</script>
<template>
<BilldogProvider :config="config">
<App />
</BilldogProvider>
</template>Analytics
<script setup lang="ts">
import { useBilldog } from 'billdogeng-vue';
const { capture, identify, group, showInAppMessages } = useBilldog();
identify('user_42', { plan: 'pro' });
group('company', 'acme', { seats: 5 });
capture('page_view', { path: '/home' });
// in-app messaging trigger
showInAppMessages('home_banner');
</script>Feature flags (remote)
<script setup lang="ts">
import { useFeatureFlag } from 'billdogeng-vue';
// boolean on/off flag
const newCheckout = useFeatureFlag('new-checkout', false);
// multivariate (string variant)
const theme = useFeatureFlag('theme', 'classic');
</script>
<template>
<CheckoutV2 v-if="newCheckout" />
<CheckoutV1 v-else />
</template>The returned ref re-evaluates automatically whenever the SDK re-fetches flags from the backend.
Surveys
Component
<script setup lang="ts">
import { Survey } from 'billdogeng-vue';
</script>
<template>
<Survey
survey-id="svy_nps"
@submit="(result, answers) => console.log(result, answers)"
@error="(e) => console.error(e)"
/>
</template>Custom rendering (scoped slot)
<Survey survey-id="svy_nps" v-slot="{ survey, loading, setAnswer, submit }">
<p v-if="loading">Loading…</p>
<form v-else-if="survey" @submit.prevent="submit">
<!-- drive the form yourself with `setAnswer(questionId, { ... })` -->
</form>
</Survey>Composable
import { useSurvey } from 'billdogeng-vue';
const { survey, loading, error, submit, refetch } = useSurvey('svy_nps');
await submit([{ question_id: 'q1', answer_choices: ['great'] }]);SSR (Nuxt / Vite SSR)
The package is SSR-safe out of the box:
- The engagement client is only instantiated in the browser (
onMounted, plus atypeof windowguard in the plugin). - Importing the package on the server never touches
window/document; the underlying browser SDKs are loaded with dynamicimport()only on the client. - During server render,
useBilldog().readyisfalse,useFeatureFlagreturns its default, and surveys do not fetch — everything activates on the client after hydration.
For Nuxt, register the plugin in a client plugin file
(plugins/billdog.client.ts) so it only runs in the browser:
// plugins/billdog.client.ts
import { createBilldog } from 'billdogeng-vue';
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(
createBilldog({ apiKey: 'bd_live_xxx', projectId: 'proj_123' }),
);
});License
MIT
