{"title":"Track","description":"Track product events from SDKs or API clients and make behavioral data queryable in your Altertable lakehouse.","order":200,"askSuggestions":["Which events should I track first?","How do I add page or screen context to every event?","Does my SDK batch events automatically?"],"navigation":true,"body":{"code":"var Component=(()=>{var m=Object.create;var o=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var k=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),I=(t,n)=>{for(var s in n)o(t,s,{get:n[s],enumerable:!0})},d=(t,n,s,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of f(n))!y.call(t,r)&&r!==s&&o(t,r,{get:()=>n[r],enumerable:!(i=v(n,r))||i.enumerable});return t};var w=(t,n,s)=>(s=t!=null?m(g(t)):{},d(n||!t||!t.__esModule?o(s,\"default\",{value:t,enumerable:!0}):s,t)),T=t=>d(o({},\"__esModule\",{value:!0}),t);var h=k((x,l)=>{l.exports=_jsx_runtime});var D={};I(D,{default:()=>u,frontmatter:()=>b});var e=w(h()),b={title:\"Track\",description:\"Track product events from SDKs or API clients and make behavioral data queryable in your Altertable lakehouse.\",order:200,askSuggestions:[\"Which events should I track first?\",\"How do I add page or screen context to every event?\",\"Does my SDK batch events automatically?\"]};function p(t){let n={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",li:\"li\",p:\"p\",ul:\"ul\",...t.components},{DocsPreviewDocument:s,DocsPreviewSection:i,DocsSdkContent:r,DocsSdkSnippetTabs:c}=n;return s||a(\"DocsPreviewDocument\",!0),i||a(\"DocsPreviewSection\",!0),r||a(\"DocsSdkContent\",!0),c||a(\"DocsSdkSnippetTabs\",!0),(0,e.jsxs)(s,{anchors:\"track-events when-to-call-it sdk-examples audience-measurement batch-events transform-events api-reference best-practices\",children:[(0,e.jsxs)(i,{sectionId:\"track-events\",sectionTitle:\"Track Events\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,e.jsx)(n.h1,{id:\"track-events\",children:\"Track Events\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Use \",(0,e.jsx)(n.code,{children:\"track\"}),\" to record product actions such as signups, purchases, feature usage, page views, and activation milestones.\"]}),`\n`,(0,e.jsx)(n.p,{children:\"Track a small set of meaningful events first. A few stable event names with useful properties are easier to query than a large stream of low-signal UI clicks.\"}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"when-to-call-it\",sectionTitle:\"When to call it\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,e.jsx)(n.h2,{id:\"when-to-call-it\",children:\"When to call it\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Use \",(0,e.jsx)(n.code,{children:\"track\"}),\" when something happened in your product and you want it available for segmentation, retention, funnel analysis, SQL, or AI agents.\"]}),`\n`,(0,e.jsx)(n.p,{children:\"Good first events often describe:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"activation moments\"}),`\n`,(0,e.jsx)(n.li,{children:\"conversion steps\"}),`\n`,(0,e.jsx)(n.li,{children:\"recurring feature usage\"}),`\n`,(0,e.jsx)(n.li,{children:\"billing or account lifecycle changes\"}),`\n`]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"sdk-examples\",sectionTitle:\"SDK examples\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,e.jsx)(n.h2,{id:\"sdk-examples\",children:\"SDK examples\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Use \",(0,e.jsx)(n.code,{children:\"track()\"}),\" where the product action happens:\"]}),`\n`,(0,e.jsx)(c,{snippetId:\"track\"}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"distinct_id\"}),\" ties an event to a person, device, or session. Client-side SDKs can manage anonymous IDs automatically. In product mode, server-side SDKs and direct API clients should pass a stable ID on each call.\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"Call \",(0,e.jsx)(n.a,{href:\"/docs/product-analytics/identify\",children:(0,e.jsx)(n.code,{children:\"identify()\"})}),\" when you know who the user is, so anonymous and authenticated activity can be analyzed together.\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"audience-measurement\",sectionTitle:\"Audience measurement\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,e.jsx)(n.h2,{id:\"audience-measurement\",children:\"Audience measurement\"}),`\n`,(0,e.jsx)(n.p,{children:\"Use audience mode to measure aggregate usage without identifying people. Create the client in audience mode with an API key bound to an environment. The mode stays fixed for the client's lifetime.\"}),`\n`,(0,e.jsx)(c,{snippetId:\"audience\"}),`\n`,(0,e.jsx)(n.p,{children:\"In audience mode, the SDK:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"Sends events without user, anonymous, session, or device IDs.\"}),`\n`,(0,e.jsxs)(n.li,{children:[\"Ignores \",(0,e.jsx)(n.code,{children:\"identify\"}),\", \",(0,e.jsx)(n.code,{children:\"alias\"}),\", and \",(0,e.jsx)(n.code,{children:\"updateTraits\"}),\".\"]}),`\n`,(0,e.jsx)(n.li,{children:\"Keeps queued events in memory only. Events that are not sent before the page or app closes are lost.\"}),`\n`]}),`\n`,(0,e.jsx)(r,{languageIds:[\"typescript\",\"react\",\"swift\",\"kotlin\"],children:(0,e.jsx)(n.p,{children:\"The SDK also trims automatic context: URLs keep only their origin and path, and the referrer keeps only its origin.\"})}),`\n`,(0,e.jsx)(r,{languageIds:[\"react-native\"],children:(0,e.jsxs)(n.p,{children:[\"The SDK also leaves out OS context and never touches native storage, so you can omit the \",(0,e.jsx)(n.code,{children:\"storage\"}),\" option.\"]})}),`\n`,(0,e.jsx)(r,{languageIds:[\"python\",\"ruby\"],children:(0,e.jsx)(n.p,{children:\"Events come from your server, so audience mode cannot tell individual browser visitors apart.\"})}),`\n`,(0,e.jsx)(n.p,{children:\"Event names and custom properties are sent unchanged, so keep personal data out of them. For example, track a search's result count rather than its query.\"}),`\n`,(0,e.jsx)(r,{languageIds:[\"typescript\",\"react\",\"react-native\",\"swift\",\"kotlin\"],children:(0,e.jsx)(n.p,{children:\"Audience mode does not replace consent. Events wait in memory while consent is pending, and the SDK discards them if consent is denied.\"})}),`\n`,(0,e.jsx)(r,{languageIds:[\"typescript\",\"react\"],children:(0,e.jsx)(n.p,{children:\"The PostHog adapter forwards PostHog's own identities, so it does not support audience mode.\"})}),`\n`,(0,e.jsxs)(n.p,{children:[\"To send audience events over HTTP, set \",(0,e.jsx)(n.code,{children:'mode: \"audience\"'}),\" on each event and leave out \",(0,e.jsx)(n.code,{children:\"distinct_id\"}),\", \",(0,e.jsx)(n.code,{children:\"anonymous_id\"}),\", \",(0,e.jsx)(n.code,{children:\"session_id\"}),\", and \",(0,e.jsx)(n.code,{children:\"device_id\"}),\". The \",(0,e.jsx)(n.a,{href:\"/docs/api-references/product-analytics#post-track\",children:\"track API\"}),\" rejects audience events that include them with \",(0,e.jsx)(n.code,{children:\"audience-identity-not-allowed\"}),\".\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"batch-events\",sectionTitle:\"Batch events\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,e.jsx)(n.h2,{id:\"batch-events\",children:\"Batch events\"}),`\n`,(0,e.jsx)(r,{languageIds:[\"typescript\",\"react\",\"react-native\",\"swift\",\"kotlin\"],children:(0,e.jsx)(n.p,{children:\"The SDK queues your calls and sends them in batches, so you don't need to group events yourself.\"})}),`\n`,(0,e.jsx)(r,{languageIds:[\"python\",\"ruby\"],children:(0,e.jsx)(n.p,{children:\"The SDK sends each call as its own request. To send several events in one request, pass an array:\"})}),`\n`,(0,e.jsx)(c,{snippetId:\"batch-track\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Direct HTTP clients can also send an array to \",(0,e.jsx)(n.a,{href:\"/docs/api-references/product-analytics#post-track\",children:(0,e.jsx)(n.code,{children:\"POST /track\"})}),\".\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"transform-events\",sectionTitle:\"Transform events\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,e.jsx)(n.h2,{id:\"transform-events\",children:\"Transform events\"}),`\n`,(0,e.jsx)(n.p,{children:\"Some SDKs let you change or drop events before they are sent. These examples label the product area from the page URL or screen name and record the surface that produced the event:\"}),`\n`,(0,e.jsx)(c,{snippetId:\"transform-event\"}),`\n`,(0,e.jsx)(r,{languageIds:[\"typescript\",\"react\"],children:(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"transformEvent\"}),\" runs on track and page events after the SDK adds context and identifiers. Return \",(0,e.jsx)(n.code,{children:\"null\"}),\" to drop an event. If the function throws, the SDK drops the event and reports the error to \",(0,e.jsx)(n.code,{children:\"onError\"}),\". It does not run on identify, alias, or events forwarded from \",(0,e.jsx)(n.a,{href:\"/docs/lakehouse/ingest/integrations/posthog\",children:\"PostHog\"}),\".\"]})}),`\n`,(0,e.jsx)(r,{languageIds:[\"react\"],children:(0,e.jsxs)(n.p,{children:[\"Configure the shared JavaScript client before rendering \",(0,e.jsx)(n.code,{children:\"<AltertableProvider>\"}),\".\"]})}),`\n`,(0,e.jsx)(r,{languageIds:[\"react-native\"],children:(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"transformEvent\"}),\" runs on track and screen events after the SDK adds context and identifiers. Return \",(0,e.jsx)(n.code,{children:\"null\"}),\" to drop an event. If the function throws, the SDK drops the event and reports the error to \",(0,e.jsx)(n.code,{children:\"onError\"}),\". It does not run on identify or alias.\"]})}),`\n`,(0,e.jsx)(r,{languageIds:[\"kotlin\"],children:(0,e.jsxs)(n.p,{children:[\"Each \",(0,e.jsx)(n.code,{children:\"beforeSend\"}),\" interceptor receives track, identify, and alias events. Return \",(0,e.jsx)(n.code,{children:\"null\"}),\" to drop an event.\"]})}),`\n`,(0,e.jsx)(r,{languageIds:[\"typescript\",\"react\",\"react-native\",\"kotlin\"],children:(0,e.jsx)(n.p,{children:\"In audience mode, the SDK applies its identity and context restrictions after your transformation runs.\"})}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"api-reference\",sectionTitle:\"API reference\",anchors:\"\",ancestors:\"\",index:\"6\",children:[(0,e.jsx)(n.h2,{id:\"api-reference\",children:\"API reference\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"For HTTP request details, batching behavior, response shape, and error codes, see \",(0,e.jsx)(n.a,{href:\"/docs/api-references/product-analytics#post-track\",children:(0,e.jsx)(n.code,{children:\"POST /track\"})}),\".\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"best-practices\",sectionTitle:\"Best practices\",anchors:\"\",ancestors:\"\",index:\"7\",children:[(0,e.jsx)(n.h2,{id:\"best-practices\",children:\"Best practices\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"Use clear event names and keep them stable over time.\"}),`\n`,(0,e.jsx)(n.li,{children:\"Track meaningful product actions, not every low-level interaction.\"}),`\n`,(0,e.jsx)(n.li,{children:\"Include only properties you plan to filter, group, or query.\"}),`\n`,(0,e.jsx)(n.li,{children:\"Avoid secrets and regulated sensitive data in event properties.\"}),`\n`]})]})]})}function u(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,{...t,children:(0,e.jsx)(p,{...t})}):p(t)}function a(t,n){throw new Error(\"Expected \"+(n?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return T(D);})();\n;return Component;"},"_id":"docs/product-analytics/track.mdx","_raw":{"sourceFilePath":"docs/product-analytics/track.mdx","sourceFileName":"track.mdx","sourceFileDir":"docs/product-analytics","contentType":"mdx","flattenedPath":"docs/product-analytics/track"},"type":"Docs","path":"/product-analytics/track","level":2,"parent":"product-analytics"}