@radiate-so/nuxt
v0.2.0
Published
Official Nuxt module for Radiate. Provides $radiate, composables (useSegment, useTrack, useIdentify, …), and runtime-config wiring.
Maintainers
Readme
@radiate-so/nuxt
Official Nuxt module for Radiate — provides $radiate, auto-imported composables, and runtime-config wiring on top of @radiate-so/browser-sdk.
Install
pnpm add @radiate-so/nuxtAdd the module in nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@radiate-so/nuxt'],
radiate: {
publicKey: process.env.NUXT_PUBLIC_RADIATE_PK,
// Any RadiateBrowserConfig field — passed through verbatim:
autoTrackPageviews: true,
skipPaths: ['/admin/**'],
},
})The NUXT_PUBLIC_RADIATE_PK env var auto-overrides radiate.publicKey at runtime per Nuxt's env-var convention.
Composables (auto-imported)
const radiate = useRadiate() // RadiateBrowser | null
const isPower = useSegment('power_user') // Ref<boolean | null>
const segments = useSegments() // Ref<string[] | null>
const personas = usePersonas() // Ref<Record<string, number> | null>
const profile = useProfile() // Ref<MeResponse | null>
useIdentify(useUser()) // sync identify/reset to a Ref or getter
const track = useTrack() // (event, props?) => voidAll read composables return a Vue Ref whose .value is null while loading or during SSR. After useIdentify(...) runs, every mounted read composable refetches automatically — no manual cache busting.
$radiate is also exposed for ad-hoc use:
<script setup>
const { $radiate } = useNuxtApp()
$radiate.flush()
</script>Server-side (Nitro)
This module owns only the client side. For server-side identify and full profile reads, install @radiate-so/js-sdk and use it from your server/ routes:
// server/api/me.ts
import { Radiate } from '@radiate-so/js-sdk'
export default defineEventHandler(async (event) => {
const cfg = useRuntimeConfig()
const radiate = new Radiate({ secretKey: cfg.radiateSk })
const rid = getCookie(event, 'rid')
if (!rid) return { id: null, segments: [], personas: {} }
return await radiate.me({ anonymous_id: rid })
})See the full Nuxt recipe for cookie sync, SSR personalization, server middleware, and tracking from server/api.
License
MIT
