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

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.

主站蜘蛛池模板: 南汇区| 都江堰市| 三明市| 曲水县| 鹿泉市| 九龙县| 普兰县| 五指山市| 兴业县| 池州市| 寿阳县| 四川省| 万全县| 三台县| 闸北区| 三亚市| 兴仁县| 阿鲁科尔沁旗| 东丽区| 郧西县| 博湖县| 柳州市| 易门县| 吴桥县| 诏安县| 黄龙县| 忻州市| 余干县| 丹寨县| 民乐县| 合作市| 元朗区| 常德市| 神池县| 方山县| 土默特右旗| 轮台县| 宝坻区| 竹北市| 忻州市| 新余市|