google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.23k stars 284 forks source link

Enhance AdSense Existing Tag detection to detect AdSense Auto Ads snippet #7259

Closed kuasha420 closed 9 months ago

kuasha420 commented 1 year ago

Feature Description

Currently AdSense existing tag detection only detects old style AdSense tags. But it does not detect new Auto Ad Snippets. We should enhance the detection to detect both snippets as existing AdSense tag.

Old tag example:

<script data-ad-client="ca-pub-xxxxxx" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

Auto ads tag example:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxx"
     crossorigin="anonymous"></script>

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

In assets/js/modules/adsense/util/tag-matchers.js:

Test Coverage

QA Brief

In order to test this functionality, a custom AdSense script of the new version format must be added to the page by a means other than site kit. This can be done via the active themes functions.php file, or via a custom mu-plugin.

add_action( 'wp_head', 'sk_add_adsense', 0, 15 );

function sk_add_adsense() {
?>
<!-- Added by QA (#7259) -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3467161889682403" crossorigin="anonymous"></script>
<?php
}
image

Changelog entry

jamesozzie commented 1 year ago

I can confirm the same. Site Kit is placing the plugin inserted AdSense snippet despite an existing AdSense snippet already manually placed. Recording.

tofumatt commented 11 months ago

ACs are good 👍🏻

eugene-manuilov commented 10 months ago

IB ✔️

wpdarren commented 10 months ago

QA Update: ⚠️

@10upsimon thanks for the helpful QAB instructions! I have an observation. I ran some additional testing with setting up AdSense with the mu-lugin activated. I saw the tag already present message, but when I enable the toggle another message appears warning of a potential conflict. See screenshot below.

When I do the same in Analytics settings, the text doesn't change. Should it?

This is what I see when the toggle is disabled. image

This is the text that appears when the toggle is enabled. image

wpdarren commented 10 months ago

QA Update: ✅

Verified:

image image