Sending events

Sending events

Events say what happened, never who. Who is identify's: it writes the contact (and an event called right after it, in the same task, belongs to that contact). An email, phone or name on any other event is only that event's ad match: never stored, never a contact. If you call identify, don't put the email on the event; if you don't (you don't want a person record), put it on the event for its ad match. Browsing events carry no email: call identify once on logged-in pages instead. See Your data.

The setup, in order

  1. The snippet on every page.
  2. Your store's events, with no email.
  3. identify at the identity moments — never added to an event:
    • the sign-up form submit, with the boxes the shopper ticked (subscribed_*);
    • ONE line in your common template: if logged in → identify(email). It is standard, not optional: it covers login and every logged-in page (the thank-you page too), re-links a new browser id (Safari's 7-day cookie cap, cleared cookies, a new device) and opens records for members from before the install. The snippet sends it once per browser + email per 30 days;
    • the order page, for every buyer (the snippet skips a repeat for 30 days per browser + email).
  4. { consent: { ads } } on track only when your own form has an ad-consent box.

Everything you send to Tocadule flows through one function:

tocadule.track(eventName, properties)

eventName is a string, properties is a plain object. That's the whole surface. Cart state has its own call (tocadule.cart(...)) and identity has tocadule.identify(...), but browsing, checkout, purchase, search and any custom signal all go through track.

Events that happen outside the browser — an order cancelled in your admin panel, a status from your ERP — go through the server API instead.

Installing the snippet

Paste these three lines into your storefront's <head> as the first code, above your pixels and tag manager (Meta, TikTok, Google Tag Manager). The first opens the connection to our server early, the second defines a tiny stub so that tocadule.track(...) exists immediately, and the third loads the real snippet asynchronously.

<link rel="preconnect" href="https://app.tocadule.com">
<script>window.tocadule=window.tocadule||{};window.tocadule._q=window.tocadule._q||[];['track','identify','cart','requestPush','setConsent'].forEach(function(m){window.tocadule[m]=window.tocadule[m]||function(){window.tocadule._q.push([m,arguments])}});</script>
<script async fetchpriority="high" data-workspace="YOUR_WORKSPACE_ID" src="https://app.tocadule.com/snippet.js"></script>

The stub queues every call into window.tocadule._q. When snippet.js finishes loading it drains the queue and replays each call in order. This means template code that runs before the async snippet loads — a cart script, an order-success script — never no-ops. You do not need to wrap calls in a setTimeout or a "snippet ready" check.

The code samples below need no if (window.tocadule) guard: the stub in your <head> defines tocadule before any of them runs.

The payload you send vs. what we store

You only ever supply two things: the event name and a properties object. The snippet wraps that into the request to /events/track:

// What the snippet actually POSTs — you never build this yourself:
{
  workspace_id: ws,          // from data-workspace
  anonymous_id: aid,         // browser identity, managed by the snippet
  event: eventName,          // your first argument
  properties: props,         // your object + auto-enrichment (below)
  consent_state: "...",      // analytics lane, auto-detected
  ad_consent: "..."          // advertising lane, auto-detected
}

workspace_id, anonymous_id, consent_state and ad_consent are all filled in for you. Your job is the event name and the properties.

Properties: send values as your store writes them

Put each value in a backtick template literal, exactly as your platform renders it: price: `{productPrice}`. A quote in a value ("Levi's") stays text and never breaks the script. Money and counts go as your store writes them (199,90 or 199.90): we read them in your source's number format, set once per source in the Data centre; a value that does not fit is flagged, never guessed.

PropertyNotes
price, subtotal, total, shipping, tax, discountmoney, as your store writes it
quantity, item_countcounts, as your store writes them
product_id, order_id, skuIDs, kept as text
currencyISO code, e.g. TRY
name, brand, categoryfree text

Unfilled template tokens

If you paste a script with {...} placeholders that your store's template engine fills in server-side, a token your page leaves unfilled (the literal string {productId}) is no value: we drop it before anything reads the event. No helper and no guard are needed. A required field that does not arrive (a purchase with no order_id) shows as Eksik (missing) in the Data centre, so you see it instead of losing the event silently.

Here is the real product_view script — copy it and map the {...} tokens to your platform's variables:

<script>
  // product_view: on your product page. Replace each {…} with your platform's token.
  tocadule.track('product_view', { product_id: `{productId}`, variant_id: `{variantId}`,
    sku: `{sku}`, name: `{productName}`, price: `{productPrice}`, discount: `{discount}`,
    url: `{productUrl}`, image_url: `{productImage}`, brand: `{productBrand}`,
    category: `{productCategory}`, currency: `{currency}` });
</script>

The purchase script, for your order-success / thank-you page. The order page identifies every buyer: identify right before the purchase writes the contact and travels with the purchase in one request (a logged-in member's repeat is skipped: the snippet sends identify once per browser + email per 30 days). If you call identify, don't put the email on the event; if you don't (you don't want a person record), put the email on the event for its ad match.

<script>
  // purchase: on your order confirmation page. Replace each {…} with your platform's token.
  var items = [];
  // inside your platform's product loop, once per product:
  items.push({ product_id: `{productId}`, variant_id: `{variantId}`, sku: `{sku}`, name: `{productName}`,
    price: `{productPrice}`, quantity: `{productQuantity}`, url: `{productUrl}`, image_url: `{productImage}` });
  tocadule.identify(`{email}`);
  tocadule.track('purchase', { order_id: `{orderId}`, total: `{total}`, subtotal: `{subtotal}`,
    shipping: `{shipping}`, tax: `{tax}`, discount: `{discount}`, coupon: `{coupon}`,
    currency: `{currency}`, items: items });
</script>
⚠️

purchase requires order_id and total. total is the value ad platforms optimise toward — send it in your store's currency, as your store writes it.

What we attach automatically

You send a small object. By the time the event lands, it carries a lot more — none of which you should ever set yourself.

Added in the browser, on every track call:

  • Marketing attribution: utm_source / utm_medium / utm_campaign / utm_content / utm_term (captured from the URL, persisted 30 min).

  • Ad click IDs, nested under click_ids (captured from the landing URL):

    KeyWhere it comes fromKept for
    gclidGoogle Ads click90 days
    gbraid / wbraidGoogle Ads click on iOS (app / web). Safari removes gclid from links in private browsing, so these are often the only Google click ID90 days
    dclidGoogle Display & Video 360 / Campaign Manager click90 days
    gad_source / gad_campaignidGoogle Ads campaign markers (they come with most ad clicks, even when the click ID itself was removed)90 days
    g_session_attrsGoogle's encoded landing context (the gad_* params, landing URL, referrer, browser). It lets Google match a click that arrived without a usable click ID. Sent once, on the first event after the landing that already has an anonymous_id90 days
    msclkidMicrosoft Ads click90 days
    fbclidMeta click28 days
    ttclidTikTok click28 days
    epikPinterest click28 days
    pinclidPinterest click (older format)28 days
    srsltidGoogle Merchant Center free listing. Not an ad click; it only marks the visit as shopping28 days

    Each key keeps its own clock: a new Meta click does not reset the Google one. If the URL no longer carries an ID (a redirect removed it), the snippet also checks a same-site referrer and, with ad consent, the ad platforms' own cookies (_gcl_aw, _gcl_gb, ttclid, _epik). _click_ts is the time of the most recent click on any platform, and _click_ts_by holds the time per platform (both in milliseconds). The _fbp / _ttp / _ga browser-identifier cookies ride along too (read from the merchant's own pixel if present, otherwise baked by us for consented visitors).

  • Device: device_type (mobile / tablet / desktop), browser, os.

  • Traffic source: traffic_source, traffic_platform, referrer_domain. The landing is classified once and the result is kept for the visit (30 minutes of inactivity), so a reload or an in-site page does not turn it into direct. The first rule that matches wins:

    traffic_sourceWhen
    paidThe URL has a Google, TikTok, Microsoft, Pinterest or ChatGPT Ads (oppref) click ID, a gad_source, an fbclid with a paid utm_medium, or any paid utm_medium (cpc, ppc, paid, cpm, paid_social, display)
    aiThe referrer is an AI assistant (ChatGPT, Perplexity, Gemini, Copilot, Claude, Grok, DeepSeek, Meta AI, Mistral, …) or utm_source names one — organic assistant traffic only; an ad clicked inside ChatGPT is paid
    shoppingThe URL has srsltid (a free Google Merchant Center listing)
    organicA search-engine referrer, or utm_medium=organic
    referralAny other external referrer or UTM tag, or an fbclid without a paid medium
    likely_aiNo longer produced (since 2026-10-19: such visits are direct); older visits may still carry it
    directNone of the above

    traffic_platform is set when the platform is known: google, meta, tiktok, microsoft, pinterest, chatgpt or other.

  • Page context: url, path, title, page_locale, user_language.

  • Environment: screen_width / screen_height, viewport_width / viewport_height, dpr, connection_type.

Added / resolved on the server:

  • Contact resolution — the server takes the browser-sent anonymous_id (see the payload above) and looks up the linked contact through the identity map. This is how anonymous browsing gets stitched to a known shopper. The anonymous_id itself is generated and sent by the browser, not added server-side.
  • Location — country, region, city, postal code, timezone (and, only with analytics consent, latitude / longitude). Resolved from the real client IP via MaxMind (offline GeoLite2). You do not pass geo; passing your own country / city on the event takes precedence if you do.
  • client_ip, user_agent — captured request-side (used to improve ad-platform match quality).
  • Bot flagging (is_bot) by user-agent, so crawler traffic is excluded from analytics and never forwarded to ad platforms.

If you set a property we would otherwise auto-fill (say your own url or country), your value wins. Auto-enrichment only fills gaps.

Dedup keys — you never set them

Tocadule dedups on two keys, and merchants set neither:

  • anonymous_id — the browser key. The snippet generates and persists it; it rides on every event automatically. It's how repeated events from the same visitor collapse to one identity.
  • source_event_id — the external-system key, used for server-to-server sources (Shopify order webhooks, future integrations) so a replayed webhook can't double-count. Browser track calls do not carry one.

You don't send dedup identifiers on tocadule.track(...). Send the real event; identity resolution and de-duplication happen behind the scenes.

Attaching a shopper's identity

Customer details reach the contact only through identify (and our popup forms, and your platform); anything personal on another event is that event's ad match only. Either way they are stripped before any event row is stored.

CallWhenCarries
tocadule.identify(email, traits)at sign-up (once, on submit), from the one logged-in line in your common template, and on the order page for every buyeremail + profile traits + the marketing boxes ticked
form events (sign_up, lead)when the form is submitted, right after its identify (one request)no email (the identify carries it); no permission fields (only identify writes permission)
tocadule.identify(email, { subscribed_* }) on your preference pagewhen the preferences are savedthe per-channel permissions, on and off
purchaseon the order-confirmation pagethe buyer: identify(email, …) right before it (then no email on the event); without identify, email / phone / names on the event for its ad match only

Browsing events (product_view, add_to_cart, view_cart, checkout_started, search, custom events) carry no customer details. Once a browser is identified, all of its events, including the earlier ones, resolve to the contact through identity_map, and forwards to Meta / TikTok / Google carry the contact's hashed email from then on (when the visitor allowed ads).

A browser is linked only when the analytics lane is granted. See Identity & contacts.

⚠️

Never put PII on tocadule.cart(...). Cart state is PII-free by design: it carries the anonymous_id and resolves to the contact through the identity map once the shopper is identified.

Custom events

track accepts any event name. A custom event is inserted just like a standard one, with all the same auto-enrichment (device, geo, UTM, click IDs, identity resolution) applied.

tocadule.track('size_guide_opened', { product_id: '101', size_chart: 'shoes-eu' });
tocadule.track('wishlist_add', { product_id: '250' });

Custom events appear in your dashboard's Events catalog alongside the standard ones — grouped by name with total fires, unique contacts, and last-fired time — and their properties are available for building segments and automation triggers. What a custom event does not get is the built-in forwarding map that standard commerce events (product_view, add_to_cart, checkout_started, purchase, search) have. If you need a custom event to reach an ad platform, map it explicitly in your destination settings.

Prefer a standard name when one fits — product_view, add_to_cart, checkout_started, purchase, view_cart, view_item_list, search — so the event automatically flows into cart intelligence, abandonment automations, and ad-platform forwarding without extra mapping.

Consent — handled for you

Every event carries two independent consent lanes, both auto-detected by the snippet from your CMP (Google Consent Mode, IAB TCF, OneTrust, Cookiebot, Iubenda, GPC, …):

  • consent_state — the analytics lane. Gates keeping an anonymous_id on events and linking the browser to a contact for reports: granted only.
  • ad_consent — the advertising lane. Gates whether an event is forwarded to ad destinations (full when granted; otherwise nothing, or a count where the destination counts). Alone, it keeps the visitor id for the ad match only.

You don't set these on track — unless a form of yours states the advertising answer for that one event: tocadule.track(name, props, { consent: { ads: true } }) (an analytics there is ignored). For your own consent screen, tocadule.setConsent({ analytics, ads }) (in the install code) states both, for every event. Both are your statements; you answer for them. Marketing permission (subscribed_email / subscribed_sms / …) is a separate record on the contact, set via identify(), our popup forms or your preference page; it is not a CMP lane. See Consent & compliance.