Guides / Conversion tracking
A conversion event closes the personalisation loop. It tells Spectare which atoms, images, and intent patterns led to an outcome, so the next visitor with a similar profile gets a better experience.
Choose based on how your site handles post-conversion state. Most sites use URL patterns. Complex flows need the manual call.
Visitor reaches a matching URL
URL pattern set in Settings
fires automatically
Your code confirms success
spectare('conversion') called
fires at the exact moment
Conversion recorded
attributed to the assembly this visitor saw
Use one path per conversion type. Using both on the same page double-fires the event.
URL pattern
No code required
Set a URL pattern in Settings. Both the script tag and PersonalisedSection check the current URL on load and fire automatically when it matches. Works for any site with a distinct thank-you or confirmation URL.
Manual call
One line of code
Fire a conversion at the exact moment one is confirmed. Script tag sites call spectare('conversion'). React and Next.js apps read the session token and POST to the conversion endpoint. Required for multi-step forms, in-app upgrades, and flows where the URL does not change.
Go to Admin, then Settings, and add one or more URL patterns under Conversion tracking. No code changes needed on your site.
<!-- No code required. -->
<!-- In your Spectare admin, go to Settings and add a URL pattern. -->
<!-- Examples: /thank-you | order-confirmed | /dashboard/welcome -->
<!-- -->
<!-- When a visitor's URL contains the pattern, Spectare fires -->
<!-- a conversion event automatically. -->Pattern matching rules
/thank-youMatches any URL containing /thank-you, including subpaths like /checkout/thank-youorder-confirmedSubstring match: fires on any URL where the string appears, with or without slashes/dashboard/welcomeUseful for SaaS products where conversion is completing signup and landing in the appWhen to use a URL pattern
Any flow with a distinct confirmation page: e-commerce thank-you pages, lead gen confirmation pages, post-signup landing screens, or content downloads that redirect on completion. If the visitor's browser URL changes to something unique after the conversion, a URL pattern is the simpler path.
Goal types and revenue
Each goal has a name and a type: pageview, signup, lead, purchase, upgrade, or download. The type is how conversions are grouped in analytics, so a “Book a demo” lead and a “Buy” purchase stay separate rather than blurring into one number. Purchase goals can also capture revenue: point a CSS selector at the element that shows the order total and set a default currency, and Spectare reads the amount off the page when the conversion fires. That value flows into analytics, so you can see revenue by audience and stage, not just conversion counts.
Fire a conversion from your own code at the moment it is confirmed. For script tag sites, call spectare('conversion'). For React and Next.js, read the session token and POST to the conversion endpoint directly. Use the manual call when the URL does not change, when you need to fire after an async operation completes, or when the conversion happens inside a single-page app.
Basic usage (script tag sites)
<script>
// Call this wherever the conversion happens:
// a button click, a form submission, a successful API response.
spectare('conversion');
</script>React or Next.js
// React / Next.js: manual conversion call
// Use this for event-driven conversions (button clicks, form submits).
// For URL-based conversions, configure patterns in Settings instead.
// PersonalisedSection fires them automatically on page load.
async function handlePurchase() {
await submitOrder();
const token = sessionStorage.getItem(`_spectare_token_${orgSlug}`);
if (token) {
fetch('https://spectare.ai/api/conversion', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token, orgSlug, url: window.location.href }),
});
}
}When to use the manual call
Fire the conversion event once, on confirmed completion of the final step. Not on each intermediate step, and not before the server confirms success. Early firing records a conversion that may not complete; multiple firings inflate your conversion count.
// Multi-step form: fire on the final step only
function Step3({ onComplete }: { onComplete: () => void }) {
function handleSubmit() {
submitFinalStep().then(() => {
spectare('conversion'); // fires once, on confirmed completion
onComplete();
});
}
return <button onClick={handleSubmit}>Submit application</button>;
}The same principle applies to payment flows: fire after the payment API responds with success, not when the user clicks Pay.
For server-side rendering stacks, native apps, or any environment without the Spectare script, call the conversion endpoint directly. Include the context token from the qualify step and the IDs of atoms and image shown to the visitor.
POST https://spectare.ai/api/conversion
Content-Type: application/json
{
"token": "<context-token-from-qualify>",
"orgSlug": "your-workspace-slug",
"url": "https://your-site.com/thank-you",
"variantId": "<variantId-from-assemble-response>",
"goalName": "Purchase",
"goalValue": 79,
"goalCurrency": "USD"
}
// Response
{ "ok": true }Where to get variantId
Both /api/assemble/components and /api/assemble/ssr return a variantId field. It is a short opaque hash that identifies the specific assembly the visitor saw. Include it in the conversion call so Spectare can attribute the outcome to that assembly and improve selection for future visitors with the same profile. If you omit it, the conversion is still recorded but cannot be tied to a specific assembly.
Each conversion event updates five systems in real time. The effects compound: more conversions mean better assembly for future visitors.
Conversion recorded
Atom ranking
Arrangement
Image weight
Conversion graph
Analytics
All five update from the same event, in real time.
Atom ranking
The assembly variant shown at conversion is recorded. Spectare resolves which atoms composed that variant and increases their score for that audience and stage combination, so they appear more frequently for similar future visitors.
Component arrangement
The arrangement of components shown at conversion is recorded with its impressions and conversions. Once an arrangement clears your signal threshold, it is fed back into assembly: Claude prefers arrangements proven to convert for that audience and stage, whenever the atoms support one.
Image optimisation
The image shown at conversion is recorded against the audience and stage. The multi-armed bandit algorithm increases the selection weight for that image, so it appears more often for matching visitors going forward.
Conversion graph
Atoms that appear together at conversion build a co-conversion graph. Spectare uses this to surface atom combinations that work, and to rank candidate sets during assembly.
Analytics
Each conversion event records the intent type, audience, stage, and the URL where it fired. These appear in the Analytics section of your admin. Filter by time range, audience, or intent type to see which segments are converting.
Common questions
Can I use both URL patterns and manual calls at the same time?
Yes, but take care not to double-fire. If your thank-you page matches a URL pattern and you also call spectare('conversion') on that page, two events are recorded for the same conversion. Use one path per conversion type.
Do conversions fire in development?
Yes. If you are testing locally with the Spectare script, conversion events will fire and be recorded. Use a separate development workspace slug if you do not want test data in your production analytics.
What if the visitor has no context token?
The conversion API requires a valid context token. If the visitor did not go through the qualify step (for example, they navigated directly to the thank-you URL), no event is recorded. This is expected behaviour: conversion attribution only works for visitors whose intent was classified.
How many conversions do I need before the algorithm improves?
The image selection algorithm starts shifting weight after around 20 to 30 conversions per audience and stage combination. Atom ranking improves faster, since even a handful of conversion events give the assembly algorithm signal to work with.
Go to Admin, then Settings, and add a URL pattern to get started without writing any code.