Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Handle no snippet WordPress case (#4152)

hq1d9cf037866d3
diff --git a/lib/plausible/verification/diagnostics.ex b/lib/plausible/verification/diagnostics.ex
index dc5477af40..c4d8b5f212 100644
--- a/lib/plausible/verification/diagnostics.ex
+++ b/lib/plausible/verification/diagnostics.ex
@@ -78,6 +78,20 @@ defmodule Plausible.Verification.Diagnostics do
error(@errors.no_snippet)
end
+ def interpret(
+ %__MODULE__{
+ plausible_installed?: false,
+ snippets_found_in_head: 0,
+ snippets_found_in_body: 0,
+ body_fetched?: true,
+ service_error: nil,
+ wordpress_likely?: true
+ },
+ _url
+ ) do
+ error(@errors.no_snippet_wp)
+ end
+
def interpret(
%__MODULE__{
plausible_installed?: false,
diff --git a/lib/plausible/verification/errors.ex b/lib/plausible/verification/errors.ex
index 6ab8a6741b..0097d0f3bc 100644
--- a/lib/plausible/verification/errors.ex
+++ b/lib/plausible/verification/errors.ex
@@ -28,6 +28,12 @@ defmodule Plausible.Verification.Errors do
recommendation: "Please insert the snippet into your site",
url: "https://plausible.io/docs/plausible-script"
},
+ no_snippet_wp: %{
+ message: "We couldn't find the Plausible snippet on your site",
+ recommendation:
+ "Please install and activate our WordPress plugin to start counting your visitors",
+ url: "https://plausible.io/wordpress-analytics-plugin"
+ },
temporary: %{
message: "We encountered a temporary problem verifying your website",
recommendation: "Please try again in a few minutes or manually check your integration",
diff --git a/test/plausible/site/verification/checks_test.exs b/test/plausible/site/verification/checks_test.exs
index 014395289b..2d44a13659 100644
--- a/test/plausible/site/verification/checks_test.exs
+++ b/test/plausible/site/verification/checks_test.exs
@@ -299,6 +299,26 @@ defmodule Plausible.Verification.ChecksTest do
|> assert_error(@errors.no_snippet)
end
+ @body_no_snippet_wp """
+ <html>
+ <head>
+ <meta name="foo" content="/wp-content/plugins/bar"/>
+ </head>
+ <body>
+ Hello
+ </body>
+ </html>
+ """
+
+ test "detecting no snippet on a wordpress site" do
+ stub_fetch_body(200, @body_no_snippet_wp)
+ stub_installation(200, plausible_installed(false))
+
+ run_checks()
+ |> Checks.interpret_diagnostics()
+ |> assert_error(@errors.no_snippet_wp)
+ end
+
test "a check that raises" do
defmodule FaultyCheckRaise do
use Plausible.Verification.Check