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

Snippet integration verification #4106

Merged
merged 39 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
381b857
Allow running browserless.io locally
aerosol May 21, 2024
b93f8b1
Compile tailwind classes based on extra/ too
aerosol May 21, 2024
4925ba6
Add browserless runtime configuration
aerosol May 21, 2024
d5228d3
Ignore verification events on ingestion
aerosol May 21, 2024
1f9b2b8
Improve extracting HTML text in tests
aerosol May 21, 2024
c7ec955
Update dependencies
aerosol May 21, 2024
674da60
Add shuttle SVG to generic components
aerosol May 21, 2024
a7da19c
Connect live socket & allow skipping awaiting the first pageview
aerosol May 21, 2024
c76e0a3
Connect live socket in general settings
aerosol May 21, 2024
93bb83b
Implement verification checks & diagnostics
aerosol May 21, 2024
3821c3b
Stub remote services with Req for testing
aerosol May 21, 2024
f81d39b
Change snippet screen copy
aerosol May 21, 2024
7d63c01
Update tracker script, so that:
aerosol May 21, 2024
c88a6e8
Implement LiveView verification UI
aerosol May 21, 2024
f37eb63
Embed the verification UIs into settings and onboarding
aerosol May 21, 2024
95a2315
Implement browserless puppeteer verification script
aerosol May 21, 2024
01490ff
Improve diagnostics for CSP
aerosol May 21, 2024
2bd9d1a
Put verification behind a feature flag/env setting
aerosol May 21, 2024
1ca2aba
Contact Us hint only for Enterprise Edition
aerosol May 21, 2024
24b6b1a
For headless code, use JS context instead of EEx interpolation
aerosol May 21, 2024
e11aa7e
Update diagnostics test with WordPress scenarios
aerosol May 21, 2024
c8e1f77
Shorten exception/throw interception
aerosol May 22, 2024
c7e7080
Rename test
aerosol May 22, 2024
4b383f0
Tidy up
aerosol May 22, 2024
3e73acd
Bust URL always on headless check
aerosol May 22, 2024
f43a063
Update moduledoc
aerosol May 22, 2024
514197e
Detect official Plausible WordPress Plugin
aerosol May 23, 2024
4cbcbd2
Stop using 'rating' in favour of 'interpretation'
aerosol May 23, 2024
a2181a4
Only report CSP error if no proxy is likely
aerosol May 23, 2024
9aa48b9
Merge branch 'master' into browserless-stack
aerosol May 23, 2024
ebbda85
Merge branch 'master' into browserless-stack
aerosol May 23, 2024
f352b93
Update CHANGELOG
aerosol May 23, 2024
b28e359
Allow event-* attributes on snippet elements
aerosol May 23, 2024
f086eef
Improve naive GTM detection, not to confuse it with GA4
aerosol May 23, 2024
6996cee
Update lib/plausible/verification.ex
aerosol May 23, 2024
1ff8c16
Update test/plausible/site/verification/checks_test.exs
aerosol May 23, 2024
25c7bd4
s/perform_wrapped/perform_safe
aerosol May 23, 2024
2a31773
Update lib/plausible/verification/checks/installation.ex
aerosol May 23, 2024
d91e3a6
Remove garbage
aerosol May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/plausible/verification/checks/snippet_cache_bust.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule Plausible.Verification.Checks.SnippetCacheBust do

state2 =
%{state | url: busted_url}
|> Plausible.Verification.Checks.ScanBody.perform()
aerosol marked this conversation as resolved.
Show resolved Hide resolved
|> Plausible.Verification.Checks.FetchBody.perform()
|> Plausible.Verification.Checks.Snippet.perform()

