Skip to content
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

Ads doesn't set status code for ads.txt #14169

Closed
hastinbe opened this issue Dec 4, 2019 · 2 comments · Fixed by #14174
Closed

Ads doesn't set status code for ads.txt #14169

hastinbe opened this issue Dec 4, 2019 · 2 comments · Fixed by #14174
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Feature] WordAds [Pri] Normal [Type] Bug When a feature is broken and / or not performing as intended
Milestone

Comments

@hastinbe
Copy link

hastinbe commented Dec 4, 2019

Steps to reproduce the issue

  1. Enable Ads under Traffic
  2. Request domain.com/ads.txt
  3. Content for the ads.txt is returned but the status code is 404

What I expected

The ads.txt data and an HTTP 200 status code.

What happened instead

The ads.txt data was returned in the response body but the HTTP status code is 404, which was set by the web server because a physical ads.txt did not exist.

The response will be ignored and the file will be considered non-existent by Google's crawler if the response code is not a 200.

@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] WordAds [Pri] Normal [Type] Bug When a feature is broken and / or not performing as intended and removed [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Dec 4, 2019
@kraftbj kraftbj added this to the 8.1 milestone Dec 4, 2019
jeherve pushed a commit that referenced this issue Dec 5, 2019
Under some configurations, the web server will set a status code of 404 for requests to domain.com/ads.txt since the physical file cannot be present for WordAds to return an automatically generated ads.txt. When the generated response is sent, no response code was set so the previous 404 is used. This will cause crawlers such as Google's to ignore the response and the file will be considered non-existent.

Fixes #14169
@htdat
Copy link
Member

htdat commented Dec 6, 2019

Just for ref, I've noticed two users with this issue:

2515605-zen - ads do not display
2541726-zen - ads earning got affected

Internal discussion: p1575611498410900-slack-jetpack-crew

@matticbot matticbot added the Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". label Dec 6, 2019
@htdat
Copy link
Member

htdat commented Dec 6, 2019

I've updated two tickets above and asked them to use this snippet (created by @zinigor).

When JP 8.1 is released, this snippet should be removed.

Note: we recommend following this guide to add snippets https://jetpack.com/support/adding-code-snippets/

function jetpack_filter_ads_txt_status_header( $string, $code, $description, $protocol ) {

	// Only running on URLs that end on /ads.txt
	if (
		! isset( $_SERVER )
		|| ! isset( $_SERVER['REQUEST_URI'] )
		|| false === strpos( '/ads.txt', $_SERVER['REQUEST_URI'], -8 )
	) {
		return $string;
	}
	return sprintf( "%s 200 OK", $protocol );
}
add_filter( 'status_header', 'jetpack_filter_ads_txt_status_header', 10, 4 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Feature] WordAds [Pri] Normal [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants