Inpage Subscribe & Unsubscribe Button
If you want your website visitors to be able to subscribe or unsubscribe from your push service via an integration on your site, you can do this via an Inpage Integration.
In addition to the following code, an element must be integrated on your site with which your visitors can perform the subscribe or unsubscribe action.
(function () {
// Cache checkbox reference for enable / disable checkbox
var getback_push_toggle = document.getElementById('push_toggle');
// Callback function, will be called by gb_enable_push/gb_disable_push after toggling --> Can be used to give a feedback after a user has enabled or disabled push
function push_callback(is_push_subscriber) {
if (is_push_subscriber) {
console.log('Vielen Dank!');
} else {
console.log('Sie wurden von Pushbenachrichtigungen abgemeldet.');
}
}
// Handle push
function push_handler() {
if (!window.gb_has_push_support) {
// No push support detected. Leave checkbox disabled, maybe display an info message etc.
return;
}
// Push support detected. Enable checkbox.
getback_push_toggle.disabled = false;
// Set initial state of checkbox
getback_push_toggle.checked = window.gb_is_push_subscriber;
// Listen to checkbox changes and fire respective function.
getback_push_toggle.addEventListener('change', function () {
if (this.checked) {
window.gb_enable_push(true, push_callback);
} else {
window.gb_disable_push(push_callback);
}
});
}
// Disable checkbox until Getback is fully loaded and we can request the current status
getback_push_toggle.disabled = true;
if (window.getback_loaded) {
// Getback has already loaded. We can use gb_has_push_support, gb_enable_push() and gb_disable_push().
push_handler();
} else {
// Getback is not yet available. 'getback_loaded' in window gets fired as soon as Getback is loaded
window.addEventListener('getback_loaded', push_handler);
}
})();