I have a Progressive Web Apps and am trying to create a function to know how many users "install" or not my app. According to the documentation ( link ) I have added the following code below the function that calls the Service Worker.js:
window.addEventListener('beforeinstallprompt', function(e) {
// beforeinstallprompt Event fired
// e.userChoice will return a Promise.
// For more details read: https://developers.google.com/web/fundamentals/getting-started/primers/promises
e.userChoice.then(function(choiceResult) {
console.log(choiceResult.outcome);
if(choiceResult.outcome == 'dismissed') {
console.log('User cancelled home screen install');
$('h1').after('Canceled');
$.get('https://www.meusite.com/register.php?a=Cancelou');
}
else {
console.log('User added to home screen');
$('h1').after('Installed');
$.get('https://www.meusite.com/register.php?a=Instalou');
}
});
});
Well, there is the question, that even adding or not to the home screen does not appear the warning under the title nor does PHP receive the information ...
To test I'm also picking up a little, the function you have in the Chorme developer tools of Add to Home Screen seems to no longer work for some versions, when I click nothing happens (just give a colsole return on Service Worker ).
Does anyone have experience with this can give me an orientation?
grateful