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

Ensure compatibility with Google Site Kit #934

Closed
adamsilverstein opened this issue Jan 5, 2021 · 7 comments
Closed

Ensure compatibility with Google Site Kit #934

adamsilverstein opened this issue Jan 5, 2021 · 7 comments
Labels
enhancement New feature or request plugin: others Concerns integration with other plugins

Comments

@adamsilverstein
Copy link

Hi! Adam here from the Google Site Kit team (https://sitekit.withgoogle.com).

We recently had some users reporting issues when they were using qtranslate-xt and Site Kit at the same time (WordPress support forum).

The underlying issue is that Site Kit identifies site's by their URL, as returned by WordPress's home_url function. When we detect that a site's URL has changed, we prompt (/force) the user to reconnect their site (going thru the auth process again). We do this to help users when they change their site URL for any reason (because otherwise, their connection is broken).

As a consequence, when plugins filter the home_url this logic can cause issues as the user gets unexpectedly disconnected. qtranslate-xt does this in qtranxf_home_url.

To improve compatibility in these types of situations, in Site Kit we added a googlesitekit_canonical_home_url filter (in google/site-kit-wp#2131). Site Kit uses the URL returned from this filter as our canonical URL, and as long as this URL doesn't change users will remain connected.

Using this filter, qtranslate-xt could add compatibility with Site Kit by returning the root site url of the site.

Pseudo code:

add_filter(
	'googlesitekit_canonical_home_url',
	function( $url ) {
		return get_option( 'home' ); // return root url (could use this or qtranslate stored option)
	}
);

I would be happy to open a PR with this change. Is this something you would consider adding to your plugin?

@herrvigg
Copy link
Collaborator

herrvigg commented Jan 6, 2021

hello,
thank you very much for getting in touch here! This is a very small change, i can integrate it directly without PR.
If i understand it right, the problem came from the fact you would get different home values depending on the current language. But that's a bit surprising, this value should not change, unless you change language (how is the query done?) or you change the value of the home.
We can add this hook to avoid any problem but i will comment on the original ticket.

@herrvigg
Copy link
Collaborator

herrvigg commented Jan 6, 2021

This was the reason:

I go to the mainpage, change the language and back to the admin panel where I get the message once more that I have been disconnected and that I have to reconnect it.

That makes sense, if the admin language is changed, the home value will also change. By adding the filter we should avoid that switch specifically for google sitekit. Sounds fine! Would be good if the user can validate it.

@herrvigg herrvigg added enhancement New feature or request plugin: others Concerns integration with other plugins labels Jan 6, 2021
@adamsilverstein
Copy link
Author

@herrvigg Thank you for reviewing this. I will ask the user to test out the fix I am suggesting here.

I was also able to reproduce the issue locally and verify the fix by setting up both plugins, then using the customizer I believe. At some point we get an admin side request with a "home_url" that includes a language folder, eg https://mysite.com/en. Site Kit gets disconnected at this point.

One thing I wasn't certain about here: does the plugin store a site's home/canonical URL - if so I would use this vs. get_option( 'home' ).

@herrvigg
Copy link
Collaborator

herrvigg commented Jan 6, 2021

With qTranslate, we don't change the stored value of the home site, but we change it dynamically through the home_url hook in WP to add the language as a suffix (this is for a standard config - there are other modes).

About the canonical URL, we have a base homesite that we may consider "canonical", but the translated content should contain a reference to the language. For a translated page or post, the canonical URL should have the full path including the language to be properly indexed in SEO, for example:

https://mysite.com/en/my-article
https://mysite.com/de/my-article
https://mysite.com/fr/my-article

When you wrote that you got a admin side request causing the disconnect, was it without your patch just to reproduce the issue? Did it work with the patch?

@adamsilverstein
Copy link
Author

When you wrote that you got a admin side request causing the disconnect, was it without your patch just to reproduce the issue? Did it work with the patch?

It was without the patch. With the patch, everything works fine and I am no longer disconnected.

herrvigg added a commit that referenced this issue Jan 10, 2021
@herrvigg
Copy link
Collaborator

A better integrated fix has been pushed to master. New release to come soon.

@herrvigg
Copy link
Collaborator

Support of Google Site Kit released in 3.9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request plugin: others Concerns integration with other plugins
Projects
None yet
Development

No branches or pull requests

2 participants