官术网_书友最值得收藏!

Tracking homescreen installs

Once the homescreen install prompt displays, the user can choose to add the PWA to their homescreen, or ignore the prompt. Businesses should track and measure everything possible to make better decisions. Knowing how many homescreen installs there have been and what rate customers install their PWA provides insight into their marketing and technology investments.

Chrome supports the beforeinstallprompt event, which can be used to track this activity. You can add a handler to this event and log each user's choice:

window.addEventListener('beforeinstallprompt', function(event) { 
  event.userChoice.then(function(result) {                                  
 
if(result.outcome == 'dismissed') {                                         
  // They dismissed, send to analytics 
}else { 
  // User accepted! Send to analytics 
} 
});  
}); 

You can POST the user's choice to your analytics system. This could be a custom API to your internal analytics or even tied to your third-party service, like Google Analytics.

The beforeinstallprompt is part of the web manifest specification, but at the time of writing this book, it is only supported by Chrome. Hopefully, other browsers will add support soon.

Browsers that don't support beforeinstallprompt can also provide feedback. The web manifest's start_url can be set either to a special start URL, or a custom querystring value appended to the default URL. You will need to add logic to your log analyzer to track this behavior. Besides just knowing how many homescreen installs you have, you can also track how many times users have launched your PWA as opposed to those who have not installed your PWA.

主站蜘蛛池模板: 拜城县| 河北区| 松原市| 庆云县| 鲁山县| 朝阳市| 陈巴尔虎旗| 荆州市| 体育| 三原县| 泰安市| 肇源县| 阿合奇县| 天柱县| 高安市| 长海县| 吴堡县| 昆山市| 普格县| 兴安盟| 定远县| 九台市| 阳西县| 巴楚县| 塔城市| 东山县| 忻城县| 华亭县| 长丰县| 湛江市| 县级市| 保德县| 遂平县| 台州市| 名山县| 新田县| 平山县| 台北县| 贞丰县| 勐海县| 道孚县|