Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 1 addition & 5 deletions lib/plausible_web/live/installationv2/instructions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ defmodule PlausibleWeb.Live.InstallationV2.Instructions do
end

defp tracker_url(tracker_script_configuration) do
if String.starts_with?(tracker_script_configuration.id, "pa-") do
"https://plausible.io/js/#{tracker_script_configuration.id}.js"
else
"https://plausible.io/js/s-#{tracker_script_configuration.id}.js"
end
"https://plausible.io/js/#{tracker_script_configuration.id}.js"
end
end
17 changes: 1 addition & 16 deletions lib/plausible_web/plugs/tracker_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ defmodule PlausibleWeb.TrackerPlug do

def call(conn, files_available: files_available) do
case conn.request_path do
"/js/s-" <> path ->
if String.ends_with?(path, ".js") do
id = String.replace_trailing(path, ".js", "")
request_tracker_script(id, conn)
else
conn
end

"/js/pa-" <> path ->
if String.ends_with?(path, ".js") do
id = String.replace_trailing(path, ".js", "")
Expand All @@ -69,7 +61,6 @@ defmodule PlausibleWeb.TrackerPlug do

def telemetry_event(name), do: [:plausible, :tracker_script, :request, name]

# at this point, id might be both with and without the `pa-` prefix
defp request_tracker_script(id, conn) do
case get_plausible_web_script(id) do
{:ok, script_tag} ->
Expand Down Expand Up @@ -104,7 +95,6 @@ defmodule PlausibleWeb.TrackerPlug do
end
end

# at this point, id can be both with and without the `pa-` prefix
defp get_plausible_web_script(id) do
script =
on_ee do
Expand All @@ -118,12 +108,7 @@ defmodule PlausibleWeb.TrackerPlug do
if script do
{:ok, script}
else
if not String.starts_with?(id, "pa-") do
# maybe the script been migrated to the new format already
get_plausible_web_script("pa-" <> id)
else
{:error, :not_found}
end
{:error, :not_found}
end
end

Expand Down
29 changes: 1 addition & 28 deletions test/plausible_web/plugs/tracker_plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,9 @@ defmodule PlausibleWeb.TrackerPlugTest do
assert String.contains?(response, "window.plausible")
end

test "returns the script requested with the legacy s- prefix, even if the id has been prefixed with pa- in the database",
%{conn: conn} do
site = new_site()

tracker_script_configuration =
Tracker.update_script_configuration!(
site,
Map.put(@example_config, :site_id, site.id),
:installation
)

assert String.starts_with?(tracker_script_configuration.id, "pa-")

response =
get(
conn,
"/js/s-#{String.replace_leading(tracker_script_configuration.id, "pa-", "")}.js"
)
|> response(200)

assert String.contains?(response, "!function(){var")
assert String.contains?(response, "domain:\"#{site.domain}\"")
assert String.contains?(response, "formSubmissions:!0")
refute String.contains?(response, "outboundLinks:!0")
refute String.contains?(response, "fileDownloads:!0")
end

test "returns 404 for unknown site", %{conn: conn} do
conn
|> get("/js/s-a14125a2-000-000-0000-000000000000.js")
|> get("/js/pa-a14125a2-000-000-0000-000000000000.js")
|> response(404)
end
end
Expand Down
Loading