How to add Clicky analytics to the AMP site
In this article, I will show you how to add Clicky analytics to your AMP site. If you are reading further, I assume that you have some basic knowledge about WordPress functions, hooks and how they work, but I’ll explain to you which code does what.
As we have analytics code already in our AMP plugin, so now let’s remove existing code, before adding our own, as we don’t want two analytics code.
Paste this code at the end of your theme’s functions.php or create a new plugin to create a plugin read this detailed article on how we can create a plugin on top of AMP.
Remove existing AMP analytics
Below code will remove all the existing amp-analytics code.
add_action(‘init’,’ampforwp_remove_existing_analytics’);
function ampforwp_remove_existing_analytics() {
remove_action(‘amp_post_template_footer’,’ampforwp_analytics’,11);
}
Add Clicky analytics code
Please make sure you add your Clicky site id in “site_id”: “YOUR_SITE_ID_HERE” , you can find site id of your clicky account from here
function ampforwp_clicky_analytics() { ?>