WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4f9ce1a

Browse files
committed
Extend expiry of user benefits cookies to 30 days
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.
1 parent 48b47c4 commit 4f9ce1a

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
*
@@ -95,7 +97,7 @@ const persistUserBenefitsCookies = ({
9597
createCookie({
9698
name: USER_BENEFITS_EXPIRY_COOKIE,
9799
res,
98-
daysTillExpiry: 1,
100+
daysTillExpiry: USER_BENEFITS_COOKIE_EXPIRATION_IN_DAYS,
99101
});
100102
if (userBenefits?.benefits?.includes('hideSupportMessaging')) {
101103
createCookie({
@@ -106,11 +108,18 @@ const persistUserBenefitsCookies = ({
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)