2017-12-27 44 views
-1

プッシュ通知後にサービスワーカーのクリックイベントを追跡する方法を知りたい。 私はサービスワーカーを登録してプッシュ通知を送り返しましたが、通知のクリックイベントを追跡して、ユーザーが通知を開いて破棄したかどうかを確認します。今あなたが唯一のちょうど通知自体にクリック追跡するだろう - また、あなたの通知にボタンを追加することができますサービスワーカーがプッシュ通知でトラッキングする

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

注:

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( 'プッシュ'、関数(イベント){ CONST analyticsPromise = pushReceivedTracking()と、 CONST pushInfoPromise =フェッチ( 'API /加入者/ MSG /') .then(関数(応答){ 戻り応答。 JSON();} ) .then(関数(応答){ CONSTタイトル= response.data.userName + 'と言う...'; CONSTメッセージ= response.data.message; 戻りself.registration。 showNotification(タイトル、{ 本文:メッセージ }); }); const promiseChain = Promise.all([ analyticsPromise 、 pushInfoPromise ]); event.waitUntil(promiseChain); }); –

答えて

関連する問題