Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deshabhishek007/28a7027f5a6f7741c36e73d93e7b3ebb to your computer and use it in GitHub Desktop.
Save deshabhishek007/28a7027f5a6f7741c36e73d93e7b3ebb to your computer and use it in GitHub Desktop.
Multiple Google Analytics in Better AMP WordPress Plugin, Use it as plugin or paste it in your function file.
<?php
/*
Plugin Name: Better AMP Mod : Multiple Analytics Code
Plugin URI: https://www.whoisabhi.com/
Description: Update your Analytics Code in this file below. Replicate Triggers if you need multiple Trackers.
Author: Abhishek
Version: 1.0
Author URI: https://www.whoisabhi.com/
*/
// Enqueue AMP Analytics js in header
function peenak_amp_js(){
better_amp_enqueue_script( 'amp-analytics', 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js' );
}
add_action( 'better-amp/template/enqueue-scripts', 'peenak_amp_js', 100 );
// Add analytics Code
function peenak_add_multiple_analytics(){
?>
<amp-analytics type="googleanalytics">
<script type="application/json">
{
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview",
"vars": {
"account": "UA-XXXXXX-1"
}
},
"trackPageview2": {
"on": "visible",
"request": "pageview",
"vars": {
"account": "UA-XXXXXX-2"
}
}
}
}
</script>
</amp-analytics>
<?php
}
add_action("better-amp/template/footer","peenak_add_multiple_analytics");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment