-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow modifications on the adsense code #336
Comments
@fu-san Thanks for the suggestion. Site Kit uses Auto Ads (Auto Ads for AMP). The recommended placement for Auto Ads code is within the tags on a users website. As intended this is where Site Kit places the code. If you have other suggestions feel free to also add them individually, with some screenshots or context and we can certainly investigate. |
@jamesozzie For example if someone wanted to stop anchor ads from autoads to coming from top, according to to help center he has to do some modification. (https://support.google.com/adsense/answer/7478225?hl=en) That kind of modifications isn't possible at the moment with sitekit. So I thought it would be great if one was able to modify the auto ad code for their purpose. |
@fu-san I will label this as an enhancement, and modify the content for that specific feature. |
Has there been any update on this? I also would need this exact feature. Either manually editing of the AdSense code or the possibility that Sitekit automatically adds the correct code of common modifications to the AdSense code (like forcing anchor ads to the bottom). |
@U-se We've no update on this just yet. In the meantime if you're looking to modify the code snippet to include such modifications the plugin can recognize existing AdSense Auto ads code placed in your site when connecting the module. |
Given that the AdSense API doesn't allow write interactions, unfortunately we cannot manage these settings from within Site Kit. However, being able to modify the AdSense snippet is definitely a great idea. We're going to prioritize this one and introduce a filter which can be used to modify the snippet parameters. |
IB ✔️ |
QA ✅ ✅ On homepage without amp ✅ On homepage with amp ✅ On webstory, with / without amp In Tried with and without these settings: For reference, used this mu-plugin to test: <?php
add_filter( 'googlesitekit_auto_ads_opt', function ($foo) {
var_dump( 'googlesitekit_auto_ads_opt');
var_dump( $foo );
} );
add_filter( 'googlesitekit_amp_auto_ads_attributes', function ($foo) {
var_dump( 'googlesitekit_amp_auto_ads_attributes');
var_dump( $foo );
} );
add_filter( 'googlesitekit_amp_story_auto_ads_attributes', function ($foo) {
var_dump( 'googlesitekit_amp_story_auto_ads_attributes');
var_dump( $foo );
} ); |
@ivankruchkoff So, turns out that if we don't have a story specific ad unit, the snippet will not be displayed: Can you add add an unit id in AdSense settings and test again? Thanks! |
Thanks for the update, that works @asvinb . |
Currently there isn't any way to make modifications (ex. make anchor tags always come from bottom) to the adsense code. Make it easier for new/novice users to do this kind of modifications.
Feature Description
Within AdSense Auto Ads there are different ad formats (Display ads, in-fedd ads, matched etc) that users can enable or disable globally across their sites.
Some users would like additional options from within Site Kit (specifically the AdSense module) to toggle such ad formats.
While the first step would naturally be allowing users to select specific ad formats some users would benefit from follow on features. The ability to disable anchor ads at the top of a page is an example. At the moment this feature must be implemented via adding parameters to Auto Ads code. With Site Kit placing the Auto Ads code this is not easily achievable for users.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
googlesitekit_auto_ads_opt
filter.google_ad_client
key is never overwritten (e.g. by re-setting it afterwards, similarly to how it is done in the AMP tag for Analytics.amp-auto-ads
):data-ad-client
key with the tag ID as value. It should be passed through a newgooglesitekit_amp_auto_ads_attributes
filter.data-ad-client
key is never overwritten.amp-auto-ads
tag (so that by default the tag looks the same as today, with adata-ad-client
attribute).amp-story-auto-ads
):data-ad-client
anddata-ad-slot
keys with the respective values as currently used. It should be passed through a newgooglesitekit_amp_story_auto_ads_attributes
filter.data-ad-client
key is never overwritten.ad-attributes
array currently used, appending to thetype
key (which should not be hard-coded because it should always beadsense
, basically like a constant, as it is also enforced in the other 2 snippets).Note that the filter name suffix
_opt
was chosen for parity with the similar Analytics filters. For AMP however, what's being filtered is not direct options passed as AdSense configuration, but rather attributes - that's why these two filters use the_attributes
suffix.Implementation Brief
includes/Modules/AdSense/Web_Tag.php
, within therender
method,wp_json_encode
function as value.googlesitekit_auto_ads_opt
filter.google_ad_client
key is not overwritten in the filtered array, set the value again in the array, i.e$this->tag_id
.wp_json_encode
function.includes/Modules/AdSense/AMP_Tag.php
, within therender
method,data-ad-client
as key and the tag ID as value.googlesitekit_amp_auto_ads_attributes
filter.data-ad-client
key is not overwritten in the filtered array, set the value again in the array, i.e$this->tag_id
.includes/Modules/AdSense/AMP_Tag.php
, within therender_story_auto_ads
method,data-ad-client
anddata-ad-slot
with their appopriate values, i.e$this->tag_id
and$this->story_ad_slot_id
respectively.googlesitekit_amp_story_auto_ads_attributes
filter.data-ad-client
key is not overwritten in the filtered array, set the value again in the array, i.e$this->tag_id
.ad-attributes
array.Test Coverage
Visual Regression Changes
QA Brief
AdSense
module and edit the theme's functions.php to run the filters in the AC.Changelog entry
The text was updated successfully, but these errors were encountered: