Build AI agent with real-time user context using Signals and Vercel AI SDK

Adding real-time behavioral context to a Next.js AI agent with Snowplow Signals and Vercel AI SDK

Most AI agents respond the same way regardless of who's asking. They don't know which pages the user has visited, what they've been exploring, or how long they've been on the site. Every conversation starts from zero.

This accelerator shows you how to change that. You'll build a Next.js AI agent that uses Snowplow Signals to understand what users are doing in real time — then injects that behavioral context directly into the agent's system prompt via the Vercel AI SDK. The agent doesn't just respond to what the user types, but it responds to what the user is actually doing.

The full implementation takes approximately 30 minutes. The stack is minimal by design: Snowplow Browser Tracker for event collection, Signals for real-time attribute computation, and Vercel AI SDK with AI Gateway for model integration.

Use Cases

  • Pricing page assistant — detect that a user has spent significant time on enterprise pricing and tailor responses around SSO, infrastructure options, or SLA tiers without the user having to explain their intent
  • Onboarding guide — surface relevant next steps based on which docs or product areas a new user has already explored in the current session
  • Support deflection — give the agent awareness of what a user was doing before they opened the chat, reducing the need for the user to restate context
  • Content discovery — adapt recommendations based on which topics or categories a user has been actively engaging with during the session

Infrastructure Overview

  • Snowplow Browser Tracker — streams behavioral events (page views, page pings, link clicks) from the Next.js front-end to the Snowplow Collector
  • Snowplow Signals — computes live session attributes from the event stream and serves them via the Profiles API, keyed by Snowplow domain session ID
  • Vercel AI SDK + AI Gateway — handles the /api/chat route, fetches fresh Signals attributes per request, appends them to the system prompt, and streams the model response back to the browser
  • Next.js — the application framework; the ChatWidget reads the session ID from the tracker cookie and passes it with every chat request

Additional Insights

The session ID is the integration point — the front-end reads it from the Snowplow tracker cookie and sends it alongside every chat message. The /api/chat route uses it to fetch fresh attributes from Signals on each turn, so the system prompt always reflects current behavior. The tutorial uses openai/gpt-4o-mini via Vercel AI Gateway, but any model supported by the gateway works without changes to the integration pattern.

Cloud Platforms

Data Platforms

Data Platforms

All Supported

Activation Products

Solution Partners

Key Outcomes

  • Implement Snowplow Browser Tracker in a Next.js app to automatically capture real-time session behavior with no manual event instrumentation required
  • Configure Snowplow Signals to compute live session attributes from the behavioral event stream and serve them via the Profiles API
  • Connect Signals to the Vercel AI SDK by passing the Snowplow session ID from the front-end to the /api/chat route on every request
  • Inject fresh behavioral attributes into the agent system prompt each turn so responses reflect what the user is doing right now

Get Started

See how Snowplow gives companies the real-time user data foundation and context layer to make better business decisions while powering the AI initiatives that will define the next era of media.