Skip to content

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

Import Oban error handling

Uku Taht1fb39957a63a
diff --git a/lib/plausible/google/api.ex b/lib/plausible/google/api.ex
index d57d226596..a1da6565f9 100644
--- a/lib/plausible/google/api.ex
+++ b/lib/plausible/google/api.ex
@@ -296,8 +296,6 @@ defmodule Plausible.Google.Api do
pageToken: page_token
}
- Logger.debug(report)
-
res =
HTTPoison.post!(
"https://analyticsreporting.googleapis.com/v4/reports:batchGet",
@@ -305,8 +303,6 @@ defmodule Plausible.Google.Api do
Authorization: "Bearer #{request.auth.access_token}"
)
- Logger.debug(res.body)
-
if res.status_code == 200 do
report = List.first(Jason.decode!(res.body)["reports"])
data = report["data"]["rows"]
diff --git a/lib/plausible_web/templates/site/settings_general.html.eex b/lib/plausible_web/templates/site/settings_general.html.eex
index 6daad6dd29..51b24d3c3c 100644
--- a/lib/plausible_web/templates/site/settings_general.html.eex
+++ b/lib/plausible_web/templates/site/settings_general.html.eex
@@ -83,9 +83,15 @@
<div class="py-2"></div>
<span class="text-gray-700 dark:text-gray-300">Linked Google account: <b><%= @site.google_auth.email %></b></span>
+ <%= if @imported_data && @imported_data.status == "error" do %>
+ <div class="mt-1 text-red-600">
+ Your last GA import resulted in an error. You can try again below.
+ </div>
+ <% end %>
+
<%= case @google_profiles do %>
<% {:ok, profiles} -> %>
- <p class="text-gray-700 dark:text-gray-300 mt-6">
+ <p class="text-gray-700 dark:text-gray-300 mt-1">
Select the Google Analytics view id you would like to import data from.
</p>
diff --git a/lib/telemetry.ex b/lib/telemetry.ex
index b9dd8c7c09..ac1fd1d4ef 100644
--- a/lib/telemetry.ex
+++ b/lib/telemetry.ex
@@ -5,10 +5,20 @@ defmodule ErrorReporter do
|> Map.take([:id, :args, :meta, :queue, :worker])
|> Map.merge(measure)
+ maybe_log_import_error(job)
+
Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: extra)
end
def handle_event([:oban, :circuit, :trip], _measure, meta, _) do
Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta)
end
+
+ defp maybe_log_import_error(job) do
+ site = Plausible.Repo.get(Plausible.Site, job.args["site_id"])
+
+ if site do
+ Plausible.Site.import_failure(site) |> Plausible.Repo.update!()
+ end
+ end
end