amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Apply AMP analytics ad tracking events to an ad without requiring a selector

Open j-e-shaw opened this issue 10 years ago • 11 comments

Currently, AMP analytics tags for ads require a selector (e.g. "selector": "#anim-id"). However, the amp-ad's id isn't necessarily known when the analytics tags are generated. Instead of requiring a selector, when the analytics events are added to the page as the result of an ad request, they should apply to the ad with which they are served.

Along with that, when shadow-DOM isn't supported, the analytics tags need to be hoisted from the ad response and placed in the main AMP page, not the iframe. Then, the AMP runtime can correctly track the viewability of the ad and fire the events.

j-e-shaw avatar Jul 11 '16 22:07 j-e-shaw

/cc @rudygalfi @kashyapnitin

dvoytenko avatar Jul 12 '16 18:07 dvoytenko

I'm not sure I'm following this. Is it related to A4A? Can you provide an example page that demonstrates the difficultly with how amp-analytics currently works.

cc a bunch of people who may also be aware of the gap here @jasti @avimehta @cramforce

rudygalfi avatar Jul 13 '16 16:07 rudygalfi

Yes, this is related to a4a. I don't have a sample page but I have been discussing with avimehta and he's aware of it.

  1. If I want to add analytics tags to a creative that I don't own/serve (e.g. 3P verification services), I don't know what the selector should be. In that case, the AMP runtime should be able to associate the analytics tag with the creative with which it is served.
  2. When shadow-DOM isn't supported, the creative is dropped into an iframe. My understanding is that there isn't an AMP runtime in that frame that can handle the analytics tags. In case case, the analytics tags will need to be lifted from the creative and added in the parent window where the runtime is present.

j-e-shaw avatar Jul 13 '16 18:07 j-e-shaw

@michaelkleber FYI

jasti avatar Jul 13 '16 19:07 jasti

I think we should probably discuss the hoisting separately.

The summary of the other feature request is basically:

Support a "closest" selector coming from the amp-analytics tag instead of a document level selector.

How about

{
  "selector": "amp-ad",
  "closest": true,
}

cramforce avatar Jul 13 '16 22:07 cramforce

A selector targeting the closest amp-ad parent seems fine to me. I think that plays nicely with hoisting too, as long as we place the hoisted amp-analytics config right outside the iframe (but still within the enclosing amp-ad element).

michaelkleber avatar Jul 14 '16 02:07 michaelkleber

@michaelkleber we can make closest inclusive :)

cramforce avatar Jul 14 '16 04:07 cramforce

what about siblings? If the dom structure is something like:

<amp-ad  id="#parent">
  <amp-ad id="#before"></amp-ad>
  <amp-analytics></amp-analytics>
  <amp-ad id="#after"></amp-ads>
</amp-ad>

What would https://github.com/ampproject/amphtml/issues/4018#issuecomment-232508277 select in this case?

avimehta avatar Jul 14 '16 19:07 avimehta

#parent. I don't think siblings are needed. We certainly don't support amp-ad nesting.

cramforce avatar Jul 14 '16 22:07 cramforce

I added basic support for this in #4368. I couldn't think of what closest=false would do. So I skipped implementing the logic for closest completely. Here's my thinking:

We should make searching for closest element implicit. In future, if we want to expand the way searching for element is done, we can add something like searchMethod with possible values closest, first, and topmost.

Does that sound good?

ps: I need to wait before I can merge the PR because a couple of other PRs(mentioned in #4368) change the same codebase and are going to cause conflicts.

avimehta avatar Aug 04 '16 17:08 avimehta

I agree with searchMethod = scope|closest or closest: true. These will map very clearly to the standard Element.querySelector and Element.closest APIs.

dvoytenko avatar Aug 10 '16 19:08 dvoytenko