Skip to content

Commit 32374ae

Browse files
authored
Extend expiry of user benefits cookies to 30 days (#3285)
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
1 parent 8c51c17 commit 32374ae

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/server/lib/user-features.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const setUserFeatureCookies = async ({
3131
accessToken: string;
3232
res: Response;
3333
}): Promise<void> => {
34-
// call the members-data-api to get the user's attributes/products if any
34+
// call the user-benefits-api to get the user's attributes/products if any
3535

3636
const userBenefits = await getUserBenefits({
3737
accessToken,
@@ -74,6 +74,8 @@ const createCookie = ({
7474
});
7575
};
7676

77+
const USER_BENEFITS_COOKIE_EXPIRATION_IN_DAYS = 30;
78+
7779
/**
7880
* https://github.com/guardian/dotcom-rendering/blob/a0eff55ee7fedf08b785557fceaa0f4f7265e0df/dotcom-rendering/src/client/userFeatures/user-features.ts
7981
*
@@ -101,16 +103,23 @@ const persistUserBenefitsCookies = ({
101103
createCookie({
102104
name: HIDE_SUPPORT_MESSAGING_COOKIE,
103105
res,
104-
daysTillExpiry: 1,
106+
daysTillExpiry: USER_BENEFITS_COOKIE_EXPIRATION_IN_DAYS,
105107
});
106108
}
107109
// Allow reject all cookie
108110
if (userBenefits?.benefits?.includes('allowRejectAll')) {
109-
createCookie({ name: ALLOW_REJECT_ALL_COOKIE, res, daysTillExpiry: 1 });
111+
createCookie({
112+
name: ALLOW_REJECT_ALL_COOKIE,
113+
res,
114+
daysTillExpiry: USER_BENEFITS_COOKIE_EXPIRATION_IN_DAYS,
115+
});
110116
}
111-
// Ad free user cookie is set for 2 days
112-
// https://github.com/guardian/frontend/blob/f17fe93c542fbd448392a0687d0b92f35796097a/static/src/javascripts/projects/common/modules/commercial/user-features.ts#L128
117+
// Ad free user cookie
113118
if (userBenefits?.benefits?.includes('adFree')) {
114-
createCookie({ name: AD_FREE_USER_COOKIE, res, daysTillExpiry: 2 });
119+
createCookie({
120+
name: AD_FREE_USER_COOKIE,
121+
res,
122+
daysTillExpiry: USER_BENEFITS_COOKIE_EXPIRATION_IN_DAYS,
123+
});
115124
}
116125
};

0 commit comments

Comments
 (0)