-
Notifications
You must be signed in to change notification settings - Fork 225
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
[NASAA-205] - Send top stories experiment analytics events #12075
base: latest
Are you sure you want to change the base?
Conversation
jest.mock('../../../lib/analyticsUtils', () => ({ | ||
...jest.requireActual('../../../lib/analyticsUtils'), | ||
getAtUserId: jest.fn().mockReturnValue('123-456-789'), | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is needed because getAtUserId()
always generates a random ID.
src/app/components/ATIAnalytics/params/genericPage/buildParams.ts
Outdated
Show resolved
Hide resolved
requests: Record<string, unknown>; | ||
triggers: Record<string, unknown>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question (non-blocking) Can this be typed any more strictly? I can see that we set base, clicks, trackClicks which we could encode here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this a bit with just the things that we've used for the experiment. There's a lot of other optional properties that I've not included, but those can be added whenever they're needed.
@@ -252,6 +263,7 @@ export const buildATIEventTrackUrl = ({ | |||
advertiserID, | |||
url, | |||
detailedPlacement, | |||
variant, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusingly, we use the term variant
for services with dual scripts e.g. serbian with cyrillic script has a variant = cyr
If this is not the intention of the term variant here, can we please rename it to something else, to avoid confusion - perhaps experimentVariant
or something similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this as well, but had a look at the utility and apparently it was set for A/B testing 3 years ago
simorgh/src/app/lib/analyticsUtils/index.js
Line 272 in 275b924
variant = '', // not a service variant - used for A/B testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've added this here to use as the experiment variant in our use-case because getEventInfo()
uses this as a variant for A/B testing, it just wasn't previously passed in here.
As the value just needs to be in the right place in the string, I'll rename it in there too and remove the comment to make it clearer
@@ -49,6 +50,7 @@ export const buildPageATIParams = ({ | |||
statsDestination, | |||
timePublished, | |||
timeUpdated, | |||
...(ampExperimentName && { ampExperimentName }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: Is spreading needed here? If ampExperimentName
is undefined, it won't be returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I left it as is in the object, the key ampExperimentName
would still be there even if the value was falsey. As it is currently written, it won't work without the spread operator because it wouldn't have a valid key/pair if it evaluated as false.
@@ -109,6 +110,7 @@ export interface ATIEventTrackingProps { | |||
advertiserID?: string; | |||
url?: string; | |||
detailedPlacement?: string; | |||
variant?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per comment above - is this an experiment variant or a dual script variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not seeing the additional variant data you've added to the page.display
event appearing in the analytics portal. I suspect they can only go on publisher.*
type events?
variants: { | ||
control: 50, | ||
show_at_halfway: 50, | ||
}, | ||
}, | ||
}; | ||
|
||
const ARTICLE_LENGTH_THRESHOLD = 10; | ||
const enableExperimentTopStories = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking suggestion, expecially as it isn't new to this PR: From reading this function name I was expecting it to do some kind of enablement rather than returning a boolean decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I think I was just struggling for a name since shouldEnableExperimentTopStories
is returned in the object from 'getExperimentTopStories()`. Happy to accept any other suggestions.
const shouldEnableExperimentTopStories = enableExperimentTopStories({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot with the MVT properties. I've had a quick check in Piano and can see the data 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sorting the variant vs experimentVariant issue - it's a lot clearer now.
@@ -215,6 +216,31 @@ export const buildATIPageTrackPath = ({ | |||
value: getATIMarketingString(href, campaignType), | |||
wrap: false, | |||
}, | |||
...(ampExperimentName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After fixing conflicts, there was an initial concern that this might be overridden by the elections banner experiment that is currently being done, but as that is only run on mundo/portuguese, this should be ok because experimentVariant
won't be defined.
Co-authored-by: Michelle <[email protected]>
[NASAA-232] - Add additional variants to top stories experiment
Resolves NASAA-205
Overall changes
Adds an
<amp-analytics/>
component that is added to the page in<AmpExperiment/>
if ananalyticsConfig
is passed in specifically to handle tracking of experiment events. This is in the same format as the config used for tracking page views in ampAnalyticsJson.ts and is used to track view and click events of the experiment Top Stories section that are viewable in Piano. This PR also includes minor refactors to the experimentTopStories helpers file, as well as the existing<ATIAnalytics/>
component that allows the amp experiment variant to come through on the page view event too.Code changes
<amp-analytics/>
component to<AmpExperiment/>
if ananalyticsConfig
is passed to the component.buildATIEventTrackUrl()
to format events ready to send to Piano via<amp-analytics/>
.variant
prop that exists ingetEventInfo()
to use the existing 'Onsite Ads - Variant' metric in Piano (renamed asexperimentVariant
to avoid it being confused with service variants. These events are registered aspublisher.click
andpublisher.display
events which is used to represent component view/click events.data-experiment
attribute to both<TopStoriesSection/>
components rendered in the article body and the secondary column. This makes it easier to make selectors in the amp-analytics to trigger tracking events for<TopStoriesSection/>
.<TopStoriesSection/>
in the secondary column won't send if the selector was only something likesection[aria-labelledby='top-stories-heading']
.experimentTopStories
blocks are always added to the data on valid assets/services, view events for thecontrol
variant which only ever shows the<TopStoriesSection/.>
in it's original position in the secondary column didn't send view events at all, hence the need for separate tracking of each one.ampExperimentName
toatiData
that is added conditionally (only whenshouldEnableTopStoriesExperiment
is true).buildATIURL
functions/types/tests to includeampExperimentName
when it exists.mpu
andwsoj
). It doesn't need to be exactly 50% of the way through, this approximation will suffice for this experiment since it will only ever be off by one position at worst.shouldEnableTopStoriesExperiment
conditions.Testing
Links
Piano dashboard with filter showing relevant columns
Control (no changes to existing behaviour):
Variant name in code:
control
Variant 1 (show Top Stories section halfway into the article content instead of after it):
Variant name in code:
show_at_halfway
Events
Ensure the following events for both variants on a valid articles are being sent through in the ATI tag inspector and are visible in the Piano dashboards.
On page view (type 'page' event in Tag Inspector, 'page.display' in Piano dashboard)
*mv_test is convenient to make relevant results show in the 'Content - MV Testing' section in Piano, so this just has the value 'Google Discover' to make it easier to find.
detailed placement id
(tag inspector)/detailedPosition
(piano dashboard) property for the page view event.When viewing the Top Stories section (type 'onSiteAds' event in Tag Inspector, 'publisher.display' in Piano dashboard):
When clicking on any promo in the Top Stories section (promo position irrelevant, type 'onSiteAds' event in Tag Inspector, 'publisher.click' in Piano dashboard):
Helpful Links
Add Links to useful resources related to this PR if applicable.
Coding Standards
Repository use guidelines