Code samples
Side-by-side code samples for the 6 canonical amba operations — init, identify, track, collection insert, storage upload, push register — across all 8 SDK languages.
Every amba SDK exposes the same 6 canonical operations. The snippets below show the idiomatic shape per language so you can compare ergonomics before committing to a stack.
API key placeholder is amb_dev_ck_XXXX throughout — replace with the dev key from amba init or app.amba.dev before running.
Snippets below are aligned with the runnable
amba-sdks/examples/kitchen-sinks — each platform's example app is a clone-and-go reference that exercises the same operations end-to-end against staging. A canonical source-path map is at the bottom of this page so you can jump from any snippet to the full surrounding context (auth setup, error handling, prerequisites). Automatedimport-from-source synchronization is on the roadmap (Task #28 follow-up); until then, deviations between this page and the kitchen-sinks should be filed as docs bugs.
1. Init
Configure the SDK once at app start.
2. Identify (sign in)
Establish an authenticated appUserId you can attach data to. Sample shown for anonymous sign-in; every SDK also supports email, Sign in with Apple, and Sign in with Google.
3. Track an event
4. Collection insert
Insert a row into a collection already created via amba collections create posts --field title:text --field body:text. The server stamps user_id from the active session.
5. Storage upload
6. Push register
Source-of-truth map
Each snippet above is a focused excerpt; the running version (with surrounding setup, error handling, and prerequisites) lives in the matching amba-sdks/examples/ kitchen-sink. Use the table below to jump straight to the canonical source for any cell.
| Language | Init | Identify | Track event | Collection insert | Storage upload | Push register |
|---|---|---|---|---|---|---|
| Web | examples/web/src/lib/amba.ts | examples/web/src/main.ts (btn-anon) | examples/web/src/main.ts (btn-anon) | examples/web/src/main.ts (btn-insert) | gated on staging server route — see web.mdx Implementation status | gated on staging server route — see web.mdx Implementation status |
| Node | examples/node/src/amba.ts | examples/node/src/index.ts (§ 3) | examples/node/src/routes/webhook-stripe.ts | examples/node/src/routes/orders.ts | examples/node/src/index.ts (§ Storage) | examples/node/src/index.ts (§ Push fan-out) |
| React | examples/react/src/lib/amba.ts + src/main.tsx | examples/react/src/components/UseUserSection.tsx | examples/react/src/components/UseTrackOnMountSection.tsx | examples/react/src/components/UseCollectionSection.tsx | examples/react/src/components/UseAmbaSection.tsx (escape hatch) | shared with Web — same Amba.push.register surface |
| React Native | examples/react-native/App.tsx | examples/react-native/App.tsx (signInAnonymously) | examples/react-native/App.tsx (trackEvent) | examples/react-native/App.tsx (insertCollection) | bare-RN-specific blob handling — see react-native.mdx § 7 | examples/react-native/App.tsx + react-native.mdx § 6 |
| Swift | examples/ios/AmbaKitchenSink/AmbaKitchenSinkApp.swift | examples/ios/AmbaKitchenSink/ContentView.swift (signInAnonymously) | examples/ios/AmbaKitchenSink/ContentView.swift (events.track) | examples/ios/AmbaKitchenSink/ContentView.swift (collections.insert) | examples/ios/AmbaKitchenSink/ContentView.swift (storage section) | examples/ios/AmbaKitchenSink/AppDelegate.swift (APNs callback) |
| Kotlin | examples/android/app/src/main/java/com/layers/amba/example/MainActivity.kt | examples/android/app/src/main/java/com/layers/amba/example/MainActivity.kt | examples/android/app/src/main/java/com/layers/amba/example/MainActivity.kt | examples/android/app/src/main/java/com/layers/amba/example/MainActivity.kt | Android storage — see android.mdx | examples/android/app/src/main/java/com/layers/amba/example/MainActivity.kt (FCM) |
| Dart | examples/flutter/lib/main.dart (main()) | examples/flutter/lib/main.dart | examples/flutter/lib/main.dart | examples/flutter/lib/main.dart | Flutter storage — see flutter.mdx | examples/flutter/lib/main.dart |
| C# | examples/unity/AmbaKitchenSink/Assets/Scripts/AmbaBootstrap.cs | examples/unity/AmbaKitchenSink/Assets/Scripts/KitchenSinkUI.cs | examples/unity/AmbaKitchenSink/Assets/Scripts/KitchenSinkUI.cs | examples/unity/AmbaKitchenSink/Assets/Scripts/KitchenSinkUI.cs | Unity storage — see unity.mdx | examples/unity/AmbaKitchenSink/Assets/Scripts/KitchenSinkUI.cs |
Cells marked gated on staging server route or see <platform>.mdx correspond to surfaces that are SDK-ready but still landing server-side. The per-platform doc pages carry the in-flight status; once each server route ships, the matching kitchen-sink and this snippet block both round-trip.
See also
- Client API reference — HTTP endpoint reference for every namespace.
- Per-platform quickstarts: Web, Node, React, React Native, Expo, iOS, Android, Flutter, Unity.