Understanding Service Worker in GTM Server Side Tagging

Last Updated: April 5, 2025

What is Service Worker?

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.

Google introduced service workers for GTM Server Side Tagging to improve data collection and reliability.

Before service workers, GTM tags use methods like navigator.sendBeacon() to send tracking data (events) directly to Google Analytics, Ads or other platforms.

The problem? Some data could be lost if the user closes the page too quickly or loses internet connection.

A Service Worker can catch the tracking requests, store them temporarily, and send 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.

If the user goes offline, the Service Worker can send data once they are back online.

Who exactly uses the Service Worker in GTM Server-Side Tagging?

Google’s Tracking Scripts (gtag.js, GTM, GA, or Ads Scripts) use the Service Worker to enhance data collection and measurement reliability.

Who deploys the Service Worker in GTM Server-Side Tagging?

If Google has implemented a Service Worker as part of its Google Tag (gtag.js) or GTM scripts, then Google itself is deploying and managing it.

If a Service Worker is part of Google’s tracking ecosystem, it is loaded dynamically by Google’s scripts, not something website owners explicitly install.

sGTM itself does not deploy or require a Service Worker to function, but it can benefit from one if Google’s tracking scripts implement it.

If a Service Worker is used, it modifies requests before they reach sGTM, ensuring that tracking data is more reliable.

A website owner would only deploy their own Service Worker if they were customising tracking beyond Google’s default implementation.

The presence of a Service Worker does not require any action from the website owner unless they wish to modify default behavior.

The website owner only interacts with the Service Worker indirectly by integrating GTM Server-Side, not by manually setting it up.

The only direct action a website owner might need to take regarding Service Workers in GTM Server-Side Tagging is updating their Content Security Policy (CSP) if it is too restrictive.

If a website has a strict CSP, it might block the registration or execution of the Service Worker. This can prevent the Service Worker from intercepting and handling GTM tracking requests.

Open your browser’s Developer Tools (F12 or right-click, select “Inspect”), and go to the Console tab. Look for any CSP-related error messages that might indicate the Service Worker is being blocked.

The name of the Service Worker script.

The name of the Service Worker script in GTM (or any implementation) is not fixed and depends on how Google has implemented it. 

Common filenames include: 

  • ‘sw.js’,
  •  ‘gtm-sw.js’,
  •  ‘gtag-sw.js’,
  • ‘google-tag-sw.js’,
  •  ‘/_/service_worker/xyz/sw.js’ (dynamic naming by Google).

How to check if Service Worker is being used on your website?

You can check if a Service Worker is being used on your website by following the steps below:

Step-1: Open a website that uses GTM Server-Side Tagging in Google Chrome.

Step-2: Right-click anywhere on the page and select “Inspect“.

Step-3: In Chrome DevTools, find and click on the “Application” tab.

Step-4: Under ‘Service Workers’, check if any script is registered by looking at the source file (e.g., sw.js, gtm-sw.js, gtag-sw.js, or another name). 

Under ‘Service Workers check if any script is registered by looking at the source file

If present, this confirms that your Google Tag is using a Service Worker to handle tracking data. If a Service Worker is registered, then proceed to the next step.

Step 5: Click on ‘Network requests’ button to see all the requests initiated by the Service Worker.

Click on ‘Network requests button to see all the requests initiated by the Service Worker

Step-6: Click on ‘Update’ to manually trigger an update of the service worker. 

Click on ‘Update to manually trigger an update of the service worker

This action forces the browser to check for a new version of the service worker script, bypassing the usual update interval.

Step-7: Click on ‘Unregister’ to manually unregister the service worker.

Click on ‘Unregister to manually unregister the service worker

This action will immediately stop the service worker from controlling the page. The service worker is removed from the browser’s registry. Any caches associated with that service worker are deleted.

This feature is particularly useful for developers and testers who want to:

  • Reset the service worker state during development.
  • Test how the site behaves without the service worker.
  • Troubleshoot issues related to service worker caching or offline functionality.

Note: After unregistering, the page will need to be reloaded for the changes to take effect fully. If the service worker is set to register automatically on page load, it may re-register unless you’ve also disabled that functionality in your code.

Step-8: Click on ‘See all registrations’ link to inspect service workers registrations across all origins that are currently active in the browser:

Click on ‘See all registrations link to inspect service workers registrations

