Skip to content

Commit f7acb06

Browse files
authored
Script v2: Change priority of CSP related error for verifying manual installations (#5707)
* Add logic to find Plausible script tag * Clarify where cookies fixtures come from * Add case for snippet not found * Fix issue with installation type not propagating to diagnostics * Better struct definition * Refactor verification tests to be more comprehensive * Fix compile error related to Test.Support.DNS * Fix DNS imports for CE * Refactor when tracker is in HTML is detected
1 parent 8d6d828 commit f7acb06

16 files changed

Lines changed: 3164 additions & 1119 deletions

File tree

config/test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ config :plausible, Plausible.InstallationSupport.Checks.Detection,
5757
plug: {Req.Test, :global}
5858
]
5959

60+
config :plausible, Plausible.InstallationSupport.Checks.InstallationV2,
61+
req_opts: [
62+
plug: {Req.Test, Plausible.InstallationSupport.Checks.InstallationV2}
63+
]
64+
6065
config :plausible, Plausible.Session.Salts, interval: :timer.hours(1)

lib/plausible/installation_support/checks/installation_v2.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ defmodule Plausible.InstallationSupport.Checks.InstallationV2 do
160160
defp parse_to_diagnostics(data),
161161
do: [
162162
disallowed_by_csp: data["disallowedByCsp"],
163+
tracker_is_in_html: data["trackerIsInHtml"],
163164
plausible_is_on_window: data["plausibleIsOnWindow"],
164165
plausible_is_initialized: data["plausibleIsInitialized"],
165166
plausible_version: data["plausibleVersion"],

lib/plausible/installation_support/verification/diagnostics.ex

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ defmodule Plausible.InstallationSupport.Verification.Diagnostics do
44
"""
55
require Logger
66

7-
# in this struct, nil means indeterminate
8-
defstruct selected_installation_type: nil,
9-
disallowed_by_csp: nil,
10-
plausible_is_on_window: nil,
11-
plausible_is_initialized: nil,
12-
plausible_version: nil,
13-
plausible_variant: nil,
14-
diagnostics_are_from_cache_bust: nil,
15-
test_event: nil,
16-
cookies_consent_result: nil,
17-
response_status: nil,
18-
service_error: nil,
19-
attempts: nil
7+
# In this struct
8+
# - the default nil value for each field means that the value is indeterminate (e.g. we didn't even get to the part where response_status is set)
9+
defstruct [
10+
:selected_installation_type,
11+
:disallowed_by_csp,
12+
:tracker_is_in_html,
13+
:plausible_is_on_window,
14+
:plausible_is_initialized,
15+
:plausible_version,
16+
:plausible_variant,
17+
:diagnostics_are_from_cache_bust,
18+
:test_event,
19+
:cookies_consent_result,
20+
:response_status,
21+
:service_error,
22+
:attempts
23+
]
2024

2125
@type t :: %__MODULE__{}
2226

@@ -150,6 +154,21 @@ defmodule Plausible.InstallationSupport.Verification.Diagnostics do
150154
end
151155
end
152156

157+
def interpret(
158+
%__MODULE__{
159+
tracker_is_in_html: false,
160+
selected_installation_type: selected_installation_type,
161+
plausible_is_on_window: plausible_is_on_window,
162+
plausible_is_initialized: plausible_is_initialized,
163+
service_error: nil
164+
},
165+
_expected_domain,
166+
_url
167+
)
168+
when selected_installation_type in ["manual", nil] and plausible_is_on_window != true and
169+
plausible_is_initialized != true,
170+
do: error_plausible_not_found(selected_installation_type)
171+
153172
@error_csp_disallowed Error.new!(%{
154173
message:
155174
"We encountered an issue with your site's Content Security Policy (CSP)",

lib/plausible_web/live/installationv2.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,19 @@ defmodule PlausibleWeb.Live.InstallationV2 do
294294
end
295295

296296
def handle_event("submit", %{"tracker_script_configuration" => params}, socket) do
297-
PlausibleWeb.Tracker.update_script_configuration!(
298-
socket.assigns.site,
299-
params,
300-
:installation
301-
)
297+
config =
298+
PlausibleWeb.Tracker.update_script_configuration!(
299+
socket.assigns.site,
300+
params,
301+
:installation
302+
)
302303

303304
{:noreply,
304305
push_navigate(socket,
305306
to:
306307
Routes.site_path(socket, :verification, socket.assigns.site.domain,
307-
flow: socket.assigns.flow
308+
flow: socket.assigns.flow,
309+
installation_type: config.installation_type
308310
)
309311
)}
310312
end

test/plausible/installation_support/checks_test.exs renamed to test/plausible/installation_support/legacy_verification/checks_test.exs

File renamed without changes.

0 commit comments

Comments
 (0)