How to add Google Analytics 4 code for AMP pages?
-
I’m in the process of setting up Google Analytics 4, but I have no idea how to add code as a function for AMP pages.
Currently using this in the functions.php to monitor Analytics legacy:
add_action( 'amp_post_template_footer', 'xyz_amp_add_analytics' ); function xyz_amp_add_analytics( $amp_template ) { $post_id = $amp_template->get( 'post_id' ); ?> <amp-analytics type="googleanalytics" id="analytics1"> <script type="application/json"> { "vars": { "account": "UA-111111111-11" }, "triggers": { "trackPageview": { "on": "visible", "request": "pageview" } } } </script> </amp-analytics> <?php }
Does anyone know the code to track Analytics 4?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to add Google Analytics 4 code for AMP pages?’ is closed to new replies.