On the web, the Pushwoosh Web SDK handles device and user registration through the init call.
-
Initialize the SDK and register the device/user: the
Pushwoosh.push(['init', { ... }])call configures the SDK and registers the browser. You can pass auserIdandtagsin the same call.<script src="//cdn.pushwoosh.com/webpush/v3/pushwoosh-web-notifications.js" async></script> <script> var Pushwoosh = Pushwoosh || []; Pushwoosh.push(['init', { logLevel: 'error', // error | info | debug applicationCode: 'XXXXX-XXXXX', // your Application Code apiToken: 'YOUR_DEVICE_API_TOKEN', // Device API token with access to this project safariWebsitePushID: 'web.com.example.site',// only if you send to Safari defaultNotificationTitle: 'Your site', autoSubscribe: true, // prompt on init; false if you trigger it yourself userId: 'your_custom_user_id', // optional tags: { // optional 'TagName': 'TagValue' } }]); </script> -
Key parameters:
-
applicationCode(required): your Application Code from the Control Panel. -
apiToken(required): a Device API Access token, created in Settings → API Access. It must be granted access to this specific project - a Server token, or a Device token without access to the app, produces401 Unauthorized. -
userId(optional): your own user identifier, linked to the browser's HWID so one user can be tracked across browser and app. It can also be set later withPushwoosh.push(function (api) { api.registerUser('YOUR_USER_ID'); });. -
tags(optional): key/value pairs used for segmentation. -
autoSubscribe(defaulttrue) andserviceWorkerUrl(default/pushwoosh-service-worker.js) control the opt-in prompt and the service worker location.
-
-
Important considerations:
- Your site must be served over HTTPS.
-
pushwoosh-service-worker.jsmust be reachable at the configured path (by default the site root), otherwise registration and the prompt fail silently. - The subscriber becomes push-capable only once the browser permission is granted and a push subscription exists; calling
initalone does not produce a push-capable device.
See Web Push SDK 3.0 and API Access token.
Comments
0 comments
Please sign in to leave a comment.