wordpress icon indicating copy to clipboard operation
wordpress copied to clipboard

Cannot set "domain name" when using self-hosted mode

Open deltamualpha opened this issue 1 year ago • 12 comments

Newly-installed plugin, latest version of both it and wordpress. Activated "self-hosted" mode, and see this being injected into the header:

<script defer data-domain='' data-api='https://<snip>/api/event' src="https://<snip>/js/plausible.outbound-links.js?ver=2.0.0" id="plausible"></script>

Tracing through the code, it looks like it's supposed to be filling in the data-domain from the plugin settings -- but those settings can only be updated if using the cloud, hosted version of Plausible.

deltamualpha avatar Feb 07 '24 01:02 deltamualpha

Looks like a workaround is to:

  1. delete the self-hosted domain from the settings and save.
  2. add the hostname and an arbitrary random string as the "API key" and save.
  3. go back and re-add the self-hosted domain to settings and save.

Embedded analytic dashboard also isn't working, but not sure why that is yet.

Edit: this workaround no longer works as of the 2.0.5 release, which attempts to validate the API key to Plausible's servers on save.

deltamualpha avatar Feb 07 '24 01:02 deltamualpha

I can confirm this is a bug, which'll be fixed in 2.0.3, which is about to be released in 3... 2... 1...

Embedded analytic dashboard also isn't working, but not sure why that is yet.

Same for this one, will be released in 2.0.3.

Dan0sz avatar Feb 07 '24 11:02 Dan0sz

Still does not work with version 2.0.7. The data-domain attribute is not added to the <script> tag unless you provide a valid access token for the plausible hosted setting. Any random access token will not be accepted, as it's directly checked for validity.

devidevio avatar Feb 26 '24 19:02 devidevio

Hmm, you're right. The API validation blocks saving the domain_name. I just created a fix for this. You can get the prerelease here.

Dan0sz avatar Feb 26 '24 21:02 Dan0sz

I have the same issue, and I tried this prerelease, and it didn't work. I've downgraded to 1.3.6, which works well with my self-hosted setup (the backend is on the new Plausible Community Edition).

tenfourty avatar Feb 27 '24 11:02 tenfourty

Does not work on the pre-release as @tenfourty mentioned, I'm still on the latest v1.3.x where everything works fine for me.

devidevio avatar Feb 27 '24 18:02 devidevio

@Unkn0wn0x and @tenfourty, does the Domain Name option under the Self-Hosted tab contain a value in your configuration? Because that's how the plugin (the prerelease) checks if a self-hosted setup is being used, and if so, it doesn't attempt to validate the API token.

Dan0sz avatar Feb 27 '24 20:02 Dan0sz

Yes, I have a value in the field, and I'm getting the error, AND I can't enter an API key.

If I remove the self-hosted info, I can enter an API key.

I don't know if this is related or if I should raise it as a separate issue, but the link to create an API key is hard-coded to plausible.io and doesn't consider the self-hosted URL.

tenfourty avatar Feb 28 '24 13:02 tenfourty

This is still an issue in 2.0.8, should we re-open this issue or would you like me to open another one?

I have a domain set on the "Settings" tab (and no API token). And I have the plausible domain set in the "Self-Hosted" tab. And still the data-domain comes up empty. This happens to me on two separate WordPress blogs.

ccoenen avatar Apr 11 '24 14:04 ccoenen

investigating further, I can pinpoint the problem down to this

https://github.com/plausible/wordpress/blob/18bc986f75baffe97fdf7868afce7193b0ef056e/src/Filters.php#L49

I added some echos for simple debugging here, and $domain_name just comes up empty for me.

grafik

grafik

if $domain_name worked, the first comment in the screenshot above would also contain something. But only the helper works correctly.

ccoenen avatar Apr 11 '24 15:04 ccoenen

a var_dump in the same place also confirms that $settings['domain_name'] contains an empty string. Please don't ask me why the get_settings() does not work here when get_domain() (which also calls get_settings() internally) works. This is not my code. I only point out what works and what doesn't.

ccoenen avatar Apr 11 '24 15:04 ccoenen

Replacing

https://github.com/plausible/wordpress/blob/18bc986f75baffe97fdf7868afce7193b0ef056e/src/Filters.php#L49

-		$domain_name = esc_html( $settings[ 'domain_name' ] ); 
+		$domain_name = esc_html( Helpers::get_domain() );

works fine for me and actually solves the problem.

ccoenen avatar Apr 11 '24 15:04 ccoenen

@ccoenen and @deltamualpha, can you confirm if you're still experiencing this issue in v2.0.9? This release contains several improvements on the self-hosters (Plausible CE) side.

Dan0sz avatar May 22 '24 12:05 Dan0sz

I just installed the latest version v2.0.9 and encountered the same issue.

robogao-net avatar May 27 '24 10:05 robogao-net

yes, 2.0.9 still has the data-domain="" attribute empty.

empty data-domain attribute

This then leads to this request failing with the error message that the data-domain needs to be filled.

failing outbound links

I should say "again" has it empty, because this update nuked my fix that I had applied manually.

ccoenen avatar May 27 '24 15:05 ccoenen

my fix from https://github.com/plausible/wordpress/issues/177#issuecomment-2049981781 still works. I just applied it and now it works fine again. It now needs to go in line 53:

https://github.com/plausible/wordpress/blob/f687aace2351fc3b849304741184b17ba4e4c7af/src/Filters.php#L53

-		$domain_name = esc_html( $settings[ 'domain_name' ] ); 
+		$domain_name = esc_html( Helpers::get_domain() );

This way, the data-domain attribute is filled correctly.

grafik

And that way, this request no longer fails with an HTTP 400 error.

grafik

And that way, I can get analytics on my self hosted plausible coming from my self hosted wordpress.

line goes up

ccoenen avatar May 27 '24 15:05 ccoenen

I investigated your fix @ccoenen and I think the reason why Helpers::get_domain() works in your case, is because if the domain_name option turns up as empty (for whatever reason) the Helpers function falls back to a regex to "guess" the domain name.

In short, implementing your fix will only work after handling #199.

Dan0sz avatar May 30 '24 17:05 Dan0sz

We can confirm this issue. And just saying while interfering the domain name is great, there could be reasons to set a domain name in plausible that differes from the actual domain. Being able to optionally set a domain name would be preferable

JoAllg avatar Jun 05 '24 07:06 JoAllg

@ccoenen I've applied your fix in this commit. So, it'll be included in v2.1.0.

Dan0sz avatar Jun 06 '24 06:06 Dan0sz

thanks :-)

ccoenen avatar Jun 06 '24 07:06 ccoenen

Howdy, I'm late to the party. Just posting for visiblity.

I wanted to confirm that installing 2.1.0-beta4 of the plugin resolved this for me.

echoblag avatar Jul 01 '24 09:07 echoblag

Thanks for confirming. Closing this.

Dan0sz avatar Jul 01 '24 20:07 Dan0sz

Can confirm that this issue did not come up for me again. Thank you to everyone involved :-)

ccoenen avatar Aug 28 '24 08:08 ccoenen