amp-ads flickering
What's the issue?
On page render, if an ad unit is in the viewport, sometimes the unit tries to collapse and then immediately tries to take back its space. It's not a consistent bug, it happens from time to time and is most probably tied to the load sequence and DFP.
See videos:
https://drive.google.com/open?id=1ITbRkU5evxrpFm4erdnHkmjoJvDPj1A7 https://drive.google.com/open?id=1UdBiqZOzPZwKSrnJRbuOT6LsGD0PDCv-
What's worth noting is that we haven't recently made any changes to our amp-ads code. So it's either something that has been there for several weeks and we just fail to catch it, or it's browser dependent or amp dependent. Our main developer being out of the office for a few weeks, it's hard to know exactly what's causing this since it falls a bit out of my skills scope.
We see in the log a warning message about multi-size validation, but it's been there since the beginning and as far as the doc goes, as long as we set it to false, it's not a problem
How do we reproduce the issue?
Hard to reproduce. We see it sometimes, on chrome 65 (what I'm using right now). Best is to refresh this page a few times (scrolled top) and you might see it happen.
https://urbania.ca https://urbania.ca/article/trouver-asile-au-quebec-fantasmes-et-realites/
What browsers are affected?
Chrome, at least.
Which AMP version is affected?
1521658019509
Hi,
Ran into this too. This is due to to the attempt of applying display:none to an ad slot that is right away in the viewport when the page is loaded and that doesn't get filled by the ad request. In your example article URL, that's line 492:
492: amp-ad.urbn--ad.amp-notsupported { display: none; }
I've been able to consistency reproduce, and in more than one platform (Chrome for OSX, Safari for OSX, Firefox for OSX, Chrome for Android).
The result is that not only the ad slot flickers, the content is constantly reflowing up and down. Also, every flickr will issue a new ad request (which is bad for adserver costs, metrics on requests, etc). This will continue until either an ad is eventually returned or the slot gets off the viewport and it is indeed permanently collapsed.
The simplest code with which you can reproduce is:
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>amp-ad</title>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!-- ## Setup -->
<!-- Import the `amp-ad` component in the header. -->
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
<link rel="canonical" href="https://ampbyexample.com/components/amp-ad/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
amp-ad.amp-notsupported {display:none}
</style>
</head>
<body>
<!-- This does not return an ad - ever -->
<amp-ad width="300" height="199"
type="doubleclick"
data-slot="/4119129/doesnt-exist">
</amp-ad>
</body>
</html>
@ereinach In your example, I'd recommend using a fallback in the AMP code, or setting a house/fallback ad in your adserver so there is no continuous flickering
Regards,
- @keithwrightbos any insights?
The issue appears to be due to toggleFallback adding 'amp-notsupported' which combined with the CSS setting display none causes the scheduler to call unlayoutCallback as part of the vsync completion (see https://github.com/ampproject/amphtml/blob/master/src/service/resources-impl.js#L1530) as wasDisplayed && !r.isDisplayed() evaluates to true. onLayoutMeasure is then called shortly thereafter. We use unlayoutCallback to clear state and onLayoutMeasure to reiniate as the assumption is that unlayoutCallback is only called "The unlayoutCallback is called when the document becomes inactive, e.g. when the user swipes away from the document, or another tab is focused."
Any particular reason the page includes this CSS? @jridgewell any thoughts?
This issue hasn't been updated in awhile. @jridgewell Do you have any updates?
@keithwrightbos had the right answer.