Skip to main content
Server-Side Tracking · 8 min read

Extend Safari ITP Cookie Lifetime With Same-Origin sGTM

Safari ITP caps JavaScript cookies at 7 days, or 24 hours after decorated ad clicks. See how same-origin server-side GTM sets longer-lived first-party cookies.

Syed Yasir

Syed Yasir

Conversion Tracking & Server-Side Attribution Expert

Diagram of a same-origin /metrics path routing browser requests to a server-side GTM container that sets long-lived first-party cookies for Safari

Short answer: Safari ITP caps cookies written by JavaScript at 7 days, and at 24 hours after a decorated ad click from a classified domain. To keep identifiers longer, have your server set them with Set-Cookie HTTP headers, and serve your server-side GTM container from the same origin as your website (for example yourdomain.com/metrics). Google lists same-origin serving as the best practice for server-side tagging, and it also avoids Safari’s CNAME and IP-mismatch cookie caps.

What does Safari ITP do to first-party cookies?

Safari’s Intelligent Tracking Prevention applies four separate limits. Which one hits you depends on how the cookie is written and where the request goes.

Rule What triggers it Effect on cookies
Script cookie cap Cookie written with document.cookie Expires 7 days after it was last written
Link decoration cap (ITP 2.2) Visitor lands from a classified domain on a URL with a query string or fragment Persistent JavaScript cookies created on that page expire in 24 hours
CNAME cloaking cap Your subdomain resolves through a CNAME to a different, third-party domain Cookies set in the HTTP response are capped at 7 days
Third-party IP cap The host setting the cookie resolves to an IP address that doesn’t match your site’s Cookies set in the HTTP response are capped at 7 days

Google’s GA4 documentation confirms the practical result: browsers limit first-party cookie lifetime when a user does not return, with a 400-day maximum in Chrome and 7 days in Safari.

The business impact: a buyer who clicks an ad on Monday and purchases on day nine appears as a new user or Direct traffic. GA4 loses the original source, and Google Ads and Meta lose the click identifier they need for attribution.

Note on the IP rule: WebKit documents the CNAME cloaking defense publicly. The IP-address check shows up in Safari’s ITP debug logs, but WebKit has not published its exact matching threshold. Stape’s documentation reports that Safari compares the first 16 bits of an IPv4 address (and 64 bits of IPv6). Treat that threshold as observed behavior, not a guarantee.

Why does same-origin server-side tagging fix this?

The script cap targets cookies written by JavaScript. A cookie set by your own server in an HTTP response header is a different mechanism, so the 7-day and 24-hour script caps don’t apply to it.

But the server has to be recognized as first party. Google’s server-side tagging documentation compares three hosting options:

Hosting option Example Server-set cookies Safari ITP risk
Default cloud domain yourcontainer.run.app Not available (JavaScript cookies only) High: all script caps apply
Custom subdomain data.yourdomain.com Available Medium: can be capped at 7 days if it resolves via a third-party CNAME or to a mismatched IP range
Same-origin path yourdomain.com/metrics Available Lowest: same host and IP as your site, so neither check is triggered

Same-origin works because requests go to your own domain and are forwarded by your CDN or load balancer to the tagging server. Safari only sees your site.

How to set up same-origin sGTM

Follow Google’s same-origin guide, with these practical points:

  1. Reserve a path. Choose a path you don’t already use. Google’s setup guide suggests a random letter-and-number combination or a readable word such as /metrics. A less guessable path is also less likely to appear on ad blocker lists.
  2. Route the path through your CDN or load balancer. Add your website as one origin and your tagging server as another, then give the measurement path a higher priority than your default rule. On Cloudflare, Google documents using Snippets to forward requests.
  3. Forward cookies and client IP. Google’s troubleshooting steps include confirming that the CDN forwards cookies. Also pass the visitor’s IP address through to the tagging server, or GA4 location data and geo-based reporting degrade.
  4. Update the server container URL. In your server container’s settings, remove old URLs and add the new path. All server container URLs must share the same path.
  5. Point your web tags at the path. Update your Google tag or web GTM container to send requests to the first-party URL.
  6. Let the server own the identifier. In the GA4 client, use the server-managed client ID so the server issues the FPID cookie as an HTTP-only cookie.
  7. Optional: load the Google tag itself first-party. Google tag gateway for advertisers serves gtm.js or gtag.js from your own domain. Cloudflare users can enable it from the Google tag or Tag Manager admin.

