Skip to content

Commit 8cf6116

Browse files
committed
Sign-in gate: emit events for ad slots
1 parent c87704a commit 8cf6116

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

dotcom-rendering/src/components/SignInGate/SignInGate.stories.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,14 @@ export const auxiaV2DismissibleModal = () => {
272272
host="https://www.theguardian.com"
273273
idUrl="https://profile.theguardian.com"
274274
contributionsServiceUrl="https://contributions.guardianapis.com"
275-
signInGateVersion="v2"
276275
auxiaGateDisplayData={{
277276
browserId: 'test-browser-id',
278277
auxiaData: {
279278
responseId: 'test-response-id',
280-
userTreatment:
281-
mockAuxiaResponseDismissible.data.userTreatment,
279+
userTreatment: {
280+
...mockAuxiaResponseDismissible.data.userTreatment,
281+
treatmentType: 'DISMISSABLE_SIGN_IN_GATE_POPUP',
282+
},
282283
},
283284
}}
284285
/>
@@ -298,13 +299,15 @@ export const auxiaV2NonDismissibleModal = () => {
298299
host="https://www.theguardian.com"
299300
idUrl="https://profile.theguardian.com"
300301
contributionsServiceUrl="https://contributions.guardianapis.com"
301-
signInGateVersion="v2"
302302
auxiaGateDisplayData={{
303303
browserId: 'test-browser-id',
304304
auxiaData: {
305305
responseId: 'test-response-id',
306-
userTreatment:
307-
mockAuxiaResponseNonDismissible.data.userTreatment,
306+
userTreatment: {
307+
...mockAuxiaResponseNonDismissible.data
308+
.userTreatment,
309+
treatmentType: 'NONDISMISSIBLE_SIGN_IN_GATE_POPUP',
310+
},
308311
},
309312
}}
310313
/>

dotcom-rendering/src/components/SignInGate/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,5 @@ export type SignInGatePropsAuxia = {
251251
) => Promise<void>;
252252
};
253253

254+
// v1 is in the article, v2 is a popup
254255
export type AuxiaGateVersion = 'v1' | 'v2';

dotcom-rendering/src/components/SignInGateSelector.importable.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type Props = {
3333
idUrl?: string;
3434
contributionsServiceUrl: string;
3535
auxiaGateDisplayData?: AuxiaGateDisplayData | undefined;
36-
signInGateVersion?: AuxiaGateVersion;
3736
};
3837

3938
// function to generate the profile.theguardian.com url with tracking params
@@ -87,12 +86,15 @@ export const SignInGateSelector = ({
8786
idUrl = 'https://profile.theguardian.com',
8887
contributionsServiceUrl,
8988
auxiaGateDisplayData,
90-
signInGateVersion,
9189
}: Props) => {
9290
if (!pageIdIsAllowedForGating(pageId)) {
9391
return <></>;
9492
}
9593

94+
const signInGateVersion = getAuxiaGateVersion(
95+
auxiaGateDisplayData?.auxiaData.userTreatment,
96+
);
97+
9698
return (
9799
<SignInGateSelectorAuxia
98100
host={host}
@@ -138,7 +140,7 @@ type PropsAuxia = {
138140
isPreview: boolean;
139141
isPaidContent: boolean;
140142
auxiaGateDisplayData?: AuxiaGateDisplayData;
141-
signInGateVersion?: AuxiaGateVersion;
143+
signInGateVersion: AuxiaGateVersion;
142144
};
143145

144146
// [1] If true, it indicates that we are using the component for the regular Auxia share of the Audience
@@ -158,7 +160,7 @@ interface ShowSignInGateAuxiaProps {
158160
interactionType: AuxiaInteractionInteractionType,
159161
actionName?: AuxiaInteractionActionName,
160162
) => Promise<void>;
161-
signInGateVersion?: AuxiaGateVersion;
163+
signInGateVersion: AuxiaGateVersion;
162164
}
163165

164166
const incrementGateDisplayCount = () => {
@@ -243,22 +245,21 @@ const buildAbTestTrackingAuxiaVariant = (
243245
};
244246
};
245247

248+
/**
249+
* Determines the gate version based on one of 2 things:
250+
* 1. url query parameter
251+
* 2. treatmentType
252+
*/
246253
export const getAuxiaGateVersion = (
247-
signInGateVersion?: AuxiaGateVersion,
248254
userTreatment?: AuxiaAPIResponseDataUserTreatment,
249255
): AuxiaGateVersion => {
250-
if (signInGateVersion) {
251-
return signInGateVersion;
252-
}
253-
254256
const params = new URLSearchParams(window.location.search);
255257
const version = params.get('auxia_gate_version');
256258

257259
if (
258260
String(version).toLowerCase().endsWith('v2') ||
259-
String(userTreatment?.treatmentType)
260-
.toLowerCase()
261-
.endsWith('POPUP')
261+
userTreatment?.treatmentType === 'DISMISSABLE_SIGN_IN_GATE_POPUP' ||
262+
userTreatment?.treatmentType === 'NONDISMISSIBLE_SIGN_IN_GATE_POPUP'
262263
) {
263264
return 'v2';
264265
}
@@ -300,6 +301,13 @@ const SignInGateSelectorAuxia = ({
300301
document.dispatchEvent(
301302
new CustomEvent('article:sign-in-gate-dismissed'),
302303
);
304+
305+
// Emit event for use by ad slots
306+
document.dispatchEvent(
307+
new CustomEvent(
308+
`article:sign-in-gate-${signInGateVersion}-dismissed`,
309+
),
310+
);
303311
}
304312
}, [isGateDismissed]);
305313

@@ -397,7 +405,7 @@ const ShowSignInGateAuxia = ({
397405
const personaliseSignInGateAfterCheckoutSwitch = undefined;
398406

399407
// Get the gate version configuration
400-
const gateVersion = getAuxiaGateVersion(signInGateVersion, userTreatment);
408+
// const gateVersion = getAuxiaGateVersion(signInGateVersion, userTreatment);
401409

402410
const [signInGatePlaceholder, setSignInGatePlaceholder] =
403411
useState<HTMLElement | null>(null);
@@ -417,6 +425,7 @@ const ShowSignInGateAuxia = ({
417425

418426
useEffect(() => {
419427
if (hasBeenSeen) {
428+
// Tell Auxia
420429
void auxiaLogTreatmentInteraction(
421430
contributionsServiceUrl,
422431
userTreatment,
@@ -436,6 +445,7 @@ const ShowSignInGateAuxia = ({
436445
);
437446
});
438447

448+
// Tell Ophan
439449
void submitComponentEventTracking(
440450
{
441451
component: {
@@ -451,6 +461,13 @@ const ShowSignInGateAuxia = ({
451461
// Once the gate is being displayed we need to update
452462
// the tracking of the number of times the gate has been displayed
453463
incrementGateDisplayCount();
464+
465+
// Emit event for use by ad slots
466+
document.dispatchEvent(
467+
new CustomEvent(
468+
`article:sign-in-gate-${signInGateVersion}-viewed`,
469+
),
470+
);
454471
}
455472
}, [
456473
componentId,
@@ -460,7 +477,7 @@ const ShowSignInGateAuxia = ({
460477
renderingTarget,
461478
treatmentId,
462479
userTreatment,
463-
gateVersion,
480+
signInGateVersion,
464481
]);
465482

466483
const commonProps = {
@@ -498,7 +515,7 @@ const ShowSignInGateAuxia = ({
498515
aria-hidden="true"
499516
style={{ height: 1, marginTop: -1 }}
500517
/>
501-
{gateVersion === 'v2' ? (
518+
{signInGateVersion === 'v2' ? (
502519
shouldShowV2Gate && <SignInGateAuxiaV2 {...commonProps} />
503520
) : (
504521
<SignInGateAuxiaV1 {...commonProps} />

dotcom-rendering/src/components/StickyBottomBanner/SignInGatePortal.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const SignInGatePortal = ({
3535
pageId: string;
3636
contributionsServiceUrl: string;
3737
idUrl: string;
38-
auxiaGateDisplayData?: AuxiaGateDisplayData | undefined;
38+
auxiaGateDisplayData: AuxiaGateDisplayData;
3939
}) => {
4040
const [shouldShowGate, setShouldShowGate] = useState<boolean>(false);
4141
const [targetElement, setTargetElement] = useState<HTMLElement | null>(
@@ -61,8 +61,7 @@ export const SignInGatePortal = ({
6161
useEffect(() => {
6262
const element = document.getElementById('sign-in-gate');
6363
const gateVersion = getAuxiaGateVersion(
64-
undefined,
65-
auxiaGateDisplayData?.auxiaData.userTreatment,
64+
auxiaGateDisplayData.auxiaData.userTreatment,
6665
);
6766

6867
/**

0 commit comments

Comments
 (0)