Keep Safari visitors in the same test version
Safari forgets script cookies after 7 days. How Varly keeps recognizing returning visitors, per platform, and what to add to your cookie list.
In this article
Varly recognizes a returning visitor by a random ID in a cookie, _varly_id, which the snippet writes in the browser. Safari on iPhone, iPad and Mac removes cookies and other storage written by scripts when a visitor hasn't been on your site for 7 days. In a three-week test, a visitor who returns in week two is then new to Varly: they can see the other version, and count twice.
What Varly does about it
Your own site keeps a copy of the ID in a second cookie, _varly_keep, set by your server. The snippet never writes that cookie. When its own cookie is gone, the snippet reads the copy, after the visitor has given consent again, and continues with the same ID. The visitor stays in the same version of every test.
| Platform | How | Who is covered |
|---|---|---|
| WordPress, with or without WooCommerce | The Varly plugin (version 1.3.0 or newer), after you turn it on in Varly | Visitors who accepted cookies and return in the same browser within a year |
| Shopify | Not available | Nobody: a Safari visitor who returns after more than 7 days counts as new |
| Any other site | Your developer adds one small address on your own server | Visitors who accepted cookies and return in the same browser within a year |
Not covered anywhere: a visitor who cleared their cookies, uses another browser or device, or browses privately.
Many cookie banners keep the visitor's choice in a script cookie too. Safari then forgets the choice after 7 days, and the visitor sees your banner again. When they accept, Varly continues with the ID it kept. If they decline, the copy is removed.
Turn it on
- Add
_varly_keepto your cookie list (see below). - In Varly, open Settings → Tracking & privacy and tick Recognize returning Safari visitors for longer than 7 days.
- Check Address on your own site that keeps the visitor ID. The Varly plugin for WordPress fills it in for you. On another site, enter the path your developer made.
- Click Save.
It is off by default because it sets one more cookie after consent. For speed it costs most visitors nothing: only a Safari visitor without the copy loads a small extra piece of about 3 kB, once. Chrome, Firefox and Edge never load anything extra.
See whether it works
Open Install. Under 4. Check that data comes in, the line Returning visitors in Safari says one of:
- recognized for up to a year: it is on and your site answers at the address shown.
- turned on, but your site did not answer: Varly asked the address and got no answer.
- turned on, but no address yet: the plugin hasn't told Varly its address, or you haven't entered one.
- recognized for 7 days: it is off.
WordPress
Update the Varly plugin to version 1.3.0 or newer and open Settings → Varly in WordPress once. The plugin then tells Varly its address. After you turn it on in Varly, the plugin starts within a day, or at once when you open Settings → Varly in WordPress again. From then on the snippet asks your site to keep the ID: after consent, only in Safari, and only while the copy is missing. The address is never served from a page cache.
The copy is only made when the visitor's browser has Varly's own cookie, which exists only after consent. With Complianz, CookieYes, Borlabs Cookie or a banner that uses the WP Consent API, the plugin also checks the stored choice for statistics: without a yes, nothing is set, and after a no the copy is removed.
To turn it off, untick the box in Varly. Settings → Varly in WordPress shows whether it is on.
Shopify
Not available on Shopify. A Shopify store can't set its own cookie for an app, and the cart is not a safe place for the ID: anyone can fill a cart field through a link. So on Shopify, a Safari visitor who returns after more than 7 days counts as new and can get the other version of a test. Keep that in mind for tests longer than a week on a shop with many iPhone visitors.
Any other site
Ask your developer to add the address described under For developers below. Then turn it on as under Turn it on, with the path of that address, for example /varly/keep.
What to add to your cookie list
_varly_keep: a first-party cookie set by your own website, kept for one year. It holds the same random visitor ID as_varly_id, so a returning visitor is still recognized after the browser removed the other cookie. Only set after consent, removed when consent is withdrawn. Not set on Shopify.
If your cookie banner removes cookies it doesn't know, add _varly_keep to its list next to _varly_id and _varly_s. Whether to mention this in your privacy statement is for you and your privacy advisor to decide.
Common problems
Install says my site did not answer. On WordPress, check that the plugin is version 1.3.0 or newer, and open Settings → Varly in WordPress once so the plugin learns you turned it on. Check that no security plugin or firewall blocks /wp-json/varly/v1/keep. On another site, open the address in your browser: it should show {"varly_keep":1}.
A Safari visitor still got the other version. They may have cleared their cookies or used another device. And the copy only exists from their first visit after you set this up.
For developers
One address on the site's own domain, on the same host as the pages (another host, or a host behind another DNS name, makes Safari apply the 7-day limit again). The Varly snippet calls it with fetch, method POST, same-origin, no body, only in Safari (and other browsers on iPhone and iPad) and only while the copy is missing, at most once a day.
GET: answer200with{"varly_keep":1}. Varly's install check uses this.POST: read the cookie_varly_idfrom the request. If the visitor has consented to analytics cookies and the value is 8 to 64 characters of letters, digits,-and_, answer withSet-Cookie: _varly_keep=<same value>; Path=/; Max-Age=31536000; SameSite=Lax; Secure, with the sameDomainyou entered for the site in Varly if the site uses subdomains. NotHttpOnly: the snippet reads it. Otherwise, if the request has a_varly_keepcookie, expire it. Answer{"kept":true}or{"kept":false}.- Always send
Cache-Control: no-store. Never cache the answer.
Whether the visitor consented is your decision, from your own consent records or cookie banner. The server SDKs have a helper that does the rest:
import { keepVisitor } from './varly-server.mjs'
app.all('/varly/keep', (req, res) => {
const answer = keepVisitor({
method: req.method,
cookie: req.headers.cookie,
consent: visitorAcceptedAnalytics(req),
domain: 'shop.com',
})
res.status(answer.status).set(answer.headers)
for (const line of answer.setCookie) res.append('Set-Cookie', line)
res.send(answer.body)
})
In PHP: \Varly\Client::keepVisitor($visitorAcceptedAnalytics, 'shop.com'); as the whole answer of that address. In Python: status, headers, body = keep_visitor(request.method, request.cookies, visitor_accepted_analytics, domain="shop.com").
Still stuck? Email support@varly.ai and we'll help you out.
Related articles
- Choose what visitors see while a test loadsThree choices for the moment before Varly has loaded, what each one costs, and what we measured.
- Cookie consent: how Varly follows your cookie bannerWhich cookie banners Varly works with, how to pick yours, and what happens before a visitor says yes.
- Privacy and GDPR: what Varly stores and for how longWhat Varly collects about visitors, what it never stores, retention periods, and sample privacy policy text.
- Server-side tests: developer referenceThe endpoints, libraries, visitor ID and rules behind server-side tests, for the developer who sets them up.