Promise, so wrap calls in try/catch or chain .catch() to handle errors gracefully.
Constructor
new TappdSDK()
Create and initialize an SDK instance. Call this once — typically at the top level of your app — and reuse the returned instance everywhere.SDK configuration object.
appId is the only required field.TappdSDK instance.
Core Methods
identify()
Identify or update a customer using one or more identifiers. When you callidentify(), the SDK automatically merges any anonymous events tracked in the current session with the resolved customer profile.
User attributes object. Must include at least one of
external_id, email, phone, or alias.Promise<void>
Lookup priority: external_id → email → phone → alias
Use
external_id whenever possible — it’s the most stable and reliable identifier. Include multiple identifiers to improve match accuracy across devices and sessions.Find or create customer
The SDK searches for an existing customer using the lookup priority order. If no match is found, it creates a new profile.
Associate events
All future
track() calls are automatically linked to this customer — no need to pass identifiers again.Merge anonymous data
Any events tracked before
identify() are automatically merged into the resolved customer profile.track()
Track a custom event with an optional properties payload. If the user is already identified, the SDK automatically associates the event — you don’t need to repeat identifiers in the properties.The name of the event to track (e.g.
'purchase', 'button_clicked').Optional event properties. Can include identifiers to associate the event with a specific customer.
Promise<void>
Identifier lookup order in properties: userId/user_id → external_id/externalId → email → phone → alias
trackPageView()
Manually track a page view. If you setautoTrack: true during initialization, the SDK handles this automatically on every navigation. Use this method when you need finer control — for example, in custom SPA routers.
The URL to record. Defaults to
window.location.href if omitted.Optional additional properties to attach to the page view event.
Promise<void>
setExternalId()
Set or update theexternal_id for the currently identified user. The user must already be identified — call identify() first.
Your internal user identifier.
Promise<void>
Throws: Error — "User must be identified first" if identify() has not been called.
setUserAttributes()
Update attributes for the currently identified user. The user must already be identified.Attributes to update on the customer profile.
Promise<void>
Throws: Error — "User must be identified first"
setCustomAttributes()
Set or overwrite custom attributes on the currently identified user’s profile.Key-value map of custom attributes to apply.
Promise<void>
Throws: Error — "User must be identified first"
Utility Methods
getSessionId()
Return the active session ID. Sessions are created automatically on initialization and resume when a hidden tab becomes visible again.string | null — the current session ID, or null if no session is active.
getAnonymousId()
Return the anonymous ID for the current browser context. This ID persists inlocalStorage across page loads and sessions until identify() is called.
string — the anonymous ID.
reset()
Clear all user data and start a fresh session. Call this on logout to prevent the next user on the same device from inheriting the previous session’s identity.void
Banners
getBanners()
Fetch banners targeted to the current user for a given CSS selector. By default the SDK renders the returned banners automatically into the matched element.A CSS selector string that identifies the DOM element(s) where banners should be rendered (e.g.
'#hero-banner', '.promo-slot').Optional rendering options.
autoRender— automatically inject the banner HTML into the matched element. Defaults totrue.forceRefresh— bypass the local cache and fetch fresh banners from the API. Defaults tofalse.
Promise<Banner[]>
banners.display()
Manually record a banner display impression and return a unique display ID. Use this whenautoRender is false and you render the banner HTML yourself.
The ID of the banner to record a display for.
The ID of the specific banner variant being shown.
The CSS selector of the container element where the banner is displayed.
Promise<string> — a unique display ID used for subsequent click and dismiss calls.
banners.click()
Track a click interaction on a displayed banner. Call this when the user clicks on the banner or a CTA within it.The ID of the banner that was clicked.
The display ID returned by
banners.display().Promise<void>
banners.dismiss()
Record that the user dismissed a banner. Call this when the user closes or hides the banner without clicking through.The ID of the banner being dismissed.
The display ID returned by
banners.display().Promise<void>
In-App Messages
getInAppMessages()
Fetch all pending in-app messages for the current user.Promise<InAppMessage[]>
displayInAppMessage()
Display a specific in-app message object.The message object returned by
getInAppMessages().Promise<void>
displayPendingMessages()
Fetch and display all messages that are currently ready to show. Use this as a shortcut instead of callinggetInAppMessages() and displayInAppMessage() separately.
Promise<void>
dismissMessage()
Dismiss a specific message and record the dismissal event in the Tappd dashboard.The ID of the message to dismiss.
Promise<void>
trackMessageEvent()
Track a custom interaction event for a specific in-app message — for example, a button click or a custom CTA action.The ID of the message.
Event type string — e.g.
'viewed', 'clicked', 'dismissed'.Optional metadata to attach to the event.
Promise<void>
Push Notifications
getVapidPublicKey()
Retrieve the VAPID public key required for setting up web push subscriptions manually.Promise<string> — the VAPID public key.
isSubscribed()
Check whether the current user is already subscribed to push notifications.Promise<boolean> — true if subscribed, false otherwise.
subscribeToPush()
Subscribe the currently identified user to push notifications. You must callidentify() before subscribing.
Optional subscription configuration passed to the browser’s Push API.
Promise<PushSubscription>
Throws: Error if:
- Push notifications are not supported in the current browser
- The user has denied notification permission
identify()has not been called
unsubscribeFromPush()
Remove the current user’s push notification subscription.Promise<void>
showPermissionPrompt()
Display a push notification permission prompt. Choose the style that best fits your UI.The prompt style to display. Use
'native' for the browser’s built-in dialog, 'slidedown' for a banner, or 'bell' for an icon-triggered prompt.Promise<void>
hidePermissionPrompt()
Programmatically hide any active permission prompt.Promise<void>
TypeScript Types
Use these interfaces to get full type safety throughout your project.TappdConfig
CustomerAttributes
EventProperties
Error Handling
All async methods can throw. Always wrap calls intry/catch to handle errors without breaking your application.
| Error Message | Cause | Fix |
|---|---|---|
"App ID is required" | appId is missing or empty in the config | Provide a valid appId from your Tappd dashboard |
"User must be identified first" | Called a method that requires identification before identify() | Call identify() with at least one valid identifier first |
"Request failed: ..." | Network failure or API error | Check your apiUrl, network connection, and CORS configuration |