AMP by Example

Introduction
Introduction

Components
Components

Advanced
Advanced

Samples & Templates
Samples & Templates

AMP for Ads (A4A)
AMP for Ads (A4A)

View Demo View Source

A4A Carousel

Introduction

Sample AMP Ad using amp-carousel to display a slide-show style ad. In general an AMP Ad should be a valid AMP document.

The code represents the body that should be returned as a response initiated through an amp-ad component or otherwise whenever we want to return an AMP Ad in any other context.

This example displays a set of images forming a slide-show: Every image is clickable. You could build more elaborate slides embedding more AMP components. See here or there.

We include a rendering tracking pixel using the amp-pixel component.

Show Hidden Code Hide Code
<!doctype html>
<html ⚡>
<head>

  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>

Setup

Import the carousel component in the header.

  <script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
Show Hidden Code Hide Code

  <link rel="canonical" href="https://ampbyexample.com/amp_for_ads_a4a/a4a_carousel/" >
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>

Basic Usage

We use type="slides" to display a list of nodes as slides: Each of these nodes may have arbitrary AMP-HTML children. Here we put in every of them a simple banner ad.

See amp-carousel for more options to display the content.

  <amp-carousel width="300"
      height="250"
      type="slides">
    <a target="_blank"
        href="https://ampbyexample.com/amp_for_ads_a4a/a4a_carousel/">
      <amp-img src="https://ampbyexample.com/img/a4a_slide1.png"
          width=300
          height=250
          alt="slide 1" />
    </a>

    <a target="_blank"
        href="https://ampbyexample.com/amp_for_ads_a4a/a4a_carousel/">
      <amp-img src="https://ampbyexample.com/img/a4a_slide2.png"
          width=300
          height=250
          alt="slide 2" />
    </a>

    <a target="_blank"
        href="https://ampbyexample.com/amp_for_ads_a4a/a4a_carousel/">
      <amp-img src="https://ampbyexample.com/img/a4a_slide3.png"
          width=300
          height=250
          alt="slide 3" />
    </a>
  </amp-carousel>

We include a tracking pixel to record that the ad was rendered using amp-pixel.

Alternatively one could make use of amp-analytics to enable much more comprenhensive measure activity.

  <amp-pixel src="https://foo.com/pixel?RANDOM"></amp-pixel>
</body>
</html>