Hello @evanmikalin
Thank you for contacting us! There is an upstream Github issue opened regarding GA4 support in AMP; there you can find the latest updates regarding the implementation of GA4 on the GitHub issue. Once upstream (product) support for AMP in GA4 is added, the AMP plugin for WordPress will make it available.
Currently, there is no official solution provided by AMP and Analytics team, however, you can mark the GA4 Analytics script as px verified so that it won’t be removed by the AMP validator
We are also working on a solution to mark GA4 scripts automatically px verified, you can check more details in GitHub issue
You can also mark scripts data-px-verified manually, make sure that you are on the Standard template mode then add the data-px-verified-tag attribute in your script tag that isn’t valid AMP.
⚠️ The user should make sure that the non-AMP markup doesn’t negatively impact Page Experience.
⚠️ The above will not work well in Transitional or Reader Mode as those already have non-AMP versions linked and might create validation errors on Google Search Console.
So how can I add GA4 to my site then?
Example: adding GA4 with data-px-verified attribute.
add_action( 'wp_head', function () {
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=ABC123" data-px-verified-tag></script>
<script data-px-verified-tag>
window.dataLayer = window.dataLayer || [];
function gtag(){
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'ABC123');
gtag('config', 'G-XXXXXXXX');
</script>
<?php
});
PS: You can also try the plugin AMP Google Analytics 4 Support which is based on a trick solution it is not officially supported but a working solution. if you are looking for basic things.
Hope this is helpful!
لا أعرف أين أضع رمز ادسنس الاعلانات ساعدنى من فضلك
@hooda660 Please create new support topic
@evanmikalin As we didn’t receive a response I’ll mark this as resolved. Feel free to open a new support topic if you require any further assistance.