Skip to content

Commit 8177a27

Browse files
authored
Track card media in data-link-name (#14400)
* Rename video -> youtube-video as this is only used for youtube videos. This makes tracking the video context somewhat easier * Adds an media field to the data link name array. This field indicates what media type the card contains. If there is no media, this is resolved to `none`. We set the link name during card enhancement but we do not know at this stage what the card's media is. This is because we do not know details such as card size, which can impact rendered media. As a result of this, we potentially override the media section of the link name at the card level IF media is displayed on the card. * Update naming convention of video -> youtube-video * Rename CardImageType to CardMediaType and use shared type in the linkName setter * Prefer an appender function to overwriting the media type
1 parent f59ec08 commit 8177a27

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../../lib/articleFormat';
1414
import { isMediaCard } from '../../lib/cardHelpers';
1515
import { isWithinTwelveHours, secondsToDuration } from '../../lib/formatTime';
16+
import { appendLinkNameMedia } from '../../lib/getDataLinkName';
1617
import { getZIndex } from '../../lib/getZIndex';
1718
import { DISCUSSION_ID_DATA_ATTRIBUTE } from '../../lib/useCommentCount';
1819
import { BETA_CONTAINERS } from '../../model/enhanceCollections';
@@ -278,7 +279,7 @@ const getMedia = ({
278279
}
279280
if (mainMedia?.type === 'Video' && canPlayInline) {
280281
return {
281-
type: 'video',
282+
type: 'youtube-video',
282283
mainMedia,
283284
} as const;
284285
}
@@ -550,6 +551,11 @@ export const Card = ({
550551
isInLoopingVideoTestControl,
551552
});
552553

554+
const resolvedDataLinkName =
555+
media && dataLinkName
556+
? appendLinkNameMedia(dataLinkName, media.type)
557+
: dataLinkName;
558+
553559
/**
554560
* For opinion type cards with avatars (which aren't onwards content)
555561
* we render the footer in a different location
@@ -734,7 +740,7 @@ export const Card = ({
734740
<CardLink
735741
linkTo={linkTo}
736742
headlineText={headlineText}
737-
dataLinkName={dataLinkName}
743+
dataLinkName={resolvedDataLinkName}
738744
isExternalLink={isExternalLink}
739745
/>
740746
{headlinePosition === 'outer' && (
@@ -879,7 +885,7 @@ export const Card = ({
879885
/>
880886
</Island>
881887
)}
882-
{media.type === 'video' && (
888+
{media.type === 'youtube-video' && (
883889
<>
884890
{showVideo ? (
885891
<div

dotcom-rendering/src/components/Card/components/CardLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css } from '@emotion/react';
22
import { isUndefined } from '@guardian/libs';
33
import { from, space } from '@guardian/source/foundations';
4-
import type { CardImageType } from '../../../types/layout';
4+
import type { CardMediaType } from '../../../types/layout';
55
import type { ImagePositionType } from './ImageWrapper';
66

77
export type GapSize = 'none' | 'tiny' | 'small' | 'medium' | 'large';
@@ -11,7 +11,7 @@ export type GapSizes = { row: GapSize; column: GapSize };
1111
type Props = {
1212
children: React.ReactNode;
1313
cardBackgroundColour: string;
14-
imageType: CardImageType | undefined;
14+
imageType: CardMediaType | undefined;
1515
imagePositionOnDesktop: ImagePositionType;
1616
imagePositionOnMobile: ImagePositionType;
1717
minWidthInPixels?: number;

dotcom-rendering/src/components/Card/components/ContentWrapper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { SerializedStyles } from '@emotion/react';
22
import { css } from '@emotion/react';
33
import { between, from, space, until } from '@guardian/source/foundations';
4-
import type { CardImageType } from '../../../types/layout';
4+
import type { CardMediaType } from '../../../types/layout';
55
import type { ImagePositionType, ImageSizeType } from './ImageWrapper';
66

77
const sizingStyles = css`
@@ -21,7 +21,7 @@ const flexBasisStyles = ({
2121
isBetaContainer,
2222
}: {
2323
imageSize: ImageSizeType;
24-
imageType?: CardImageType;
24+
imageType?: CardMediaType;
2525
isBetaContainer: boolean;
2626
}): SerializedStyles => {
2727
if (imageType === 'avatar') {
@@ -115,7 +115,7 @@ const getImageDirection = (
115115

116116
type Props = {
117117
children: React.ReactNode;
118-
imageType?: CardImageType;
118+
imageType?: CardMediaType;
119119
imageSize: ImageSizeType;
120120
isBetaContainer: boolean;
121121
imagePositionOnDesktop: ImagePositionType;

dotcom-rendering/src/components/Card/components/ImageWrapper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { SerializedStyles } from '@emotion/react';
22
import { css } from '@emotion/react';
33
import { between, from, space, until } from '@guardian/source/foundations';
4-
import type { CardImageType } from '../../../types/layout';
4+
import type { CardMediaType } from '../../../types/layout';
55

66
const imageFixedSize = {
77
tiny: 86,
@@ -34,7 +34,7 @@ type Props = {
3434
children: React.ReactNode;
3535
imageSize: ImageSizeType;
3636
imageFixedSizes?: ImageFixedSizeOptions;
37-
imageType?: CardImageType;
37+
imageType?: CardMediaType;
3838
imagePositionOnDesktop: ImagePositionType;
3939
imagePositionOnMobile: ImagePositionType;
4040
/**
@@ -173,7 +173,7 @@ export const ImageWrapper = ({
173173
css={[
174174
(imageType === 'slideshow' ||
175175
imageType === 'picture' ||
176-
imageType === 'video' ||
176+
imageType === 'youtube-video' ||
177177
imageType === 'loop-video') &&
178178
isHorizontalOnDesktop &&
179179
flexBasisStyles({

dotcom-rendering/src/lib/getDataLinkName.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FEFrontCardStyle } from '../frontend/feFront';
2-
import type { RichLinkCardType } from '../types/layout';
2+
import type { CardMediaType, RichLinkCardType } from '../types/layout';
33
import {
44
ArticleDesign,
55
type ArticleFormat,
@@ -58,6 +58,7 @@ export type Group = `${number}` | `${number}+`;
5858
*
5959
* @see {JSX.IntrinsicAttributes}
6060
*/
61+
6162
export const getDataLinkNameCard = (
6263
format: ArticleFormat,
6364
group: Group,
@@ -69,3 +70,12 @@ export const getDataLinkNameCard = (
6970
`group-${group}`,
7071
`card-@${Math.max(index + 1, 1)}`,
7172
].join(' | ');
73+
74+
type MediaType = CardMediaType | 'none';
75+
76+
export const appendLinkNameMedia = (
77+
dataLinkName: string,
78+
mediaType: MediaType,
79+
): string => {
80+
return `${dataLinkName} | media-${mediaType}`;
81+
};

dotcom-rendering/src/types/layout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ export type RichLinkCardType =
2121
| 'external'
2222
| 'news';
2323

24-
export type CardImageType =
24+
export type CardMediaType =
2525
| 'picture'
2626
| 'avatar'
2727
| 'crossword'
2828
| 'slideshow'
29-
| 'video'
29+
| 'youtube-video'
3030
| 'loop-video'
3131
| 'podcast';
3232

0 commit comments

Comments
 (0)