{"title":"Product Analytics API","description":"Product Analytics HTTP API reference for tracking events, identifying users, and authenticating HTTP requests from your applications.","order":300,"codeExamples":true,"askSuggestions":["Which header should I use to send my API key?","How do I wait for an event to finish ingesting?","Why is my /track request rejected?"],"navigation":true,"body":{"code":"var Component=(()=>{var m=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var P=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),v=(i,e)=>{for(var t in e)d(i,t,{get:e[t],enumerable:!0})},l=(i,e,t,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of g(e))!A.call(i,r)&&r!==t&&d(i,r,{get:()=>e[r],enumerable:!(s=f(e,r))||s.enumerable});return i};var k=(i,e,t)=>(t=i!=null?m(b(i)):{},l(e||!i||!i.__esModule?d(t,\"default\",{value:i,enumerable:!0}):t,i)),I=i=>l(d({},\"__esModule\",{value:!0}),i);var h=P((w,u)=>{u.exports=_jsx_runtime});var T={};v(T,{default:()=>y,frontmatter:()=>_});var n=k(h()),_={title:\"Product Analytics API\",description:\"Product Analytics HTTP API reference for tracking events, identifying users, and authenticating HTTP requests from your applications.\",order:300,codeExamples:!0,askSuggestions:[\"Which header should I use to send my API key?\",\"How do I wait for an event to finish ingesting?\",\"Why is my /track request rejected?\"]};function p(i){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...i.components},{DocsApiReferenceEndpoint:t,DocsApiReferenceQuickReference:s,DocsPreviewDocument:r,DocsPreviewSection:o,DocsTable:c}=e;return t||a(\"DocsApiReferenceEndpoint\",!0),s||a(\"DocsApiReferenceQuickReference\",!0),r||a(\"DocsPreviewDocument\",!0),o||a(\"DocsPreviewSection\",!0),c||a(\"DocsTable\",!0),(0,n.jsxs)(r,{anchors:\"product-analytics-api authentication response-statuses post-track post-identify post-alias related-guides\",children:[(0,n.jsxs)(o,{sectionId:\"product-analytics-api\",sectionTitle:\"Product Analytics API\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,n.jsx)(e.h1,{id:\"product-analytics-api\",children:\"Product Analytics API\"}),`\n`,(0,n.jsx)(s,{items:[{label:\"Base URL\",value:\"https://api.altertable.ai\"},{label:\"Authentication\",value:\"Public API key\",to:\"#authentication\"},{label:\"Recommended client\",value:\"Product Analytics SDKs\",to:\"/docs/product-analytics/setup#2-initialize-the-client-and-send-data\"}],links:[{label:\"Track events\",to:\"#post-track\"},{label:\"Identify users\",to:\"#post-identify\"},{label:\"Merge identities\",to:\"#post-alias\"}]}),`\n`,(0,n.jsxs)(e.p,{children:[\"The Product Analytics API provides direct HTTP access to track events and identify users. For most applications, use an \",(0,n.jsx)(e.a,{href:\"/docs/product-analytics/setup#2-initialize-the-client-and-send-data\",children:\"SDK\"}),\" instead. Client-side SDKs manage anonymous IDs, sessions, batching, and retries for you.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Successful responses return \",(0,n.jsx)(e.code,{children:\"ok: true\"}),\", an optional \",(0,n.jsx)(e.code,{children:\"task_id\"}),\", and nullable \",(0,n.jsx)(e.code,{children:\"error_code\"}),\". A \",(0,n.jsx)(e.code,{children:\"task_id\"}),\" identifies asynchronous processing; it does not mean processing has finished.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"See the \",(0,n.jsx)(e.a,{href:\"https://api.altertable.ai/openapi/product-analytics.json\",children:\"deployed OpenAPI contract\"}),\" for machine-readable schemas.\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"authentication\",sectionTitle:\"Authentication\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,n.jsx)(e.h2,{id:\"authentication\",children:\"Authentication\"}),`\n`,(0,n.jsx)(e.p,{children:\"All API requests require a public Product Analytics API key for the target environment.\"}),`\n`,(0,n.jsx)(c,{columns:[\"Method\",\"Value\"],data:[{Method:\"`X-API-Key` header\",Value:\"`X-API-Key: {{API_KEY}}`\"},{Method:\"`Authorization` header\",Value:\"`Authorization: Bearer {{API_KEY}}`\"},{Method:\"Query parameter\",Value:\"`?apiKey={{API_KEY}}`\"}]}),`\n`,(0,n.jsx)(e.p,{children:\"These keys accept product events and identity updates. They do not authorize lakehouse SQL queries or access to historical analytics data. Prefer a header over the query parameter so the key does not appear in request URLs and access logs.\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"See the \",(0,n.jsx)(e.a,{href:\"/docs/product-analytics/authentication\",children:\"Authentication guide\"}),\" for details on obtaining and managing API keys.\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"response-statuses\",sectionTitle:\"Response statuses\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,n.jsx)(e.h2,{id:\"response-statuses\",children:\"Response statuses\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"200\"}),\": JSON acceptance response, as shown for each endpoint.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"400\"}),\": JSON rejection such as \",(0,n.jsx)(e.code,{children:'{\"ok\":false,\"error_code\":\"environment-not-found\"}'}),\". The endpoint sections list domain error codes.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"401\"}),\": plain-text authentication error: \",(0,n.jsx)(e.code,{children:\"API key is required\"}),\" or \",(0,n.jsx)(e.code,{children:\"Unauthorized\"}),\".\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"All three endpoints accept one JSON object or an array. Send \",(0,n.jsx)(e.code,{children:\"Content-Type: application/json\"}),\".\"]}),`\n`]}),(0,n.jsx)(o,{sectionId:\"post-track\",sectionTitle:\"\",anchors:\"post-track\",ancestors:\"response-statuses\",index:\"3\",children:(0,n.jsxs)(t,{id:\"post-track\",method:\"POST\",path:\"/track\",summary:\"Track one event or a batch of events.\",authentication:\"Public Product Analytics API key\",permission:\"Write events\",parameters:[{name:\"sync\",type:\"boolean\",location:\"query\",required:!1,description:\"Wait for ingestion to finish before returning when true.\"},{name:\"environment\",type:\"string\",location:\"body\",required:!1,description:\"Environment slug. Omit to use the API key environment; required for keys without an environment binding.\"},{name:\"mode\",type:\"product | audience\",location:\"body\",required:!1,description:\"Defaults to product. Audience events cannot supply identity fields.\"},{name:\"event\",type:\"string\",location:\"body\",required:!0,description:\"Event name.\"},{name:\"properties\",type:\"object\",location:\"body\",required:!0,description:\"Custom key-value properties. Send an empty object when no properties apply.\"},{name:\"distinct_id\",type:\"string\",location:\"body\",required:!1,description:\"User or visitor identifier.\"},{name:\"anonymous_id\",type:\"string\",location:\"body\",required:!1,description:\"Anonymous identifier used before the user is known.\"},{name:\"device_id\",type:\"string\",location:\"body\",required:!1,description:\"Device identifier.\"},{name:\"session_id\",type:\"string\",location:\"body\",required:!1,description:\"Session identifier.\"},{name:\"timestamp\",type:\"integer | ISO 8601 string\",location:\"body\",required:!1,description:\"Event time as Unix milliseconds or an ISO 8601 timestamp.\"}],requestExamples:[{language:\"curl\",code:`curl -X POST https://api.altertable.ai/track \\\\\n  -H \"X-API-Key: {{API_KEY}}\" \\\\\n  -H \"Content-Type: application/json\" \\\\\n  -d '{\n    \"event\": \"Purchase Completed\",\n    \"properties\": {\"amount\": 99.99, \"currency\": \"USD\"},\n    \"distinct_id\": \"u_01jza857w4f23s1hf2s61befmw\"\n  }'`},{language:\"javascript\",code:`await fetch('https://api.altertable.ai/track', {\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    'X-API-Key': process.env.ALTERTABLE_API_KEY,\n  },\n  body: JSON.stringify({\n    event: 'Purchase Completed',\n    properties: { amount: 99.99, currency: 'USD' },\n    distinct_id: 'u_01jza857w4f23s1hf2s61befmw',\n  }),\n});`}],response:{status:\"200 OK\",language:\"json\",code:'{\"ok\":true,\"task_id\":\"019d68d4-c4cb-7e40-ad50-fd4b68c2045e\",\"error_code\":null}'},children:[(0,n.jsx)(e.h3,{id:\"error-codes\",children:\"Error codes\"}),(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"environment-not-found\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"product-analytics-not-enabled\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"invalid-headers\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"audience-identity-not-allowed\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"unknown-built-in-property\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"event-name-too-long\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"property-name-too-long\"})}),`\n`]}),(0,n.jsx)(e.p,{children:\"Event names and property names can contain up to 400 characters. Requests with longer names are rejected before ingestion.\"}),(0,n.jsx)(e.h3,{id:\"audience-events\",children:\"Audience events\"}),(0,n.jsxs)(e.p,{children:[\"Set \",(0,n.jsx)(e.code,{children:\"mode\"}),\" to \",(0,n.jsx)(e.code,{children:\"audience\"}),\" and omit all four identity fields: \",(0,n.jsx)(e.code,{children:\"distinct_id\"}),\", \",(0,n.jsx)(e.code,{children:\"anonymous_id\"}),\", \",(0,n.jsx)(e.code,{children:\"session_id\"}),\", and \",(0,n.jsx)(e.code,{children:\"device_id\"}),\".\"]}),(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-bash\",children:`curl https://api.altertable.ai/track \\\\\n  -H \"Authorization: Bearer $ALTERTABLE_API_KEY\" \\\\\n  -H \"Content-Type: application/json\" \\\\\n  -d '{\"mode\":\"audience\",\"event\":\"Search Performed\",\"properties\":{\"result_count\":12}}'\n`})}),(0,n.jsxs)(e.p,{children:[\"Audience mode rejects supplied identity fields with \",(0,n.jsx)(e.code,{children:\"audience-identity-not-allowed\"}),\". It does not remove personal data from custom event names or properties.\"]})]})}),(0,n.jsx)(o,{sectionId:\"post-identify\",sectionTitle:\"\",anchors:\"post-identify\",ancestors:\"response-statuses\",index:\"4\",children:(0,n.jsxs)(t,{id:\"post-identify\",method:\"POST\",path:\"/identify\",summary:\"Create or update one identity or a batch of identities.\",authentication:\"Public Product Analytics API key\",permission:\"Write identities\",parameters:[{name:\"sync\",type:\"boolean\",location:\"query\",required:!1,description:\"Wait for ingestion to finish before returning when true.\"},{name:\"environment\",type:\"string\",location:\"body\",required:!1,description:\"Environment slug. Omit to use the API key environment; required for keys without an environment binding.\"},{name:\"distinct_id\",type:\"string\",location:\"body\",required:!0,description:\"The user's unique identifier.\"},{name:\"anonymous_id\",type:\"string\",location:\"body\",required:!1,description:\"Previous visitor ID used to link anonymous events.\"},{name:\"traits\",type:\"object\",location:\"body\",required:!1,description:\"User traits to shallow-merge into the existing identity.\"},{name:\"timestamp\",type:\"integer | ISO 8601 string\",location:\"body\",required:!1,description:\"Timestamp used for last-write-wins ordering.\"}],requestExamples:[{language:\"curl\",code:`curl -X POST https://api.altertable.ai/identify \\\\\n  -H \"X-API-Key: {{API_KEY}}\" \\\\\n  -H \"Content-Type: application/json\" \\\\\n  -d '{\n    \"distinct_id\": \"u_01jza857w4f23s1hf2s61befmw\",\n    \"traits\": {\"email\": \"john.doe@example.com\", \"plan\": \"premium\"}\n  }'`}],response:{status:\"200 OK\",language:\"json\",code:`{\n  \"ok\": true,\n  \"task_id\": \"019d68d4-c4cb-7e40-ad50-fd5bd4956505\",\n  \"error_code\": null\n}`},children:[(0,n.jsx)(e.h3,{id:\"error-codes-1\",children:\"Error codes\"}),(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"environment-not-found\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"product-analytics-not-enabled\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"trait-name-too-long\"})}),`\n`]}),(0,n.jsx)(e.p,{children:\"Trait names can contain up to 400 characters. Requests with longer trait names are rejected before ingestion.\"})]})}),(0,n.jsx)(o,{sectionId:\"post-alias\",sectionTitle:\"\",anchors:\"post-alias\",ancestors:\"response-statuses\",index:\"5\",children:(0,n.jsxs)(t,{id:\"post-alias\",method:\"POST\",path:\"/alias\",summary:\"Merge an existing distinct ID into the user ID that should remain.\",authentication:\"Public Product Analytics API key\",permission:\"Write identities\",parameters:[{name:\"sync\",type:\"boolean\",location:\"query\",required:!1,description:\"Wait for the task to finish before returning.\"},{name:\"environment\",type:\"string\",location:\"body\",required:!1,description:\"Environment slug. Omit to use the API key environment; required for keys without an environment binding.\"},{name:\"distinct_id\",type:\"string\",location:\"body\",required:!0,description:\"Existing ID to merge into the target user.\"},{name:\"new_user_id\",type:\"string\",location:\"body\",required:!0,description:\"Target user ID that should remain.\"}],requestExamples:[{language:\"curl\",code:`curl -X POST https://api.altertable.ai/alias \\\\\n  -H \"X-API-Key: {{API_KEY}}\" \\\\\n  -H \"Content-Type: application/json\" \\\\\n  -d '{\n    \"distinct_id\":\"legacy:user_123\",\n    \"new_user_id\":\"u_01jza857w4f23s1hf2s61befmw\"\n  }'`}],response:{status:\"200 OK\",language:\"json\",code:`{\n  \"ok\": true,\n  \"task_id\": \"019d68d4-c4cb-7e40-ad50-fd5bd4956505\",\n  \"error_code\": null\n}`},children:[(0,n.jsxs)(e.p,{children:[\"Use \",(0,n.jsx)(e.code,{children:\"/alias\"}),\" only when changing ID systems or attaching an external identifier to a known user. Most login and signup flows should use \",(0,n.jsx)(e.a,{href:\"/docs/api-references/product-analytics#post-identify\",children:(0,n.jsx)(e.code,{children:\"/identify\"})}),\".\"]}),(0,n.jsx)(e.p,{children:\"The API also accepts an array of alias payloads for batch merges.\"}),(0,n.jsx)(e.h3,{id:\"error-codes-2\",children:\"Error codes\"}),(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"environment-not-found\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.code,{children:\"product-analytics-not-enabled\"})}),`\n`]})]})}),(0,n.jsxs)(o,{sectionId:\"related-guides\",sectionTitle:\"Related guides\",anchors:\"\",ancestors:\"\",index:\"6\",children:[(0,n.jsx)(e.h2,{id:\"related-guides\",children:\"Related guides\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"/docs/product-analytics/setup\",children:\"Set up tracking\"}),\" to install and initialize an SDK.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"/docs/product-analytics/track\",children:\"Track events\"}),\" to choose events and properties.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"/docs/product-analytics/identify\",children:\"Identify users\"}),\" to link activity to user profiles.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"/docs/product-analytics/alias\",children:\"Alias users\"}),\" to merge identifiers.\"]}),`\n`]})]})]})}function y(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,{...i,children:(0,n.jsx)(p,{...i})}):p(i)}function a(i,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+i+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return I(T);})();\n;return Component;"},"_id":"docs/api-references/product-analytics.mdx","_raw":{"sourceFilePath":"docs/api-references/product-analytics.mdx","sourceFileName":"product-analytics.mdx","sourceFileDir":"docs/api-references","contentType":"mdx","flattenedPath":"docs/api-references/product-analytics"},"type":"Docs","path":"/api-references/product-analytics","level":2,"parent":"api-references"}