Expand Down
3 changes: 0 additions & 3 deletions lib/plausible/verification/diagnostics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ defmodule Plausible.Verification.Diagnostics do
when count_head + count_body > 1 do
%Rating{
ok?: false,
# FIXME
errors: ["We've found multiple Plausible snippets on your site."],
recommendations: [
{"Please ensure that only one snippet is used",
Expand Down Expand Up @@ -260,7 +259,6 @@ defmodule Plausible.Verification.Diagnostics do
def rate(%__MODULE__{snippets_found_in_head: 0, snippets_found_in_body: n}, _url) when n >= 1 do
%Rating{
ok?: false,
# FIXME
errors: ["Plausible snippet is placed in the body of your site"],
recommendations: [
{"Please relocate the snippet to the header of your site",
Expand All @@ -272,7 +270,6 @@ defmodule Plausible.Verification.Diagnostics do
def rate(%__MODULE__{data_domain_mismatch?: true}, url) do
%Rating{
ok?: false,
# FIXME
errors: ["Your data-domain is different than #{url}"],
recommendations: [
{"Please ensure that the site in the data-domain attribute is an exact match to the site as you added it to your Plausible account",
Expand Down
134 changes: 132 additions & 2 deletions test/plausible/site/verification/diagnostics_tests.exs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,55 @@ defmodule Plausible.Verification.DiagnosticsTest do
]
end

@normal_body_wordpress """
<html>
<head>
<meta name="foo" content="/wp-content/plugins/bar"/>
<script defer data-domain="example.com" src="http://localhost:8000/js/script.js"></script>
</head>
<body>Hello</body>
</html>
"""

test "detecting snippet after busting WordPress cache" do
stub_fetch_body(fn conn ->
conn = fetch_query_params(conn)

if conn.query_params["plausible_verification"] do
conn
|> put_resp_content_type("text/html")
|> send_resp(200, @normal_body_wordpress)
else
conn
|> put_resp_content_type("text/html")
|> send_resp(200, @body_no_snippet)
end
end)

stub_installation(fn conn ->
{:ok, body, _} = read_body(conn)

if String.contains?(body, "?plausible_verification") do
conn
|> put_resp_content_type("application/json")
|> send_resp(200, Jason.encode!(plausible_installed()))
else
raise "Should not get here even"
end
end)

result = run_checks()

rating = Checks.interpret_diagnostics(result)
refute rating.ok?
assert rating.errors == ["We encountered an issue with your site cache"]

assert rating.recommendations == [
{"Please clear your cache (or wait for your provider to clear it) to ensure that the latest version of your site is being displayed to all your visitors",
"https://plausible.io/docs/troubleshoot-integration"}
]
end

test "detecting no snippet" do
stub_fetch_body(200, @body_no_snippet)
stub_installation(200, plausible_installed(false))
Expand Down Expand Up @@ -500,6 +549,33 @@ defmodule Plausible.Verification.DiagnosticsTest do
]
end

@proxied_script_body_wordpress """
<html>
<head>
<meta name="foo" content="/wp-content/plugins/bar"/>
<script defer data-domain="example.com" src="https://proxy.example.com/js/script.js"></script>
</head>
<body>Hello</body>
</html>
"""

test "proxied WordPress setup, function undefined, callback won't fire" do
stub_fetch_body(200, @proxied_script_body_wordpress)
stub_installation(200, plausible_installed(false, 0))

result = run_checks()
rating = Checks.interpret_diagnostics(result)

refute rating.ok?
assert rating.errors == ["We encountered an error with your Plausible proxy"]

assert rating.recommendations ==
[
{"Please re-enable the proxy in our WordPress plugin to start counting your visitors",
"https://plausible.io/wordpress-analytics-plugin"}
]
end

test "proxied setup, function undefined, callback won't fire" do
stub_fetch_body(200, @proxied_script_body)
stub_installation(200, plausible_installed(false, 0))
Expand All @@ -522,16 +598,70 @@ defmodule Plausible.Verification.DiagnosticsTest do
stub_installation(200, plausible_installed(true, 0))

result = run_checks()

rating = Checks.interpret_diagnostics(result)

refute rating.ok?
assert ["Your Plausible integration is not working"]
assert rating.errors == ["Your Plausible integration is not working"]

assert rating.recommendations == [
{"Please manually check your integration to make sure that the Plausible snippet has been inserted correctly",
"https://plausible.io/docs/troubleshoot-integration"}
]
end

@body_unknown_attributes """
<html>
<head>
<script foo="bar" defer data-domain="example.com" src="http://localhost:8000/js/script.js"></script>
</head>
<body>Hello</body>
</html>
"""

test "unknown attributes" do
stub_fetch_body(200, @body_unknown_attributes)
stub_installation(200, plausible_installed(false, 0))

result = run_checks()
rating = Checks.interpret_diagnostics(result)

refute rating.ok?
assert rating.errors == ["Something seems to have altered our snippet"]

assert rating.recommendations == [
{"Please manually check your integration to make sure that nothing prevents our script from working",
"https://plausible.io/docs/troubleshoot-integration"}
]
end

@body_unknown_attributes_wordpress """
<html>
<head>
<meta name="foo" content="/wp-content/plugins/bar"/>
<script foo="bar" defer data-domain="example.com" src="http://localhost:8000/js/script.js"></script>
</head>
<body>Hello</body>
</html>
"""

test "unknown attributes for WordPress installation" do
stub_fetch_body(200, @body_unknown_attributes_wordpress)
stub_installation(200, plausible_installed(false, 0))

result = run_checks()
rating = Checks.interpret_diagnostics(result)

refute rating.ok?

assert rating.errors == [
"A performance optimization plugin seems to have altered our snippet"
]

assert rating.recommendations == [
{"Please install and activate our WordPress plugin to avoid the most common plugin conflicts",
"https://plausible.io/wordpress-analytics-plugin "}
]
end
end

defp run_checks(extra_opts \\ []) do
Expand Down