service worker - How to measure the number of people disabling push notifications from my progressive web app? -


i'm using new web push api service workers in progressive web app worried users disabling push notification permission after enabling it.

what best way detect users disabling notification permission (i.e. add instrumentation/analytics) can track this?

i believe you're looking covered in permissions api, includes change event. event fired both initial user decision , again if user later changes mind.

at basic, do:

if ('permissions' in navigator) {   navigator.permissions.query({name:'notifications'}).then(function(notificationperm) {     // notificationperm.state 1 of 'granted', 'denied', or 'prompt'.     // @ point can compare notificationperm.state     // cached value, , listen changes while page open via     // onchange handler.      notificationperm.onchange = function() {       // permissions have changed while page open.       // based on current notificationperm.state value.     };   }); } 

there few resources out there demonstrating how used:

the permissions api supported in chrome of version 43, , firefox of upcoming version 45 release.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -