• Austin SEO
    • TastyPlacement in the Press
    • Meet the Team
  • Blog
  • Services
    • SEO Services
      • WordPress SEO Service
      • Magento SEO Services
      • Conversion Rate Optimization
      • SEO Audit Service
      • Why Google Certification Matters
    • PPC & Adwords
      • Adwords & PPC Management
      • Remarketing Services
      • Display Ad Management
      • Facebook Ad Management
      • Google Ad Grants Management for Non-Profits
      • Adwords App Install Ad Management
      • Product Listing Ad Management
    • Analytics & Data
      • Analytics and Monitoring
      • Google Tag Manager Experts
      • Data Studio Development & Consulting
    • Social Media & Local Marketing
      • Social Media Marketing
      • Local SEO
    • Web Development
      • Mobile Website Design
      • WordPress Development
  • Case Studies
    • SEO Case Studies
      • SEO Case Study: We Beat Lowes, Then We Beat Home Depot
      • SEO Case Study: Total Domination in Houston for Medical Provider
    • Analytics Case Studies
      • Case Study: Updated Design Yields 43% Increase in Conversion Rate
      • Case Study: PPC Optimization Yields Tripled Conversion Rate
    • Social Media Case Studies
      • Social Media Case Study: Hundreds of New Customers From Core Facebook Campaign
  • Portfolios
    • Display Ad Portfolio
    • Design Portfolio
    • Infographic Portfolio
    • SEO Testimonials
  • Contact
    • New Customers: Get to Know Us
    • Customer Service & Support
    • Referral Program
    • SEO Training Seminars
    • Job: Paid Search/PPC/Adwords Analyst
    • Job: Local Digital Marketing Specialist
    • Job: SEO/Marketing Junior Analyst
    • Privacy Policy & Terms of Use
  • Menu Menu
AMP Accelerated Mobile Pages

How to Install Google Analytics on Your WordPress AMP Content

February 22, 2016/0 Comments/in Analytics, Mobile SEO/by Matthew Bey

In the last post we talked about how to get AMP working in WordPress and how to get it optimized for the Accelerated Mobile Pages search results. Today we’re going to talk about how to get Google Analytics working on the AMP content. We’re huge GA fans, and if we’re not tracking the traffic for our site, we really wonder why we’re doing it in the first place.

Google recommends that you create a new property for your AMP pages. The analytics library for AMP doesn’t have all the capabilities of a full-scale GA snippet, so there would be a bit of apples and oranges if you put that traffic into your main account. Also, there’s not going to be much traffic shuttling between the two versions of your site. There will be no traffic going from the real site to the AMP templates, and any traffic coming off the /amp pages will have only one source: Google mobile search.

Just like the logo we did in the previous blog post, you’re going to insert the Google Analytics onto your page using hooks dropped into functions.php. The AMP guidelines only allow pre-vetted one-size fits all javascript, which means you can’t just drop the normal GA snippet into your head. You will add Google Analytics using the “amp-analytics” tag, which you customize to your account using JSON.

Which is to say, copy and paste the code below and replace the “UA-xxxxxxx” with the Google Analytics ID for your new property, and that should do the trick.

//////////////adding analytics to AMP///////////

add_action( 'amp_post_template_head', 'xyz_amp_add_analytics_library' );
add_action( 'amp_post_template_footer', 'xyz_amp_add_analytics' );
function xyz_amp_add_analytics_library( $amp_template ) {
$post_id = $amp_template->get( 'post_id' );
?>
<script async custom-element="amp-analytics"
    src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<?php
}
function xyz_amp_add_analytics( $amp_template ) {
    $post_id = $amp_template->get( 'post_id' );
    // see https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/amp-analytics.md for more on amp-analytics
    ?>
 <amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
  "vars": {
    "account": "UA-xxxxxxx"
  },
  "triggers": {
    "trackPageview": { 
      "on": "visible",
      "request": "pageview"
    }
  }
}
</script>
</amp-analytics>
    <?php
}
/////////////end adding AMP analytics////////////////

I haven’t been seeing the GA AMP tag showing up in the Tag Assistant extension, so you will need to look at this property through the real-time viewer to see if it’s actually tracking.

Tags: mobile, mobile design, mobile SEO
Share this entry
  • Share on Facebook
  • Share on Twitter
You might also like
Siri Search Optimization
Best Android Apps for SEO
AMP Accelerated Mobile Pages How to Implement and Optimize AMP in WordPress
How to Make a Mobile Site Click to Call Link
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tutorials & Case Studies

  • Analytics
  • Case Studies
  • Infographics
  • Internet Marketing
  • Local Maps and Local Listings
  • Magento
  • Mobile SEO
  • Our Book: SEO for Wordpress
  • PPC
  • Programming & PHP
  • SEO
  • SEO Power Tools
  • SEO Resources
  • Social Media Marketing
  • Web Design
  • WordPress

Our Most Recent Tutorials & Case Studies

  • Infographic: Fonts & Colors That Drive the World’s Top Brands
  • Research Shows a 23% Divergence Between UA and GA4
  • How to Track Google Analytics Conversions on BuilderTrend’s iFrame Form
  • Test Results: How to Stop Google Re-Writing Your Title Tags in the SERPs
  • Pro Tip: Track Your Website Goals in Google Analytics (and More)

Search

Archives & Tutorial Categories

  • Analytics
  • Case Studies
  • Infographics
  • Internet Marketing
  • Local Maps and Local Listings
  • Magento
  • Mobile SEO
  • Our Book: SEO for Wordpress
  • PPC
  • Programming & PHP
  • SEO
  • SEO Power Tools
  • SEO Resources
  • Social Media Marketing
  • Web Design
  • WordPress

Austin SEO Company, TastyPlacement

TastyPlacement
4150 Freidrich Ln Ste C
Austin, TX 78744
Tel: (512) 535-2492

Google Maps: Get Directions or Read Our Awesome Reviews

Quick Navigation: Our Most Important Pages

  • Austin SEO [Home]
  • WordPress SEO Service
  • PPC Management
  • Social Media Marketing
  • Analytics and Monitoring
  • Remarketing Experts
  • Conversion Rate Optimization
© Copyright - TastyPlacement. Made in Austin, Texas
  • Twitter
  • Facebook
How to Implement and Optimize AMP in WordPress AMP Accelerated Mobile Pages SEO Case Study: Total Domination in Houston for Medical Provider
Scroll to top