site-kit-wp: Error: Invalid site state null

Bug Description

One user is Multiple users are encountering a “Error: Invalid site state null” message when trying to connect the AdSense module. It occurs before OAuth, and without any browser console errors.

The initial user shared a recording of their experience within their support topic. This can be viewed here.

There is a page loader evident on their site, which may be contributing to checking their site. There may also be issues with the PHP version (8.1.10) which remains in Beta support for their version of WP, although during internal testing I wasn’t able to recreate this issue with PHP 8.1 and 2 subdomain sites.

Note also that this can occur when an AdSense account and site are approved, as evident from other reports (see below impacted users). This doesn’t stop ads from appearing, or stop Site Kit from placing the AdSense snippet.

One impacted user encounters this error on one subdomain site but not another.

Based on the above user, who encounters this on one site, it looks like the response from the site check displays differently. Subdomain site where this doesn’t occur:

adsense_account_status: ready
adsense_site_status: ready
adsense_use_snippet: yes

Subdomain site where this does occur:

adsense_account_status: ready
adsense_site_status: none
adsense_use_snippet: yes

Steps to reproduce

Unable to recreate so far. Internal testing with various scenarios performed here.

Screenshots

image

Additional Context

  • Original report
  • PHP Version: 8.1.10 (Awaiting a user check with 7.4)
  • Site Kit 1.83.0
  • The users AdSense account status is “ready”
  • No issues connecting the other modules
  • Nothing output in their SH status
  • SH info provided

Insights & Troubleshooting Checks performed

  • Health Check & Troubleshooting plugin check - The same occurs with only SK active
  • Front end check (mixed content, minified content, combined JS) - Nothing obvious, REST endpoints accessible
  • No CND used
  • Incognito mode - The same occurs
  • Checked users Site Health info, no identified causes
  • Additional .htaccess rules applied - Yes, additional rules applies
  • Confirmed no modification of Site Kit placed snippet
  • Uninstalled and reinstalled plugin
  • User confirmed no ““Critical errors”” in their Site Health status
  • Attempted setup/viewing dashboards from another device
  • Temporary disabled WAF rules at host level - including ModSecurity
  • Checked site setup and dashboard from another WordPress site on the same hosting platform
  • Reset Site Kit (on the SK service)
  • Disconnected Site Kit
  • Disconnected impacted service and connected once more - The same occurs
  • Reviewed error logs
  • Reviewed XHR requests
  • PHP 8.1 check - can’t replicate. AdSense completes set up fine.

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

Acceptance criteria

  • The AdSense module’s internal matching of an AdSense Site by domain should be updated as follows:
    • Only sites with a non-empty state should ever be matched
    • An exact match should always be attempted first
    • Matching a sub-domain to its parent domain site, should be enhanced to avoid false positive matches

Implementation Brief

Test Coverage

  • Update tests to cover new criteria

QA Brief

  • This is a very specific scenario which is no longer possible to create on AdSense, so it requires an existing account with a list of sites that include a subdomain site where the subdomain is alphabetically sorted before the parent domain.
    • Alternatively, this can be consistently reproduced using development tools to control the API response (ask @aaemnnosttv)

Changelog entry

  • Fix a bug that could prevent AdSense from being set up on a subdomain.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 22

Most upvoted comments

QA Update: ✅

Verified:

  • As mentioned above, have gone through and completed my testing around setting up AdSense with all the different scenarios around account and site statuses. All looks good.
  • Evan went through how the issue is generated and saw the error message on screen. Then changed the branch to main to confirm that the code change has fixed the error message for subdomains.

QA Update: ⚠️

@aaemnnosttv I have gone through and completed my testing around setting up AdSense with all the different scenarios around account and site statuses. All looks good.

I have added a meeting in our calendars for tomorrow to go through the more complex, sub-domain testing.

While testing more, I noticed an additional condition for this error to happen which makes it a bit more specific to the site (and hence has been more difficult to reproduce). It only seems to happen when the subdomain is alphabetically “earlier” than the top level domain.

That is, if site example.com and www.example.com are in the list, example.com will still be used as the site. But if the subdomain is blog.example.com then this is the site that would be matched. Again, this requires the subdomain site to exist in AdSense to the above still applies but is a specific nuance that is also confirmed in James’ latest report above https://github.com/google/site-kit-wp/issues/5852#issuecomment-1570076213

Thanks @jamesozzie! Agreed that this is okay to close. I’ll close out as not planned but do let us know if you see this come up again.

@jamesozzie I chatted with Evan about this one today and he thinks that this could be occurring because there’s a response coming back from the AdSense API that Site Kit does not expect. If that’s the case, we can make an update on our side to accommodate for it, but we need to know what has changed.

As with #6036, can you follow up with our AdSense contacts on this one? I’ll keep this open for now for possible next steps.

Another user in the support forums, previously impacted, was able to proceed without the error appearing, by following the steps which @adamdunnage suggested above.

Edit: Another user confirmed the same. Removing the site from AdSense and disconnecting the AdSense module, before connecting once more allowed them to proceed, with the error no longer occurring.

Hello Adam, I tried the above workaround and it works like a charm. Thanks.

I was unable to recreate this error based on the above which means I am unable to test the steps taken by the user that fixed this. I attempted this with both an existing subdomain and a newly created one. I also tried with AdSense in the ‘getting ready’ state and also once approved and connected.

@oussjarrousse Thanks so much for the detailed comment you’ve added here and all the information it’s very welcome. If you could continue to provide answers and information via your support forum topic that would be great and we will happily add anything further to this issue that is relevant.