Send Safari Push Notifications to your Mac users using Sitecore – part 2

SafarIPush

Push notifications have been around for a while and we have all experienced them in our phones and tablets. Sending notifications to web users have also been possible but the browser and the website must be active.

But did you know that you can send push notifications to your web users even when the browser is closed? It’s called Safari Push Notifications and was presented when Apple released their latest OS – Maverick. It works on Safari running on Maverick – basically every Mac user.

In my previous post, Send Safari Push Notifications to your Mac users using Sitecore – part 1, I showed you guys how to prepare your website for Safari Push Notifications and store the the receivers/visitors in Sitecore.
In this post I will show you the benefits of using Safari Push Notifications, not only to push/send notifications but also to identify visitors

I recently read John West(Sitecore) Blog – Share Your Common Sense. So I will try to keep my blog post short 🙂

When the receivers(visitors) accept push notifications from the website(see my previous post) they will automatically be registered into Sitecore.
PushNotifications
Accepting push notifications

StoreReceiver
Receivers in Sitecore

When the visitors accept push notifications they will receive a device ID which is generated by Apple. The ID is unique for that computer and stays permanently. That means you don’t have to store it in a cookie. Next time the visitor enters the website we can easily check the device ID by using following JavaScript code:

var PushBroker = PushBroker || {};


jQuery(document).ready(function () {
    PushBroker.SafariNotifications.DomReady();
});


PushBroker.SafariNotifications = {
    DomReady: function() {

        var safariNotifications = new PushBroker.SafariNotifications.Init();

        safariNotifications.prepareForPushNotification();

    },
    Init: function() {

        var self = this;

        self.dataContainer = jQuery(".notificationSettings");

        self.prepareForPushNotification = function () {
            "use strict";

            if ('safari' in window && 'pushNotification' in window.safari) {
                var permissionData = window.safari.pushNotification.permission(self.dataContainer.data("pushId"));
                checkRemotePermission(permissionData);
            } else {
                alert("Push notifications not supported.");
            }
        };

        self.checkRemotePermission = function (permissionData) {
            "use strict";

            if (permissionData.permission === 'default') {
                console.log("The user is making a decision");
                window.safari.pushNotification.requestPermission(
                    self.dataContainer.data("restURL"),
                    self.dataContainer.data("pushId"),
                    {},
                    checkRemotePermission
                );
            } else if (permissionData.permission === 'denied') {
                console.dir(arguments);
           } else if (permissionData.permission === 'granted') {
                console.log("The user said yes, with token: " + permissionData.deviceToken);
           }
        };

    }
}

The last part permissionData.permission === ‘granted’ allows us to get the ID permissionData.deviceToken. Yes! We now have a unique ID for that visitor on that computer which stays permanently and we can hook it up in the DMS – So if you don’t want to send push notifications, use it to identify visitors 🙂

That’s all for now folks 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.