Site logo

Archived topic

AMP Analytics

5 replies · Started by PJ on March 10, 2021

Viewing posts 1–6 of 6

Is there a Hook to add Google Analytics to AMP? I'm using the Transitional mode.

Hi there,

you should still be able to use the wp_head hook for AMP pages as thats a core hook that should be present on AMP.

Hi David,

My tag manager code is showing across all pages including the AMP pages however AMP pages should have a different script.

I've added the hook for the AMP code which is showing on both the non AMP and AMP pages.

Is there a way to either exclude amp pages from the hook from amp pages? I can't see how I could do this.

You can use the is_amp_endpoint conditional tag to wrap your scripts eg.

<?php
// Load scripts for AMP
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
    ?>
    // Your AMP Scripts
    <?php
}
// Load scripts for NON AMP
if (!function_exists( 'is_amp_endpoint' ) && !is_amp_endpoint()) {
    ?>
    // Your NON AMP Scripts
    <?php
}
?>

If you're using the Hook Element - make sure to Check Execute PHP.

Thanks David, because GP is a lot faster I'm going with the bold decision to not use AMP.

Should save me a load of hassel.

Sounds like a good idea :)

This archived topic is closed to new replies.