var useragentid = null; var OneSignal = window.OneSignal || []; function OneSignalInit() { // Do NOT call init() twice OneSignal.push([ 'init', { // Your other init options here appId: '<%= DeviseOnesignal.configuration.app_id %>', autoRegister: <%= DeviseOnesignal.configuration.auto_register ? 'true' : 'false' %>, welcomeNotification: { disable: true, title: '', message: '' }, notifyButton: { enable: false }, persistNotification: <%= DeviseOnesignal.configuration.persist_notification ? 'true' : 'false' %> // Automatically dismiss the notification after ~20 seconds in Chrome Desktop v47+ }]); // Firstly this will check user id OneSignal.push(function() { OneSignal.getUserId().then(function(userId) { if ( userId != null ) { useragentid = userId; document.cookie = 'oneSignalUserId=' + userId; }; OneSignal.push([ 'getNotificationPermission', function(permission) { document.cookie = 'oneSignalUserPermission=' + permission; }]); }); }); }; function OneSignalSubscribe() { if ( useragentid != null ) { OneSignal.setSubscription(true); } else { OneSignal.registerForPushNotifications({ modalPrompt: <%= DeviseOnesignal.configuration.subscribe_with_modal ? 'true' : 'false' %> }); }; } function OneSignalUnsubscribe() { OneSignal.setSubscription(false); }