GoogleChrome / workbox

📦 Workbox: JavaScript libraries for Progressive Web Apps
https://developers.google.com/web/tools/workbox/
MIT License
12.34k stars 814 forks source link

Workbox Google Analytics doesn't work log events to resent later #3041

Closed renatosalopes closed 2 years ago

renatosalopes commented 2 years ago

Library Affected: workbox-google-analytics, workbox-webpack-plugin

Browser & Platform: Microsoft Edge 99.0.1150.36, Chrome 99.0.4844.51

Issue or Feature Request Description: Hello! I'm trying to implement the Google Analytics's Workbox Plugin on my application, which works most of the time offline. I used the webpack plugin as well to generate the service worker (SW). I used the method GenerateSW({offlineGoogleAnalytics: true}). But, unfortunately, after the SW be registered it didn't created an database for the workbox background sync, neither a table for the request (as seeing on this demo). On my application the SW is active and running but it doens't make requests, neither setup the indexDB. I'm using and local version of the gtag.js and it works as expected when the application is online, the events are logged on Analytics real time dashboard. But offline the requests aren't saved to be resent later. What I missed for this feature to work?

jeffposnick commented 2 years ago

Apologies—I believe this is related to these earlier issues: #2389, #2552, and #2759.

@philipwalton was going to look into some of them, but he's no longer working on the Workbox project. (Maybe I can bait him into responding, though 😄 )

I don't know enough about the changes introduced with gtag.js to say whether this can be retrofit in workbox-google-analytics in a backwards-compatible way.

renatosalopes commented 2 years ago

Hi, @jeffposnick, thanks for the feeback! I tried to make it work with analytics.js as well but it didn't work as well. I tried to use UA and GA4 (measurement protocol). On my application the service worker didn't create the database for the faileds requests automatically. Within (official demo) the requests are duplicated, one made by the analytics.js and the other by workbox-core.prod.js but the second one doesn't appears for me. I agree that a better documentation would be great! But I think that my problem is a little different. I can give more details to explain better my issue.

jeffposnick commented 2 years ago

FYI: we have some thoughts on how to deal with offline analytics moving forward in the Workbox project at https://github.com/GoogleChrome/workbox/issues/3055

renatosalopes commented 2 years ago

Thanks, @jeffposnick. I'm sorry for the depreciation of the module and I hope that the community will continue to support the tool because the concept is very useful and interesting.

jeffposnick commented 2 years ago

We definitely want this functionality to continue to be supported—we would just like to support it via unpackaged "recipes".

Stay tuned for updates to #3055, where we'll post a few of the recipes for common use cases, including Google Analytics 4. Assuming they look good after sharing them there, we will add them to the docs, and evaluate whether including them in the workbox-recipes module is needed.