---
title: "GTM / GA4 Script Proxy - Serpwise Documentation"
description: "Rewrite Google tracking scripts and measurement calls through a first-party path."
url: "https://serpwise.ai/docs/script-proxy/"
source: "https://serpwise.ai/docs/script-proxy/"
---
[Back to Serpwise](/)

Serpwise Documentation

Connect · Configure · Execute

Search documentation

`/`

No documentation found.

↑↓ Navigate Enter to open

Browse documentation

The GTM / GA4 Script Proxy rewrites Google tracking URLs in HTML responses so browsers load them from your own domain instead of directly from Google tracking domains.

This helps recover client-side analytics that would otherwise be blocked by filter lists targeting `googletagmanager.com` or `google-analytics.com`.

## What Gets Rewritten

When script proxying is enabled, the gateway rewrites known tracking URLs to the configured first-party prefix.

| Original URL                                    | Default first-party path |
|-------------------------------------------------|--------------------------|
| `https://www.googletagmanager.com/gtm.js`       | `/sw-t/gtm.js`           |
| `https://www.googletagmanager.com/gtag/js`      | `/sw-t/gtag/js`          |
| `https://www.google-analytics.com/analytics.js` | `/sw-t/analytics.js`     |
| `https://www.google-analytics.com/g/collect`    | `/sw-t/g/collect`        |

The gateway rewrites both:

- external `<script src="...">` tags, and
- inline script text that constructs known Google URLs dynamically.

## Request Flow

```
Browser requests:  https://example.com/sw-t/gtm.js?id=GTM-XXXX
Gateway proxies:   https://www.googletagmanager.com/gtm.js?id=GTM-XXXX
Browser sees:      first-party script from example.com
```

Script responses are cached for one hour. Measurement requests to `/g/collect` are proxied with `Cache-Control: no-store`.

## Configure Script Proxying

Open **Tracking &gt; Settings** for a domain.

| Setting                                | Description                                                          |
|----------------------------------------|----------------------------------------------------------------------|
| **Enable Script Proxying**             | Turns HTML URL rewriting and script proxy routes on.                 |
| **Path Prefix**                        | First-party prefix, default `/sw-t`. You can choose a custom prefix. |
| **Google Tag Manager (`gtm.js`)**      | Rewrites and proxies GTM loader requests.                            |
| **Google Analytics 4 (`gtag/js`)**     | Rewrites and proxies GA4 loader requests.                            |
| **Measurement Endpoint (`g/collect`)** | Proxies GA4 collection requests.                                     |

## Inject Google Tracking

The same Settings page can inject GA4 and/or GTM when tracking is missing.

| Setting                | Description                                                       |
|------------------------|-------------------------------------------------------------------|
| **Enable Injection**   | Allows the gateway to add Google tracking bootstraps to the page. |
| **Google Analytics 4** | Injects `gtag.js` using a GA4 Measurement ID.                     |
| **Google Tag Manager** | Injects the GTM container bootstrap and noscript fallback.        |
| **Only if missing**    | Skips injection when the origin already contains Google tracking. |

When Script Proxy is enabled, injected GA4/GTM loader URLs use the first-party prefix. GA4 injection also sets `transport_url` to the proxy prefix so measurement calls route through the gateway.

## How It Relates to Server-Side Conversions

Script proxying improves client-side analytics capture. Server-side conversions forward events directly from the gateway to ad-platform APIs.

Use both when possible:

- **Script proxy** recovers browser analytics and existing GTM/GA4 behavior.
- **Server-side conversions** preserve purchase, lead, and goal delivery when client-side tags are blocked or cookies expire.

## Troubleshooting

| Symptom                              | Check                                                                                                     |
|--------------------------------------|-----------------------------------------------------------------------------------------------------------|
| Script URL is not rewritten          | Confirm Script Proxy is enabled and the origin HTML uses a supported Google URL.                          |
| Browser gets 404 for `/sw-t/...`     | Confirm the request is going through the Serpwise gateway and the path prefix matches the domain setting. |
| Duplicate Google tracking            | Enable the injection `onlyIfMissing` guard or disable injection if the origin already loads GA4/GTM.      |
| GA4 events still hit Google directly | Confirm `proxyCollect` is enabled and injected GA4 uses the proxy `transport_url`.                        |

## Next Steps

[**Tracking Overview**  
→  
\
See how script proxying fits into the full tracking pipeline.](/docs/conversion-tracking)

[**Tracking Events**  
→  
\
Define server-side conversions that complement proxied client-side analytics.](/docs/tracking-events)