我试图在beforeinstallprompt
触发并显示迷你信息栏后实施对用户选择的跟踪。这是MDN上BeforeInstallPromptEvent的片段
window.addEventListener("beforeinstallprompt", function(e) {
// log the platforms provided as options in an install prompt
console.log(e.platforms); // e.g., ["web", "android", "windows"]
e.userChoice.then(function(outcome) {
console.log(outcome); // either "accepted" or "dismissed"
}, handleError);
});
Run Code Online (Sandbox Code Playgroud)
这是我基于Google的示例的实现
window.addEventListener('beforeinstallprompt', (e) => {
ga(`${experimentName}.send`, 'speedlink_offer', 'show', 'true');
e.userChoice.then((choice) => {
if (choice.outcome === 'accepted') {
ga(`${experimentName}.send`, 'speedlink_offer', 'click', 'true');
} else {
ga(`${experimentName}.send`, 'speedlink_offer', 'close', 'true');
}
} );
});
Run Code Online (Sandbox Code Playgroud)
但是承诺userChoice
永远不会解决。在用户单击“取消”或“添加”按钮后,为什么无法解决?是错误还是我错过了什么?
PS。我发现,如果你捕捉用户的动作(例如点击)并执行event.prompt()
,然后userChoice
将得到解决。但这将独立于用户与“本地” Chrome的 …