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

Share AdTargeting between Islands #8095

Merged
merged 4 commits into from
Jul 3, 2023
Merged
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
21 changes: 0 additions & 21 deletions dotcom-rendering/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,27 +277,6 @@ interface FENavType {

type StageType = 'DEV' | 'CODE' | 'PROD';

/**
* BlocksRequest is the expected body format for POST requests made to /Blocks
*/
interface FEBlocksRequest {
blocks: Block[];
format: FEFormat;
host?: string;
pageId: string;
webTitle: string;
ajaxUrl: string;
isAdFreeUser: boolean;
isSensitive: boolean;
edition: string;
section: string;
sharedAdTargeting: Record<string, unknown>;
adUnit: string;
videoDuration?: number;
switches: { [key: string]: boolean };
keywordIds: string;
}

/**
* KeyEventsRequest is the expected body format for POST requests made to /KeyEvents
*/
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@emotion/react": "11.10.5",
"@emotion/server": "11.10.0",
"@guardian/ab-core": "4.0.0",
"@guardian/atoms-rendering": "31.0.0",
"@guardian/atoms-rendering": "32.2.0",
"@guardian/braze-components": "13.3.0",
"@guardian/bridget": "2.3.0",
"@guardian/browserslist-config": "5.0.0",
Expand Down
4 changes: 0 additions & 4 deletions dotcom-rendering/src/components/ArticleBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Props = {
format: ArticleFormat;
blocks: Block[];
pinnedPost?: Block;
adTargeting: AdTargeting;
host?: string;
pageId: string;
webTitle: string;
Expand Down Expand Up @@ -123,7 +122,6 @@ export const ArticleBody = ({
format,
blocks,
pinnedPost,
adTargeting,
host,
pageId,
webTitle,
Expand Down Expand Up @@ -183,7 +181,6 @@ export const ArticleBody = ({
format={format}
blocks={blocks}
pinnedPost={pinnedPost}
adTargeting={adTargeting}
host={host}
pageId={pageId}
webTitle={webTitle}
Expand Down Expand Up @@ -239,7 +236,6 @@ export const ArticleBody = ({
<ArticleRenderer
format={format}
elements={blocks[0] ? blocks[0].elements : []}
adTargeting={adTargeting}
host={host}
pageId={pageId}
webTitle={webTitle}
Expand Down
15 changes: 15 additions & 0 deletions dotcom-rendering/src/components/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ArticleDesign } from '@guardian/libs';
import { brandAlt, focusHalo, neutral } from '@guardian/source-foundations';
import { StrictMode } from 'react';
import { DecideLayout } from '../layouts/DecideLayout';
import { buildAdTargeting } from '../lib/ad-targeting';
import { filterABTestSwitches } from '../model/enhance-switches';
import type { NavType } from '../model/extract-nav';
import type { FEArticleType } from '../types/frontend';
Expand All @@ -16,6 +17,7 @@ import { Island } from './Island';
import { Metrics } from './Metrics.importable';
import { ReaderRevenueDev } from './ReaderRevenueDev.importable';
import { SetABTests } from './SetABTests.importable';
import { SetAdTargeting } from './SetAdTargeting.importable';
import { SkipTo } from './SkipTo';

interface BaseProps {
Expand All @@ -39,6 +41,16 @@ interface AppProps extends BaseProps {
* */
export const ArticlePage = (props: WebProps | AppProps) => {
const { article, format, renderingTarget } = props;

const adTargeting = buildAdTargeting({
isAdFreeUser: article.isAdFreeUser,
isSensitive: article.config.isSensitive,
edition: article.config.edition,
section: article.config.section,
sharedAdTargeting: article.config.sharedAdTargeting,
adUnit: article.config.adUnit,
});

return (
<StrictMode>
<Global
Expand Down Expand Up @@ -102,6 +114,9 @@ export const ArticlePage = (props: WebProps | AppProps) => {
isDev={!!article.config.isDev}
/>
</Island>
<Island clientOnly={true}>
<SetAdTargeting adTargeting={adTargeting} />
</Island>
</>
)}
{renderingTarget === 'Apps' ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useEffect, useRef, useState } from 'react';
import { initPerf } from '../client/initPerf';
import { submitComponentEvent } from '../client/ophan/ophan';
import { isServer } from '../lib/isServer';
import { useIsInView } from '../lib/useIsInView';

const isServer = typeof window === 'undefined';

const pinnedPost: HTMLElement | null = !isServer
? window.document.querySelector('[data-gu-marker=pinned-post]')
: null;
Expand Down
14 changes: 14 additions & 0 deletions dotcom-rendering/src/components/FrontPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { css, Global } from '@emotion/react';
import { brandAlt, focusHalo, neutral } from '@guardian/source-foundations';
import { StrictMode } from 'react';
import { FrontLayout } from '../layouts/FrontLayout';
import { buildAdTargeting } from '../lib/ad-targeting';
import { filterABTestSwitches } from '../model/enhance-switches';
import type { NavType } from '../model/extract-nav';
import type { DCRFrontType } from '../types/front';
Expand All @@ -12,6 +13,7 @@ import { FocusStyles } from './FocusStyles.importable';
import { Island } from './Island';
import { Metrics } from './Metrics.importable';
import { SetABTests } from './SetABTests.importable';
import { SetAdTargeting } from './SetAdTargeting.importable';
import { ShowHideContainers } from './ShowHideContainers.importable';
import { SkipTo } from './SkipTo';

Expand All @@ -29,6 +31,15 @@ type Props = {
* @param {NAVType} props.NAV - The article JSON data
* */
export const FrontPage = ({ front, NAV }: Props) => {
const adTargeting = buildAdTargeting({
isAdFreeUser: front.isAdFreeUser,
isSensitive: front.config.isSensitive,
edition: front.config.edition,
section: front.config.section,
sharedAdTargeting: front.config.sharedAdTargeting,
adUnit: front.config.adUnit,
});

return (
<StrictMode>
<Global
Expand Down Expand Up @@ -75,6 +86,9 @@ export const FrontPage = ({ front, NAV }: Props) => {
isDev={!!front.config.isDev}
/>
</Island>
<Island clientOnly={true}>
<SetAdTargeting adTargeting={adTargeting} />
</Island>
<FrontLayout front={front} NAV={NAV} />
</StrictMode>
);
Expand Down
48 changes: 0 additions & 48 deletions dotcom-rendering/src/components/LiveBlock.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ export const VideoAsSecond = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -113,10 +109,6 @@ export const Title = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -183,10 +175,6 @@ export const Video = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -228,10 +216,6 @@ export const RichLink = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -264,10 +248,6 @@ export const FirstImage = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -326,10 +306,6 @@ export const ImageRoles = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -377,10 +353,6 @@ export const Thumbnail = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -414,10 +386,6 @@ export const ImageAndTitle = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -447,10 +415,6 @@ export const Updated = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -484,10 +448,6 @@ export const Contributor = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.News,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -519,10 +479,6 @@ export const NoAvatar = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.Opinion,
design: ArticleDesign.LiveBlog,
Expand Down Expand Up @@ -557,10 +513,6 @@ export const TitleAndContributor = () => {
return (
<Wrapper>
<LiveBlock
adTargeting={{
customParams: { sens: 'f', urlkw: [] },
adUnit: '',
}}
format={{
theme: ArticlePillar.Sport,
design: ArticleDesign.LiveBlog,
Expand Down
3 changes: 0 additions & 3 deletions dotcom-rendering/src/components/LiveBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type Props = {
block: Block;
pageId: string;
webTitle: string;
adTargeting: AdTargeting;
host?: string;
ajaxUrl: string;
isAdFreeUser: boolean;
Expand All @@ -26,7 +25,6 @@ export const LiveBlock = ({
block,
pageId,
webTitle,
adTargeting,
host = 'https://www.theguardian.com',
ajaxUrl,
isAdFreeUser,
Expand Down Expand Up @@ -68,7 +66,6 @@ export const LiveBlock = ({
key={index}
format={format}
element={element}
adTargeting={adTargeting}
ajaxUrl={ajaxUrl}
host={host}
index={index}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { LiveBlock } from './LiveBlock';
type Props = {
format: ArticleFormat;
blocks: Block[];
adTargeting: AdTargeting;
pinnedPost?: Block;
host?: string;
pageId: string;
Expand All @@ -26,7 +25,6 @@ export const LiveBlogBlocksAndAdverts = ({
format,
blocks,
pinnedPost,
adTargeting,
host,
pageId,
webTitle,
Expand All @@ -47,7 +45,6 @@ export const LiveBlogBlocksAndAdverts = ({
block={block}
pageId={pageId}
webTitle={webTitle}
adTargeting={adTargeting}
host={host}
ajaxUrl={ajaxUrl}
isLiveUpdate={isLiveUpdate}
Expand Down Expand Up @@ -93,7 +90,6 @@ export const LiveBlogBlocksAndAdverts = ({
block={block}
pageId={pageId}
webTitle={webTitle}
adTargeting={adTargeting}
host={host}
ajaxUrl={ajaxUrl}
isLiveUpdate={isLiveUpdate}
Expand Down
3 changes: 1 addition & 2 deletions dotcom-rendering/src/components/Liveness.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import { initHydration } from '../client/islands/initHydration';
import { updateTimeElement } from '../client/relativeTime/updateTimeElements';
import { isServer } from '../lib/isServer';
import { useApi } from '../lib/useApi';
import { Toast } from './Toast';

Expand All @@ -19,8 +20,6 @@ type Props = {
selectedTopics?: Topic[];
};

const isServer = typeof window === 'undefined';

const topOfBlog: Element | null = !isServer
? window.document.getElementById('top-of-blog')
: null;
Expand Down
3 changes: 0 additions & 3 deletions dotcom-rendering/src/components/MainMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type Props = {
format: ArticleFormat;
elements: FEElement[];
hideCaption?: boolean;
adTargeting?: AdTargeting;
starRating?: number;
host?: string;
pageId: string;
Expand All @@ -80,7 +79,6 @@ export const MainMedia = ({
elements,
format,
hideCaption,
adTargeting,
starRating,
host,
pageId,
Expand All @@ -98,7 +96,6 @@ export const MainMedia = ({
key={index}
format={format}
element={element}
adTargeting={adTargeting}
ajaxUrl={ajaxUrl}
host={host}
index={index}
Expand Down
Loading