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

Invalid handling of non-root home url #199

Closed
FlyingDR opened this issue Apr 12, 2024 · 1 comment
Closed

Invalid handling of non-root home url #199

FlyingDR opened this issue Apr 12, 2024 · 1 comment

Comments

@FlyingDR
Copy link

At this moment plugin incorrectly handles domain name extraction in case a non-root path is used as a home. \Plausible\Analytics\WP\Helpers::get_domain() for some reason tries to use a regular expression instead of using the standard parse_url() function:

return preg_replace( '/^http(s?)\:\/\/(www\.)?/i', '', $url );

Regular expression completely ignores the fact that there may be something after the domain name itself, effectively generating the wrong result. The most common scenario is use of the multilanguage plugins like WPML, see #160 for examples.

Since Plausible analytics strictly expects hostname for the domain name it is currently not possible to use Plausible analytics for multilingual sites. Any registration attempt results in "Oops! The API token you used is invalid" notification and attempt to use "create an API token" link causes issue because it takes invalid URL for Plausible because the value for domain is taken from the form.

Correct implementation would be:

return preg_replace('/^www\./i', '', parse_url($url, PHP_URL_HOST));
@Dan0sz
Copy link
Collaborator

Dan0sz commented Jun 6, 2024

Thanks for your thorough report!

I've investigated the issue, and the actual issue was that the API client would always use the hosted domain stored in the DB, resulting in the API token invalid error message. In this commit any submitted options in POST are grabbed when get_settings() is called.

Also, Plausible has supported domain names with a subdirectory structure (i.e. multilingual sites) for a while now. So parsing just the hostname is no longer needed.

@Dan0sz Dan0sz closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants