Error when trying to track amp adsense ad visibility with amp analytics and using data variable(s)
I would like to track with amp analytics when an adsense ad is seen. To be able to do this I added a data var for amp-ad:
<amp-ad data-vars-event-category="list1" layout="fixed-height" height=100 type="adsense" data-ad-client="..." data-ad-slot="...">
And I got this error message:
Unknown attribute for adsense: varsEventCategory
You will need to create a dedicated amp-analytics element for this and place a unique identifier on the amp-ad element. Something like the following though I'm not sure if visiblePercentageMin 0 is more correct:
`<amp-ad id='adsenseAd1' ....>
`
Closing with https://github.com/ampproject/amphtml/issues/8852#issuecomment-295826775.
@keithwrightbos you are right, actually there is no need to add a separate analytics tag, it can be done with an existing analytics by adding a dedicated trigger AND a dedicated request.
The request would be totally unnecessary when the data-var attributes were working for amp-ad elements (assuming I am using data-vars for what they are intended for: creating one request for multiple items and inserting variable from the items' data variables).
Now my real concern is, that there is a feature (data-var attributes) which really should work for the amp-ad element as well, like it does work for other amp elements.
@jridgewell can you please reopen the issue? Or should I open a new issue?
Is there an unresolved question on whether there's support for data-var attributes for amp-ad, or is that confirmed to be the case? I know this got added for supporting click events, so maybe they're only supported on <a> tags right now?
@rudygalfi: it appears there is no support for data-var attributes for amp-ad, since I get the following error when I try to do it
Unknown attribute for adsense: varsEventCategory
The support is not bound to a tags, it is defined here: https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/analytics-vars.md
In an ideal world amp-ad tags should support data-var attributes like any other element.
@rudygalfi This issue is that we have a conflict between <amp-ad> data-* var gathering (which it uses to create the ad iframe), and <amp-analytics> data-var-* var gathering (which is uses for URL manipulations).
Since none of the ad tags currently depend on any data-var-* to set themselves up (they'd have to declare it in their AMP ad code), we should probably just not pass those vars to the ad.