AMP for E-Commerce Part 1: Basic Building Blocks and UI Using AMP

How Reliable Is AMP? Can I Take It to Production?

Basics of AMP

<!doctype html>
<html >
<head>
<meta charset="utf-8">
<title>Sample document</title>
<link rel="canonical" href="./regularpage.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-custom>
h1 {color: red}
</style>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"headline": "Article headline",
"image": [
"thumbnail1.jpg"
],
"datePublished": "2015-02-05T08:00:00+08:00"
}
</script>
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<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>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<h1>AMP Simple Page</h1>
<p>
Text to fill the paragraph tag
<amp-img src=sample.jpg width=300 height=300></amp-img>
</p>
<amp-ad width=300 height=250
type="a9"
data-aax_size="300x250"
data-aax_pubname="test123"
data-aax_src="302">
</amp-ad>
</body>
</html>

Design and Layout

<amp-img alt="Hummingbird"
src="images/hummingbird-wide.jpg"
width="640"
height="457"
srcset="images/hummingbird-wide.jpg 640w,
images/hummingbird-narrow.jpg 320w"
sizes="(min-width: 650px) 50vw, 100vw"
heights="(min-width:500px) 200px, 80%">
</amp-img>
<style amp-custom>
@font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("https://somedomain.org/VeraSeBd.ttf");
}
body {
font-family: "Bitstream Vera Serif Bold", serif;
}
</style>

Actions and Events

<div id="warning-message">Warning...</div>
<button on="tap:warning-message.hide">Cool, thanks!</button>
<amp-img src="images/sunset.jpg"
width="264"
height="195"
layout="responsive">
<noscript>
<img src="images/sunset.jpg" width="264" height="195" />
</noscript>
</amp-img>
<amp-anim width="400"
height="300"
src="images/wavepool.gif">
<amp-img placeholder
width="400"
height="300"
src="images/wavepool.png">
</amp-img>
</amp-anim>
<amp-video controls
width="640"
height="360"
src="videos/kitten-playing.mp4"
poster="images/kitten-playing.png">
<div fallback>
<p>This browser does not support the video element.</p>
</div>
</amp-video>
<amp-audio width="400"
height="200"
src="audio/cat-meow.mp3">
<div fallback>
<p>Your browser doesn’t support HTML5 audio.</p>
</div>
<source type="audio/mpeg"
src="audio/cat-meow.mp3">
<source type="audio/ogg"
src="audio/cat-meow.ogg">
</amp-audio>
<script async custom-element="amp-iframe"
src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
<amp-iframe width="200" height="100"
sandbox="allow-scripts allow-same-origin"
layout="responsive"
src="https://www.google.com/maps/embed/v1/place?key=AIzaSyDG9YXIhKBhqclZizcSzJ0ROiE0qgVfwzI&q=europe">
</amp-iframe>

Serving ads on AMP

<amp-ad width="300"
height="250"
type="a9"
data-aax_size="300x250"
data-aax_pubname="test123"
data-aax_src="302">
</amp-ad>

Analytics

<amp-analytics>
<script type="application/json">
{
"requests": {
"pageview": "https://foo.com/pixel?RANDOM",
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
}
}
}
</script>
</amp-analytics>

Wrap Up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store