Created
March 17, 2017 08:40
-
-
Save newbieboss/1fec7506e956ecbaf5dc29e3542a6a43 to your computer and use it in GitHub Desktop.
Add Analytics to AMP Pages
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
//Add Analytics to AMP Pages | |
add_action('amp_post_template_footer','awtsamp_google_analytics'); | |
function awtsamp_google_analytics() { ?> | |
<amp-analytics type="googleanalytics" id="analytics1"> | |
<script type="application/json"> | |
{ | |
"vars": { | |
"account": "UA-XXXXX-Y" /*這邊改成你的google analytics ID*/ | |
}, | |
"triggers": { | |
"trackPageview": { | |
"on": "visible", | |
"request": "pageview" | |
} | |
} | |
} | |
</script> | |
</amp-analytics> | |
<?php } | |
/* | |
* Adding Google Analytics JS Code on AMP Head | |
*/ | |
add_action('amp_post_template_head','awts_amp_google_analytics_head'); | |
function awts_amp_google_analytics_head() { | |
?> | |
<!-- Google Analytics for AMP pages --> | |
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment