-
Notifications
You must be signed in to change notification settings - Fork 208
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
Amp access toggle for ads #6079
Conversation
</Helmet> | ||
<div | ||
amp-access="toggles.ads.enabled AND geoIp.advertiseCombined" | ||
amp-access-hide="true" |
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.
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.
And this attribute hides the div
by default, until we get a successful authorization response right?
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.
Yep that is correct 💪 noted in this doc, I should've linked... https://amp.dev/documentation/components/amp-access/
The amp-access-hide attribute can be used to optimistically hide the element before the Authorization response has been received, which can show it. It provides the semantics of “invisible by default”. The authorization response returned by the Authorization later may rescind this default and make section visible.
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 just gone down a bit of a rabbit hole looking into this - it looks like react is buggy around boolean, non-standard, html attributes (i.e. amp-access-hide
isn't an html attribute). See here: facebook/react#9230 - they recommend using amp-access-hide=""
instead, which is rendered as amp-access-hide
. This is a bit weird, not sure which I prefer, as amp-access-hide="true"
isn't quite what we should be passing to the AMP component (and amp-access-hide="false"
wouldn't have the opposite effect, due to how boolean attributes work)
{AMP_ACCESS_JS} | ||
{AMP_ACCESS_FETCH(service)} | ||
</Helmet> | ||
<div |
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 created a div here to pass the amp attributes to (amp-access
/amp-access-hide
), as styled components strip out the attributes that are not on their whitelist.
@@ -36,29 +63,54 @@ const ampAdPropsDesktop = ({ service }) => ({ | |||
json: JSON.stringify(constructAdJsonData({ service })), | |||
}); | |||
|
|||
const AMP_ACCESS_DATA = (endpoint) => ({ | |||
authorization: endpoint, | |||
noPingback: true, |
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 don't think we need a pingback to happen so I've disabled it
pingback doc: https://amp.dev/documentation/components/amp-access/#pingback-endpoint
@@ -36,29 +63,54 @@ const ampAdPropsDesktop = ({ service }) => ({ | |||
json: JSON.stringify(constructAdJsonData({ service })), | |||
}); | |||
|
|||
const AMP_ACCESS_DATA = (endpoint) => ({ | |||
authorization: endpoint, |
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.
authorization doc: https://amp.dev/documentation/components/amp-access/#authorization-endpoint
…into AmpAccessToggleForAds
scripts/bundleSizeConfig.js
Outdated
@@ -2,5 +2,5 @@ module.exports = { | |||
// Size limit for all bundles used by each service (K) | |||
// Keep these +/- 5K and update frequently! | |||
MIN_SIZE: 743, | |||
MAX_SIZE: 793, | |||
MAX_SIZE: 800, |
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.
{AMP_ACCESS_FETCH(service)} | ||
</Helmet> | ||
<div | ||
amp-access="toggles.ads.enabled AND geoIp.advertiseCombined" |
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.
So this will be either true or false depending on the response returned by the endpoint, right?
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.
Yep that is correct.
This is an example of the endpoint data response btw:
{
"toggles": {
"ads": {
"enabled": true,
"value": ""
}
},
"geoIp": {
"ukCombined": true,
"advertiseCombined": false,
"countryCode": "gb"
}
}
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 looks good to me, thanks for the comments @thekp 👍
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.
Looks good to me, just one little discussion point! Would be worth someone who was more involved in the canonical toggles work taking a look too :)
</Helmet> | ||
<div | ||
amp-access="toggles.ads.enabled AND geoIp.advertiseCombined" | ||
amp-access-hide="true" |
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 just gone down a bit of a rabbit hole looking into this - it looks like react is buggy around boolean, non-standard, html attributes (i.e. amp-access-hide
isn't an html attribute). See here: facebook/react#9230 - they recommend using amp-access-hide=""
instead, which is rendered as amp-access-hide
. This is a bit weird, not sure which I prefer, as amp-access-hide="true"
isn't quite what we should be passing to the AMP component (and amp-access-hide="false"
wouldn't have the opposite effect, due to how boolean attributes work)
This PR is waiting for testing as the GeoIp shows error status in isite. Once this is fixed then it could be picked up for testing. |
Testing: |
This is again blocked because the geoIP endpoint seem to have changed and we got to update our toggle API to use the new endpoint. @thekp is creating a new issue to do this work. |
Seems like the geoIP endpoint has been fixed. As a team, we decided to get this work merged since this is not shown on LIVE and test this on our TEST env. |
Testing on Test env: Testing on latest opera mini couldn't be performed as this browser doesn't have proxy settings. |
@EinsteinNjoroge verified in opera mini and it looks good. |
Resolves #5924
Overall change:
Use amp access to conditionally render amp-ads by fetching data from the toggles endpoint.
Code changes:
Testing:
CYPRESS_APP_ENV=local CYPRESS_SMOKE=false npm run test:e2e:interactive
)