From 7625d2dc44c343482997b27f340ebc82377459fe Mon Sep 17 00:00:00 2001 From: hotinglok Date: Mon, 21 Oct 2024 13:38:39 +0100 Subject: [PATCH 01/37] Add amp-analytics to AmpExperiment --- .../ATIAnalytics/atiUrl/index.test.ts | 3 +- .../components/ATIAnalytics/atiUrl/index.ts | 2 + src/app/components/ATIAnalytics/types.ts | 1 + src/app/components/AmpExperiment/index.tsx | 28 ++++++- src/app/pages/ArticlePage/ArticlePage.tsx | 9 ++- .../experimentTopStories/helpers.tsx | 73 ++++++++++++++++++- 6 files changed, 109 insertions(+), 7 deletions(-) diff --git a/src/app/components/ATIAnalytics/atiUrl/index.test.ts b/src/app/components/ATIAnalytics/atiUrl/index.test.ts index 1564681ed1e..1c0a0e05ea0 100644 --- a/src/app/components/ATIAnalytics/atiUrl/index.test.ts +++ b/src/app/components/ATIAnalytics/atiUrl/index.test.ts @@ -244,6 +244,7 @@ describe('buildATIEventTrackUrl', () => { format: 'format', url: 'url', detailedPlacement: 'detailedPlacement', + variant: 'variant_1', }); expect(splitUrl(atiEventTrackUrl)).toEqual([ @@ -255,7 +256,7 @@ describe('buildATIEventTrackUrl', () => { 're=getBrowserViewPort', 'hl=getCurrentTime', 'lng=getDeviceLanguage', - 'atc=PUB-[campaignID]-[component]-[]-[format]-[pageIdentifier]-[detailedPlacement]-[]-[url]', + 'atc=PUB-[campaignID]-[component]-[variant_1]-[format]-[pageIdentifier]-[detailedPlacement]-[]-[url]', 'type=AT', ]); }); diff --git a/src/app/components/ATIAnalytics/atiUrl/index.ts b/src/app/components/ATIAnalytics/atiUrl/index.ts index 6b2bcda0ab6..6f2ef2a1264 100644 --- a/src/app/components/ATIAnalytics/atiUrl/index.ts +++ b/src/app/components/ATIAnalytics/atiUrl/index.ts @@ -252,6 +252,7 @@ export const buildATIEventTrackUrl = ({ advertiserID, url, detailedPlacement, + variant, }: ATIEventTrackingProps) => { // on AMP, variable substitutions are used in the value and they cannot be // encoded: https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md @@ -323,6 +324,7 @@ export const buildATIEventTrackUrl = ({ advertiserID, url, detailedPlacement, + variant, }), wrap: false, disableEncoding: true, diff --git a/src/app/components/ATIAnalytics/types.ts b/src/app/components/ATIAnalytics/types.ts index a5f438cec35..4cb09de134d 100644 --- a/src/app/components/ATIAnalytics/types.ts +++ b/src/app/components/ATIAnalytics/types.ts @@ -109,6 +109,7 @@ export interface ATIEventTrackingProps { advertiserID?: string; url?: string; detailedPlacement?: string; + variant?: string; } export interface ATIPageTrackingProps { diff --git a/src/app/components/AmpExperiment/index.tsx b/src/app/components/AmpExperiment/index.tsx index 54e7d615c95..f3c3692aa23 100644 --- a/src/app/components/AmpExperiment/index.tsx +++ b/src/app/components/AmpExperiment/index.tsx @@ -18,8 +18,13 @@ type AmpExperimentConfig = { }; }; -type AmpExperimentProps = { - [key: Experiment]: AmpExperimentConfig; +type AmpAnalyticsConfig = { + requests?: { + [key: string]: string; + }; + triggers?: { + [key: string]: object; + }; }; const AmpHead = () => ( @@ -32,7 +37,13 @@ const AmpHead = () => ( ); -const AmpExperiment = ({ experimentConfig }: AmpExperimentProps) => { +const AmpExperiment = ({ + experimentConfig, + analyticsConfig, +}: { + experimentConfig: AmpExperimentConfig; + analyticsConfig: AmpAnalyticsConfig; +}) => { return ( <> @@ -43,6 +54,17 @@ const AmpExperiment = ({ experimentConfig }: AmpExperimentProps) => { dangerouslySetInnerHTML={{ __html: JSON.stringify(experimentConfig) }} /> + {analyticsConfig && ( + + + + + + + + `); + }); + it(`should add amp-experiment extension script to page head`, async () => { render(); diff --git a/src/app/components/AmpExperiment/index.tsx b/src/app/components/AmpExperiment/index.tsx index f3c3692aa23..6d664f5342b 100644 --- a/src/app/components/AmpExperiment/index.tsx +++ b/src/app/components/AmpExperiment/index.tsx @@ -27,6 +27,11 @@ type AmpAnalyticsConfig = { }; }; +type AmpExperimentProps = { + experimentConfig: AmpExperimentConfig; + analyticsConfig?: AmpAnalyticsConfig; +}; + const AmpHead = () => (