ウェブアプリの
この OK 、
参考
Tracking PWA events with Google Analytics – Dev Channel – Medium
PWAのoffline 時の event を 収集する 実装方法に ついて 記載されています。 イベント トラッキング | ウェブ向け
アナリティクス(analytics.js) | Google Developers
実装
送信する 値
event 送付時は、
eventCategory
A2H
(Add to homescreen の略) eventAction
OK or Cancel が判断できる 値 eventLabel
ページタイトルnonInteraction
非インタラクションイベントとして 送信します。
実装内容
eventListner とbeforeinstallprompt
を
// Setup a listener to track Add to Homescreen events. window.addEventListener('beforeinstallprompt', e => { e.userChoice.then(choiceResult => { if (typeof ga !== "undefined") { ga('send', { hitType: 'event', eventCategory: 'A2H', eventAction: choiceResult.outcome, eventLabel: document.title, nonInteraction: true }); } }); });
export default function configure() { if ("serviceWorker" in navigator) { // Setup a listener to track Add to Homescreen events. window.addEventListener('beforeinstallprompt', e => { e.userChoice.then(choiceResult => { if (typeof ga !== "undefined") { ga('send', { hitType: 'event', eventCategory: 'A2H', eventAction: choiceResult.outcome, eventLabel: document.title, nonInteraction: true }); } }); }); } }
補足. PWA の offline 時の event 送付に ついて
参考に
面白そうなので、
補足. GTMを 使用して、 event を 送付する 場合
GTM を
Google Tag Manger から
私は、
- beforeinstallprompt で、
GTM の カスタムイベントを 送付する。 // Setup a listener to track Add to Homescreen events. window.addEventListener('beforeinstallprompt', (e) => { e.userChoice.then((choiceResult) => { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: "sendEvent", eventName: "A2H", eventData:{ category : "A2H", action : choiceResult.outcome, label : document.title, value : "", nonInteraction : true } }); }); });
上記、
以上です。
コメント