{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"redocly_category":"Products","product_name":"Engage Studio","type":"markdown"},"seo":{"title":"Event Tracking — In-Browser Messaging","description":"Define and implement business events for In-Browser Messaging using GA4-compatible naming, including page views, product interactions, and cart events.","siteUrl":"https://docs.treasure.ai","lang":"en-US","jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.treasure.ai/","name":"Treasure AI","url":"https://www.treasure.ai/","logo":"https://www.treasure.ai/hubfs/assets/images/logos/primary-logo.svg"},{"@type":"WebSite","@id":"https://docs.treasure.ai/#website","name":"Treasure AI Documentation","url":"https://docs.treasure.ai/","inLanguage":["en","ja"],"publisher":{"@id":"https://www.treasure.ai/"}}]},"llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"event-tracking","__idx":0},"children":["Event Tracking"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide covers how to define and send business events from your website to Treasure AI. Well-structured events are the foundation for In-Browser Message targeting — they determine when campaigns are triggered and what personalization attributes are available."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Responsibility boundary"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["You define"]},": business events (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["view_item"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["purchase"]},", etc.) and authenticated user IDs."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["The SDK handles automatically"]},": page views, session tracking, device/browser properties, message impression and click tracking (current and future)."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Future SDK versions will also auto-track page views and SPA route changes — the manual patterns in this page will become optional."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"event-architecture","__idx":1},"children":["Event Architecture"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["All events — page views, business events, and future SDK auto-tracked events — are sent to a ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["single table"]},". Use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["event_name"]}," to distinguish event types in queries."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"What happened"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["What happened"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"Table"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Table"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"40%","data-label":"Used for"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Used for"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Page view, session start/end"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["events"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["event_name: 'page_view'"]},")"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["RT entry criteria, audience segmentation"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Product view, cart, purchase"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["events"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["event_name: 'view_item'"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["'add_to_cart'"]},", etc.)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["RT attributes, trigger conditions"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Message shown / clicked / dismissed"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["events"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["event_name: 'td_msg_shown'"]},", etc.) — future, automatic"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Campaign reporting, frequency capping"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Count page views"]},": ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["SELECT count(*) FROM events WHERE event_name = 'page_view'"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"ga4-compatible-event-naming","__idx":2},"children":["GA4-Compatible Event Naming"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["We recommend adopting ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["GA4 standard event names"]}," for business events. This minimizes implementation cost for teams already using GA4, allows GTM dataLayer reuse, and provides a consistent schema for RT 2.0 targeting."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"standard-e-commerce-events","__idx":3},"children":["Standard e-commerce events"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"25%","data-label":"Event name"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Event name"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"35%","data-label":"When to fire"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["When to fire"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"40%","data-label":"Key properties"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Key properties"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["view_item"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["User views a product detail page"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_name"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["price"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_category"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_brand"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["add_to_cart"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["User adds a product to the cart"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_name"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["price"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["quantity"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["view_cart"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["User opens the cart"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["cart_total"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_count"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["items"]}," (JSON string)"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["purchase"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Order confirmation page"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["transaction_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["revenue"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_count"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["items"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["add_to_wishlist"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["User saves a product"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_id"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["price"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["login"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["User logs in"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["method"]}," (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["\"email\""]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["\"google\""]},")"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sign_up"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["User registers"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["method"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"property-naming-conventions","__idx":4},"children":["Property naming conventions"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"Category"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Category"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"Property name"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Property name"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"15%","data-label":"Type"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Type"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"25%","data-label":"Notes"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Notes"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Product ID"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["GA4 compatible"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Product name"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_name"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Unit price"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["price"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Order revenue"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["revenue"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Quantity"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["quantity"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Category (up to 5 levels)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_category"]}," – ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_category5"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["GA4 compatible"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Brand"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_brand"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Order ID"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["transaction_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["GA4 compatible"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Product array"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["items"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string (JSON)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["See array handling below"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sending-events","__idx":5},"children":["Sending Events"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"basic-event","__idx":6},"children":["Basic event"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"td.trackEvent('events', {\n  item_id: 'SKU-001',\n  item_name: 'Essential Crew Tee',\n  price: 29,\n  item_category: 'tops',\n  item_brand: 'BASIQ',\n  event_name: 'view_item',\n})\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"cart-event","__idx":7},"children":["Cart event"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"// Add to cart\ntd.trackEvent('events', {\n  event_name: 'add_to_cart',\n  item_id: 'SKU-001',\n  item_name: 'Essential Crew Tee',\n  price: 29,\n  quantity: 1,\n  item_category: 'tops',\n})\n\n// Cart view (aggregate)\ntd.trackEvent('events', {\n  event_name: 'view_cart',\n  cart_total: 87,\n  item_count: 3,\n  items: JSON.stringify([\n    { item_id: 'SKU-001', price: 29, quantity: 1 },\n    { item_id: 'SKU-014', price: 58, quantity: 2 },\n  ]),\n})\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"purchase-event","__idx":8},"children":["Purchase event"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"td.trackEvent('events', {\n  event_name: 'purchase',\n  transaction_id: 'ORDER-10432',\n  revenue: 87,\n  item_count: 3,\n  // Flat fields from the primary item — easy to use in RT triggers and attributes\n  item_id: 'SKU-001',\n  item_category: 'tops',\n  // Full product array as JSON string for completeness\n  items: JSON.stringify([\n    { item_id: 'SKU-001', item_name: 'Essential Crew Tee', price: 29, quantity: 1 },\n    { item_id: 'SKU-014', item_name: 'Wide-leg Pants', price: 58, quantity: 2 },\n  ]),\n})\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"handling-array-data-items","__idx":9},"children":["Handling array data (items)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Events with multiple products (cart, purchase) require a strategy for the product list:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"Approach"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Approach"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"35%","data-label":"Pros"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Pros"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"35%","data-label":"Cons"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Cons"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["JSON-stringify (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["items: \"[{...}]\""]},")"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Simple to implement; GTM-friendly"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["TD queries become complex; cannot use directly in RT attributes"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Flat fields (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_id_0"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_id_1"]},", ...)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Easy to query"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Field count explodes with cart size"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Recommended: flat primary + JSON full list"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Best of both worlds for triggers + completeness"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Slightly more implementation"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Use the recommended pattern"]},": send the properties most useful for trigger conditions as flat fields (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_category"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["price"]},"), and include the complete list as a JSON string for reporting."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"td.trackEvent('events', {\n  event_name: 'purchase',\n  transaction_id: 'ORDER-001',\n  revenue: 8760,\n  item_count: 2,\n  // Flat: primary item fields (easy for RT attribute conditions)\n  item_id: 'SKU-123',\n  item_category: 'electronics',\n  price: 4380,\n  // Full list as JSON string (for reporting)\n  items: JSON.stringify([\n    { item_id: 'SKU-123', item_name: 'Headphones', price: 4380, quantity: 1 },\n    { item_id: 'SKU-456', item_name: 'Case', price: 4380, quantity: 1 },\n  ]),\n})\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"firing-events-before-the-sdk-loads","__idx":10},"children":["Firing Events Before the SDK Loads"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["On pages where the SDK script loads asynchronously, events fired before the SDK is ready could be dropped. Use the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["command queue pattern"]}," to safely fire events at any time — they are replayed once the SDK is ready."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"// Safe to call at any time — queued if SDK not yet loaded\n;(window.__tdEventQueue = window.__tdEventQueue || []).push([\n  'trackEvent', 'events', { event_name: 'view_item', item_id: 'SKU-001', price: 29 }\n])\n\n// In your SDK initialization (sdk-loader.js or equivalent):\n;(function drainQueue() {\n  var queue = window.__tdEventQueue || []\n  window.__tdEventQueue = { push: function(entry) {\n    if (!entry || !entry.length) return\n    var method = entry[0]\n    if (window.td && typeof window.td[method] === 'function') {\n      window.td[method].apply(window.td, entry.slice(1))\n    }\n  }}\n  queue.forEach(window.__tdEventQueue.push)\n})()\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"gtm-integration","__idx":11},"children":["GTM Integration"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"using-the-ga4-datalayer","__idx":12},"children":["Using the GA4 dataLayer"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If your site already sends GA4 events via GTM, you can intercept the dataLayer and forward events to TD with minimal additional code."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"// GTM Custom HTML Tag — fires on All Pages\n<script>\n;(function () {\n  var _push = window.dataLayer.push.bind(window.dataLayer)\n  window.dataLayer.push = function (event) {\n    _push(event)\n    // Forward GA4-style events to TD\n    if (event && event.event && window.td) {\n      var GA4_EVENTS = [\n        'view_item', 'add_to_cart', 'view_cart',\n        'purchase', 'add_to_wishlist', 'login', 'sign_up'\n      ]\n      if (GA4_EVENTS.indexOf(event.event) !== -1) {\n        var props = Object.assign({}, event)\n        props.event_name = props.event   // preserve as event_name field\n        delete props.event\n        delete props.gtm  // remove GTM internals\n        window.td.trackEvent('events', props)\n      }\n    }\n  }\n})()\n</script>\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"GTM global variable"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The TD Web SDK exposes ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["window.td"]}," (or ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["window.Treasure"]},") as a global, so GTM Custom HTML tags can call ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["window.td.trackEvent(...)"]}," directly without needing additional setup."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"separate-gtm-tag-per-event","__idx":13},"children":["Separate GTM tag per event"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Alternatively, create a GTM ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Custom HTML"]}," tag for each event type, triggered by the corresponding GA4 event or custom GTM trigger:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","header":{"controls":{"copy":{}}},"source":"<!-- GTM tag: fires on GA4 \"view_item\" event -->\n<script>\n  if (window.td && {{ecommerce.items}}) {\n    var item = {{ecommerce.items}}[0] || {}\n    window.td.trackEvent('events', {\n      event_name: 'view_item',\n      item_id: item.item_id,\n      item_name: item.item_name,\n      price: item.price,\n      item_category: item.item_category,\n    })\n  }\n</script>\n","lang":"html"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"using-events-in-rt-20","__idx":14},"children":["Using Events in RT 2.0"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Once events are flowing into your TD database, they become available in RT 2.0 for:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"Feature"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Feature"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"70%","data-label":"How events are used"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["How events are used"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["RT Attributes"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Compute per-user attributes from event history (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["most_recent_product"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["total_spend"]},"). These feed into Entry Criteria and audience segmentation."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Entry Criteria"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Trigger a personalization section when specific event conditions are met (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["item_category == \"electronics\""]},"). Currently supports event name matching (L1); property-based filtering (L2) is planned."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Audience Segments"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Build batch segments from event history (e.g., \"users who purchased in the last 30 days\") for use in campaign targeting."]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"what-the-sdk-will-auto-track-in-the-future","__idx":15},"children":["What the SDK Will Auto-Track in the Future"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following events currently require manual implementation. Future SDK versions will capture them automatically — the table and field names are defined in the SDK Event Requirements specification."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"30%","data-label":"Event"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Event"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"20%","data-label":"Current"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Current"]}," "]},{"$$mdtype":"Tag","name":"th","attributes":{"width":"50%","data-label":"Future (SDK auto)"},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Future (SDK auto)"]}," "]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Page view"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Manual ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["trackEvent('events', { event_name: 'page_view' })"]}," call required on every route change"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Automatic on page load and SPA route change"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Session start / end"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Not available"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Automatic (30-min timeout, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_session_id"]}," attached to all events)"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["First visit"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Not available"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Automatic on first page load (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_first_visit"]}," event)"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Message impression"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Not available"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Automatic when SDK renders a popup or inline message (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_msg_shown"]},")"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Message click"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Not available"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Automatic on CTA interaction (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_msg_clicked"]},")"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Message dismiss"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Not available"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Automatic on close (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td_msg_dismissed"]},")"]}]}]}]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Future-proof your implementation"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using GA4-compatible event names and the flat-field pattern described in this guide means your custom business events will work with future RT 2.0 trigger condition features (L2 property matching) without schema changes."]}]}]},"headings":[{"value":"Event Tracking","id":"event-tracking","depth":1},{"value":"Event Architecture","id":"event-architecture","depth":2},{"value":"GA4-Compatible Event Naming","id":"ga4-compatible-event-naming","depth":2},{"value":"Standard e-commerce events","id":"standard-e-commerce-events","depth":3},{"value":"Property naming conventions","id":"property-naming-conventions","depth":3},{"value":"Sending Events","id":"sending-events","depth":2},{"value":"Basic event","id":"basic-event","depth":3},{"value":"Cart event","id":"cart-event","depth":3},{"value":"Purchase event","id":"purchase-event","depth":3},{"value":"Handling array data (items)","id":"handling-array-data-items","depth":3},{"value":"Firing Events Before the SDK Loads","id":"firing-events-before-the-sdk-loads","depth":2},{"value":"GTM Integration","id":"gtm-integration","depth":2},{"value":"Using the GA4 dataLayer","id":"using-the-ga4-datalayer","depth":3},{"value":"Separate GTM tag per event","id":"separate-gtm-tag-per-event","depth":3},{"value":"Using Events in RT 2.0","id":"using-events-in-rt-20","depth":2},{"value":"What the SDK Will Auto-Track in the Future","id":"what-the-sdk-will-auto-track-in-the-future","depth":2}],"frontmatter":{"seo":{"title":"Event Tracking — In-Browser Messaging","description":"Define and implement business events for In-Browser Messaging using GA4-compatible naming, including page views, product interactions, and cart events."}},"lastModified":"2026-06-18T03:34:22.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/marketing-cloud/engage-studio/experiences/event-tracking","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}