Google has introduced service workers for GTM Server Side Tagging to improve data collection and reliability. This innovation helps ensure that your website’s tracking data is captured more effectively, even when users have poor internet connections or quickly exit your pages.
What are service workers and why do they matter?
A service worker is a script that can intercept network requests, store data temporarily, and retry sending it later if the internet connection is lost. This represents a significant improvement over previous tracking methods.
Before service workers, GTM tags relied on methods like navigator.sendBeacon() to send tracking data directly to Google Analytics, Ads or other platforms. The problem with this approach was that some data could be lost if the user closed the page too quickly or lost internet connection.
Service workers solve this problem by catching the tracking requests, storing them temporarily, and sending them later when the internet connection is back. This ensures more complete data collection, reducing the risk of missing events due to bad connectivity or fast exits.
How to check if a service worker is being used on your website
If you’re wondering whether your website is already using service workers for GTM, here’s a simple process to check:
First, open a website that uses GTM Server-Side Tagging. Right-click anywhere on the page and select “Inspect” to open Chrome DevTools. Then find and click on the “Application” tab.
Under ‘Service Workers’, check if any script is registered by looking at the source file. Common names include ‘sw.js’, ‘gtm-sw.js’, ‘gtag-sw.js’, or ‘/_/service_worker/xyz/sw.js’ (which uses dynamic naming by Google). If a service worker is present, this confirms that your Google Tag is using it to handle tracking data.
For a deeper analysis, click the “Inspect” button next to the active service worker to open a dedicated debugging window. Navigate to the ‘Network’ tab to verify if the service worker is intercepting tracking requests.
In the Filter bar, type “is:service-worker-initiated” to show requests initiated by a service worker. Click on a tracking request (such as collect?v=2) and open the “Headers” tab. Look for ‘service-worker-allowed: /_/service_worker’ under the response header. If present, it confirms that GTM’s service worker is allowed and active.
For an optional final check, navigate to your SS tagging domain (e.g., sgtm.example.com), open the Console tab in DevTools and run this command: navigator.serviceWorker.getRegistrations().then(console.log). If the command returns an object that begins with “ServiceWorkerRegistration{installing:”, a service worker is registered and actively controlling the page.
Important considerations for implementation
If your website has strict security rules, you may need to update your Content Security Policy (CSP) to allow service workers. This is an important step that shouldn’t be overlooked.
It’s also worth noting that Google hasn’t provided full details on how it uses service workers, so monitoring your network requests for any unexpected behaviour is good practice. The name of the service worker script in GTM isn’t fixed and depends on Google’s implementation.
Conclusion
Service workers represent an important advancement in how GTM collects and manages tracking data. By implementing this technology, Google has made data collection more reliable, ensuring that important analytics information isn’t lost due to connectivity issues or user behaviour. For website owners concerned about data accuracy, this is a welcome improvement that helps provide more complete insights into user interactions.