【发布时间】:2017-12-27 04:02:42
【问题描述】:
我想知道我们如何在推送通知显示后跟踪服务人员点击事件。 我已经注册了服务工作者并发送回推送通知,但现在我想追踪通知点击事件是否用户打开通知并丢弃它。
self.addEventListener('push', function(event) {
const analyticsPromise = pushReceivedTracking();
const pushInfoPromise = fetch('api/subscriber/msg/')
.then(function(response) { return response.json(); })
.then(function(response) {
const title = response.data.userName + ' says...';
const message = response.data.message;
return self.registration.showNotification(title, { body: message });
});
const promiseChain = Promise.all([ analyticsPromise, pushInfoPromise ]);
event.waitUntil(promiseChain);
})
【问题讨论】:
-
你能分享一些你到目前为止写的代码吗?您能描述一下您遇到的问题吗?
-
self.addEventListener('push', function(event) { const analyticsPromise = pushReceivedTracking(); const pushInfoPromise = fetch('api/subscriber/msg/') .then(function(response) { return response.json(); }) .then(function(response) { const title = response.data.userName + 'says...'; const message = response.data.message; return self.registration.showNotification(title , { body: message }); }); const promiseChain = Promise.all([ analyticsPromise, pushInfoPromise ]); event.waitUntil(promiseChain); });
标签: javascript push-notification service-worker