question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Workbox Google Analytics] [Offline] No payload sent to GTM when network resumed.

See original GitHub issue

Library Affected: workbox-google-analytics

Browser & Platform: Google Chrome Version 83.0.4103.116 (Official Build) (64-bit).

Issue Description: I used GTM in my site with heavily using dataLayer to sent data to GTM and GA.

The problem is GTM request is using POST method with passing data via long query parameters append in the url, no body used.

currently, when offline, workbox stores the un-reachable GTM requests to indexedDB and used them later when network resumed. after network resumed, Workbox retry all the requests but without body sent.

here is my debugging console with showing values of variables in the scope of onSync method from google-analytics in compiled version (v5.1.2) (https://github.com/GoogleChrome/workbox/blob/v6/packages/workbox-google-analytics/src/initialize.ts#L49)

Screen Shot 2563-06-25 at 13 43 24

As you can see ( I debugged in generated version), I did print t in console, which is params. It was only return qt (queue time) which should return many parameters according to the request context in the right side panel ( s.url variable )

My purpose solution is at this line (https://github.com/GoogleChrome/workbox/blob/v6/packages/workbox-google-analytics/src/initialize.ts#L59) we cloud do check bodyUsed also.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
lewis-geekcommented, Dec 1, 2020

Hi @philipwalton , the GA4 has been released for a while, when your team will support it?

1reaction
philipwaltoncommented, Jun 26, 2020

Sorry you’re running into issues here. From looking at your example you, I see you’re using the new App+Web (beta) in Google Analytics, and that ultimately appears to be the source of the problem.

I looked into it, and as far as I can tell there are two issues, one of which Workbox can fix, and one of which we can’t:

1) It looks like the RegExp that workbox-google-analytics is using was overly lax, and it ended up matching the new collection endpoint used by gtag.js with App+Web properties (e.g. https://www.google-analytics.com/g/collect).

We can update our code to only match the endpoints used by analytics.js (e.g. /collect, /r/collect, and /j/collect), which will prevent our plugin from handling those requests, but that will also mean those requests will be lost when users are offline.

2) The main issue is that the new /g/collect endpoint used by App+Web properties does not support the &qt param to specify time offsets, which means we can’t backdate timestamps (which is needed to associate hits sent after returning online to their correct offline time). The other issue is that the /g/collect endpoint is still in beta and it’s not documented, and I’m not particularly comfortable supporting an undocumented API (that could change without notice).

If offline analytics is important to you, I’d suggest not using a App+Web property at the moment. We can look into adding support if/when App+Web properties come out of beta and support setting custom timestamps.

(cc: @diminishedprime who might know more about Google Analytic’s plans to support this feature.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

workbox-google-analytics - Chrome Developers
Support for replaying offline Google Analytics interactions.
Read more >
Issues · GoogleChrome/workbox · GitHub
Workbox: JavaScript libraries for Progressive Web Apps - Issues ... [Workbox Google Analytics] [Offline] No payload sent to GTM when network resumed.
Read more >
Track Users Who Are Offline In Google Analytics - Simo Ahava
Use this solution to automatically collect data from users who are offline, and send the data to Google Analytics once they are back...
Read more >
node.js - workbox-google-analytics / service-worker offline ...
I can see items caching in IndexedDB when offline, and then the queue clearing when connectivity comes back. I can also see on...
Read more >
How to check if Google Tag Manager is Working?
Google Tag Manager. The thing that makes the lives of marketers and web analysts easier. But the purpose of this blog post is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found