Skip to content

Conversation

@tjmw
Copy link
Member

@tjmw tjmw commented Nov 7, 2025

What does this change?

This PR extends the expiration of all user benefits cookies to 30 days - GU_AF1, gu_allow_reject_all, gu_hide_support_messaging. The gu_user_benefits_expiry cookies continues to have an expiry of 1 day, so we'll recheck every day while the user is signed in.

Why?

Previously they were short lived (1-2 days) but this resulted in edge cases where if a signed-in user didn't visit the site for more than a couple of days, when they returned their first page view wouldn't reflect their benefits (i.e. they would see ads). This is due to a race condition between the user benefits refresh and ads code. However, we don't want to delay ads until after the user benefits have been refreshed as that would impact performance. So instead, extend the expiration of the cookie.

Note: this may result in a user getting benefits they no longer have on the first returning pageview, but this will be correct from the second page view onwards. We think this is OK.

This also means we now remove cookies if the user benefits response says they no longer have the benefit, rather than simply letting the cookie expire.

Note: this logic also exists in frontend and gateway, so has been updated in both those repos too:
guardian/frontend#28352
guardian/gateway#3285

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

@tjmw tjmw changed the title WIP: Extend expiration of user benefits cookies to 30 days Extend expiration of user benefits cookies to 30 days Nov 7, 2025
@tjmw tjmw force-pushed the tw/extend-benefits-cookie-expiration branch from 933b667 to b14c278 Compare December 1, 2025 12:23
tjmw added a commit to guardian/support-frontend that referenced this pull request Dec 2, 2025
The cookie which tracks when to refresh benefits cookies is reduced to 1
day, like everywhere else.

This is part of a wider change to benefits cookie expiration to fix an
issue where signed-in users with ad free benefits who didn't visit the
site for time period would sometimes see ads on their first returning
pageview. This change makes this less likely to happen by extending the
expiration of user benefits cookies.

This is due to a race condition between the user benefits refresh and
the ads code. However, we don't want to delay ads until after the user
benefits have been refreshed as that would impact performance. So
instead, extend the expiry of the cookie.

See also:
guardian/frontend#28352
guardian/dotcom-rendering#14810
guardian/gateway#3285
tjmw added 3 commits December 3, 2025 14:06
Previouly they were short lived (1-2 days) but this resulted in edge
cases where if a signed in user didn't visit the site for more than a
couple of days, when they returned their first page view wouldn't reflect
their benefits (i.e. they would see ads). This is due to a race
condition between the user benefits refresh and the ads code. However,
we don't want to delay ads until after the user benefits have been
refreshed as that would impact performance. So instead, extend the
expiry of the cookie.

Note: this may result in a user getting benefits they no longer have on
the first returning pageview, but this will be correct from the second
page view onwards. We think this is OK.

This also means we now remove cookies if the user benefits response says
they no longer have the benefit, rather than simply letting the cookie
expire.
@tjmw tjmw force-pushed the tw/extend-benefits-cookie-expiration branch from b14c278 to 5179c55 Compare December 3, 2025 14:06
@tjmw tjmw marked this pull request as ready for review December 3, 2025 16:54
@tjmw tjmw requested a review from a team as a code owner December 3, 2025 16:54
@github-actions
Copy link

github-actions bot commented Dec 3, 2025

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

@tjmw tjmw added the run_chromatic Runs chromatic when label is applied label Dec 3, 2025
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Dec 3, 2025
Copy link
Member

@rupertbates rupertbates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@tjmw tjmw merged commit b1c2335 into main Dec 8, 2025
29 checks passed
@tjmw tjmw deleted the tw/extend-benefits-cookie-expiration branch December 8, 2025 13:37
tjmw added a commit to guardian/frontend that referenced this pull request Dec 8, 2025
Before this change signed-in users who didn't visit the site for > 2 days would
sometimes see ads on their first returning pageview, even if they have a
product which gives them ad free access. This change makes this less likely to
happen by extending the expiration of user benefits cookies.

This PR extends the expiration of all user benefits cookies to 30 days -
GU_AF1, gu_allow_reject_all, gu_hide_support_messaging.

Previously user benefits cookies were short lived (1-2 days) but this resulted
in edge cases as described above. This is due to a race condition between the
user benefits refresh and the ads code. However, we don't want to delay ads
until after the user benefits have been refreshed as that would impact
performance. So instead, extend the expiry of the cookie.

Note: this may result in a user getting benefits they no longer have on the
first returning pageview, but this will be correct from the second page view
onwards. We think this is OK.

This also means we now remove cookies if the user benefits response says they
no longer have the benefit, rather than simply letting the cookie expire.

See also guardian/dotcom-rendering#14810.
tjmw added a commit to guardian/support-frontend that referenced this pull request Dec 8, 2025
Extend benefits cookie expiry to 30 days. The cookie which tracks when to
refresh benefits cookies is reduced to 1 day, like everywhere else.

This is part of a wider change to benefits cookie expiration to fix an issue
where signed-in users with ad free benefits who didn't visit the site for > the
length of the cookie expiration period would sometimes see ads on their first
returning pageview. This change makes this less likely to happen by extending
the expiration of user benefits cookies.

This is due to a race condition between the user benefits refresh and the ads
code. However, we don't want to delay ads until after the user benefits have
been refreshed as that would impact performance. So instead, extend the expiry
of the cookie.

See also:
guardian/frontend#28352
guardian/dotcom-rendering#14810
guardian/gateway#3285
@gu-prout
Copy link

gu-prout bot commented Dec 8, 2025

Overdue on PROD (merged by @tjmw 30 minutes and 6 seconds ago) What's gone wrong?

tjmw added a commit to guardian/gateway that referenced this pull request Dec 8, 2025
This PR extends the expiration of all user benefits cookies to 30 days -
`GU_AF1`, `gu_allow_reject_all`, `gu_hide_support_messaging`. The cookie
which tracks when the other cookies need refreshing
(`gu_user_benefits_expiry`) continue to have an expiry of 1 day.

Previously these cookies were short lived (1-2 days) but this resulted
in edge cases where if a signed in user didn't visit the site for more
than a couple of days, when they returned their first page view wouldn't
reflect their benefits (i.e. they would see ads). This is due to a race
condition between the user benefits refresh and the ads code. However,
we don't want to delay ads until after the user benefits have been
refreshed as that would impact performance. So instead, extend the
expiry of the cookie.

Note: this may result in a user getting benefits they no longer have on
the first returning pageview, but this will be correct from the second
page view onwards. We think this is OK.

See also:

guardian/frontend#28352
guardian/dotcom-rendering#14810
guardian/support-frontend#7559
@gu-prout
Copy link

gu-prout bot commented Dec 8, 2025

Seen on PROD (merged by @tjmw 1 hour, 46 minutes and 38 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants