Skip to main content
The Tappd Web SDK exposes a set of async methods that let you identify users, track events, manage sessions, render banners, display in-app messages, and handle push notifications. Every async method returns a 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.
TappdConfig
required
SDK configuration object. appId is the only required field.
Returns: TappdSDK instance.

Core Methods

identify()

Identify or update a customer using one or more identifiers. When you call identify(), the SDK automatically merges any anonymous events tracked in the current session with the resolved customer profile.
CustomerAttributes
required
User attributes object. Must include at least one of external_id, email, phone, or alias.
Returns: Promise<void> Lookup priority: external_idemailphonealias
Use external_id whenever possible — it’s the most stable and reliable identifier. Include multiple identifiers to improve match accuracy across devices and sessions.
CustomerAttributes interface:
Identification examples:
How identification works:
1

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.
2

Associate events

All future track() calls are automatically linked to this customer — no need to pass identifiers again.
3

Merge anonymous data

Any events tracked before identify() are automatically merged into the resolved customer profile.
4

Link sessions

The current session and all future sessions are attached to the identified user.

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.
string
required
The name of the event to track (e.g. 'purchase', 'button_clicked').
EventProperties
Optional event properties. Can include identifiers to associate the event with a specific customer.
Returns: Promise<void> Identifier lookup order in properties: userId/user_idexternal_id/externalIdemailphonealias

trackPageView()

Manually track a page view. If you set autoTrack: 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.
string
The URL to record. Defaults to window.location.href if omitted.
EventProperties
Optional additional properties to attach to the page view event.
Returns: Promise<void>

setExternalId()

Set or update the external_id for the currently identified user. The user must already be identified — call identify() first.
string
required
Your internal user identifier.
Returns: 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.
CustomerAttributes
required
Attributes to update on the customer profile.
Returns: Promise<void> Throws: Error"User must be identified first"

setCustomAttributes()

Set or overwrite custom attributes on the currently identified user’s profile.
Record<string, any>
required
Key-value map of custom attributes to apply.
Returns: 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.
Returns: 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 in localStorage across page loads and sessions until identify() is called.
Returns: 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.
Returns: 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.
string
required
A CSS selector string that identifies the DOM element(s) where banners should be rendered (e.g. '#hero-banner', '.promo-slot').
object
Optional rendering options.
  • autoRender — automatically inject the banner HTML into the matched element. Defaults to true.
  • forceRefresh — bypass the local cache and fetch fresh banners from the API. Defaults to false.
Returns: Promise<Banner[]>

banners.display()

Manually record a banner display impression and return a unique display ID. Use this when autoRender is false and you render the banner HTML yourself.
string
required
The ID of the banner to record a display for.
string
required
The ID of the specific banner variant being shown.
string
required
The CSS selector of the container element where the banner is displayed.
Returns: 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.
string
required
The ID of the banner that was clicked.
string
required
The display ID returned by banners.display().
Returns: Promise<void>

banners.dismiss()

Record that the user dismissed a banner. Call this when the user closes or hides the banner without clicking through.
string
required
The ID of the banner being dismissed.
string
required
The display ID returned by banners.display().
Returns: Promise<void>

In-App Messages

getInAppMessages()

Fetch all pending in-app messages for the current user.
Returns: Promise<InAppMessage[]>

displayInAppMessage()

Display a specific in-app message object.
InAppMessage
required
The message object returned by getInAppMessages().
Returns: Promise<void>

displayPendingMessages()

Fetch and display all messages that are currently ready to show. Use this as a shortcut instead of calling getInAppMessages() and displayInAppMessage() separately.
Returns: Promise<void>

dismissMessage()

Dismiss a specific message and record the dismissal event in the Tappd dashboard.
string
required
The ID of the message to dismiss.
Returns: Promise<void>

trackMessageEvent()

Track a custom interaction event for a specific in-app message — for example, a button click or a custom CTA action.
string
required
The ID of the message.
string
required
Event type string — e.g. 'viewed', 'clicked', 'dismissed'.
object
Optional metadata to attach to the event.
Returns: Promise<void>

Push Notifications

getVapidPublicKey()

Retrieve the VAPID public key required for setting up web push subscriptions manually.
Returns: Promise<string> — the VAPID public key.

isSubscribed()

Check whether the current user is already subscribed to push notifications.
Returns: Promise<boolean>true if subscribed, false otherwise.

subscribeToPush()

Subscribe the currently identified user to push notifications. You must call identify() before subscribing.
PushSubscriptionOptions
Optional subscription configuration passed to the browser’s Push API.
Returns: 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.
Returns: Promise<void>

showPermissionPrompt()

Display a push notification permission prompt. Choose the style that best fits your UI.
'slidedown' | 'bell' | 'native'
required
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.
Returns: Promise<void>
After showing the prompt, call subscribeToPush() when the user grants permission to complete the subscription flow.

hidePermissionPrompt()

Programmatically hide any active permission prompt.
Returns: 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 in try/catch to handle errors without breaking your application.
Common error messages: