Desktop PWA works with Discourse!

One thing I played with a bit is adding stats like:

  • Pageviews from PWA
  • Installations

To the Discourse Admin Dashboard and/or Google Analytics.

We can detect pageviews with that media query and installs with:

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');
    }
    else {
      console.log('User added to home screen');
    }
  });
});
12 Likes