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() { ?>
<amp-analytics type="clicky">
<script type="application/json">
{
"vars":
Source: https://managewp.org/articles/14119/how-to-add-clicky-analytics-to-the-amp-site
source https://williechiu40.wordpress.com/2017/01/03/how-to-add-clicky-analytics-to-the-amp-site/
No comments:
Post a Comment