-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Supporter Revenue cookie lifecycle #13277
Conversation
513b12d
to
effeacc
Compare
Size Change: -1.47 kB (-0.16%) Total Size: 899 kB
ℹ️ View Unchanged
|
@@ -0,0 +1,17 @@ | |||
import { getCookie } from '@guardian/libs'; | |||
|
|||
export const USER_BENEFITS_EXPIRY_COOKIE = 'gu_user_features_expiry'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to change the name of this cookie to gu_user_benefits_expiry
at some point but I'm waiting for the go ahead from Transparency and Consent before doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got the go ahead from Emily for this change now.
if ((await isUserLoggedInOktaRefactor()) && featuresDataIsOld()) { | ||
return requestNewData(); | ||
} else if ((await userHasDataAfterSignOut()) && !forcedAdFreeMode) { | ||
deleteAllCookies(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't explicitly delete any user benefits cookies now, we just let the expiry time remove them which will take a maximum of 24 hrs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And to check my understanding -
if the user is signed in and the cookie has expired, then the client will refresh the cookie? And so there cannot be a period between expiry and the next refresh where the benefits are missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there could be a gap, but if there is (if the benefits expiry cookie is not up to date) then we err on the side of giving benefits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1a42fd9
to
e542c62
Compare
Hello 👋! When you're ready to run Chromatic, please apply the You will need to reapply the label each time you want to run Chromatic. |
const expiresValue = timeInDaysFromNow(daysTillExpiry); | ||
setCookie({ | ||
name: cookieName, | ||
value: expiresValue.toString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in thinking the value is never used by DCR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's right, we have to give it some value so I thought I'd put the expiry value in there even though we don't really use it. If you have a better suggestion though I'm open to changing it.
return tmpDate.getTime(); | ||
}; | ||
|
||
export const extendCookieExpiry = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function works like an upsert right? I.e. it'll create if it doesn't already exist or update if it does. I wonder if there's a name which reflects that, just to make it really clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this to createOrRenewCookie
…-benefits-cookies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good (with one minor question) 👍
describe('Refreshing the features data', () => { | ||
const expectUserBenefitExpiryCookieHasBeenSetCorrectly = () => { | ||
const expectedNextRefreshDate = new Date( | ||
timeInDaysFromNow(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a danger here that the system clock could tick over to the next second between the cookie being set and running this assertion, resulting in flaky tests? Should we be freezing time in the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check just looks at the date though not the time, so I think it's ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry yep you're right, how did I miss that?!
Seen on PROD (merged by @rupertbates 9 minutes and 46 seconds ago) Please check your changes! |
What does this change?
This PR changes the way that DCR handles supporter-revenue cookies to be consistent with this document
Why?
As described in the document, this gives us greater control over the benefits received by users on DCR, particularly in the way they can be set from support.theguardian.com.