In this chapter, we'll cover ads and analytics support in AMP. While perhaps not the most exciting topics, they are important nonetheless. Analytics can offer insights into how well a website is performing against its goals, and into user behavior and interaction with the site. Ads offer a monetization model for many sites for which there may be no other revenue source available.
We'll start off with analytics and see how to add different types of tracking to our web pages. We'll see how to do the following:
- Track different types of events, such as pageviews, clicks, scrolling, and social sharing
- Apply this to our e-commerce cart, and see how to track addition and removal of products from the cart
- Unify sessions across the AMP cache and the original domain
We'll then look at ad support in AMP, and review the types and formats of ads that can be added to AMP pages.
Buy "AMP: Building Accelerated Mobile Pages" on Amazon US, Amazon UK
View Examples
- Pixel-based tracking with
<amp-pixel>
ga-pixel.html - Custom analytics with
<amp-analytics>
: amp-analytics.html - Google Analytics: ga.html
- Click and tap tracking with Google Analytics: ga-click-button.html
- Click and tap tracking with custom analytics vendor:novendor-click.html
- Tracking outbound links: ga-click-link.html
- Scroll tracking: ga-scroll.html
- Tracking time on page: ga-timer.html
- Tracking items added and removed from shopping cart: ga-cart.html
- Session stitching: ga-session.html
- Adsense ads in AMP: ad-adsense.html
- Sticky ads in AMP: ad-sticky.html
- Carousel with embedded ad: ad-carousel.html
- Flying carpet ad: ad-flying-carpet.html
Download code
Download all code for this chapter: ch10.zip