Created
January 3, 2017 13:04
-
-
Save MohammedKaludi/dc4f140412f7cb6b1f8b73c064d0e55c to your computer and use it in GitHub Desktop.
Add Clicky Analytics to AMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Remove all the existing analytics code | |
add_action('init','ampforwp_remove_existing_analytics'); | |
function ampforwp_remove_existing_analytics() { | |
remove_action('amp_post_template_footer','ampforwp_analytics',11); | |
} | |
// Build the markup for Clicky Analytics code | |
function ampforwp_clicky_analytics() { ?> | |
<amp-analytics type="clicky"> | |
<script type="application/json"> | |
{ | |
"vars": { | |
"site_id": "YOUR_SITE_ID_HERE" | |
} | |
} | |
</script> | |
</amp-analytics> | |
<?php | |
} | |
// Hook / add clicky ads code into AMP pages | |
add_action('init','ampforwp_add_clicky_analytics_hook'); | |
function ampforwp_add_clicky_analytics_hook() { | |
add_action('amp_post_template_footer','ampforwp_clicky_analytics',11); | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment