amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

[amp-ad] Uncaught Error: Unknown attribute for medianet: ampSlotIndex

Open lannka opened this issue 10 years ago • 10 comments

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.

lannka avatar Nov 07 '16 21:11 lannka

@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.

lannka avatar Nov 07 '16 22:11 lannka

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.

glevitzky avatar Nov 07 '16 23:11 glevitzky

i see. how about change it to slot-index, to not mess up with custom data attribute.

lannka avatar Nov 07 '16 23:11 lannka

Change "data-amp-slot-index" to "data-slot-index" you mean? Or just "slot-index"?

glevitzky avatar Nov 07 '16 23:11 glevitzky

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 avatar Nov 07 '16 23:11 jridgewell

@jridgewell I may be a little out of the loop here, what do you mean by context?

glevitzky avatar Nov 07 '16 23:11 glevitzky

The opt_context @lannka linked to. We created it to specifically get rid of the ampCid attribute.

jridgewell avatar Nov 07 '16 23:11 jridgewell

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).

glevitzky avatar Nov 07 '16 23:11 glevitzky

that sounds good too. avoid passing data via attribute is a goal.

lannka avatar Nov 07 '16 23:11 lannka

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.

glevitzky avatar Nov 08 '16 03:11 glevitzky