Choose the property or view in your Google Analytics account that will be imported to the <%= @site.domain %> dashboard.
diff --git a/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex b/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex
index 6a969b332..0f65b725a 100644
--- a/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex
+++ b/lib/plausible_web/templates/google_analytics/user_metric_form.html.heex
@@ -40,8 +40,7 @@
property_or_view: @property_or_view,
access_token: @access_token,
refresh_token: @refresh_token,
- expires_at: @expires_at,
- legacy: @legacy
+ expires_at: @expires_at
)
}
class="underline text-indigo-600"
@@ -58,8 +57,7 @@
refresh_token: @refresh_token,
expires_at: @expires_at,
start_date: @start_date,
- end_date: @end_date,
- legacy: @legacy
+ end_date: @end_date
),
class: "button sm:w-auto w-full"
) %>
diff --git a/lib/plausible_web/templates/site/settings_google_import.html.heex b/lib/plausible_web/templates/site/settings_google_import.html.heex
deleted file mode 100644
index bb6d2c4d6..000000000
--- a/lib/plausible_web/templates/site/settings_google_import.html.heex
+++ /dev/null
@@ -1,124 +0,0 @@
-
diff --git a/lib/plausible_web/templates/site/settings_imports_exports.html.heex b/lib/plausible_web/templates/site/settings_imports_exports.html.heex
index 439c0d065..983d88ccc 100644
--- a/lib/plausible_web/templates/site/settings_imports_exports.html.heex
+++ b/lib/plausible_web/templates/site/settings_imports_exports.html.heex
@@ -4,7 +4,12 @@
Import Data
- Import existing data from external sources. Pick one of the options below to start a new import.
+ Import existing data from external sources.
+ <%= if FunWithFlags.enabled?(:csv_imports_exports, for: @site) do %>
+ Pick one of the options below to start a new import.
+ <% else %>
+ Click below to start a new import.
+ <% end %>
diff --git a/lib/plausible_web/templates/site/settings_integrations.html.heex b/lib/plausible_web/templates/site/settings_integrations.html.heex
index bc10f7eef..79ac2220e 100644
--- a/lib/plausible_web/templates/site/settings_integrations.html.heex
+++ b/lib/plausible_web/templates/site/settings_integrations.html.heex
@@ -3,14 +3,6 @@
search_console_domains={@search_console_domains}
/>
-<%= if not FunWithFlags.enabled?(:imports_exports, for: @site) do %>
-
NB: You also need to set up your site on
diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.ex
index ca93c07ea..bc4c52d35 100644
--- a/lib/plausible_web/views/layout_view.ex
+++ b/lib/plausible_web/views/layout_view.ex
@@ -49,6 +49,13 @@ defmodule PlausibleWeb.LayoutView do
end
def settings_tabs(conn) do
+ imports_exports_key =
+ if FunWithFlags.enabled?(:csv_imports_exports, for: conn.assigns.site) do
+ "Imports & Exports"
+ else
+ "Imports"
+ end
+
[
%{key: "General", value: "general", icon: :rocket_launch},
%{key: "People", value: "people", icon: :users},
@@ -59,9 +66,7 @@ defmodule PlausibleWeb.LayoutView do
end,
%{key: "Custom Properties", value: "properties", icon: :document_text},
%{key: "Integrations", value: "integrations", icon: :arrow_path_rounded_square},
- if FunWithFlags.enabled?(:imports_exports, for: conn.assigns.site) do
- %{key: "Imports & Exports", value: "imports-exports", icon: :arrows_up_down}
- end,
+ %{key: imports_exports_key, value: "imports-exports", icon: :arrows_up_down},
%{
key: "Shields",
icon: :shield_exclamation,
diff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.ex
index b394dbf4c..a3ae89f77 100644
--- a/lib/plausible_web/views/site_view.ex
+++ b/lib/plausible_web/views/site_view.ex
@@ -2,10 +2,6 @@ defmodule PlausibleWeb.SiteView do
use PlausibleWeb, :view
use Plausible
- alias Plausible.Imported.SiteImport
-
- require Plausible.Imported.SiteImport
-
def plausible_url do
PlausibleWeb.Endpoint.url()
end
diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exs
index 461ccf2e1..c55356b18 100644
--- a/test/plausible_web/controllers/auth_controller_test.exs
+++ b/test/plausible_web/controllers/auth_controller_test.exs
@@ -1484,7 +1484,7 @@ defmodule PlausibleWeb.AuthControllerTest do
conn = get(conn, Routes.auth_path(conn, :google_auth_callback), callback_params)
assert redirected_to(conn, 302) ==
- Routes.site_path(conn, :settings_integrations, site.domain)
+ Routes.site_path(conn, :settings_imports_exports, site.domain)
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
"unable to authenticate your Google Analytics"
diff --git a/test/plausible_web/controllers/google_analytics_controller_test.exs b/test/plausible_web/controllers/google_analytics_controller_test.exs
index ccaccf946..770e13484 100644
--- a/test/plausible_web/controllers/google_analytics_controller_test.exs
+++ b/test/plausible_web/controllers/google_analytics_controller_test.exs
@@ -24,8 +24,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"refresh_token" => "foo",
"expires_at" => "2022-09-22T20:01:37.112777",
"start_date" => "2020-02-22",
- "end_date" => "2022-09-22",
- "legacy" => "true"
+ "end_date" => "2022-09-22"
})
|> html_response(200)
@@ -36,8 +35,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
refresh_token: "foo",
expires_at: "2022-09-22T20:01:37.112777",
start_date: "2020-02-22",
- end_date: "2022-09-22",
- legacy: "true"
+ end_date: "2022-09-22"
)
|> String.replace("&", "&")
end
@@ -46,30 +44,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
describe "GET /:website/import/google-analytics/property-or-view" do
setup [:create_user, :log_in, :create_new_site]
- test "lists Google Analytics views (legacy)", %{conn: conn, site: site} do
- expect(
- Plausible.HTTPClient.Mock,
- :get,
- fn _url, _opts ->
- body = "fixture/ga_list_views.json" |> File.read!() |> Jason.decode!()
- {:ok, %Finch.Response{body: body, status: 200}}
- end
- )
-
- response =
- conn
- |> get("/#{site.domain}/import/google-analytics/property-or-view", %{
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "true"
- })
- |> html_response(200)
-
- assert response =~ "57238190 - one.test"
- assert response =~ "54460083 - two.test"
- end
-
test "lists Google Analytics views and properties", %{conn: conn, site: site} do
expect(
Plausible.HTTPClient.Mock,
@@ -94,8 +68,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
|> get("/#{site.domain}/import/google-analytics/property-or-view", %{
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
|> html_response(200)
@@ -106,176 +79,166 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
assert response =~ "GA4 - Google Merch Shop (properties/213025502)"
end
- for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do
- test "redirects to #{view} on auth error with flash error (legacy: #{legacy})", %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :get,
- fn _url, _opts ->
- {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: %{}}}}
- end
- )
+ test "redirects to imports and exports on auth error with flash error", %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :get,
+ fn _url, _opts ->
+ {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: %{}}}}
+ end
+ )
- conn =
- conn
- |> get("/#{site.domain}/import/google-analytics/property-or-view", %{
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> get("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "We were unable to authenticate your Google Analytics account"
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "We were unable to authenticate your Google Analytics account"
+ end
- test "redirects to #{view} on timeout error with flash error (legacy: #{legacy})", %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :get,
- fn _url, _opts ->
- {:error, %Mint.TransportError{reason: :timeout}}
- end
- )
+ test "redirects to imports and exports on timeout error with flash error", %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :get,
+ fn _url, _opts ->
+ {:error, %Mint.TransportError{reason: :timeout}}
+ end
+ )
- conn =
- conn
- |> get("/#{site.domain}/import/google-analytics/property-or-view", %{
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> get("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "Google Analytics API has timed out."
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "Google Analytics API has timed out."
+ end
- test "redirects to #{view} on list retrival failure with flash error (legacy: #{legacy})",
- %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :get,
- fn _url, _opts ->
- {:error,
- %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}}
- end
- )
+ test "redirects to imports and exports on list retrival failure with flash error",
+ %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :get,
+ fn _url, _opts ->
+ {:error, %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}}
+ end
+ )
- conn =
- conn
- |> get("/#{site.domain}/import/google-analytics/property-or-view", %{
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> get("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "We were unable to list your Google Analytics properties and views"
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "We were unable to list your Google Analytics properties and views"
end
end
describe "POST /:website/import/google-analytics/property-or-view" do
setup [:create_user, :log_in, :create_new_site]
- for legacy <- ["true", "false"] do
- test "redirects to user metrics notice (UA legacy: #{legacy})", %{conn: conn, site: site} do
- expect(
- Plausible.HTTPClient.Mock,
- :post,
- fn _url, _opts, _params ->
- body = "fixture/ga_start_date.json" |> File.read!() |> Jason.decode!()
- {:ok, %Finch.Response{body: body, status: 200}}
- end
- )
+ test "redirects to user metrics notice", %{conn: conn, site: site} do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :post,
+ fn _url, _opts, _params ->
+ body = "fixture/ga_start_date.json" |> File.read!() |> Jason.decode!()
+ {:ok, %Finch.Response{body: body, status: 200}}
+ end
+ )
- expect(
- Plausible.HTTPClient.Mock,
- :post,
- fn _url, _opts, _params ->
- body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!()
- {:ok, %Finch.Response{body: body, status: 200}}
- end
- )
+ expect(
+ Plausible.HTTPClient.Mock,
+ :post,
+ fn _url, _opts, _params ->
+ body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!()
+ {:ok, %Finch.Response{body: body, status: 200}}
+ end
+ )
- conn =
- conn
- |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
- "property_or_view" => "57238190",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "property_or_view" => "57238190",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) =~
- "/#{URI.encode_www_form(site.domain)}/import/google-analytics/user-metric"
- end
+ assert redirected_to(conn, 302) =~
+ "/#{URI.encode_www_form(site.domain)}/import/google-analytics/user-metric"
+ end
- test "redirects to confirmation (UA legacy: #{legacy})", %{conn: conn, site: site} do
- expect(
- Plausible.HTTPClient.Mock,
- :post,
- fn _url, _opts, _params ->
- body = "fixture/ga_start_date_later.json" |> File.read!() |> Jason.decode!()
- {:ok, %Finch.Response{body: body, status: 200}}
- end
- )
+ test "redirects to confirmation", %{conn: conn, site: site} do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :post,
+ fn _url, _opts, _params ->
+ body = "fixture/ga_start_date_later.json" |> File.read!() |> Jason.decode!()
+ {:ok, %Finch.Response{body: body, status: 200}}
+ end
+ )
- expect(
- Plausible.HTTPClient.Mock,
- :post,
- fn _url, _opts, _params ->
- body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!()
- {:ok, %Finch.Response{body: body, status: 200}}
- end
- )
+ expect(
+ Plausible.HTTPClient.Mock,
+ :post,
+ fn _url, _opts, _params ->
+ body = "fixture/ga_end_date.json" |> File.read!() |> Jason.decode!()
+ {:ok, %Finch.Response{body: body, status: 200}}
+ end
+ )
- conn =
- conn
- |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
- "property_or_view" => "57238190",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "property_or_view" => "57238190",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) =~
- "/#{URI.encode_www_form(site.domain)}/import/google-analytics/confirm"
- end
+ assert redirected_to(conn, 302) =~
+ "/#{URI.encode_www_form(site.domain)}/import/google-analytics/confirm"
end
test "redirects to confirmation (GA4)", %{conn: conn, site: site} do
@@ -303,8 +266,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"property_or_view" => "properties/428685906",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
assert redirected_to(conn, 302) =~
@@ -365,8 +327,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"property_or_view" => "properties/428685906",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
|> html_response(200)
@@ -415,117 +376,110 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"property_or_view" => "properties/428685906",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
|> html_response(200)
assert response =~ "No data found. Nothing to import."
end
- for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do
- test "redirects to #{view} on failed property/view choice with flash error (legacy: #{legacy})",
- %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :post,
- fn _url, _opts, _params ->
- {:error,
- %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}}
- end
- )
+ test "redirects to imports and exports on failed property/view choice with flash error",
+ %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :post,
+ fn _url, _opts, _params ->
+ {:error, %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}}
+ end
+ )
- conn =
- conn
- |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
- "property_or_view" => "properties/428685906",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "property_or_view" => "properties/428685906",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "We were unable to retrieve information from Google Analytics"
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "We were unable to retrieve information from Google Analytics"
+ end
- test "redirects to #{view} on expired authentication with flash error (legacy: #{legacy})",
- %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :post,
- fn _url, _opts, _params ->
- {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}}
- end
- )
+ test "redirects to imports and exports on expired authentication with flash error",
+ %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :post,
+ fn _url, _opts, _params ->
+ {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}}
+ end
+ )
- conn =
- conn
- |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
- "property_or_view" => "properties/428685906",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "property_or_view" => "properties/428685906",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "Google Analytics authentication seems to have expired."
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "Google Analytics authentication seems to have expired."
+ end
- test "redirects to #{view} on timeout with flash error (legacy: #{legacy})",
- %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :post,
- fn _url, _opts, _params ->
- {:error, %Mint.TransportError{reason: :timeout}}
- end
- )
+ test "redirects to imports and exports on timeout with flash error",
+ %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :post,
+ fn _url, _opts, _params ->
+ {:error, %Mint.TransportError{reason: :timeout}}
+ end
+ )
- conn =
- conn
- |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
- "property_or_view" => "properties/428685906",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> post("/#{site.domain}/import/google-analytics/property-or-view", %{
+ "property_or_view" => "properties/428685906",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "Google Analytics API has timed out."
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "Google Analytics API has timed out."
end
end
@@ -550,8 +504,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"refresh_token" => "foo",
"expires_at" => "2022-09-22T20:01:37.112777",
"start_date" => "2012-01-18",
- "end_date" => "2022-09-22",
- "legacy" => "true"
+ "end_date" => "2022-09-22"
})
|> html_response(200)
@@ -565,8 +518,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
assert text_of_attr(response, ~s|input[name=expires_at]|, "value") ==
"2022-09-22T20:01:37.112777"
- assert text_of_attr(response, ~s|input[name=legacy]|, "value") == "true"
-
assert text_of_attr(response, ~s|input[name=property_or_view]|, "value") == "57238190"
assert text_of_attr(response, ~s|input[name=start_date]|, "value") == "2012-01-18"
@@ -592,8 +543,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"refresh_token" => "foo",
"expires_at" => "2022-09-22T20:01:37.112777",
"start_date" => "2024-02-22",
- "end_date" => "2024-02-26",
- "legacy" => "true"
+ "end_date" => "2024-02-26"
})
|> html_response(200)
@@ -607,8 +557,6 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
assert text_of_attr(response, ~s|input[name=expires_at]|, "value") ==
"2022-09-22T20:01:37.112777"
- assert text_of_attr(response, ~s|input[name=legacy]|, "value") == "true"
-
assert text_of_attr(response, ~s|input[name=property_or_view]|, "value") ==
"properties/428685444"
@@ -617,115 +565,109 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
assert text_of_attr(response, ~s|input[name=end_date]|, "value") == "2024-02-26"
end
- for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do
- test "redirects to #{view} on failed property/view retrieval with flash error (legacy: #{legacy})",
- %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :get,
- fn _url, _params ->
- {:error,
- %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}}
- end
- )
+ test "redirects to imports and exports on failed property/view retrieval with flash error",
+ %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :get,
+ fn _url, _params ->
+ {:error, %HTTPClient.Non200Error{reason: %{status: 500, body: "Internal server error"}}}
+ end
+ )
- conn =
- conn
- |> get("/#{site.domain}/import/google-analytics/confirm", %{
- "property_or_view" => "properties/428685906",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "start_date" => "2024-02-22",
- "end_date" => "2024-02-26",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> get("/#{site.domain}/import/google-analytics/confirm", %{
+ "property_or_view" => "properties/428685906",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777",
+ "start_date" => "2024-02-22",
+ "end_date" => "2024-02-26"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "We were unable to retrieve information from Google Analytics"
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "We were unable to retrieve information from Google Analytics"
+ end
- test "redirects to #{view} on expired authentication with flash error (legacy: #{legacy})",
- %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :get,
- fn _url, _params ->
- {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}}
- end
- )
+ test "redirects to imports and exports on expired authentication with flash error",
+ %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :get,
+ fn _url, _params ->
+ {:error, %HTTPClient.Non200Error{reason: %{status: 403, body: "Access denied"}}}
+ end
+ )
- conn =
- conn
- |> get("/#{site.domain}/import/google-analytics/confirm", %{
- "property_or_view" => "properties/428685906",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "start_date" => "2024-02-22",
- "end_date" => "2024-02-26",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> get("/#{site.domain}/import/google-analytics/confirm", %{
+ "property_or_view" => "properties/428685906",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777",
+ "start_date" => "2024-02-22",
+ "end_date" => "2024-02-26"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "Google Analytics authentication seems to have expired."
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "Google Analytics authentication seems to have expired."
+ end
- test "redirects to #{view} on timeout with flash error (legacy: #{legacy})",
- %{
- conn: conn,
- site: site
- } do
- expect(
- Plausible.HTTPClient.Mock,
- :get,
- fn _url, _params ->
- {:error, %Mint.TransportError{reason: :timeout}}
- end
- )
+ test "redirects to imports and exports on timeout with flash error",
+ %{
+ conn: conn,
+ site: site
+ } do
+ expect(
+ Plausible.HTTPClient.Mock,
+ :get,
+ fn _url, _params ->
+ {:error, %Mint.TransportError{reason: :timeout}}
+ end
+ )
- conn =
- conn
- |> get("/#{site.domain}/import/google-analytics/confirm", %{
- "property_or_view" => "properties/428685906",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "start_date" => "2024-02-22",
- "end_date" => "2024-02-26",
- "legacy" => unquote(legacy)
- })
+ conn =
+ conn
+ |> get("/#{site.domain}/import/google-analytics/confirm", %{
+ "property_or_view" => "properties/428685906",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777",
+ "start_date" => "2024-02-22",
+ "end_date" => "2024-02-26"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "Google Analytics API has timed out."
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "Google Analytics API has timed out."
end
end
@@ -740,8 +682,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"end_date" => "2022-03-01",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
assert redirected_to(conn, 302) ==
@@ -762,12 +703,11 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"end_date" => "2022-03-01",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "true"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(conn, :settings_integrations, site.domain)
+ PlausibleWeb.Router.Helpers.site_path(conn, :settings_imports_exports, site.domain)
[site_import] = Plausible.Imported.list_all_imports(site)
@@ -776,7 +716,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
assert site_import.status == SiteImport.pending()
end
- test "redirects to imports and exports when creating UA job with legacy set to false", %{
+ test "redirects to imports and exports when creating UA job", %{
conn: conn,
site: site
} do
@@ -787,8 +727,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"end_date" => "2022-03-01",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
assert redirected_to(conn, 302) ==
@@ -808,8 +747,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"end_date" => "2022-03-01",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
assert [%{id: import_id, legacy: false}] = Plausible.Imported.list_all_imports(site)
@@ -835,11 +773,10 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"end_date" => "2022-03-01",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "true"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
- assert [%{id: import_id, legacy: true}] = Plausible.Imported.list_all_imports(site)
+ assert [%{id: import_id, legacy: false}] = Plausible.Imported.list_all_imports(site)
assert_enqueued(
worker: Plausible.Workers.ImportAnalytics,
@@ -872,8 +809,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"end_date" => "2022-03-01",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "false"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
conn =
@@ -883,8 +819,7 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
"end_date" => "2022-03-01",
"access_token" => "token",
"refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => "true"
+ "expires_at" => "2022-09-22T20:01:37.112777"
})
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
@@ -895,43 +830,40 @@ defmodule PlausibleWeb.GoogleAnalyticsControllerTest do
assert job.args.import_id == import_id
end
- for {legacy, view} <- [{"true", :settings_integrations}, {"false", :settings_imports_exports}] do
- test "redirects to #{view} with no time window error flash error (legacy: #{legacy})", %{
- conn: conn,
- site: site
- } do
- start_date = ~D[2022-01-12]
- end_date = ~D[2024-03-13]
+ test "redirects to imports and exports with no time window error flash error", %{
+ conn: conn,
+ site: site
+ } do
+ start_date = ~D[2022-01-12]
+ end_date = ~D[2024-03-13]
- _existing_import =
- insert(:site_import,
- site: site,
- start_date: start_date,
- end_date: end_date,
- status: :completed
- )
+ _existing_import =
+ insert(:site_import,
+ site: site,
+ start_date: start_date,
+ end_date: end_date,
+ status: :completed
+ )
- conn =
- post(conn, "/#{site.domain}/settings/google-import", %{
- "property_or_view" => "123456",
- "start_date" => "2023-03-01",
- "end_date" => "2022-03-01",
- "access_token" => "token",
- "refresh_token" => "foo",
- "expires_at" => "2022-09-22T20:01:37.112777",
- "legacy" => unquote(legacy)
- })
+ conn =
+ post(conn, "/#{site.domain}/settings/google-import", %{
+ "property_or_view" => "123456",
+ "start_date" => "2023-03-01",
+ "end_date" => "2022-03-01",
+ "access_token" => "token",
+ "refresh_token" => "foo",
+ "expires_at" => "2022-09-22T20:01:37.112777"
+ })
- assert redirected_to(conn, 302) ==
- PlausibleWeb.Router.Helpers.site_path(
- conn,
- unquote(view),
- site.domain
- )
+ assert redirected_to(conn, 302) ==
+ PlausibleWeb.Router.Helpers.site_path(
+ conn,
+ :settings_imports_exports,
+ site.domain
+ )
- assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
- "Import failed. No data could be imported because date range overlaps with existing data."
- end
+ assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
+ "Import failed. No data could be imported because date range overlaps with existing data."
end
end
end
diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs
index d6a876ff2..52942c823 100644
--- a/test/plausible_web/controllers/site_controller_test.exs
+++ b/test/plausible_web/controllers/site_controller_test.exs
@@ -679,7 +679,7 @@ defmodule PlausibleWeb.SiteControllerTest do
end
test "disables import buttons when imports are at maximum", %{conn: conn, site: site} do
- insert_list(Plausible.Imported.max_complete_imports(), :site_import,
+ insert_list(Plausible.Imported.max_complete_imports(site), :site_import,
site: site,
status: SiteImport.completed()
)
@@ -687,7 +687,7 @@ defmodule PlausibleWeb.SiteControllerTest do
conn = get(conn, "/#{site.domain}/settings/imports-exports")
assert html_response(conn, 200) =~
- "Maximum of #{Plausible.Imported.max_complete_imports()} imports is reached."
+ "Maximum of #{Plausible.Imported.max_complete_imports(site)} imports is reached."
end
test "considers older legacy imports when showing pageview count", %{conn: conn, site: site} do