Race Condition when using amp-ad in amp-carousel
I am trying to use amp-carousel to replicate as much of the behavior of our site's current slick based carousel as possible. Part of this functionality is that we have interstitial ads every 5 slides. In order to get this to work with amp we decided to place an interstitial ad every 5 slides. This worked great when working on desktop with the emulator, but when we tested it out on an ios device, we noticed that some of interstitial ads were getting called before making it to the slide. It seems to me that it's a race condition based on the fact that there isn't anything preventing ads that are contained within carousels to delay their calls until the carousel has initialized, which interferes with the view-ability of the ads.
How do we reproduce the issue?
Please post a public URL and ideally post a reduced test case. E.g. on jsbin.com that exhibits only your issue and nothing else.
http://jsbin.com/xadubotuka/edit?html,console,output
In this jsbin I've created a carousel that contains an interstitial every 5 slides, with a total of 4 ads.
If you go to the page, you should notice that occasionally (but not all of the time) the ads will attempt to load before the carousel has initialized. In my experience this has rarely happened on my desktop, but happens nearly every time on ios.
What browsers are affected?
It should affect all browsers, but since it's a race condition it seems to depend more on the specs of the machine.
Which AMP version is affected?
Version 1472690078859
Note that I didn't log the version at first sighting, so I'm unable to determine how long this has been an issue, and if it was something that was introduced recently.
Which iOS device are you using? I'm unable to duplicate, the ad's always load once they're in viewport.
We tested it using both an iphone 6 (os ver. 8) and an iphone 6+ (os ver 9.3.2) and both versions were occasionally firing all of the ads on the page at once (although sometimes it did only fire the single mobile ad.)
Here is a page on our front end using the real code that we are running, it's possible my example page doesn't have this issue. http://www.forbes.com/test/krogers/ampcaradtest.html
I've included some screenshots taken from Charles Web Debugging Proxy that I had connected the iphone 6 plus, as you can see it not only fires the mobile ad, but every mobileint ad (the interstitial ads) on the page. As I said this doesn't happen every single time, only occasionally.


If it helps, we were actually able to fix the issue with some tricky and abusive css (targeting the slides after the carousel has initialized that aren't suppose to be in view which you mark with visibility: hidden),
.slide[style*="visibility: hidden"] .ad-slide { display: none; }
Which we had to put in place because some of our ads were ignoring visibility: hidden, and were actually breaking out of the carousel and displaying over it (which is how we noticed this issue initially). We were only able to see this behavior on ios, every other browser we tested was fine, so it could be some weirdness with how safari ios handles visibility.
@aghassemi Could you take a look at this?
Right. We did run into cases like this with videos and iframes sometimes failing visibility:hidden on iOS. Our typical fix was adding opacity: 0 as well. This might help here as well.
But I also think that the new carousel should not have this issue since slides are always positioned side-by-side and not behind each other.
I see two separate issues here,
1- ads loading too early
2- loaded ads (despite being invisible) leaking their UI through the visible slides . Indeed in iOS some UI elements (specially native ones like the OS provided play icon for videos) can leak through even when invisible. That issues is fixed in the new carousel (you can see the new carousel by enabling the amp-slidescroll experiment)
I will investigate.
When we were trying to hide the ads leaking through, we tried pretty much everything else before settling on the hacky display: none, and one of the failed fixes was adding opacity: 0 and additional visibility hiddens at lower levels of the slide, none of it seemed to affect the ads from leaking through though.
cc/ @jasti
The new scrollable carousel has been launched now and hence you should not see this issue any longer