How to add google analytics 4 with AMP?
-
GA 4 is out and there is no clear guide on how to add it in your AMP pages. For now I am using older version of analytics on my AMP pages by adding following code in my child theme’s functions.php
add_filter( 'amp_post_template_analytics', 'mysite_amp_add_custom_analytics' ); function mysite_amp_add_custom_analytics( $analytics ) { if ( ! is_array( $analytics ) ) { $analytics = array(); } $analytics['googleanalytics'] = array( 'type' => 'gtag', 'attributes' => array( 'data-credentials' => 'include', ), 'config_data' => array( 'vars' => array( 'gtag' => "UA-XXXXXX-1", 'config' => array( "UA-XXXXXX-1" => array('groups' => 'default') ), ) ), ); return $analytics; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to add google analytics 4 with AMP?’ is closed to new replies.