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

Amp access toggle for ads #6079

Merged
merged 19 commits into from
Apr 15, 2020
Merged

Amp access toggle for ads #6079

merged 19 commits into from
Apr 15, 2020

Conversation

thekp
Copy link
Contributor

@thekp thekp commented Apr 2, 2020

Resolves #5924

Overall change:
Use amp access to conditionally render amp-ads by fetching data from the toggles endpoint.

Code changes:

  • Following the same implementation as the current AMP page, using amp-access to conditionally render amp-ads
  • Update snapshots
  • Added some comments, to clarify the ads work is currently just on Pidgin
  • enabled Ads for the following services:
arabic
hindi
mundo
portuguese
russian
zhongwen

  • I have assigned myself to this PR and the corresponding issues
  • I have added labels to this PR for the relevant pod(s) affected by these changes
  • I have assigned this PR to the Simorgh project

Testing:

  • Automated (jest and/or cypress) tests added (for new features) or updated (for existing features)
  • If necessary, I have run the local E2E non-smoke tests relevant to my changes (CYPRESS_APP_ENV=local CYPRESS_SMOKE=false npm run test:e2e:interactive)
  • This PR requires manual testing

@thekp thekp added AMP Work related to AMP ws-home ads labels Apr 2, 2020
@thekp thekp added this to the Simorgh 3.0 milestone Apr 2, 2020
@thekp thekp self-assigned this Apr 2, 2020
@thekp thekp added this to PR in Progress in Simorgh via automation Apr 2, 2020
</Helmet>
<div
amp-access="toggles.ads.enabled AND geoIp.advertiseCombined"
amp-access-hide="true"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a string here because when I run the unit tests for Ads I get this console warning...
image

Copy link
Contributor

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?

Copy link
Contributor Author

@thekp thekp Apr 3, 2020

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.

Copy link
Contributor

@tochwill tochwill Apr 3, 2020

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
Copy link
Contributor Author

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,
Copy link
Contributor Author

@thekp thekp Apr 2, 2020

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,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thekp thekp marked this pull request as ready for review April 2, 2020 16:33
@thekp thekp moved this from PR in Progress to Code review in Simorgh Apr 2, 2020
@@ -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,
Copy link
Contributor Author

@thekp thekp Apr 3, 2020

Choose a reason for hiding this comment

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

Highest current bundle:
image

{AMP_ACCESS_FETCH(service)}
</Helmet>
<div
amp-access="toggles.ads.enabled AND geoIp.advertiseCombined"
Copy link
Contributor

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?

Copy link
Contributor Author

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"
 }
}

Copy link
Contributor

@DenisHdz DenisHdz left a 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 👍

Copy link
Contributor

@tochwill tochwill left a 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"
Copy link
Contributor

@tochwill tochwill Apr 3, 2020

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)

@thekp thekp requested a review from sareh April 6, 2020 09:00
@sareh sareh moved this from Ready for Test to In Test in Simorgh Apr 9, 2020
@PriyaKR
Copy link
Contributor

PriyaKR commented Apr 9, 2020

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.

@PriyaKR PriyaKR added the blocked This issue should not be worked on until another internal issue is completed - see desc for details label Apr 9, 2020
@PriyaKR PriyaKR moved this from In Test to Ready for Test in Simorgh Apr 9, 2020
@PriyaKR PriyaKR moved this from Ready for Test to In Test in Simorgh Apr 14, 2020
@PriyaKR PriyaKR removed the blocked This issue should not be worked on until another internal issue is completed - see desc for details label Apr 14, 2020
@thekp thekp mentioned this pull request Apr 14, 2020
1 task
@PriyaKR
Copy link
Contributor

PriyaKR commented Apr 14, 2020

Testing:
I tried using VPN to set the geo location as outside UK and looking at the http://localhost:7080/mundo.amp i dont see any ads being displayed.

Screenshot 2020-04-14 at 14 15 56

@PriyaKR
Copy link
Contributor

PriyaKR commented Apr 14, 2020

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.

@PriyaKR PriyaKR added the blocked This issue should not be worked on until another internal issue is completed - see desc for details label Apr 14, 2020
@PriyaKR PriyaKR moved this from In Test to Ready for Test in Simorgh Apr 14, 2020
@PriyaKR PriyaKR moved this from Ready for Test to In Test in Simorgh Apr 14, 2020
@PriyaKR PriyaKR removed the blocked This issue should not be worked on until another internal issue is completed - see desc for details label Apr 15, 2020
@thekp
Copy link
Contributor Author

thekp commented Apr 15, 2020

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.

@thekp thekp merged commit 064769b into latest Apr 15, 2020
Simorgh automation moved this from In Test to Done Apr 15, 2020
@thekp thekp deleted the AmpAccessToggleForAds branch April 15, 2020 09:58
@thekp thekp moved this from Done to In Test in Simorgh Apr 15, 2020
@PriyaKR PriyaKR moved this from In Test to Ready for Test in Simorgh Apr 16, 2020
@PriyaKR PriyaKR moved this from Ready for Test to In Test in Simorgh Apr 16, 2020
@PriyaKR
Copy link
Contributor

PriyaKR commented Apr 16, 2020

Testing on Test env:
https://www.test.bbc.com/pidgin.amp
The ads are displayed across all browsers and devices when the toggle is enabled(for non-uk) and ads are not shown when the toggle is disabled(for non-uk).

Testing on latest opera mini couldn't be performed as this browser doesn't have proxy settings.

@PriyaKR
Copy link
Contributor

PriyaKR commented Apr 17, 2020

@EinsteinNjoroge verified in opera mini and it looks good.

@PriyaKR PriyaKR moved this from In Test to Done in Simorgh Apr 17, 2020
@PriyaKR PriyaKR mentioned this pull request Apr 22, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ads AMP Work related to AMP
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Ads: Fetch remote toggles service data for AMP ads using amp-access, and only show ads if ad toggle is on
6 participants