2017-12-27 33 views
-1

푸시 알림이 표시된 후 서비스 작업자 클릭 이벤트를 어떻게 추적 할 수 있는지 알고 싶습니다. 서비스 작업자를 등록하고 푸시 알림을 다시 보냈지 만 이제 사용자가 알림을 열고 삭제했는지 여부를 알림 클릭 이벤트를 추적하고 싶습니다.푸시 알림으로 서비스 작업자 추적

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); 
}) 
+0

지금까지 작성한 코드 중 일부를 공유 할 수 있습니까? 당신이 가진 문제를 설명 할 수 있습니까? –

+0

self.addEventListener ('푸시', 함수 (이벤트) { analyticsPromise = CONST pushReceivedTracking()를; = CONST pushInfoPromise 페치 ("API/가입자/MSG/') 그 때는 (함수 (대응) { 반환 응답. JSON();} ) 그 때는 (함수 (대응) { CONST 타이틀 = response.data.userName + '라고 ...'; CONST 메시지 = response.data.message; 복귀 self.registration. showNotification (제목, { 본문 : 메시지 }), }), const promiseChain = Promise.all ([ analyticsPromise , pushInfoPromise ]); event.waitUntil (promiseChain); }}); –

답변

1

당신은 당신의 서비스 노동자의 NotificationEvent을 처리 할 수 ​​

self.addEventListener('notificationclick', function (event) { 
    event.notification.close(); 
    // track the notification click here 
}); 

참고 또한 당신의 통지에 버튼을 추가 할 수 있습니다 - 지금 당신은 단지 알림 자체에 클릭 추적 할 것입니다.