Send storefront events
Connect your storefront to Nucleo Catalog with the Collector: install, consent, custom events and testing.
What the Collector does
The Collector receives what shoppers do on your storefront — page and product views, searches, cart changes, checkout and purchase — and turns it into the signals Nucleo Catalog uses for search ranking, recommendations and the Shoppers section. It only stores events of shoppers who granted consent.
Install the script
- In Nucleo, go to Settings > Catalog > Search > Installations (permission
catalog.search.install: owners and admins by default; with custom roles the permission is what counts). - Create an installation and add the domains your storefront runs on (for example
shop.acme.example;*.acme.examplecovers every subdomain). - Copy the snippet with your public key and paste it into your theme.
The snippet looks like this:
<script async src="https://api-catalog.nucleoplatform.com/collect/v1/nucleo.js" data-key="pk_3f9a1c7e5b2d4f60a8c1e9b7d3f5a2c4" data-consent="auto"></script>| Attribute | What it does |
|---|---|
data-key | Required. The installation's public key. Without it the script does nothing. |
data-consent | auto (default) reads consent from Shopify's privacy banner when the page has one. manual ignores the banner: only your calls to nucleo.consent() count. |
data-locale | The visitor's language. Default: Shopify's locale, otherwise the page's <html lang>. |
data-customer | The signed customer reference, if you print it here instead of in <meta name="nucleo-customer">. See CustomerReference. |
The hosted script nucleo.js sends page and product views, searches and cart changes on its own, waits for consent and batches events. On Shopify it reads consent from the store's own privacy banner, and the checkout Web Pixel adds checkout and purchase events when you enable it on the installation. A visitor whose browser sends Global Privacy Control is always treated as denied.
To check that everything is wired, call the configuration endpoint from your storefront's domain:
curl "https://api-catalog.nucleoplatform.com/api/collect/v1/config?key=$NUCLEO_COLLECTOR_KEY" \
-H "Origin: https://shop.acme.example"Consent
Nothing is written without consent. Every batch carries the visitor's consent state:
granted— events are stored; thepurposesyou pass (analytics,personalisation…) decide what they are used for.deniedorrevoked— Nucleo deletes what it knows about that visitor and keeps only a hashed tombstone for 30 days.pending— nothing is written or counted.
The script sends a refusal or a withdrawal to POST /consent at once. A consent granted is not sent on its own: it travels with the next batch of events. Events collected on the page while consent was pending (the latest 50) are sent as soon as it is granted.
Outside Shopify, wire your consent banner to the script, so that every change reaches Nucleo:
// when the shopper accepts
nucleo.consent("granted", ["analytics", "personalisation"]);
// when the shopper refuses or withdraws consent
nucleo.consent("denied");
// calls made before nucleo.js has loaded are queued
window.nucleoq = window.nucleoq || [];
nucleoq.push(["consent", "granted", ["analytics"]]);The script also exposes:
nucleo.track(kind, data)for events it cannot see on its own,nucleo.search(query, results)andnucleo.flush();nucleo.identify(reference)to set the signed customer reference after the page has loaded (for example after a login without a reload); any value that is not a non-empty string clears it. An expired reference is not sent;nucleo.visitorId()returns the visitor id, ornulluntil consent is granted;nucleo.state()returns a read-only snapshot for debugging:consent,source,visitorId,session,queued(events waiting),sent(requests sent),cart,customer(the reference that would be sent) andtest.
Wire it so that every change reaches Nucleo. A shopper's identity (to link events to a customer) is accepted only as a reference signed by your store, and only when the shopper granted personalisation.
Send events yourself
Headless storefronts and apps can call the Collector directly. Browsers must send the body as text/plain with the key in the body: that makes the call a CORS simple request, without a preflight.
navigator.sendBeacon(
"https://api-catalog.nucleoplatform.com/api/collect/v1/events",
new Blob(
[
JSON.stringify({
key: "pk_3f9a1c7e5b2d4f60a8c1e9b7d3f5a2c4",
v: 1,
sentAt: new Date().toISOString(),
visitor: { id: visitorId, consent: "granted", purposes: ["analytics"] },
events: [
{ uid: crypto.randomUUID().slice(0, 12), kind: "product_view", ref: { sku: "TEE-BLK-M" } },
],
}),
],
{ type: "text/plain" },
),
);- Up to 50 events and 64 KB per batch.
- Give each event a random
uid: resending it is harmless, it is counted as a duplicate. - Events can be up to 7 days old; if
sentAtis set, Nucleo corrects a browser clock that is off by more than 30 seconds and at most 24 hours. - The seven kinds and the fields each accepts are in the events reference.
Test without writing data
In Nucleo, go to Catalog > Shoppers > Test events to get a test code. Add it as test to a batch: Nucleo validates everything and answers as usual, but writes nothing.