API Reference
Complete API reference for the Pushary client SDK
createPushary
Creates a new Pushary instance.
const pushary = createPushary(config: PusharyConfig): PusharyInstancePusharyConfig
interface PusharyConfig {
siteKey: string
apiUrl?: string
autoPrompt?: boolean
promptDelay?: number
debug?: boolean
onSubscribe?: (subscription: PushSubscription) => void
onPermissionDenied?: () => void
onNotSupported?: () => void
onNotificationClick?: (url: string, data: NotificationData) => boolean | void
}PusharyInstance
interface PusharyInstance {
promptForPermission(): Promise<PushSubscription | null>
subscribe(): Promise<PushSubscription | null>
unsubscribe(): Promise<void>
setExternalId(externalId: string): Promise<void>
setTags(tags: Record<string, string>): Promise<void>
processRetryQueue(): Promise<void>
isSupported(): boolean
}Methods
promptForPermission
Requests notification permission from the user. If permission is already granted, subscribes immediately.
const subscription = await pushary.promptForPermission()
if (subscription) {
console.log('User subscribed:', subscription.endpoint)
} else {
console.log('Permission denied or not supported')
}subscribe
Subscribes to push notifications. Requires permission to already be granted.
if (Notification.permission === 'granted') {
const subscription = await pushary.subscribe()
}unsubscribe
Unsubscribes the user from push notifications.
await pushary.unsubscribe()setExternalId
Associates your internal user ID with the subscriber. Enables targeting by user ID from your backend.
await pushary.setExternalId('user-123')setTags
Sets tags for subscriber segmentation.
await pushary.setTags({
plan: 'premium',
interests: 'sports,news',
})isSupported
Checks if push notifications are supported in the current browser.
if (pushary.isSupported()) {
// Push is available
}Callbacks
onSubscribe
Called when the user successfully subscribes.
createPushary({
siteKey: 'pk_xxx',
onSubscribe: (subscription) => {
console.log('Subscribed:', subscription.endpoint)
},
})onPermissionDenied
Called when the user denies notification permission.
createPushary({
siteKey: 'pk_xxx',
onPermissionDenied: () => {
console.log('User denied notifications')
},
})onNotificationClick
Called when a notification is clicked. Return false to prevent default navigation.
createPushary({
siteKey: 'pk_xxx',
onNotificationClick: (url, data) => {
console.log('Clicked:', url, data)
if (data.campaignId === 'special') {
window.location.href = '/special-page'
return false
}
return true
},
})Browser Support
| Browser | Minimum Version |
|---|---|
| Chrome | 50+ |
| Firefox | 44+ |
| Safari | 16+ (macOS & iOS) |
| Edge | 17+ |
| Opera | 37+ |