Created
July 9, 2019 06:29
-
-
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.
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 | |
/* | |
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