It provides a comprehensive overview of all service worker activity in the browser, which can be crucial for understanding complex web applications or troubleshooting service worker-related issues.

Step-9: Navigate to the ‘Network‘ tab to verify if the service worker is intercepting the tracking request. 

Step-10: In the Filter bar, type is:service-worker-initiated. This filter shows requests initiated by a Service Worker.

shows requests initiated by a Service Worker

Step-11: Click on a tracking request. 

Step-12: Open the ‘Headers’ tab and look at the request URL:

Open the ‘Headers tab and look at the request URL

Step-13: Look for ‘service-worker-allowed: /_/service_worker‘ under the response header. If present, it confirms that GTM’s Service Worker is allowed and active.

Step-14 (optional): 

  1. Navigate to your GTM server side tagging domain (e.g., sgtm.example.com).
  2. Open the Console tab in DevTools and run the following command: navigator.serviceWorker.getRegistrations().then(console.log)

If the command returns the following similar object, a Service Worker is registered and actively controlling this page.

If the command returns the following similar object

If the command returns an empty array [], it means the Service Worker is registered under a different subdomain (may be ‘www.example.com’).

Note: In GTM Server-Side Tagging, the Service Worker is most likely registered on the server-side tagging domain (e.g., sgtm. example. com), not on the main website (e.g., www.example.com).

Can the service worker cause a loss in data collection?

Yes, if the service worker is not correctly registered or fails to activate, it will not intercept requests as intended. 

This could happen if:

  • The browser blocks Service Worker registration due to strict security settings.
  • The scope of the Service Worker does not cover the tracking events.
  • Users disable JavaScript or block Service Workers using browser extensions.

If a user clears their cache, the Service Worker may be removed from the browser, causing it to lose any pending tracking events that were queued for resending.

Note: Google has not provided full details on how it uses Service Workers, so monitoring your network requests for any unexpected behavior is a good practice.

Clarification about the navigator.serviceWorker.getRegistrations() Command.

This command only shows Service Workers registered for the current origin and scope.

If the Service Worker is registered under a different subdomain, this command returns an empty array even if a Service Worker is actually in use.

If the scope of the Service Worker does not cover the current page, the command will not detect it.

A Service Worker can still process tracking requests (e.g., via fetch events) without being “active” in the way getRegistrations() checks for.

Cross-Origin Service Workers Won’t Appear in Console Commands.

Checking the Console logs with navigator.serviceWorker.getRegistrations() is NOT a 100% reliable way to confirm whether a Service Worker is being used for tracking.

Analysis of the Service Worker URL.

https://sgtm.example.com/_/service_worker/5230/sw.js?origin=https%3A%2F%2Fwww.example.com

Service Worker File: sw.js

This is the actual Service Worker script.

Hosted under sgtm.example.com, which suggests Server-Side GTM (sGTM) is using a Service Worker.

Path Contains /_/service_worker/5230/

/_/service_worker/ indicates that this script is being dynamically generated or loaded via GTM’s Service Worker implementation.

The number 5230 likely represents a versioning or unique identifier for the Service Worker instance.

Query Parameter: ?origin=https%3A%2F%2Fwww.example.com

The Service Worker is being registered with an origin restriction, meaning it is likely scoped to https://www.example.com/.

This ensures that the Service Worker only operates within this website’s context.

Chrome DevTools does not always show an initiator for requests made by Service Workers.

If you’re seeing a Service Worker URL in the “Application” tab, but the initiator data is missing for its requests in the Network tab, this means:

The Service Worker intercepted and handled the request, but the browser doesn’t attribute an initiator.

This is normal for requests that Service Workers create on their own (e.g., resending stored events when the user goes back online).

  1. Server Side Tracking for Google Analytics via GTM
  2. How to Create Server-Side Container for Google Tag Manager
  3. How to Configure DNS for GTM Server Side Container
  4. How to send data from Website to Server Side Container
  5. Setting up Facebook Conversion API via Google Tag Manager (GTM)
  6. Google Tag Manager Tutorial
  7. How to set up Data Layer for GTM Server Side Container
  8. GTM Server Side Preview Mode – Tutorial
  9. How Developers Prevent GTM Scripts from Ad Blockers.
  10. Is cheap GA4 server-side tagging worth it?
  11. How to Fix GA4 DebugView with Server-Side Tagging.
  12. Top Reasons Why Your GA4 GTM Server Side Tracking is a Mess.

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade