Lorixen.
EN

Safari deleting your site's cookies after 7 days? ITP explained

Short answer: Safari's Intelligent Tracking Prevention (ITP) caps cookies that your site's JavaScript creates through document.cookie at seven days, and in some cases one day, no matter what expiry you set. That's why Safari visitors can look like "new" users in your analytics after a week, why a "remember my basket" cookie disappears, and why consent banners reappear. Logins aren't affected if you set them the right way: from the server, in an HTTP response, marked Secure and HttpOnly. Move anything that must persist out of JavaScript cookies.

What Safari actually does

WebKit, the engine behind Safari, explained the rule when it introduced ITP 2.1: cookies can be set either in HTTP responses or through the document.cookie API. With ITP 2.1, all persistent cookies created through document.cookie are capped to a seven-day expiry. Session cookies stay session cookies, and cookies with a shorter expiry keep it. The rule applies in first-party contexts as well as third-party iframes.

Two later changes tighten it further:

  • Link decoration. ITP 2.2 caps cookies set through document.cookie to one day when the visitor arrived from a domain classified as having cross-site tracking capabilities and the landing URL has a query string or fragment. Ad and social click IDs in URLs are the typical case.
  • CNAME cloaking. WebKit's 2020 post explains that ITP also caps cookies set in HTTP responses from a subdomain that is actually a CNAME pointing to a third party, such as an analytics or ad vendor, to seven days. Setting a cookie from track.yourdomain.com doesn't escape the cap if that subdomain resolves to someone else's service.

Other browsers have their own tracking protections, but Safari's rules are the ones most small business sites trip over, because iPhone users are a large share of mobile visitors in many markets.

Symptoms you might be seeing

  • Analytics: Safari users counted as new visitors again after a week, inflated user counts, returning-visitor reports that look wrong for iPhone traffic.
  • Attribution: campaign conversions that happen more than a week after the first click are credited to "direct" or lost.
  • Shop: a basket, wishlist or "recently viewed" list stored in a JavaScript cookie vanishes for Safari users after a week.
  • Consent: the cookie banner reappears every week for Safari users because their choice was saved in a JavaScript cookie.
  • Preferences: language, currency or store-location choices reset.

What isn't affected: properly set logins

WebKit addressed the most common worry directly: authentication cookies should be Secure and HttpOnly to protect them from interception, cross-site scripting and speculative execution attacks, and cookies created through document.cookie can't be HttpOnly. So if your login cookie is set by the server with those flags, the seven-day cap doesn't apply to it.

If customers on Safari get logged out after a week, that's a sign the login state lives in a JavaScript-created cookie, which is a security problem as well as a usability one.

Fixes, by type of data

Logins and sessions. Set them in a server response with Secure and HttpOnly, and SameSite as appropriate. Never store tokens in JavaScript-created cookies.

Basket, wishlist and preferences. Options, depending on your platform:

  • Store them on the server against a session or customer account, with a server-set cookie holding only an identifier.
  • For signed-in customers, keep baskets and wishlists in their account so they survive any browser or device change.
  • Accept that guest data on Safari may expire, and design so losing it isn't painful, for example by prompting to save a basket by email.

Consent choices. Have your consent tool store the choice in a cookie set by your server, or accept re-prompting and make it quick. Check how your consent platform handles Safari.

Analytics and attribution. Here the cap is working as designed: it limits tracking. Options:

  • Expect Safari users to be undercounted as returning visitors, and read reports with that in mind.
  • Rely more on conversions you can tie to a signed-in customer or an order.
  • Be careful with "first-party" tricks. Setting analytics cookies from a subdomain that CNAMEs to a vendor is exactly what WebKit's CNAME defence caps. A genuine server-side setup on your own infrastructure is different, but don't use it to work around a visitor's privacy choices.

How to check what your site sets

  1. Open your site in Safari with the Web Inspector, or in any browser's developer tools.
  2. Look at the cookies under Storage: note which are HttpOnly (server-set) and which aren't.
  3. Search your theme and plugins for document.cookie to find what writes cookies in JavaScript.
  4. For each cookie, decide: does it need to last more than seven days? If yes, move it server-side or into the customer account.

Talk to whoever runs your marketing

Much of this lands on marketing reports rather than code. Agree in advance how you'll read Safari numbers, which conversions count, and which decisions shouldn't rest on returning-visitor figures alone.

An illustrative example

A hypothetical Chicago coffee-subscription shop noticed its Safari visitors kept losing their saved grind and delivery preferences and kept seeing the cookie banner. Both were stored in cookies written by front-end scripts. The developer moved preferences into the customer account, stored consent in a server-set cookie, and added a note to analytics reports that Safari returning-visitor numbers are understated.

FAQ

Does this affect Chrome on iPhone?

All iPhone browsers have historically used WebKit, but behaviour can differ by browser and iOS version. Test the browsers your customers use.

Can I just set the expiry to a year?

Not for document.cookie in Safari. ITP caps it regardless of the expiry you set.

Will server-set cookies always last?

Not always. WebKit's CNAME rules cap some server-set cookies, and users can clear data. Treat cookies as convenience, not storage.

Is localStorage a workaround?

Don't rely on it for important data; Safari applies its own limits there too, and it's readable by scripts.

If Safari visitors keep losing baskets, preferences or consent on your site and you'd like it fixed properly, tell us which platform your shop runs on.

Sources

WhatsAppBook a call