512-535-2492
Austin SEO Company | TastyPlacement
  • Austin SEO
    • TastyPlacement in the Press
    • Team
    • Our Markets
      • SEO Dallas TX
      • SEO Houston TX
      • SEO San Antonio TX
    • TastyPlacement Reviews
  • Blog
  • Services
    • SEO
      • WordPress SEO Service
      • Magento SEO Services
      • Penguin/Panda Recovery
      • Mobile SEO and Digital Marketing
      • 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
      • Infographic Development
      • Local SEO
      • Proximity Beacons
    • Web Development
      • Ecommerce Web Dev
      • Mobile Website Design
      • WordPress Development
  • Case Studies
    • Case Study: Updated Design Yields 43% Increase in Conversion Rate
    • Case Study: PPC Optimization Yields Tripled Conversion Rate
    • SEO Case Studies
  • Portfolios
    • Display Ad Portfolio
    • Design Portfolio
    • Infographic Portfolio
    • SEO Testimonials
  • Contact
    • Job: Paid Search/PPC/Adwords Analyst
    • Referral Program
    • SEO Training Seminars
    • Support Request (Small Task)
    • Job: Local Digital Marketing Specialist
    • Job: Search Marketing Junior Analyst
    • Privacy Policy & Terms of Use
  • 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
  • Share on Pinterest
  • Share on Linkedin
You might also like
AMP Accelerated Mobile Pages How to Implement and Optimize AMP in WordPress
Best Android Apps for SEO
Siri Search Optimization
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 *

Categories

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

Recent Posts

  • Case Study: Updated Design Yields 43% Increase in Conversion Rate
  • Merging Duplicate Yelp Listings: Tutorial for Business Owners (and Analysts)
  • Before Moving a WordPress Site, Follow These Tips
  • Analytics Tutorial: How to Segment Out Time Zones & Regions
  • How to Set Up Form Confirmation Emails in WordPress (Gravity Forms)

Austin SEO Company, TastyPlacement

TastyPlacement
1701 Directors Blvd #520
Austin, TX 78744
Tel: (512) 535-2492

Google Maps: Get Directions or Read Our Awesome Reviews

Popular Pages

  • Austin SEO [Home]
  • WordPress SEO Service
  • PPC Management
  • Social Media Marketing
  • Analytics and Monitoring
  • Remarketing Experts
© Copyright - TastyPlacement. Made in Austin, Texas.
  • Twitter
  • Facebook
  • Linkedin
How to Implement and Optimize AMP in WordPress AMP Accelerated Mobile Pages WordPress Media Upload HTTP Error: The Fix
Scroll to top