Skip to content
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

Connect the Liveblog Gutter Ask to SDC #13326

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4162626
bump version of SDC
Feb 6, 2025
0aa91d1
wip: build payload, call SDC via useSDC
Feb 6, 2025
2368321
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
Feb 7, 2025
2d98529
Pull test and variant data from SDC for the gutter ask
Feb 10, 2025
649bf40
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 10, 2025
7df9ac0
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 10, 2025
9e5230c
re-order, add abtest data to tracking, ensure module retrieved before…
Feb 10, 2025
4cf6409
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 10, 2025
7d5e624
No longer setting setShowSupportMessaging where we're also using it.
Feb 10, 2025
3432af8
Add GutterAskWrapper to handle ophan events and enrich urls.
Feb 11, 2025
fcb918b
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 11, 2025
22f5c93
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 12, 2025
b73b79d
remove tracking from SDC payload
Feb 12, 2025
38d45fc
Fix gutterAsk file name casing
Feb 12, 2025
ed0d892
Pick up all paragraphs in body copy from RRCP.
Feb 12, 2025
af29005
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 12, 2025
692da95
weird renaming issue
Feb 12, 2025
9bf11a5
Rename to original with case as intended
Feb 12, 2025
160a07c
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 12, 2025
0b03eb8
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 12, 2025
11f60b5
tidy and re-organise
Feb 12, 2025
0cd593c
Merge branch 'skb/connect-gutter-ask-to-sdc' of github.com:guardian/d…
Feb 12, 2025
b6fbbef
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 12, 2025
8f56704
Rename GutterWrapper for clarity
Feb 12, 2025
f664caf
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 13, 2025
7af23f0
reduce duplication
Feb 13, 2025
732641f
Remove unnecessary error
Feb 13, 2025
627efd2
optimisation - if hide reader revenue, don't call API
Feb 13, 2025
3236ea6
linting fix
Feb 13, 2025
3eec503
logging error to sentry
Feb 13, 2025
21c8dce
hide CTA in component if variants CTA is undefined - for instance if …
Feb 13, 2025
26aed4c
Remove unused function call to useSDC
Feb 13, 2025
b93c2c8
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 13, 2025
9161861
Refactor GutterAskWrapper into its own file
Feb 13, 2025
bc5ac42
Renaming StickyLiveblogAsk.importable.tsx file to LiveblogGutterAsk.i…
Feb 13, 2025
3da3893
Rename storybook component and file
Feb 13, 2025
f251654
Fix import order
Feb 13, 2025
f28b877
Renamed island to match exported component.
Feb 13, 2025
8f0d262
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 13, 2025
9b80bb3
Merge branch 'main' into skb/connect-gutter-ask-to-sdc
sookburt Feb 14, 2025
4ef7d2e
switch logic for support messaging.
Feb 14, 2025
bf87c34
Comments - add and remove
Feb 14, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import { css } from '@emotion/react';
import type { OphanComponentEvent } from '@guardian/libs';
import { getCookie, isUndefined } from '@guardian/libs';
import { palette, space } from '@guardian/source/foundations';
import { getGutterLiveblog } from '@guardian/support-dotcom-components';
import type {
ModuleData,
ModuleDataResponse,
} from '@guardian/support-dotcom-components/dist/dotcom';
import type {
GutterPayload,
GutterProps,
} from '@guardian/support-dotcom-components/dist/shared/types';
import type { Tracking } from '@guardian/support-dotcom-components/dist/shared/types/props/shared';
import { useEffect, useState } from 'react';
import { submitComponentEvent } from '../client/ophan/ophan';
import { shouldHideSupportMessaging } from '../lib/contributions';
import { useIsSignedIn } from '../lib/useAuthStatus';
import { useCountryCode } from '../lib/useCountryCode';
import { usePageViewId } from '../lib/usePageViewId';
import type { TagType } from '../types/tag';
import { useConfig } from './ConfigContext';
import { GutterAskWrapper } from './marketing/gutters/GutterAskWrapper';

interface LiveblogGutterAskBuilderProps {
sectionId: string | undefined;
tags: TagType[];
contributionsServiceUrl: string;
countryCode: string;
pageViewId: string;
pageUrl: string;
}

