Я работаю над сервисным работником (на самом деле сервисом облачных сообщений firebase, например это), и я хотел бы отслеживать каждый раз, когда пользователь получает нажатие на Google TagManager.
Любая помощь в том, как включить сценарий и отправить треки в SW?
Спасибо.





The Service worker runs outside the main thread and does not have access to the Window object, meaning that it cannot access the data layer or the ga command queue to create trackers. In short, the actions of a service worker cannot be tracked using the normal on-page, JavaScript-based tracking snippets. What we can do, however, is configure our service worker to send HTTP hits directly to GA.
Вот пример кода
fetch('https://www.google-analytics.com/collect', {
method: 'post',
body: JSON.stringify({
v: 1, // Version Number
t: eventName, // Hit Type
ec: eventCategory, // Event Category
ea: eventAction, // Event Action
el: 'serviceworker' // Event Label
})
})
Если вы хотите получить более подробную информацию, я бы рекомендовал прочитать эту статью. https://builtvisible.com/google-analytics-for-pwas-tracking-offline-behaviour-and-more/