Browser SDK
Tiny Analytics ships a browser runtime that powers the generated snippet and an ESM helper package for apps that prefer direct imports. Both use the same runtime and the same public ingest API.
Browser global
The browser runtime exposes a single global command: tinyAnalytics.
<script>
window.tinyAnalytics = window.tinyAnalytics || function () {
;(window.tinyAnalytics.q = window.tinyAnalytics.q || []).push(arguments)
}
</script>
<script src="https://your-tiny-api/sdk.js" async></script>
Once the runtime is loaded, call tinyAnalytics("init", config) exactly once.
Init config
All install paths use the same config shape.
- Name
publicKey- Type
- string
- Description
Required. Must look like
pk_...and should come from the source created inAnalytics > Setup.
- Name
apiBaseUrl- Type
- string
- Description
Required. Must be an absolute
httporhttpsURL with no query string or hash.
- Name
autoPageviews- Type
- boolean
- Description
Optional. Defaults to
true. Tiny sends an initial pageview after bootstrap and tracks navigation changes in browser environments that support history listeners.
- Name
debug- Type
- boolean
- Description
Optional. When
true, Tiny logs runtime events to the console with a[Tiny Analytics]prefix.
- Name
userId- Type
- string
- Description
Optional. If provided at init time, Tiny associates future events with the identified user.
- Name
orgId- Type
- string
- Description
Optional. Included in shared event context when your app wants to pass a higher-level organization identifier.
Commands
The public browser command surface is:
- Name
tinyAnalytics("init", config)- Type
- Promise
- Description
Bootstraps the source session and resolves to
{ sessionId, sourceId }.
- Name
tinyAnalytics("track", eventName, props?)- Type
- boolean
- Description
Queues a named track event such as
report_generated.
- Name
tinyAnalytics("page", pathOrProps?)- Type
- boolean
- Description
Sends a page event. You can pass a path string or an object containing page overrides such as
path,url, ortitle.
- Name
tinyAnalytics("identify", userId, traits?)- Type
- boolean
- Description
Associates future events with a user ID and optional traits.
For page events, Tiny uses the event name page_view. For identify events, Tiny uses the event name identify.
Esm helpers
@tiny/analytics exposes the same runtime through helper functions:
- Name
initTinyAnalytics(config)- Type
- Promise
- Description
Initializes the runtime and dedupes concurrent init calls.
- Name
track(name, props?)- Type
- boolean
- Description
Sends a track event.
- Name
identify(userId, traits?)- Type
- boolean
- Description
Identifies future events with a user ID.
- Name
trackPageView(path?, props?)- Type
- boolean
- Description
Convenience helper for page events.
- Name
useTinyAnalytics()- Type
- object
- Description
Returns the helper functions from the package for app-level composition.
Examples
<script>
tinyAnalytics("init", {
publicKey: "pk_your_source_key",
apiBaseUrl: "https://your-tiny-api",
autoPageviews: true
})
tinyAnalytics("track", "report_generated", {
reportType: "weekly"
})
<\/script>
Keep initialization separate from event tracking. Tiny is designed so
init boots the source session first, then pageviews and track events follow.