{"title":"Set up tracking","description":"Authenticate clients, track events, identify users, and alias identities into the built-in `product_analytics` catalog.","order":100,"askSuggestions":["Should I use a client-side or server-side SDK?","How do I check that my first event arrived?","Why are no events showing up after setup?"],"navigation":true,"routeId":"ingestDataProductAnalytics","body":{"code":"var Component=(()=>{var k=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var I=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),A=(t,n)=>{for(var s in n)c(t,s,{get:n[s],enumerable:!0})},g=(t,n,s,o)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let i of S(n))!b.call(t,i)&&i!==s&&c(t,i,{get:()=>n[i],enumerable:!(o=w(n,i))||o.enumerable});return t};var x=(t,n,s)=>(s=t!=null?k(D(t)):{},g(n||!t||!t.__esModule?c(s,\"default\",{value:t,enumerable:!0}):s,t)),P=t=>g(c({},\"__esModule\",{value:!0}),t);var f=I((T,y)=>{y.exports=_jsx_runtime});var K={};A(K,{default:()=>v,frontmatter:()=>C});var e=x(f()),C={title:\"Set up tracking\",routeId:\"ingestDataProductAnalytics\",description:\"Authenticate clients, track events, identify users, and alias identities into the built-in `product_analytics` catalog.\",order:100,askSuggestions:[\"Should I use a client-side or server-side SDK?\",\"How do I check that my first event arrived?\",\"Why are no events showing up after setup?\"]};function m(t){let n={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",ol:\"ol\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...t.components},{DocsAppAction:s,DocsPreviewDocument:o,DocsPreviewSection:i,DocsPrompt:l,DocsSdkCodeTabs:h,DocsSdkContent:a,DocsSdkInstallTabs:p,DocsSdkSnippetTabs:d,DocsSectionCards:u}=n;return s||r(\"DocsAppAction\",!0),o||r(\"DocsPreviewDocument\",!0),i||r(\"DocsPreviewSection\",!0),l||r(\"DocsPrompt\",!0),h||r(\"DocsSdkCodeTabs\",!0),a||r(\"DocsSdkContent\",!0),p||r(\"DocsSdkInstallTabs\",!0),d||r(\"DocsSdkSnippetTabs\",!0),u||r(\"DocsSectionCards\",!0),(0,e.jsxs)(o,{anchors:\"set-up-tracking set-up-with-your-coding-agent goal prerequisites steps 1-install-an-sdk 2-initialize-the-client-and-send-data 3-check-where-your-sdk-runs 4-configure-page-screen-and-consent-helpers verification choose-a-collection-mode troubleshooting next-steps\",children:[(0,e.jsxs)(i,{sectionId:\"set-up-tracking\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,e.jsx)(n.h1,{id:\"set-up-tracking\",children:\"Set up tracking\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Send product events and identity updates to Altertable with SDKs or direct HTTP requests. The same payload model writes to the built-in \",(0,e.jsx)(n.code,{children:\"product_analytics\"}),\" catalog, so client, server, mobile, and batch sources can be analyzed together.\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"set-up-with-your-coding-agent\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,e.jsx)(n.h2,{id:\"set-up-with-your-coding-agent\",children:\"Set up with your coding agent\"}),`\n`,(0,e.jsx)(n.p,{children:\"Open this prompt in your coding agent from your application repository. It will inspect your stack and guide the implementation.\"}),`\n`,(0,e.jsx)(l,{children:(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-text\",children:`Set up Altertable Product Analytics in this repository. Read https://altertable.ai/docs/product-analytics/setup.md and the linked official SDK documentation first.\n\nInspect my framework, runtime, package manager, authentication, and existing analytics. Choose the matching SDK. Ask which user journey I want to measure and propose a small event plan before changing code.\n\nGuide me through enabling Product Analytics and configuring its environment-specific API key without committing secrets. MCP and lakehouse credentials do not replace this key.\n\nReuse or initialize one shared client. Track completed actions, identify signed-in users, reset identity at sign-out, and respect consent. Check which helpers the SDK supports and avoid sensitive properties.\n\nRun checks. Send one named verification event with a unique test identity in the chosen environment. Query product_analytics.main.events by that event name and identity, and confirm the properties and timestamp. Do not use the newest row as proof. Use my Altertable connection if available. Summarize changed files, verification results, and remaining setup.\n`})})}),`\n`,(0,e.jsx)(n.p,{children:\"Prefer to configure it yourself? Follow the steps below.\"}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"goal\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,e.jsx)(n.h2,{id:\"goal\",children:\"Goal\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Choose an SDK, connect it with a Product Analytics API key, and send events and identity updates to the built-in \",(0,e.jsx)(n.code,{children:\"product_analytics\"}),\" catalog.\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"prerequisites\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,e.jsx)(n.h2,{id:\"prerequisites\",children:\"Prerequisites\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[\"Enable \",(0,e.jsx)(n.a,{href:\"/docs/product-analytics\",children:\"Product Analytics\"}),\" for the target environment.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"Copy a Product Analytics \",(0,e.jsx)(n.a,{href:\"/docs/product-analytics/authentication\",children:\"API key\"}),\".\"]}),`\n`,(0,e.jsx)(n.li,{children:\"Choose a client-side or server-side SDK based on where your application sends events.\"}),`\n`]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"steps\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,e.jsx)(n.h2,{id:\"steps\",children:\"Steps\"}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"1-install-an-sdk\",anchors:\"\",ancestors:\"steps\",index:\"5\",children:[(0,e.jsx)(n.h3,{id:\"1-install-an-sdk\",children:\"1. Install an SDK\"}),`\n`,(0,e.jsx)(n.p,{children:\"Choose the SDK for your application language:\"}),`\n`,(0,e.jsx)(p,{}),`\n`,(0,e.jsx)(a,{languageIds:[\"react-native\"],children:(0,e.jsxs)(n.p,{children:[\"The command also installs AsyncStorage, which keeps identity and unsent events across restarts. In Expo projects, install AsyncStorage with \",(0,e.jsx)(n.code,{children:\"npx expo install @react-native-async-storage/async-storage\"}),\" instead. In bare React Native projects, run \",(0,e.jsx)(n.code,{children:\"npx pod-install\"}),\" afterward to install the iOS dependencies.\"]})}),`\n`,(0,e.jsx)(a,{languageIds:[\"swift\"],children:(0,e.jsxs)(n.p,{children:[\"Add the package declaration to the \",(0,e.jsx)(n.code,{children:\"dependencies\"}),\" in \",(0,e.jsx)(n.code,{children:\"Package.swift\"}),\", then link the \",(0,e.jsx)(n.code,{children:\"Altertable\"}),\" product to your target.\"]})}),`\n`,(0,e.jsx)(a,{languageIds:[\"kotlin\"],children:(0,e.jsxs)(n.p,{children:[\"Add the dependency to \",(0,e.jsx)(n.code,{children:\"build.gradle.kts\"}),\" and include Maven Central in your Gradle repositories. Android apps add the \",(0,e.jsx)(n.code,{children:\"altertable-android\"}),\" dependency as well.\"]})}),`\n`,(0,e.jsxs)(n.p,{children:[\"See the \",(0,e.jsx)(n.a,{href:\"/docs/api-references/sdks#product-analytics-sdks\",children:\"SDK reference\"}),\" for versions and platform requirements.\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"2-initialize-the-client-and-send-data\",anchors:\"\",ancestors:\"steps\",index:\"6\",children:[(0,e.jsx)(n.h3,{id:\"2-initialize-the-client-and-send-data\",children:\"2. Initialize the client and send data\"}),`\n`,(0,e.jsx)(n.p,{children:\"Use these examples as the starting point for your application code:\"}),`\n`,(0,e.jsx)(h,{category:\"product-analytics\"}),`\n`,(0,e.jsx)(a,{languageIds:[\"react-native\"],children:(0,e.jsxs)(n.p,{children:[\"Await \",(0,e.jsx)(n.code,{children:\"createAltertable()\"}),\" before rendering components that call \",(0,e.jsx)(n.code,{children:\"useAltertable()\"}),\". It restores identity, consent, and unsent events, and rejects if storage cannot be read.\"]})}),`\n`,(0,e.jsx)(n.p,{children:\"After initialization:\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsx)(n.li,{children:\"Track events with event properties.\"}),`\n`,(0,e.jsx)(n.li,{children:\"Identify users and attach traits.\"}),`\n`,(0,e.jsx)(n.li,{children:\"Optionally alias related identities.\"}),`\n`]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"3-check-where-your-sdk-runs\",anchors:\"\",ancestors:\"steps\",index:\"7\",children:[(0,e.jsx)(n.h3,{id:\"3-check-where-your-sdk-runs\",children:\"3. Check where your SDK runs\"}),`\n`,(0,e.jsx)(n.p,{children:\"Client-side SDKs run in a browser or app and keep one identity per client. Server-side SDKs run in backend services or jobs that send events for many users.\"}),`\n`,(0,e.jsx)(a,{languageIds:[\"typescript\",\"react\",\"react-native\",\"swift\",\"kotlin\"],children:(0,e.jsxs)(n.p,{children:[\"The SDK runs client-side and manages anonymous IDs, sessions, and queued events for you. Call \",(0,e.jsx)(n.code,{children:\"identify\"}),\" when a user signs in.\"]})}),`\n`,(0,e.jsx)(a,{languageIds:[\"python\",\"ruby\"],children:(0,e.jsxs)(n.p,{children:[\"The SDK runs server-side, so pass a stable \",(0,e.jsx)(n.code,{children:\"distinct_id\"}),\" on each call to associate the event with its user.\"]})}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"4-configure-page-screen-and-consent-helpers\",anchors:\"\",ancestors:\"steps\",index:\"8\",children:[(0,e.jsx)(n.h3,{id:\"4-configure-page-screen-and-consent-helpers\",children:\"4. Configure page, screen, and consent helpers\"}),`\n`,(0,e.jsx)(n.p,{children:\"If your SDK provides page or screen helpers, configure them for the views you want to track:\"}),`\n`,(0,e.jsx)(d,{snippetId:\"page-screen\"}),`\n`,(0,e.jsx)(n.p,{children:\"Where supported, use consent helpers to control whether the SDK sends data:\"}),`\n`,(0,e.jsx)(d,{snippetId:\"consent\"}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"verification\",anchors:\"\",ancestors:\"\",index:\"9\",children:[(0,e.jsx)(n.h2,{id:\"verification\",children:\"Verification\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Send a verification event named \",(0,e.jsx)(n.code,{children:\"docs_verification\"}),\" with a unique test identity. Replace \",(0,e.jsx)(n.code,{children:\"docs_test_<unique-id>\"}),\" below with the identity you sent. Use a new identity for each run:\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-sql\",children:`SELECT *\nFROM product_analytics.main.events\nWHERE event = 'docs_verification'\n  AND distinct_id = 'docs_test_<unique-id>'\nORDER BY timestamp DESC\nLIMIT 10;\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"Confirm that the event name, distinct ID, timestamp, and properties match the payload your application sent. A different recent event does not prove this test succeeded. Allow for ingestion delay and retry the same filtered query before sending another event.\"}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"choose-a-collection-mode\",anchors:\"\",ancestors:\"\",index:\"10\",children:[(0,e.jsx)(n.h2,{id:\"choose-a-collection-mode\",children:\"Choose a collection mode\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Use the default product mode for identified users, funnels, and retention. For aggregate usage without persistent client identifiers, see \",(0,e.jsx)(n.a,{href:\"/docs/product-analytics/track#audience-measurement\",children:\"audience measurement\"}),\". Audience mode changes identity handling and persistence; choose it before initializing the SDK.\"]}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"troubleshooting\",anchors:\"\",ancestors:\"\",index:\"11\",children:[(0,e.jsx)(n.h2,{id:\"troubleshooting\",children:\"Troubleshooting\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"No events appear:\"}),\" confirm that Product Analytics is enabled in the same environment as the API key.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Requests are rejected:\"}),\" check the \",(0,e.jsx)(n.a,{href:\"/docs/product-analytics/authentication\",children:\"authentication methods\"}),\" and replace an incorrect or expired API key.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Users remain anonymous:\"}),\" call \",(0,e.jsx)(n.code,{children:\"identify\"}),\" when a stable user ID becomes available, and pass \",(0,e.jsx)(n.code,{children:\"distinct_id\"}),\" explicitly from server-side SDKs.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Events stop after an SDK upgrade:\"}),\" current SDKs ignore the \",(0,e.jsx)(n.code,{children:\"environment\"}),\" option and send events to the API key's environment. Use an API key bound to the target environment.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Automatic page or screen events are missing:\"}),\" confirm that your SDK supports page or screen capture, then enable its helper.\"]}),`\n`]}),`\n`,(0,e.jsx)(s,{destination:\"productAnalyticsIngest\"}),`\n`]}),(0,e.jsxs)(i,{sectionId:\"next-steps\",anchors:\"\",ancestors:\"\",index:\"12\",children:[(0,e.jsx)(n.h2,{id:\"next-steps\",children:\"Next steps\"}),`\n`,(0,e.jsx)(u,{path:\"related\",alsoInclude:[\"product-analytics/authentication\",\"product-analytics/track\",\"product-analytics/identify\",\"product-analytics/alias\"]})]})]})}function v(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,{...t,children:(0,e.jsx)(m,{...t})}):m(t)}function r(t,n){throw new Error(\"Expected \"+(n?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return P(K);})();\n;return Component;"},"_id":"docs/product-analytics/setup.mdx","_raw":{"sourceFilePath":"docs/product-analytics/setup.mdx","sourceFileName":"setup.mdx","sourceFileDir":"docs/product-analytics","contentType":"mdx","flattenedPath":"docs/product-analytics/setup"},"type":"Docs","path":"/product-analytics/setup","level":2,"parent":"product-analytics"}