Skip to content

Commit

Permalink
Merge pull request #12983 from guardian/remove-support-cookies
Browse files Browse the repository at this point in the history
Remove lastOneOffContributionDate and isRecurringContributor from payload sent to SDC
  • Loading branch information
rupertbates authored Dec 12, 2024
2 parents 9895a0d + 5d2f6a9 commit 4212c19
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 236 deletions.
2 changes: 1 addition & 1 deletion dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@guardian/shimport": "1.0.2",
"@guardian/source": "8.0.0",
"@guardian/source-development-kitchen": "12.0.0",
"@guardian/support-dotcom-components": "3.1.0",
"@guardian/support-dotcom-components": "3.2.0",
"@guardian/tsconfig": "0.2.0",
"@playwright/test": "1.45.3",
"@sentry/browser": "7.75.1",
Expand Down
55 changes: 0 additions & 55 deletions dotcom-rendering/src/client/userFeatures/user-features.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,11 @@ const getAuthStatus = getAuthStatus_ as jest.MockedFunction<

const PERSISTENCE_KEYS = {
USER_FEATURES_EXPIRY_COOKIE: 'gu_user_features_expiry',
PAYING_MEMBER_COOKIE: 'gu_paying_member',
RECURRING_CONTRIBUTOR_COOKIE: 'gu_recurring_contributor',
AD_FREE_USER_COOKIE: 'GU_AF1',
ACTION_REQUIRED_FOR_COOKIE: 'gu_action_required_for',
DIGITAL_SUBSCRIBER_COOKIE: 'gu_digital_subscriber',
SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE: 'gu.contributions.contrib-timestamp',
ONE_OFF_CONTRIBUTION_DATE_COOKIE: 'gu_one_off_contribution_date',
HIDE_SUPPORT_MESSAGING_COOKIE: 'gu_hide_support_messaging',
SUPPORT_MONTHLY_CONTRIBUTION_COOKIE:
'gu.contributions.recurring.contrib-timestamp.Monthly',
SUPPORT_ANNUAL_CONTRIBUTION_COOKIE:
'gu.contributions.recurring.contrib-timestamp.Annual',
};

