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

WSTEAM1-1514: Lite Site Piano Analytics - Spike #12332

Open
wants to merge 8 commits into
base: latest
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions src/app/components/ATIAnalytics/canonical/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getEnvConfig } from '#app/lib/utilities/getEnvConfig';
import { RequestContext } from '#app/contexts/RequestContext';
import isOperaProxy from '#app/lib/utilities/isOperaProxy';
import { Helmet } from 'react-helmet';
import { liteTrackingScript } from '#app/hooks/useClickTrackerHandler';
import sendBeacon from '../../../lib/analyticsUtils/sendBeacon';
import { ATIAnalyticsProps } from '../types';
import sendBeaconOperaMiniScript from './sendBeaconOperaMiniScript';
Expand Down Expand Up @@ -42,9 +43,11 @@ const addOperaMiniExtremeScript = (atiPageViewUrlString: string) => {

const addLiteScript = (atiPageViewUrlString: string) => {
const script = sendBeaconLite(atiPageViewUrlString);
const clickTrackerScript = liteTrackingScript();

return (
<Helmet>
<script type="text/javascript">{clickTrackerScript}</script>
<script type="text/javascript">{script}</script>
</Helmet>
);
Expand Down
12 changes: 8 additions & 4 deletions src/app/components/ATIAnalytics/canonical/sendBeaconLite.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const sendBeaconLite = (atiPageViewUrlString: string) => `
var xhr = new XMLHttpRequest();
xhr.open("GET", "${atiPageViewUrlString}", true);
xhr.withCredentials = true;
xhr.send();
function sendBeaconLite (atiPageViewUrlString) {
var xhr = new XMLHttpRequest();
xhr.open("GET", atiPageViewUrlString, true);
xhr.withCredentials = true;
xhr.send();
}

sendBeaconLite("${atiPageViewUrlString}");
`;

export default sendBeaconLite;
14 changes: 14 additions & 0 deletions src/app/components/LiteSiteCta/index.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comment - we mentioned that we wanted to add click tracking to the LiteSiteCTA button - could we carve it out into a separate PR (so that it could be merged sooner, and we can start getting metrics), or does it need to be included in this one?

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @jsx jsx */
import { useContext } from 'react';
import { jsx } from '@emotion/react';
import useClickTrackerHandler, {
constructLiteSiteURL,
} from '#app/hooks/useClickTrackerHandler';
import Paragraph from '../Paragraph';
import Text from '../Text';
import { LeftChevron, RightChevron } from '../icons';
Expand All @@ -17,6 +20,7 @@ type CtaLinkProps = {
showChevron?: boolean;
ignoreLiteExtension?: boolean;
className?: string;
eventTrackingData: { componentName: string };
};

const CtaLink = ({
Expand All @@ -27,18 +31,24 @@ const CtaLink = ({
showChevron = false,
ignoreLiteExtension = false,
className,
eventTrackingData,
}: CtaLinkProps) => {
const chevron = isRtl ? (
<LeftChevron css={styles.chevron} />
) : (
<RightChevron css={styles.chevron} />
);

const clickTrackerHandler = useClickTrackerHandler(eventTrackingData);
const liteUrl = constructLiteSiteURL(eventTrackingData);

return (
<a
href={href}
className={className}
css={styles.link}
onClick={clickTrackerHandler}
{...(liteUrl && { 'add-lite-tracker-params': liteUrl })}
{...(ignoreLiteExtension && { 'data-ignore-lite': true })}
>
<Text size="brevier" fontVariant={fontVariant} css={styles.linkText}>
Expand All @@ -62,6 +72,8 @@ const LiteSiteCta = () => {
dataSaving,
} = liteSite;
const id = 'LiteSiteCta';
const eventTrackingDataSiteSwitch = { componentName: 'switch-to-canonical' };
const eventTrackingLiteSiteInfo = { componentName: 'lite-site-info' };

return (
<section
Expand All @@ -86,6 +98,7 @@ const LiteSiteCta = () => {
css={styles.topLinkSpacing}
ignoreLiteExtension
showChevron
eventTrackingData={eventTrackingDataSiteSwitch}
/>
</Paragraph>
<Paragraph data-e2e="information-page">
Expand All @@ -94,6 +107,7 @@ const LiteSiteCta = () => {
href={informationPageLink}
text={informationPage}
css={styles.bottomLinkSpacing}
eventTrackingData={eventTrackingLiteSiteInfo}
/>
</Paragraph>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/app/components/MostRead/Canonical/Item/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** @jsx jsx */
import React, { PropsWithChildren } from 'react';
import React, { PropsWithChildren, useContext } from 'react';

Check failure on line 2 in src/app/components/MostRead/Canonical/Item/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

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

Check failure on line 2 in src/app/components/MostRead/Canonical/Item/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'useContext' is declared but its value is never read.
import { jsx } from '@emotion/react';
import useClickTrackerHandler from '#hooks/useClickTrackerHandler';
import useClickTrackerHandler, {
constructLiteSiteURL,
} from '#hooks/useClickTrackerHandler';
import styles from './index.styles';
import {
mostReadListGridProps,
Expand All @@ -15,6 +17,7 @@
} from '../../types';
import { Direction } from '../../../../models/types/global';
import Grid from '../../../../legacy/components/Grid';
import { RequestContext } from '#app/contexts/RequestContext';

Check failure on line 20 in src/app/components/MostRead/Canonical/Item/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (18.x)

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

Check failure on line 20 in src/app/components/MostRead/Canonical/Item/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

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

export const getParentColumns = (columnLayout: ColumnLayout) => {
return columnLayout !== 'oneColumn'
Expand Down Expand Up @@ -47,13 +50,15 @@
eventTrackingData,
}: PropsWithChildren<MostReadLinkProps>) => {
const clickTrackerHandler = useClickTrackerHandler(eventTrackingData);
const liteUrl = constructLiteSiteURL(eventTrackingData);

return (
<div css={getItemCss({ dir, size })} dir={dir}>
<a
css={[styles.link, size === 'default' && styles.defaultLink]}
href={href}
onClick={clickTrackerHandler}
{...(liteUrl && {'add-lite-tracker-params': liteUrl})}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make 'add-lite-tracker-params' into a const somewhere which we can reuse in other places?

Suggested change
{...(liteUrl && {'add-lite-tracker-params': liteUrl})}
{...(liteUrl && {LITE_TRACKER_PARAM: liteUrl})}

>
{title}
</a>
Expand Down
5 changes: 4 additions & 1 deletion src/app/components/MostRead/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const MostRead = ({
className = '',
sendOptimizelyEvents = false,
}: MostReadProps) => {
const { isAmp, pageType, variant } = useContext(RequestContext);
const { isLite, isAmp, pageType, variant } = useContext(RequestContext);
const { optimizely } = useContext(OptimizelyContext);
const {
service,
Expand Down Expand Up @@ -145,6 +145,9 @@ const MostRead = ({
optimizely,
optimizelyMetricNameOverride: 'most_read',
}),
...(isLite && {
liteSiteUrl: 'liteSiteUrl',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just a spike, but what is this value supposed to be - the .lite version of the page it's on?

})
};

return isAmp ? (
Expand Down
Loading
Loading