Enabling WebPush (Specific to Automation Service)
Metrix creates a server-side User for each user to send push notifications (if a User does not already exist for that user). This User is created after obtaining the user’s permission to send push notifications and can be viewed in the Metrix dashboard under User Lookup.
If you wish to send push notifications to your users through your website, enable the Enable Push Notification option and enter the Public Key. You can obtain this value in the following path:
Dashboard -> Workspace -> Settings -> Channel Integration -> Web Push Settings
You can create web push campaigns through the dashboard to send web push notifications to your users.
To obtain push notification permission from your users, enable the Show Subscription Bell option, which will display a bell icon in the corner of the website.
Sample Implementation in WordPress with PHP:
<?php
// Identify the user before WebPush
$current_user = wp_get_current_user();
if ($current_user->ID) {
Metrix_SDK::authorize_user($current_user->user_login);
}
// Add the Service Worker
Metrix_SDK::add_sdk_script(); // Your method that adds the JS SDK file
?>
<script>
// Initialize the SDK with WebPush
Metrix.init("<?php echo $wp_settings['app_id'] ?>", "<?php echo $wp_settings['api_key'] ?>", {
push: {
enabled: true,
publicKey: "<?php echo $wp_settings['push_public_key'] ?>",
hasSW: true,
showBell: true,
showBackdrop: true,
backdropText: "Do you want to receive push notifications?",
backdropDelay: 1000
}
});
// Request push permission on button click
document.getElementById('subscribePushBtn').addEventListener('click', () => {
Metrix.subscribePush().then(state => {
console.log('Push state:', state); // 'subscribed', 'blocked', or 'closed'
});
});
</script>
<button id="subscribePushBtn">Subscribe to Push Notifications</button>