const setAllFeaturesData = (opts: { isExpired: boolean }) => {
Expand All @@ -58,11 +51,6 @@ const setAllFeaturesData = (opts: { isExpired: boolean }) => {
const adFreeExpiryDate = opts.isExpired
? new Date(currentTime - msInOneDay * 2)
: new Date(currentTime + msInOneDay * 2);
setCookie({ name: PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE, value: 'true' });
setCookie({
name: PERSISTENCE_KEYS.RECURRING_CONTRIBUTOR_COOKIE,
value: 'true',
});
setCookie({
name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE,
value: 'true',
Expand All @@ -86,8 +74,6 @@ const setAllFeaturesData = (opts: { isExpired: boolean }) => {
};

const deleteAllFeaturesData = () => {
removeCookie({ name: PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE });
removeCookie({ name: PERSISTENCE_KEYS.RECURRING_CONTRIBUTOR_COOKIE });
removeCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE });
removeCookie({ name: PERSISTENCE_KEYS.USER_FEATURES_EXPIRY_COOKIE });
removeCookie({ name: PERSISTENCE_KEYS.AD_FREE_USER_COOKIE });
Expand Down Expand Up @@ -125,14 +111,6 @@ describe('Refreshing the features data', () => {
it('Does not delete the data just because it has expired', async () => {
setAllFeaturesData({ isExpired: true });
await refresh();
expect(
getCookie({ name: PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE }),
).toBe('true');
expect(
getCookie({
name: PERSISTENCE_KEYS.RECURRING_CONTRIBUTOR_COOKIE,
}),
).toBe('true');
expect(
getCookie({
name: PERSISTENCE_KEYS.USER_FEATURES_EXPIRY_COOKIE,
Expand All @@ -148,15 +126,6 @@ describe('Refreshing the features data', () => {
await refresh();
expect(fetchJsonSpy).not.toHaveBeenCalled();
});

it('Performs an update if membership-frontend wipes just the paying-member cookie', async () => {
// Set everything except paying-member cookie
setAllFeaturesData({ isExpired: true });
removeCookie({ name: PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE });

await refresh();
expect(fetchJsonSpy).toHaveBeenCalledTimes(1);
});
});
});
describe('If user signed out', () => {
Expand All @@ -178,14 +147,6 @@ describe('If user signed out', () => {
expect(
getCookie({ name: PERSISTENCE_KEYS.AD_FREE_USER_COOKIE }),
).toBeNull();
expect(
getCookie({ name: PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE }),
).toBeNull();
expect(
getCookie({
name: PERSISTENCE_KEYS.RECURRING_CONTRIBUTOR_COOKIE,
}),
).toBeNull();
expect(
getCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE }),
).toBeNull();
Expand Down Expand Up @@ -270,14 +231,6 @@ describe('Storing new feature data', () => {
}),
);
return refresh().then(() => {
expect(
getCookie({ name: PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE }),
).toBe('false');
expect(
getCookie({
name: PERSISTENCE_KEYS.RECURRING_CONTRIBUTOR_COOKIE,
}),
).toBe('false');
expect(
getCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE }),
).toBe('false');
Expand All @@ -300,14 +253,6 @@ describe('Storing new feature data', () => {
}),
);
return refresh().then(() => {
expect(
getCookie({ name: PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE }),
).toBe('true');
expect(
getCookie({
name: PERSISTENCE_KEYS.RECURRING_CONTRIBUTOR_COOKIE,
}),
).toBe('true');
expect(
getCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE }),
).toBe('true');
Expand Down
24 changes: 0 additions & 24 deletions dotcom-rendering/src/client/userFeatures/user-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,18 @@ import {
import type { UserFeaturesResponse } from './user-features-lib';

const USER_FEATURES_EXPIRY_COOKIE = 'gu_user_features_expiry';
const PAYING_MEMBER_COOKIE = 'gu_paying_member';
const ACTION_REQUIRED_FOR_COOKIE = 'gu_action_required_for';
const DIGITAL_SUBSCRIBER_COOKIE = 'gu_digital_subscriber';
const HIDE_SUPPORT_MESSAGING_COOKIE = 'gu_hide_support_messaging';
const AD_FREE_USER_COOKIE = 'GU_AF1';

const RECURRING_CONTRIBUTOR_COOKIE = 'gu_recurring_contributor';
const ONE_OFF_CONTRIBUTION_DATE_COOKIE = 'gu_one_off_contribution_date';

const forcedAdFreeMode = !!/[#&]noadsaf(&.*)?$/.exec(window.location.hash);

const userHasData = () => {
const cookie =
getAdFreeCookie() ??
getCookie({ name: ACTION_REQUIRED_FOR_COOKIE }) ??
getCookie({ name: USER_FEATURES_EXPIRY_COOKIE }) ??
getCookie({ name: PAYING_MEMBER_COOKIE }) ??
getCookie({ name: RECURRING_CONTRIBUTOR_COOKIE }) ??
getCookie({ name: ONE_OFF_CONTRIBUTION_DATE_COOKIE }) ??
getCookie({ name: DIGITAL_SUBSCRIBER_COOKIE }) ??
getCookie({ name: HIDE_SUPPORT_MESSAGING_COOKIE });
return !!cookie;
Expand All @@ -69,14 +62,6 @@ const persistResponse = (JsonResponse: UserFeaturesResponse) => {
name: USER_FEATURES_EXPIRY_COOKIE,
value: timeInDaysFromNow(1),
});
setCookie({
name: PAYING_MEMBER_COOKIE,
value: String(JsonResponse.contentAccess.paidMember),
});
setCookie({
name: RECURRING_CONTRIBUTOR_COOKIE,
value: String(JsonResponse.contentAccess.recurringContributor),
});
setCookie({
name: DIGITAL_SUBSCRIBER_COOKIE,
value: String(JsonResponse.contentAccess.digitalPack),
Expand All @@ -85,12 +70,6 @@ const persistResponse = (JsonResponse: UserFeaturesResponse) => {
name: HIDE_SUPPORT_MESSAGING_COOKIE,
value: String(!JsonResponse.showSupportMessaging),
});
if (JsonResponse.oneOffContributionDate) {
setCookie({
name: ONE_OFF_CONTRIBUTION_DATE_COOKIE,
value: JsonResponse.oneOffContributionDate,
});
}

removeCookie({ name: ACTION_REQUIRED_FOR_COOKIE });
if (JsonResponse.alertAvailableFor) {
Expand All @@ -110,12 +89,9 @@ const persistResponse = (JsonResponse: UserFeaturesResponse) => {
const deleteOldData = (): void => {
removeCookie({ name: AD_FREE_USER_COOKIE });
removeCookie({ name: USER_FEATURES_EXPIRY_COOKIE });
removeCookie({ name: PAYING_MEMBER_COOKIE });
removeCookie({ name: RECURRING_CONTRIBUTOR_COOKIE });
removeCookie({ name: ACTION_REQUIRED_FOR_COOKIE });
removeCookie({ name: DIGITAL_SUBSCRIBER_COOKIE });
removeCookie({ name: HIDE_SUPPORT_MESSAGING_COOKIE });
removeCookie({ name: ONE_OFF_CONTRIBUTION_DATE_COOKIE });
};

const requestNewData = () => {
Expand Down
5 changes: 0 additions & 5 deletions dotcom-rendering/src/components/LiveBlogEpic.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { createPortal } from 'react-dom';
import { submitComponentEvent } from '../client/ophan/ophan';
import { useArticleCounts } from '../lib/articleCount';
import {
getLastOneOffContributionTimestamp,
isRecurringContributor,
shouldHideSupportMessaging,
useHasOptedOutOfArticleCount,
} from '../lib/contributions';
Expand Down Expand Up @@ -125,9 +123,6 @@ const usePayload = ({
isPaidContent,
tags,
showSupportMessaging: !hideSupportMessagingForUser,
isRecurringContributor: isRecurringContributor(isSignedIn),
lastOneOffContributionDate:
getLastOneOffContributionTimestamp() ?? undefined,
mvtId,
countryCode,
epicViewLog: getEpicViewLog(storage.local),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { css } from '@emotion/react';
import { cmp } from '@guardian/libs';
import { getCookie, startPerformanceMeasure, storage } from '@guardian/libs';
import {
cmp,
getCookie,
startPerformanceMeasure,
storage,
} from '@guardian/libs';
import type { ComponentEvent } from '@guardian/ophan-tracker-js';
import { getEpic, getEpicViewLog } from '@guardian/support-dotcom-components';
import type {
Expand All @@ -12,11 +16,9 @@ import type {
import { useEffect, useState } from 'react';
import { submitComponentEvent } from '../../client/ophan/ophan';
import {
getLastOneOffContributionTimestamp,
hasCmpConsentForBrowserId,
hasCmpConsentForWeeklyArticleCount,
hasOptedOutOfArticleCount,
isRecurringContributor,
shouldHideSupportMessaging,
} from '../../lib/contributions';
import { lazyFetchEmailWithTimeout } from '../../lib/fetchEmail';
Expand Down Expand Up @@ -70,10 +72,6 @@ const buildPayload = async (
isPaidContent: data.isPaidContent,
tags: data.tags,
showSupportMessaging: !data.hideSupportMessagingForUser,
isRecurringContributor: isRecurringContributor(
data.isSignedIn ?? false,
),
lastOneOffContributionDate: getLastOneOffContributionTimestamp(),
epicViewLog: getEpicViewLog(storage.local),
weeklyArticleHistory: await data.asyncArticleCount,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useEffect, useState } from 'react';
import { submitComponentEvent } from '../../client/ophan/ophan';
import type { ArticleCounts } from '../../lib/articleCount';
import {
getLastOneOffContributionDate,
getPurchaseInfo,
hasCmpConsentForBrowserId,
hasOptedOutOfArticleCount,
Expand Down Expand Up @@ -165,7 +164,6 @@ const buildPayload = async ({
: undefined,
purchaseInfo: getPurchaseInfo(),
isSignedIn,
lastOneOffContributionDate: getLastOneOffContributionDate(),
hasConsented: userConsent,
abandonedBasket: parseAbandonedBasket(
getCookie({ name: 'GU_CO_INCOMPLETE', shouldMemoize: true }),
Expand Down
2 changes: 0 additions & 2 deletions dotcom-rendering/src/components/TopBarSupport.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
import { useEffect, useState } from 'react';
import { submitComponentEvent } from '../client/ophan/ophan';
import {
getLastOneOffContributionDate,
getPurchaseInfo,
shouldHideSupportMessaging,
} from '../lib/contributions';
Expand Down Expand Up @@ -81,7 +80,6 @@ const ReaderRevenueLinksRemote = ({
mvtId: Number(
getCookie({ name: 'GU_mvt_id', shouldMemoize: true }),
),
lastOneOffContributionDate: getLastOneOffContributionDate(),
purchaseInfo: getPurchaseInfo(),
isSignedIn,
},
Expand Down
58 changes: 12 additions & 46 deletions dotcom-rendering/src/lib/contributions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
HIDE_SUPPORT_MESSAGING_COOKIE,
isRecentOneOffContributor,
NO_RR_BANNER_KEY,
ONE_OFF_CONTRIBUTION_DATE_COOKIE,
recentlyClosedBanner,
setLocalNoBannerCachePeriod,
SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE,
Expand All @@ -22,23 +21,10 @@ const clearAllCookies = () => {
}
};

describe('getLastOneOffContributionDate', () => {
describe('getLastOneOffContributionTimestamp', () => {
beforeEach(clearAllCookies);

it('returns date from attributes cookie if only cookie found', () => {
const somePastDate = '2020-01-28';
setCookie({
name: ONE_OFF_CONTRIBUTION_DATE_COOKIE,
value: somePastDate,
});
const lastOneOffContributionDate = getLastOneOffContributionTimestamp();

// Our function will convert YYYY-MM-DD into a timestamp
const somePastDateToTimestamp = Date.parse(somePastDate);
expect(lastOneOffContributionDate).toBe(somePastDateToTimestamp);
});

it('returns a support cookie date if only cookie found', () => {
it('returns a support cookie date if found', () => {
const somePastDate = 1582567969093;
setCookie({
name: SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE,
Expand All @@ -48,31 +34,10 @@ describe('getLastOneOffContributionDate', () => {
expect(lastOneOffContributionDate).toBe(somePastDate);
});

it('returns the most recent date if both cookies present', () => {
const muchLongerAgo = '2020-01-28';
setCookie({
name: ONE_OFF_CONTRIBUTION_DATE_COOKIE,
value: muchLongerAgo,
});

const notSoLongAgo = 1582567969093;
it('returns undefined if the date cannot be parsed correctly', () => {
setCookie({
name: SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE,
value: String(notSoLongAgo),
});

const lastOneOffContributionDate = getLastOneOffContributionTimestamp();
expect(lastOneOffContributionDate).toBe(notSoLongAgo);
});

it('returns an empty string if no dates can be parsed correctly', () => {
setCookie({
name: ONE_OFF_CONTRIBUTION_DATE_COOKIE,
value: 'CANT_TOUCH_THIS',
});
setCookie({
name: SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE,
value: 'OR_THIS',
value: 'NOT_A_DATE',
});

const lastOneOffContributionDate = getLastOneOffContributionTimestamp();
Expand All @@ -97,27 +62,28 @@ describe('isRecentOneOffContributor', () => {

it('returns true if there are 5 days between the last contribution date and now', () => {
setCookie({
name: ONE_OFF_CONTRIBUTION_DATE_COOKIE,
value: '2018-08-01',
name: SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE,
value: Date.parse('2018-08-01').toString(),
});

MockDate.set(Date.parse('2018-08-07T10:50:34'));
expect(isRecentOneOffContributor()).toBe(true);
});

it('returns true if there are 0 days between the last contribution date and now', () => {
const theDate = Date.parse('2018-08-01T13:00:30');
setCookie({
name: ONE_OFF_CONTRIBUTION_DATE_COOKIE,
value: '2018-08-01',
name: SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE,
value: theDate.toString(),
});
MockDate.set(Date.parse('2018-08-01T13:00:30'));
MockDate.set(theDate);
expect(isRecentOneOffContributor()).toBe(true);
});

it('returns false if the one-off contribution was more than 3 months ago', () => {
setCookie({
name: ONE_OFF_CONTRIBUTION_DATE_COOKIE,
value: '2018-08-01',
name: SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE,
value: Date.parse('2018-08-01').toString(),
});
MockDate.set(Date.parse('2019-08-01T13:00:30'));
expect(isRecentOneOffContributor()).toBe(false);
Expand Down
Loading

0 comments on commit 4212c19

Please sign in to comment.