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

Transcript-tracking (NoJS): Experimental branch #12250

Draft
wants to merge 1 commit into
base: WSTEAM1-TRANSCRIPT-SIGNPOST-CLONE
Choose a base branch
from
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
47 changes: 47 additions & 0 deletions src/app/components/ATIAnalytics/canonical/sendBeaconTranscript.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useEffect, useState } from 'react';
import { getEnvConfig } from '#app/lib/utilities/getEnvConfig';
import isOperaProxy from '#app/lib/utilities/isOperaProxy';
import sendBeacon from '../../../lib/analyticsUtils/sendBeacon';
import { ATIAnalyticsProps } from '../types';

// some other metric?
const getNoJsATIPageViewUrl = (atiPageViewUrl: string) =>
atiPageViewUrl.includes('x8=[simorgh]')
? atiPageViewUrl.replace('x8=[simorgh]', 'x8=[simorgh-nojs]')
: `${atiPageViewUrl}&x8=[BLAH]`;

const renderNoScriptTrackingPixel = (atiPageViewUrl: string) => {
return (
<noscript>
<img
height="1px"
width="1px"
alt=""
// This should probably have been a styled component. But the author is
// lazy and didn't want to write a fuzzy matcher for the unit AND e2e
// tests (you can't predict the class names chosen by emotion)
style={{ position: 'absolute' }}
src={getNoJsATIPageViewUrl(atiPageViewUrl)}
/>
</noscript>
);
};

const MyAnalytics = ({ pageviewParams }: ATIAnalyticsProps) => {
const atiPageViewUrlString =
getEnvConfig().SIMORGH_ATI_BASE_URL + pageviewParams;

console.log('atiPageViewUrlString', atiPageViewUrlString);

const [atiPageViewUrl] = useState(atiPageViewUrlString);

console.log('atiPageViewUrl', atiPageViewUrl);

useEffect(() => {
if (!isOperaProxy()) sendBeacon(atiPageViewUrl);
}, [atiPageViewUrl]);

return <>{renderNoScriptTrackingPixel(atiPageViewUrl)}</>;
};

export default MyAnalytics;
22 changes: 22 additions & 0 deletions src/app/components/ATIAnalytics/myAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { useContext } from 'react';
import { RequestContext } from '#contexts/RequestContext';
import { ServiceContext } from '../../contexts/ServiceContext';
import MyAnalytics from './canonical/sendBeaconTranscript';
import { ATIProps } from './types';
import buildATIUrl from './params';

const ATIAnalyticsTranscript = ({ data, atiData }: ATIProps) => {
const requestContext = useContext(RequestContext);
const serviceContext = useContext(ServiceContext);

const pageviewParams = buildATIUrl({
requestContext,
serviceContext,
data,
atiData,
}) as string;

return <MyAnalytics pageviewParams={pageviewParams} />;
};

export default ATIAnalyticsTranscript;
8 changes: 8 additions & 0 deletions src/app/components/Transcript/index.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import pixelsToRem from '#app/utilities/pixelsToRem';
import { focusIndicatorThickness } from '../ThemeProvider/focusIndicator';

export default {
isThisTerrible: () =>
css({
display: 'none',
}),

details: ({ spacings, palette, isDarkUi }: Theme) =>
css({
backgroundColor: isDarkUi ? palette.GREY_7 : palette.WHITE,
Expand All @@ -19,6 +24,9 @@ export default {
'&[open] summary svg': {
transform: 'rotate(90deg)',
},
'&[open] #isThisTerrible': {
display: 'initial',
},
}),

summary: ({ spacings, palette }: Theme) =>
Expand Down
20 changes: 20 additions & 0 deletions src/app/components/Transcript/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import VisuallyHiddenText from '../VisuallyHiddenText';
import { RightArrow as ArrowSvg } from '../icons';
import { TranscriptBlock, TranscriptItem } from './types';
import ATIAnalyticsTranscript from '../ATIAnalytics/myAnalytics';

// TO DO - move this to BFF
const removeHoursMilliseconds = (timestamp: string) => timestamp.slice(3, -4);
Expand Down Expand Up @@ -35,8 +36,23 @@
return null;
}

const formattedTitle = title ? `, ${title}` : '';

Check failure on line 39 in src/app/components/Transcript/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'myATIData' is declared but its value is never read.

Check failure on line 39 in src/app/components/Transcript/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

'myATIData' is declared but its value is never read.

const myATIData = {
categoryName: null,
contentId: 'urn:bbc:optimo:asset:ce42wzqr2mko',
contentType: 'article',
language: 'es',
ldpThingIds: null,
ldpThingLabels: null,
nationsProducer: null,
pageIdentifier: 'mundo.articles.ce42wzqr2mko.page',
pageTitle:
'Este artículo de prueba ha sido creado para que podamos ejecutar pruebas',
timePublished: '2019-10-04T10:58:46.977Z',
timeUpdated: '2019-10-04T10:58:46.977Z',
};

return (
<details css={styles.details}>
<summary css={styles.summary}>
Expand All @@ -49,6 +65,10 @@
{title && <VisuallyHiddenText>{formattedTitle}</VisuallyHiddenText>}
</span>
</summary>
{/* dont think this works */}
<span css={styles.isThisTerrible} id="isThisTerrible">
<ATIAnalyticsTranscript />
</span>
<ul css={styles.ul} role="list">
{/* eslint-disable-next-line @typescript-eslint/no-unused-vars */}
{transcriptItems.map((item, _index) => (
Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
showRelatedTopics && topics.length > 0 && !isTransliterated,
);

console.log('atiData', atiData);

return (
<div css={styles.pageWrapper}>
{shouldEnableExperimentTopStories && (
Expand Down
Loading