Skip to content

Commit

Permalink
Pass down & use producerId
Browse files Browse the repository at this point in the history
  • Loading branch information
hotinglok committed Oct 21, 2024
1 parent ef8f7f1 commit a7cd6af
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/app/pages/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
isTrustProjectParticipant,
showRelatedTopics,
brandName,
atiAnalyticsProducerId,
} = useContext(ServiceContext);

const { enabled: preloadLeadImageToggle } = useToggle('preloadLeadImage');
Expand Down Expand Up @@ -231,7 +232,11 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
{shouldEnableExperimentTopStories && (
<AmpExperiment
experimentConfig={experimentTopStoriesConfig}
analyticsConfig={getExperimentAnalyticsConfig({ env, service })}
analyticsConfig={getExperimentAnalyticsConfig({
env,
service,
atiAnalyticsProducerId,
})}
/>
)}
<ATIAnalytics atiData={atiData} />
Expand Down
26 changes: 17 additions & 9 deletions src/app/pages/ArticlePage/experimentTopStories/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('AMP top stories experiment', () => {

describe('getExperimentAnalyticsConfig()', () => {
process.env.SIMORGH_ATI_BASE_URL = 'http://foobar.com?';

const PS_NEWS_DESTINATION_ID = 598285;
const PS_NEWS_TEST_DESTINATION_ID = 598286;
const PS_NEWS_GNL_DESTINATION_ID = 598287;
Expand All @@ -125,21 +126,28 @@ describe('AMP top stories experiment', () => {
const PS_SPORT_TEST_DESTINATION_ID = 598311;
const PS_SPORT_GNL_DESTINATION_ID = 598308;
const PS_SPORT_GNL_TEST_DESTINATION_ID = 598309;
const NEWS_PRODUCER_ID = 64;
const SPORT_PRODUCER_ID = 85;

it.each`
service | env | destinationId | gnlId
${'news'} | ${'live'} | ${PS_NEWS_DESTINATION_ID} | ${PS_NEWS_GNL_DESTINATION_ID}
${'news'} | ${'test'} | ${PS_NEWS_TEST_DESTINATION_ID} | ${PS_NEWS_GNL_TEST_DESINTATION_ID}
${'sport'} | ${'live'} | ${PS_SPORT_DESTINATION_ID} | ${PS_SPORT_GNL_DESTINATION_ID}
${'sport'} | ${'test'} | ${PS_SPORT_TEST_DESTINATION_ID} | ${PS_SPORT_GNL_TEST_DESTINATION_ID}
service | env | destinationId | gnlId | producerId
${'news'} | ${'live'} | ${PS_NEWS_DESTINATION_ID} | ${PS_NEWS_GNL_DESTINATION_ID} | ${NEWS_PRODUCER_ID}
${'news'} | ${'test'} | ${PS_NEWS_TEST_DESTINATION_ID} | ${PS_NEWS_GNL_TEST_DESINTATION_ID} | ${NEWS_PRODUCER_ID}
${'sport'} | ${'live'} | ${PS_SPORT_DESTINATION_ID} | ${PS_SPORT_GNL_DESTINATION_ID} | ${SPORT_PRODUCER_ID}
${'sport'} | ${'test'} | ${PS_SPORT_TEST_DESTINATION_ID} | ${PS_SPORT_GNL_TEST_DESTINATION_ID} | ${SPORT_PRODUCER_ID}
`(
'should create the analytics config with the correct parameters for $service on $env.',
({ env, service, destinationId, gnlId }) => {
const analyticsConfig = getExperimentAnalyticsConfig({ env, service });
({ env, service, destinationId, gnlId, producerId }) => {
const analyticsConfig = getExperimentAnalyticsConfig({
env,
service,
atiAnalyticsProducerId: producerId,
});
expect(analyticsConfig).toMatchInlineSnapshot(`
{
"requests": {
"topStoriesClick": "http://foobar.com?idclient=123-456-789&s=$IF($EQUALS($MATCH(\${ampGeo}, gbOrUnknown, 0), gbOrUnknown), ${destinationId}, ${gnlId})&s2=64&p=SOURCE_URL&r=\${screenWidth}x\${screenHeight}x\${screenColorDepth}&re=\${availableScreenWidth}x\${availableScreenHeight}&hl=\${timestamp}&lng=\${browserLanguage}&atc=PUB-[article]-[top-stories-promo]-[topStoriesExperiment:VARIANT(topStoriesExperiment)]-[]-[SOURCE_URL]-[]-[]-[]&type=AT",
"topStoriesView": "http://foobar.com?idclient=123-456-789&s=$IF($EQUALS($MATCH(\${ampGeo}, gbOrUnknown, 0), gbOrUnknown), ${destinationId}, ${gnlId})&s2=64&p=SOURCE_URL&r=\${screenWidth}x\${screenHeight}x\${screenColorDepth}&re=\${availableScreenWidth}x\${availableScreenHeight}&hl=\${timestamp}&lng=\${browserLanguage}&ati=PUB-[article]-[top-stories-section]-[topStoriesExperiment:VARIANT(topStoriesExperiment)]-[]-[SOURCE_URL]-[]-[]-[]&type=AT",
"topStoriesClick": "http://foobar.com?idclient=123-456-789&s=$IF($EQUALS($MATCH(\${ampGeo}, gbOrUnknown, 0), gbOrUnknown), ${destinationId}, ${gnlId})&s2=${producerId}&p=SOURCE_URL&r=\${screenWidth}x\${screenHeight}x\${screenColorDepth}&re=\${availableScreenWidth}x\${availableScreenHeight}&hl=\${timestamp}&lng=\${browserLanguage}&atc=PUB-[article]-[top-stories-promo]-[topStoriesExperiment:VARIANT(topStoriesExperiment)]-[]-[SOURCE_URL]-[]-[]-[]&type=AT",
"topStoriesView": "http://foobar.com?idclient=123-456-789&s=$IF($EQUALS($MATCH(\${ampGeo}, gbOrUnknown, 0), gbOrUnknown), ${destinationId}, ${gnlId})&s2=${producerId}&p=SOURCE_URL&r=\${screenWidth}x\${screenHeight}x\${screenColorDepth}&re=\${availableScreenWidth}x\${availableScreenHeight}&hl=\${timestamp}&lng=\${browserLanguage}&ati=PUB-[article]-[top-stories-section]-[topStoriesExperiment:VARIANT(topStoriesExperiment)]-[]-[SOURCE_URL]-[]-[]-[]&type=AT",
},
"triggers": {
"trackTopStoriesClick": {
Expand Down
20 changes: 17 additions & 3 deletions src/app/pages/ArticlePage/experimentTopStories/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ const buildTopStoriesEventUrl = ({
type,
env,
service,
atiAnalyticsProducerId,
}: {
type: 'view' | 'click';
env: Environments;
service: Services;
atiAnalyticsProducerId: string;
}) => {
return buildATIEventTrackUrl({
campaignID: 'article',
componentName: `${type === 'view' ? 'top-stories-section' : 'top-stories-promo'}`,
pageIdentifier: 'SOURCE_URL',
platform: 'amp',
producerId: '64',
producerId: atiAnalyticsProducerId,
statsDestination: `${getStatsDestinationKey({ env, service })}`,
variant: `${experimentName}:VARIANT(${experimentName})`,
type,
Expand All @@ -56,14 +58,26 @@ const buildTopStoriesEventUrl = ({
export const getExperimentAnalyticsConfig = ({
env,
service,
atiAnalyticsProducerId,
}: {
env: Environments;
service: Services;
atiAnalyticsProducerId: string;
}) => {
return {
requests: {
topStoriesView: buildTopStoriesEventUrl({ type: 'view', env, service }),
topStoriesClick: buildTopStoriesEventUrl({ type: 'click', env, service }),
topStoriesView: buildTopStoriesEventUrl({
type: 'view',
env,
service,
atiAnalyticsProducerId,
}),
topStoriesClick: buildTopStoriesEventUrl({
type: 'click',
env,
service,
atiAnalyticsProducerId,
}),
},
triggers: {
trackTopStoriesView: {
Expand Down

0 comments on commit a7cd6af

Please sign in to comment.