From 986839281856b6d3304d72fd983a69f4a0108db2 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 4 Sep 2019 12:40:08 +0100 Subject: [PATCH] Fix Google Search Console white page --- lib/plausible/google/api.ex | 2 +- .../templates/stats/google_referrer.html.eex | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/plausible/google/api.ex b/lib/plausible/google/api.ex index 90fd3e900..14df65ae3 100644 --- a/lib/plausible/google/api.ex +++ b/lib/plausible/google/api.ex @@ -48,7 +48,7 @@ defmodule Plausible.Google.Api do case res.status_code do 200 -> - terms = Jason.decode!(res.body)["rows"] + terms = (Jason.decode!(res.body)["rows"] || []) |> Enum.filter(fn row -> row["clicks"] > 0 end) |> Enum.map(fn row -> {row["keys"], round(row["clicks"])} end) diff --git a/lib/plausible_web/templates/stats/google_referrer.html.eex b/lib/plausible_web/templates/stats/google_referrer.html.eex index fff84e45e..ff702118a 100644 --- a/lib/plausible_web/templates/stats/google_referrer.html.eex +++ b/lib/plausible_web/templates/stats/google_referrer.html.eex @@ -7,6 +7,15 @@

<%= @total_visitors %> new visitors from Google

<%= timeframe_to_human(@query) %>

<%= case @search_terms do %> + <% {:ok, []} -> %> +
+ Search term + Visitors +
+
+ +
Could not find any search terms for this period
+
<% {:ok, search_terms} -> %>
Search term