amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Intent to Implement: amp-ad-exit

Open clawr opened this issue 9 years ago • 10 comments

Objective

For users: Provide a high-quality navigation experience for AMP creatives with fast-click protection and predictable exit behavior.

For developers: Provide features needed for display ad exits, such as pinging click tracking URLs and substituting custom URL variables. Allow exits to be configured without changing creative markup.

This initial version is only intended for ads that navigate to landing pages. This could plausibly be extended to handle other types of exits, like phone calls, but for now those are better handled by specialized components.

Background

Display ad clicks behave differently than other static web content. The ad server needs to know that the ad was clicked for proper accounting, either by redirecting through a click tracking server or by pinging the server asynchronously, and that tracking URL depends on impression-time information (e.g. an event ID) and client-side information like click location. The ad network may choose to improve click quality and the user's experience by not navigating in response to certain clicks, such as those very close to the edge of the device.

Proposal

This document proposes a new element to configure and perform exits. The element is configured with a JSON child script element and will expose an "exit" action to other elements on the page. Elements in the creative can be annotated to exit when tapped, passing a target name and extra URL parameters to insert. The exit action will perform these steps:

  1. parse the JSON config (if it hasn't yet been parsed)
  2. find the requested exit target
  3. determine whether the exit should be allowed by processing the click event through declared filters
  4. rewrite URLs using standard variable substitution rules
  5. ping any click tracking URLs
  6. perform the navigation by opening the target URL in a new tab

Details

Exit Configuration

When the JSON is parsed, the resulting object should conform to this ExitConfig type (this type description uses Closure Compiler type annotations):

/** @typedef {string} */
const Url;

/** @typedef {string|number|boolean} */
const VariableValue;

/** @typedef {!Object<string, (VariableValue|!Array<VariableValue>)>} */
const Variables;

/**
 * @typedef {{
 *   final_url: Url,
 *   tracking_urls: (!Array<Url>|undefined),
 *   vars: (Variables|undefined),
 *   filters: (!Array<string>|undefined>
 * }}
 */
const NavigationTarget;

/**
 * @typedef {{
 *   delay: (number|undefined)
 * }}
 */
const FastClickFilter;

/** @typedef {string} */
const UniqueElementSelector;

/**
 * @typedef {{
 *   top: (number|undefined),
 *   right: (number|undefined),
 *   bottom: (number|undefined),
 *   left: (number|undefined),
 *   relativeTo: (UniqueElementSelector|undefined)
 * }}
 */
const ClickLocationFilter;

/** @typedef {FastClickFilter|ClickLocationFilter} */
const Filter;

/**
 * @typedef {{
 *   targets: !Object<string, NavigationTarget>,
 *   filters: !Object<string, Filter>
 * }}
 */
const ExitConfig;

Filtering

There are initially two types of filters: location-based and time-based. Other filters (such as a confirmation prompt) could be added as needed.

ClickLocationFilter specifies the minimum distance a click must be from the edges of an element in the creative.

FastClickFilter specifies the time to wait before responding to clicks. This element will impose a minimum delay of 1 second on all exits.

Variable substitution

The final_url and tracking_urls will be processed for variable substitution. This includes the standard URL variables, click coordinates (CLICK_X and CLICK_Y), data from signal collection frames, and custom params.

Custom params are inspired by amp-analytics' vars option. URLs can include ${var} placeholders which will be replaced on exit. Variables can have default values which can be overridden by the element requesting the exit (see the "exit action" secton).

exit action

The component will expose an exit action that other elements will reference in on="tap:..." attributes. The action accepts a "target" string parameter that must match a named NavigationTarget in the ExitConfig. Other parameters can be passed for variable substitution by prefixing their name with an underscore.

Parameter name Parameter value type Meaning
target string The name of a NavigationTarget in the ExitConfig
_([a-zA-Z0-9_-])+ string|boolean|number Insert a query parameter with this key and value into the final or tracking URLs. Default values can be specified in the NavigationTarget config.

Example

<amp-ad-exit id="exit-api">
<script type="application/json">
{
  "targets": {
    "Product_0": {
      "final_url": "https://adclickserver.com/click?id=af319adec901&x=CLICK_X&y=CLICK_Y&elem=${elem}&adurl=https://example.com/product1",
      "vars": {
        "elem": {
          "default": "headline",
        }
      }
    },
    "Product_1": {
      "final_url": "https://example.com/product2",
      "tracking_urls": [
        "https://adclickserver.com/click?id=af319adec901&x=CLICK_X&y=CLICK_Y",
        "https://tracker.adnetwork.com/?url=example.com",
      ],
      "filters": ["fast_click", "border_protection"]
    }
  },
  "filters": {
    "fast_click": {
      "delay": 1000
    },
    "border_protection": {
      "top": 10,
      "right": 5,
      "bottom": 10,
      "left": 10,
      "relativeTo": "#product1"
    }
  }
}
</script>
</amp-ad-exit>

<div id="product0" on="tap:exit-api.exit(target='Product_0', _elem='p1')">
  <p>Description of first product</p>
  <amp-img src="..." width="..." height="..."></amp-img>
</div>
<div id="product1" on="tap:exit-api.exit(target='Product_1')">
  <p>Description of second product</p>
  <amp-img src="..." width="..." height="..."></amp-img>
</div>

clawr avatar Mar 30 '17 21:03 clawr

@ampproject/a4a for review

jasti avatar Mar 30 '17 21:03 jasti

@clawr Thanks a lot for the spec. I have a few questions:

Allow exits to be configured without changing creative markup.

The amp-ad-exit is however always in the creative itself, right? Looking at the "tap" events and config itself - it's fairly extensive and it'd seem that overall markup changes are very likely? E.g. what is _elem='p1'?

FastClickFilter specifies the time to wait before responding to clicks. This element will impose a minimum delay of 1 second on all exits.

a. Do you take a risk of not being able to open a new tab because user action has expired? This would seem to be especially possible on iOS... b. How do you measure the delay? From the touchstart?

ClickLocationFilter specifies the minimum distance a click must be from the edges of an element in the creative.

Edge of the event element? Or edge of the creative itself in the overall document?

"border_protection": {...}

Can you describe the meaning of border protection like you did with other filters?

ping any click tracking URLs

  1. I assume this URLs also allow var substitution?
  2. In some environments (e.g. WebViews, CCT) navigation to new tab often substituted with top navigation. In that case pings like this could (and will often) fail. I can see couple ways to get around this: (a) try if this reliably works using sendBeacon; (b) instead or in-addition-to, also call the same pings from the target/landing page.

<div id="product0" on="tap:exit-api.exit(target='Product_0', _elem='p1')">

Is this just for an example? Is there a reason why these are not <a> or other accessible tags?

dvoytenko avatar Apr 05 '17 00:04 dvoytenko

Looks good overall. Second the feedback on why not to use an <a> tag. I think that should be the recommendation. Do you want to support stuff like "control click", "middle mouse button click" and long presses?

cramforce avatar Apr 06 '17 18:04 cramforce

This looks good. I assume the CLICK_X/CLICK_Y document click listener will remain in existence for creatives that want a straight forward redirect? Or will they be required to move to the new element?

I would also like further clarification around when the time based filters start. Presumably they apply to the entire creative? Could they start based on any custom, amp-analytics like trigger (e.g. firstVisible or standard visibility)?

keithwrightbos avatar Apr 06 '17 20:04 keithwrightbos

Thanks for the feedback!

Allow exits to be configured without changing creative markup.

The amp-ad-exit is however always in the creative itself, right? Looking at the "tap" events and config itself - it's fairly extensive and it'd seem that overall markup changes are very likely? E.g. what is _elem='p1'?

What I mean is that often we'll have some ad content and the only thing that differs between impressions is the destination URL. With this element we can regenerate the amp-ad-exit config but leave the rest of the HTML as is (instead of templating it or generating it each time). In the example, _elem is some advertiser-defined parameter inserted into the URL that means e.g. "the user clicked on the first product".

a. Do you take a risk of not being able to open a new tab because user action has expired? This would seem to be especially possible on iOS... b. How do you measure the delay? From the touchstart?

The delay is time-after-load/visibility. The fast click filter is trying to prevent accidental clicks that occur before the user has had a chance to read the ad.

I would also like further clarification around when the time based filters start. Presumably they apply to the entire creative? Could they start based on any custom, amp-analytics like trigger (e.g. firstVisible or standard visibility)?

Probably on load, but I'd love to use visibility if it's not too heavyweight. Would it require integration with amp-analytics, or is the AMP runtime able to know when we're on screen?

ClickLocationFilter specifies the minimum distance a click must be from the edges of an element in the creative.

Edge of the event element? Or edge of the creative itself in the overall document?

Either, indicated by the "relativeTo" property (maybe it should be called "selector" for consistency with amp-analytics). A value of self, meaning the element that was clicked, could be useful.

Can you describe the meaning of border protection like you did with other filters?

This is just an example of the ClickLocationFilter. The filter names are arbitrary to allow different NavigationTargets to reference different filters.

  1. I assume this URLs also allow var substitution?

Yes

  1. In some environments (e.g. WebViews, CCT) navigation to new tab often substituted with top navigation. In that case pings like this could (and will often) fail. I can see couple ways to get around this: (a) try if this reliably works using sendBeacon; (b) instead or in-addition-to, also call the same pings from the target/landing page.

Ack. I think we'll try:

  1. navigator.sendBeacon, if available
  2. ALP integration, if availalbe
  3. best-effort pings via something like document.createElement('img').src = tracking_url

What is CCT?

Is there a reason why these are not or other accessible tags?

No, that's a good idea. I hadn't considered accessibility.

I assume the CLICK_X/CLICK_Y document click listener will remain in existence for creatives that want a straight forward redirect? Or will they be required to move to the new element?

I'd be happy to make those exclusive to this element to encourage adoption (since the user experience is better with fast-click protection).

@clawr

Probably on load, but I'd love to use visibility if it's not too heavyweight. Would it require integration with amp-analytics, or is the AMP runtime able to know when we're on screen?

For now it's relatively heavyweight. We can expose it anyway, but let's start with simpler option and enhance as needed.

What is CCT?

Custom Chrome Tabs

dvoytenko avatar Apr 12 '17 17:04 dvoytenko

Could we simplify the format to

<amp-ad-exit>
  <script type="application/json">
{
  "target": {
      "final_url": "https://example.com/product2",
      "tracking_urls": [
        "https://adclickserver.com/click?id=af319adec901&x=CLICK_X&y=CLICK_Y",
        "https://tracker.adnetwork.com/?url=example.com",
      ],
      "filters": ["fast_click", "border_protection"]
  },
  "filters": {
    "fast_click": {
      "delay": 1000
    },
    "border_protection": {
      "top": 10,
      "right": 5,
      "bottom": 10,
      "left": 10,
      "relativeTo": "#product1"
    }
  }
}
</script>
  <div id="product1" on="tap:exit-api.exit()">
    <p>Description of second product</p>
    <amp-img src="..." width="..." height="..."></amp-img>
  </div>
</amp-ad-exit>

camelburrito avatar Apr 12 '17 20:04 camelburrito

@clawr One variation is to setup global click handler and avoid on=tap actions. E.g.

<amp-ad-exit>
{
  targets: {
    "target1": {...}
  }
}
</amp-ad-exit>

<a amp-ad-exit="target1" data-var1="" data-var2="" ...>...</a>

This model might be a bit more explicit and more compact depending on how many vars you may have.

/cc @cramforce Is this what you meant?

dvoytenko avatar Apr 12 '17 21:04 dvoytenko

@camelburrito I think that makes it more complex in a couple ways:

  1. Potential duplication of URLs, vars, and filters. One change might require updates in multiple places.
  2. Putting the config parts and content parts of the ad together could make it harder to programatically insert/rewrite and could interfere with CSS (e.g. a direct child selector).

clawr avatar Apr 14 '17 17:04 clawr

@dvoytenko I like that too. I guess it would work by the amp-ad-exit element looking at the click event's target element and recursing up its parents until it finds a data-exit-target attribute. One interesting option then is to allow a hierarchy of vars, like

<div data-exit-var-foo="foo1">
  <p data-exit-var-bar="bar1">
    <a data-exit-target="target1" data-exit-var-qux="qux1">target 1</a>
    <a data-exit-target="target2" data-exit-var-qux="qux2">target 2</a>
  </p>
</div>

One downside with a global click handler is that only one amp-ad-exit element would be allowed (or at least all target names across amp-ad-exits would need to be unique). But I'm having a hard time imagining when that would be a problem.

clawr avatar Apr 14 '17 17:04 clawr