Skip to content

Nuxt quickstart

Add Insights Orbit to a Nuxt website, send your own events, wait for consent and check that visits arrive.

Tutorial5 min read

In about 10 minutes you add Insights Orbit to a Nuxt website for Northwilds. Page views count on every page, also when Nuxt changes pages without reloading, a button sends a Brochure requested event, and an optional banner asks visitors before anything is counted.

Tested with: Nuxt 4.6.4, Vue 3.5.45, Node.js 24, in nuxi dev and a production build.

Before you start

You need:

  • A site in Insights Orbit with your website's addresses under Site settings. Add localhost too while you build on your computer, or events from it answer 403. See Add your first site.
  • The site key, from the site's Install screen. It isn't a secret.
  • Node.js 20 or later.

1Create the project

Shell
npx create-nuxt@latest northwilds-site --template minimal --packageManager npm --gitInit false --no-modulescd northwilds-sitemkdir -p app/pages app/components app/composables

Make the site key a public runtime setting in nuxt.config.ts:

nuxt.config.tsTypeScript
export default defineNuxtConfig({  compatibilityDate: '2025-07-15',  devtools: { enabled: true },  runtimeConfig: {    public: { insightsSite: '' },  },})
.envShell
NUXT_PUBLIC_INSIGHTS_SITE=SITE_KEY

NUXT_PUBLIC_INSIGHTS_SITE is read when the server starts, so the same build can run with a different key on staging and in production.

2Add the script

Add the script with useHead in app/app.vue, so it is on every page. Replace the file:

Vue
<!-- app/app.vue --><script setup lang="ts">const { insightsSite } = useRuntimeConfig().publicuseHead({  script: insightsSite    ? [{ src: 'https://api.bifrostorbit.com/insights/v1/script.js', defer: true, 'data-site': insightsSite }]    : [],})</script><template>  <header>    <NuxtLink to="/">Northwilds</NuxtLink> <NuxtLink to="/trips">Trips</NuxtLink>  </header>  <NuxtPage /></template>
  • The script follows Nuxt's page changes through history.pushState, so you don't need a page view call or a plugin.
  • Without a key, no script is added.

Add a home page:

Vue
<!-- app/pages/index.vue --><template>  <main>    <h1>Northwilds</h1>    <p>Guided trips in the far north.</p>    <NuxtLink to="/trips">See the trips</NuxtLink>  </main></template>

3Send your own events

A composable calls the script, or queues the call when the script hasn't loaded yet. Nuxt imports functions from app/composables for you.

app/composables/insights.tsTypeScript
export type Details = Record<string, string | number | boolean>export type Money = { revenue: number; currency: string }type Insights = {  track?: (name: string, details?: Details, money?: Money) => void  consent?: (given?: boolean) => void  q?: unknown[][]}declare global {  interface Window {    insights?: Insights  }}export function track(name: string, details?: Details, money?: Money) {  if (window.insights?.track) window.insights.track(name, details, money)  else (window.insights ??= { q: [] }).q?.push(['track', name, details, money])}export function consent(given = true) {  if (window.insights?.consent) window.insights.consent(given)  else (window.insights ??= { q: [] }).q?.push(['consent', given])}

Call track from the browser only, such as in a click handler or onMounted, never while the page renders on the server:

Vue
<!-- app/pages/trips.vue --><script setup lang="ts">const sent = ref(false)function requestBrochure() {  track('Brochure requested', { trip: 'lofoten-ski-touring' })  sent.value = true}</script><template>  <main>    <h1>Lofoten ski touring week</h1>    <p>Seven days of ski touring above the fjords, from €2,450.</p>    <button type="button" :disabled="sent" @click="requestBrochure">      {{ sent ? 'On its way' : 'Send me the brochure' }}    </button>  </main></template>
  • Event names are what goals look for, so use plain words. Details are text, numbers or true or false; never names or email addresses. Send your own events has the limits.
  • Revenue goes in the third argument: track('Trip booked', { trip: 'lofoten-ski-touring' }, { revenue: 2450, currency: 'EUR' }).
  • To count it as success, an Editor adds a goal under Goals that sends the event Brochure requested. See Set up goals.

Insights Orbit uses no cookies and keeps no personal data. Whether you still ask first is your decision with your adviser. See What to write in your privacy notice. To ask first, add 'data-consent': 'wait' to the script in app/app.vue:

TypeScript
[{ src: 'https://api.bifrostorbit.com/insights/v1/script.js', defer: true, 'data-site': insightsSite, 'data-consent': 'wait' }]

The script now counts nothing until the page calls insights.consent(). It doesn't remember the answer, so your banner keeps it and calls consent() on every page:

Vue
<!-- app/components/ConsentBanner.vue --><script setup lang="ts">const KEY = 'northwilds-analytics'const open = ref(false)onMounted(() => {  const saved = localStorage.getItem(KEY)  if (saved === 'yes') consent()  open.value = saved === null})function choose(answer: 'yes' | 'no') {  localStorage.setItem(KEY, answer)  open.value = false  consent(answer === 'yes')}</script><template>  <aside v-if="open" aria-label="Analytics">    <p>May we count your visit? We use no cookies and keep no personal data.</p>    <button type="button" @click="choose('yes')">Yes</button>    <button type="button" @click="choose('no')">No thanks</button>  </aside></template>

Put <ConsentBanner /> after <NuxtPage /> in app/app.vue.

  • Page views before the answer wait in memory, up to 50, and are sent the moment the visitor says yes, so the page where they agreed still counts.
  • No thanks drops what is waiting, and nothing is sent on later pages.
  • If you already have a consent tool, call consent() from it instead of this banner.

5Check that events arrive

Run npm run dev, open http://localhost:3000, go to Trips and select Send me the brochure. If you added the banner, select Yes first.

  • In the browser: the Network tab shows POST requests to collect answering 202, with your page views and the event. Events are sent two seconds after they happen, or at once when the page is hidden.
  • In Insights Orbit: Install says Visits are arriving, Right now on the overview shows you on /trips, and Events lists Brochure requested within a few seconds.
  • From the API, on the Growth plan, with a key that reads events:
Shell
curl "https://api.bifrostorbit.com/insights/v1/events?site=SITE_KEY&name=Brochure%20requested" \  -H "Authorization: Bearer ins_live_…"

Nothing arrives? Browsers with Do Not Track or Global Privacy Control on, and automated browsers such as Playwright, send nothing on purpose. Troubleshooting for developers lists every other cause.

Next steps

Was this page helpful?

Read next