To follow GDPR and cookie consent rules you can initialise the Web SDK on page load but keep it silent until the user consents. Pass communicationEnabled: false in the init call: in this mode the SDK skips its registration step entirely — no Hardware ID (HWID) is created, no configuration or device data is sent to Pushwoosh, and the browser permission prompt is not shown.
var Pushwoosh = window.Pushwoosh || [];
Pushwoosh.push(['init', {
logLevel: 'info',
applicationCode: 'YOUR_APP_CODE',
defaultNotificationTitle: 'Your Title',
communicationEnabled: false
}]);
When the user accepts, enable communication. The SDK then registers the device and requests push permission:
// Run this after the user clicks 'Accept' or 'Subscribe'
function onConsentGranted() {
Pushwoosh.push(function (api) {
api.setCommunicationEnabled(true);
});
}
// Trigger it from your consent manager
// window.addEventListener('consent-received', onConsentGranted);
Calling setCommunicationEnabled(false) later unregisters the device and stops communication again.
If you prefer not to load the SDK at all before consent, you can also keep the whole Pushwoosh.push(['init', {...}]) call inside a function and run it only after consent — both approaches are valid, but communicationEnabled: false is the supported one and keeps the SDK available for later. See Manage user consent for web push notifications.
Comments
0 comments
Please sign in to leave a comment.