Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/app/components/ATIAnalytics/atiUrl/index.client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ describe('atiUrl', () => {
x18: 'isLocServeCookieSet',
},
};
const userParams = { isSignedIn: false, hashedId: null };
const userParams = {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
};

expect(reverbAnalyticsModel.params.page).toEqual(pageParams);
expect(reverbAnalyticsModel.params.user).toEqual(userParams);
Expand Down Expand Up @@ -203,7 +207,11 @@ describe('atiUrl', () => {
x18: 'isLocServeCookieSet',
},
};
const userParams = { isSignedIn: false, hashedId: null };
const userParams = {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
};

expect(reverbAnalyticsModel.params.page).toEqual(pageParams);
expect(reverbAnalyticsModel.params.user).toEqual(userParams);
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/ATIAnalytics/atiUrl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const buildReverbAnalyticsModel = ({
experimentVariant,
isSignedIn = false,
hashedId = null,
isPersonalisationOn = false,
}: ATIPageTrackingProps): ReverbBeaconConfig => {
const href = getHref(platform);
const referrer = getReferrer(platform);
Expand Down Expand Up @@ -140,6 +141,7 @@ export const buildReverbAnalyticsModel = ({
user: {
isSignedIn,
hashedId,
isPersonalisationOn,
},
},
eventDetails,
Expand Down
21 changes: 18 additions & 3 deletions src/app/components/ATIAnalytics/index.client.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('ATI Analytics Container', () => {
},
},
user: {
isPersonalisationOn: false,
isSignedIn: false,
hashedId: null,
},
Expand Down Expand Up @@ -213,7 +214,11 @@ describe('ATI Analytics Container', () => {
x18: false,
},
},
user: { isSignedIn: false, hashedId: null },
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: { eventName: 'pageView' },
});
Expand Down Expand Up @@ -379,7 +384,11 @@ describe('ATI Analytics Container', () => {
x18: false,
},
},
user: { isSignedIn: false, hashedId: null },
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: { eventName: 'pageView' },
});
Expand Down Expand Up @@ -483,7 +492,11 @@ describe('ATI Analytics Container', () => {
x18: false,
},
},
user: { isSignedIn: false, hashedId: null },
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: { eventName: 'pageView' },
});
Expand Down Expand Up @@ -640,6 +653,7 @@ describe('ATI Analytics Container', () => {
},
},
user: {
isPersonalisationOn: false,
isSignedIn: false,
hashedId: null,
},
Expand Down Expand Up @@ -746,6 +760,7 @@ describe('ATI Analytics Container', () => {
},
},
user: {
isPersonalisationOn: false,
isSignedIn: false,
hashedId: null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('implementation of buildPageATIParams', () => {
categoryName: undefined,
contentId: 'urn:bbc:tipo:topic:cm7682qz7v1t',
contentType: 'index-home',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUk: undefined,
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('implementation of buildPageATIParams', () => {
categoryName: 'Refugees%20and%20asylum%20seekers~Myanmar~Military',
contentId: 'urn:bbc:optimo:asset:c9wxnzvwp3mo',
contentType: 'article',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: false,
Expand Down Expand Up @@ -199,6 +201,7 @@ describe('implementation of buildPageATIParams', () => {
categoryName: 'Environment~Narendra+Modi~Nature~India~Severe+weather',
contentId: 'urn:bbc:optimo:asset:c4nrpd0d4nro',
contentType: 'article-sfv',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: false,
Expand Down Expand Up @@ -249,6 +252,7 @@ describe('implementation of buildPageATIParams', () => {
categoryName: undefined,
contentId: 'urn:bbc:tipo:topic:c95y35941vrt',
contentType: 'index-category',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: undefined,
Expand Down Expand Up @@ -306,6 +310,7 @@ describe('implementation of buildPageATIParams', () => {
categoryName: undefined,
contentId: undefined,
contentType: 'list-datadriven',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: undefined,
Expand Down Expand Up @@ -387,6 +392,7 @@ describe('implementation of buildPageATIParams', () => {
contentId:
'urn:bbc:cps:curie:asset:3137d6de-62c2-4637-a002-29d2ab075990',
contentType: 'article',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: undefined,
Expand Down Expand Up @@ -466,6 +472,7 @@ describe('implementation of buildPageATIParams', () => {
contentId:
'urn:bbc:cps:curie:asset:6d745333-c79d-e245-a5b2-f4acb7de35e1',
contentType: 'article-media-asset',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: undefined,
Expand Down Expand Up @@ -543,6 +550,7 @@ describe('implementation of buildPageATIParams', () => {
contentId:
'urn:bbc:cps:curie:asset:08e22e90-7361-cd47-b586-7cb53fc5a012',
contentType: 'article-photo-gallery',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: undefined,
Expand Down Expand Up @@ -613,6 +621,7 @@ describe('implementation of buildPageATIParams', () => {
contentId:
'urn:bbc:cps:curie:asset:c1c8b1bf-4c9c-44e8-be0d-c81a2aa59e46',
contentType: 'article-correspondent',
isPersonalisationOn: false,
hashedId: null,
isSignedIn: false,
isUK: undefined,
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/ATIAnalytics/params/buildParams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export const buildPageATIParams = ({
serviceContext,
isSignedIn = false,
hashedId = null,
isPersonalisationOn = false,
}: ATIDataWithContexts & {
isSignedIn?: boolean;
hashedId?: string | null;
isPersonalisationOn?: boolean;
}) => {
const { isUK, platform, statsDestination, destinationSiteId } =
requestContext;
Expand Down Expand Up @@ -67,6 +69,7 @@ export const buildPageATIParams = ({
timeUpdated,
isSignedIn,
hashedId,
isPersonalisationOn,
...(ampExperimentName && { ampExperimentName }),
...(experimentName && { experimentName }),
...(experimentVariant && { experimentVariant }),
Expand All @@ -76,6 +79,7 @@ export const buildPageATIParams = ({
type BuildPageParamsArgs = ATIDataWithContexts & {
isSignedIn?: boolean;
hashedId?: string | null;
isPersonalisationOn?: boolean;
};

const buildPageReverbParams = ({
Expand All @@ -84,6 +88,7 @@ const buildPageReverbParams = ({
serviceContext,
isSignedIn,
hashedId,
isPersonalisationOn,
}: BuildPageParamsArgs) =>
buildReverbAnalyticsModel(
buildPageATIParams({
Expand All @@ -92,6 +97,7 @@ const buildPageReverbParams = ({
serviceContext,
isSignedIn,
hashedId,
isPersonalisationOn,
}),
);

Expand All @@ -118,6 +124,7 @@ export const buildAnalyticsParams = ({
serviceContext,
isSignedIn,
hashedId,
isPersonalisationOn,
}: BuildPageParamsArgs) => {
const { resonanceEnabled } = serviceContext;
const { platform } = requestContext;
Expand All @@ -132,6 +139,7 @@ export const buildAnalyticsParams = ({
serviceContext,
isSignedIn,
hashedId,
isPersonalisationOn,
}),
resonanceParams: sendResonanceEvents
? buildPageResonanceParams({
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/ATIAnalytics/params/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ describe('ATIAnalytics params', () => {
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: {
Expand Down Expand Up @@ -191,6 +192,7 @@ describe('ATIAnalytics params', () => {
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: {
Expand Down Expand Up @@ -235,6 +237,7 @@ describe('ATIAnalytics params', () => {
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: {
Expand Down Expand Up @@ -278,6 +281,7 @@ describe('ATIAnalytics params', () => {
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: {
Expand Down Expand Up @@ -322,6 +326,7 @@ describe('ATIAnalytics params', () => {
user: {
isSignedIn: false,
hashedId: null,
isPersonalisationOn: false,
},
},
eventDetails: {
Expand Down
3 changes: 3 additions & 0 deletions src/app/components/ATIAnalytics/params/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ export default ({
atiData,
isSignedIn,
hashedId,
isPersonalisationOn,
}: ReverbDetailsProviders & {
isSignedIn?: boolean;
hashedId?: string | null;
isPersonalisationOn?: boolean;
}) =>
buildAnalyticsParams({
atiData,
requestContext,
serviceContext,
isSignedIn,
hashedId,
isPersonalisationOn,
});
2 changes: 2 additions & 0 deletions src/app/components/ATIAnalytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export type ReverbPageVars = {
export type ReverbUserVars = {
isSignedIn: boolean;
hashedId?: string | null;
isPersonalisationOn?: boolean;
};

export type ReverbEventDetails = {
Expand Down Expand Up @@ -238,6 +239,7 @@ export interface ATIPageTrackingProps {
experimentVariant?: string | null;
isSignedIn?: boolean;
hashedId?: string | null;
isPersonalisationOn?: boolean;
}

export interface ATIProps {
Expand Down
17 changes: 16 additions & 1 deletion src/app/contexts/AccountContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import { getIdctaUserOrigin } from '#app/lib/idcta/getIDCTAUserOrigin';
import useToggle from '#app/hooks/useToggle';
import isLocal from '#app/lib/utilities/isLocal';
import { USER_ID_COOKIE_KEY } from '#app/lib/uasApi/uasUtility';
import { TOKEN_COOKIE_NAME } from '#app/lib/uasApi/tokenRefresh/tokenManager';
import {
TOKEN_COOKIE_NAME,
getDecodedToken,
} from '#app/lib/uasApi/tokenRefresh/tokenManager';

// Claim set by Account in the ckns_id JWT when a signed-in user opts out of personalisation
const ENABLE_PERSONALISATION_CLAIM = 'ep';

export const AccountContext = createContext<AccountContextProps>(
{} as AccountContextProps,
Expand Down Expand Up @@ -88,6 +94,13 @@ export const AccountProvider = ({

const isPersonalizationEnabled = isPersonalizationAvailable && isSignedIn;

const decodedIdToken = signedInToken ? getDecodedToken(signedInToken) : null;
const hasOptedOutOfPersonalisation =
decodedIdToken?.[ENABLE_PERSONALISATION_CLAIM] === false;

const isPersonalisationOn =
isPersonalizationEnabled && !hasOptedOutOfPersonalisation;

const isRefreshAvailable =
isIdctaAvailable && initialConfig?.availability?.refresh === 'GREEN';

Expand All @@ -104,6 +117,7 @@ export const AccountProvider = ({
forYouUrl,
isPersonalizationAvailable,
isPersonalizationEnabled,
isPersonalisationOn,
}),
[
hashedUserId,
Expand All @@ -117,6 +131,7 @@ export const AccountProvider = ({
signOutUrl,
isPersonalizationAvailable,
isPersonalizationEnabled,
isPersonalisationOn,
],
);

Expand Down
5 changes: 5 additions & 0 deletions src/app/contexts/ReverbParamsContext/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('ReverbParamsContext', () => {
user: {
hashedId: null,
isSignedIn: false,
isPersonalisationOn: false,
},
},
},
Expand Down Expand Up @@ -149,6 +150,7 @@ describe('ReverbParamsContext', () => {
user: {
hashedId: null,
isSignedIn: false,
isPersonalisationOn: false,
},
},
},
Expand Down Expand Up @@ -201,6 +203,7 @@ describe('ReverbParamsContext', () => {
user: {
hashedId: null,
isSignedIn: false,
isPersonalisationOn: false,
},
},
},
Expand Down Expand Up @@ -253,6 +256,7 @@ describe('ReverbParamsContext', () => {
user: {
hashedId: null,
isSignedIn: false,
isPersonalisationOn: false,
},
},
},
Expand Down Expand Up @@ -309,6 +313,7 @@ describe('ReverbParamsContext', () => {
user: {
hashedId: null,
isSignedIn: false,
isPersonalisationOn: false,
},
},
},
Expand Down
Loading
Loading