[amp-ad] Uncaught Error: Unknown attribute for medianet: ampSlotIndex
This error occurs in the current canary for amp-ad of some specific ad networks (e.g., a9). It's introduced in #5837.
This error is harmless though, it will not affect ad rendering.
@glevitzky thinking twice, I think we probably should not introduce ampSlotIndex as a data attribute. Instead, we can pass it directly via opt_context here.
Using opt_context was my initial hope. However, I don't think it'll be that simple. The ad slot index needs to be known as soon as the amp-ad element is created, which happens in amp-ad.js. The only way of carrying that information forward from amp-ad.js, that I can see, is by adding it as a data attribute, or polluting the global namespace. An alternative that would allow us to keep the data-amp-slot-index attribute might be to alter validateData in 3p.js to always consider "data-amp-slot-index" as a valid attribute.
i see. how about change it to slot-index, to not mess up with custom data attribute.
Change "data-amp-slot-index" to "data-slot-index" you mean? Or just "slot-index"?
The ad slot index needs to be known as soon as the amp-ad element is created, which happens in amp-ad.js. The only way of carrying that information forward from amp-ad.js, that I can see, is by adding it as a data attribute, or polluting the global namespace.
Isn't this the reason we created context?
@jridgewell I may be a little out of the loop here, what do you mean by context?
The opt_context @lannka linked to. We created it to specifically get rid of the ampCid attribute.
Okay. For that to work, I'll need to add the slot index as an instance variable to both AmpA4A and AmpAd3pImple, then set the variable before returning whichever instance in AmpAd. If that sounds reasonable to you, then I will have a PR out shortly (or early tomorrow morning at the worst).
that sounds good too. avoid passing data via attribute is a goal.
After further consideration, I remember now why we didn't originally go with the solution I proposed here. We need the slot index inside the AmpA4A subclass constructor, which would mean we would have to pass the index in as a constructor argument. This would require that other ad networks change their constructors' signatures, which is obviously undesirable. The cleanest approach I think is just to modify the validateData function to allow data-amp-slot-index, or whatever we decide to call it.