I am trying to put a code for the Google analytics for AMP. For the life of me, cannot figure it out. I’ve read how to articles but I’m still not getting it. Can someone help?
]]>Hi Guys,
Do wordpress any plan to add the Jetpack Site stats tracker in Google Cache AMP? like the one in Google Analytics..
For now, any visitor from the AMP Cache version of my site from Google (eg. https://www.google.com/amp/s/YOUR_WEBSITE.com/thepage/amp/) is not tracked in my Jetpack Site Stats.
Thank you!
]]>Hi!
Just to let you know there is support in the plugin sponsored by Automattic, hooking your function into the filter amp_post_template_analytics
:
I’ve implemented it with this function in my theme:
add_filter('amp_post_template_analytics', function() {
$data = ['pageview1' => [
'type' => 'googleanalytics',
'attributes' => [],
'config_data' => [
'vars' => ['account' => get_option('theme_google_ua') ],
'triggers' => [
'trackPageview' => ['on' => 'visible', 'request' => 'pageview']
],
],
]];
return $data;
});
It allows more easily add customizations like events and social interactions. Maybe it would be nice this plugin will help people to add custom configs for this, just hooking in the filter provided.
]]>Bonus points for sanitizing it when saving to the DB ??
Current
<?php echo $options['amp_analytics_ga_ua']; ?>
<?php echo '"account":' . ' "' . $options["amp_analytics_ga_ua"] . '"' . "\n"; ?>
Proposed
<?php echo esc_attr( $options['amp_analytics_ga_ua'] ); ?>
<?php echo '"account":' . ' "' . esc_js( $options["amp_analytics_ga_ua"] ) . '"' . "\n"; ?>