Need a hand with the DNS and CDN side? Run our Server-Side Tracking Checker or read the Server-Side Tracking guide.

Which cookies should the server set, and for how long?

Browsers cap cookie lifetime, and Chrome’s ceiling is 400 days, so never request more than that.

Cookie Platform Set by Lifetime guidance
FPID GA4 sGTM GA4 client (HTTP-only) Up to 400 days (Max-Age=34560000)
_fbp, _fbc Meta Your server, via Set-Cookie Meta documents 90 days (Max-Age=7776000)

A server-set GA4 cookie looks like this on the wire. The sGTM client generates it for you, so you don’t write it by hand:

HTTP/2 200 OK
Set-Cookie: FPID=FPID2.2.exampleFirstPartyId; Max-Age=34560000; Domain=.yourdomain.com; Path=/; Secure; HttpOnly; SameSite=Lax

Meta Conversions API: the API is server-to-server and doesn’t read cookies itself. The cookies matter because fbp and fbc are sent as event parameters, and Meta recommends sending them whenever they’re available. Meta also advises capturing them early on the landing page and not altering their format, because _fbc is case sensitive.

  1. Open Web Inspector → Network, select a request to your /metrics path, and confirm the response carries a Set-Cookie header.
  2. Open Storage → Cookies and check that FPID shows a long expiry, plus the HttpOnly and Secure flags.
  3. For Google tag gateway, open Tag Assistant and confirm under Hits Sent that requests go to your measurement path.
  4. Enable Intelligent Tracking Prevention Debug Mode from Safari’s Develop menu and look for messages about capped cookie expiry. A capped-expiry message on your tagging host means Safari still sees it as third party.

Common mistakes

  • Leaving the tagging server on its default cloud domain. Only JavaScript cookies can be set there.
  • Pointing a subdomain CNAME at a cloud host on a different IP range than your website.
  • A CDN rule that strips cookies or doesn’t forward the client IP.
  • Old server container URLs left in settings after switching to a path.
  • Setting Max-Age beyond 400 days. Browsers will clamp it anyway.
  • Ignoring consent. Longer-lived cookies still need a lawful basis. Make sure writes respect your Consent Mode V2 state.

If you host on Stape, its Cookie Keeper and Own CDN features are alternative ways to extend cookie lifetime. See Stape Server-Side Tracking.

Frequently asked questions

How long do cookies last in Safari with ITP?

JavaScript cookies are capped at 7 days, or 24 hours when the visitor arrives from a classified domain on a URL with a query string or fragment. Cookies set by your server are not subject to the script cap, but can be capped at 7 days if Safari treats the response as CNAME-cloaked or from a mismatched IP address.

Does server-side tagging automatically bypass Safari ITP?

No. The server must set the cookie through a Set-Cookie header, and the tagging server must run in a first-party context. On its default cloud domain it can only set JavaScript cookies.

Sometimes. A subdomain is a valid first-party setup, but Safari may cap its cookies at 7 days if it resolves through a third-party CNAME or to an IP outside your main site’s range. A same-origin path avoids both checks.

400 days, which is Chrome’s limit. Meta documents 90 days for _fbc and _fbp.

Do I need server-set cookies for Meta Conversions API?

The API doesn’t read cookies, but the fbp and fbc values you send with each event come from them. Keeping those values alive longer improves matching for returning visitors.

Sources and last verified

Last verified against official documentation on 6 December 2026. Safari and platform behavior changes, so re-test after major Safari releases.

Not sure whether your setup is being capped? Book a free server-side tracking audit and we’ll check your cookies in Safari, or run the free in-browser GTM Container JSON Auditor.

Topics: Safari ITP First-Party Cookies Same-Origin sGTM Attribution GA4 Meta CAPI
Share this article

Free Tracking Audit

Want Me to Audit Your Conversion Tracking Stack?

Book a free tracking audit. I'll review your GTM, GA4, Server-Side Tracking, Meta CAPI, Google Ads Enhanced Conversions, and Consent Mode V2 setup and highlight exactly what to fix.

Keep Reading

All articles →
Syed Yasir Chat on WhatsApp Available now · Replies under 5 min