const LiveblogGutterAskBuilder = ({
sectionId,
tags,
contributionsServiceUrl,
countryCode,
pageViewId,
pageUrl,
}: LiveblogGutterAskBuilderProps) => {
const [supportGutterResponse, setSupportGutterResponse] =
useState<ModuleData<GutterProps> | null>(null);

const { renderingTarget } = useConfig();
const isSignedIn = useIsSignedIn();

// get gutter props
useEffect((): void => {
if (isUndefined(countryCode) || isSignedIn === 'Pending') {
return;
}
const tagIds = tags.map((tag) => tag.id);

const hideSupportMessagingForUser =
shouldHideSupportMessaging(isSignedIn);
if (hideSupportMessagingForUser === 'Pending') {
// We don't yet know the user's supporter status
return;
}

// CALL the API
const payload: GutterPayload = {
targeting: {
showSupportMessaging: !hideSupportMessagingForUser,
countryCode,
mvtId: Number(
getCookie({ name: 'GU_mvt_id', shouldMemoize: true }),
),
isSignedIn,
tagIds,
sectionId,
},
};

getGutterLiveblog(contributionsServiceUrl, payload)
.then((response: ModuleDataResponse<GutterProps>) => {
if (response.data) {
const { module } = response.data;
setSupportGutterResponse(module);
}
})
.catch((error) => {
const msg = `Error fetching gutter-ask tests: ${String(error)}`;

console.log(msg);
window.guardian.modules.sentry.reportError(
new Error(msg),
'rr-gutter-liveblog-ask-fetch',
);
});
}, [
countryCode,
isSignedIn,
contributionsServiceUrl,
pageViewId,
pageUrl,
sectionId,
tags,
]);

if (supportGutterResponse) {
const { props } = supportGutterResponse;

const tracking: Tracking = {
...props.tracking,
ophanPageId: pageViewId,
platformId: 'GUARDIAN_WEB',
referrerUrl: pageUrl,
};

const enrichedProps: GutterProps = {
...props,
tracking,
countryCode,
submitComponentEvent: (componentEvent: OphanComponentEvent) =>
submitComponentEvent(componentEvent, renderingTarget),
};

return (
<>
<div css={stickyLeft}>
<GutterAskWrapper {...enrichedProps} />
</div>
</>
);
} else {
return <></>;
}
};

// -------------------------------------------------------

// CSS outer container handles the position and stickiness
const stickyLeft = css`
background: ${palette.neutral[100]};
position: sticky;
top: ${space[3]}px;
width: 220px;
margin-left: ${space[5]}px;
margin-top: ${space[6]}px;
`;

interface LiveblogGutterAskWrapperProps {
shouldHideReaderRevenueOnArticle: boolean;
sectionId: string | undefined;
tags: TagType[];
contributionsServiceUrl: string;
pageUrl: string;
}

export const LiveblogGutterAskWrapper = ({
shouldHideReaderRevenueOnArticle,
sectionId,
tags,
contributionsServiceUrl,
pageUrl,
}: LiveblogGutterAskWrapperProps) => {
const { renderingTarget } = useConfig();
const countryCode = useCountryCode('liveblog-gutter-ask');
const pageViewId = usePageViewId(renderingTarget);

if (
shouldHideReaderRevenueOnArticle ||
isUndefined(countryCode) ||
isUndefined(pageViewId)
) {
return null;
}

return (
<LiveblogGutterAskBuilder
sectionId={sectionId}
tags={tags}
contributionsServiceUrl={contributionsServiceUrl}
countryCode={countryCode}
pageViewId={pageViewId}
pageUrl={pageUrl}
/>
);
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { css } from '@emotion/react';
import { space } from '@guardian/source/foundations';
import type { Meta, StoryObj } from '@storybook/react';
import lzstring from 'lz-string';
import { GutterAsk } from './gutterAsk';
import { GutterAsk } from './GutterAsk';
import { props } from './utils/storybook';

const { variant, enrichedUrl, onCtaClick } = props;

const Wrapper = ({ children }: { children: React.ReactNode }) => (
const VisualWrapper = ({ children }: { children: React.ReactNode }) => (
<div
css={css`
margin-left: ${space[5]}px;
Expand All @@ -23,7 +23,7 @@ type Props = WithJsonProps<React.ComponentProps<typeof GutterAsk>>;

const meta: Meta<Props> = {
component: GutterAsk,
title: 'Components/Marketing/StickyLiveblogAsk',
title: 'Components/Marketing/GutterAsk',
args: {
variant,
enrichedUrl,
Expand All @@ -35,9 +35,9 @@ const meta: Meta<Props> = {
? JSON.parse(lzstring.decompressFromEncodedURIComponent(json))
: {};
return (
<Wrapper>
<VisualWrapper>
<GutterAsk {...args} {...jsonProps} />
</Wrapper>
</VisualWrapper>
);
},
};
Expand Down
Loading
Loading