mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 09:33:19 +03:00
Show favicons for referrers (#39)
This commit is contained in:
parent
e21b59fa4c
commit
cc5722050a
@ -44,6 +44,7 @@ class ReferrersModal extends React.Component {
|
||||
return (
|
||||
<tr className="text-sm" key={referrer.name}>
|
||||
<td className="p-2">
|
||||
<img src={`https://icons.duckduckgo.com/ip3/${referrer.url}.ico`} className="h-4 w-4 mr-2 align-middle" />
|
||||
<Link className="hover:underline truncate" style={{maxWidth: '80%'}} to={`/${encodeURIComponent(this.props.site.domain)}/referrers/${referrer.name}${window.location.search}`}>{ referrer.name }</Link>
|
||||
</td>
|
||||
<td className="p-2 w-32 font-medium" align="right">{numberFormatter(referrer.count)}</td>
|
||||
|
@ -39,7 +39,10 @@ export default class Referrers extends React.Component {
|
||||
<div className="flex items-center justify-between my-1 text-sm" key={referrer.name}>
|
||||
<div className="w-full h-8" style={{maxWidth: 'calc(100% - 4rem)'}}>
|
||||
<Bar count={referrer.count} all={this.state.referrers} color="blue" />
|
||||
<Link className="hover:underline block px-2" style={{marginTop: '-23px'}} to={`/${encodeURIComponent(this.props.site.domain)}/referrers/${referrer.name}${window.location.search}`}>{ referrer.name }</Link>
|
||||
<Link className="hover:underline block px-2" style={{marginTop: '-23px'}} to={`/${encodeURIComponent(this.props.site.domain)}/referrers/${referrer.name}${window.location.search}`}>
|
||||
<img src={`https://icons.duckduckgo.com/ip3/${referrer.url}.ico`} className="h-4 w-4 mr-2 align-middle" />
|
||||
{ referrer.name }
|
||||
</Link>
|
||||
</div>
|
||||
<span className="font-medium">{numberFormatter(referrer.count)}</span>
|
||||
</div>
|
||||
|
@ -154,22 +154,26 @@ defmodule Plausible.Stats do
|
||||
|
||||
def top_referrers_for_goal(site, query, limit \\ 5) do
|
||||
Repo.all(from e in base_query(site, query),
|
||||
select: %{name: e.initial_referrer_source, count: count(e.user_id, :distinct)},
|
||||
select: %{name: e.initial_referrer_source, url: min(e.initial_referrer), count: count(e.user_id, :distinct)},
|
||||
group_by: e.initial_referrer_source,
|
||||
where: not is_nil(e.initial_referrer_source),
|
||||
order_by: [desc: 2],
|
||||
order_by: [desc: 3],
|
||||
limit: ^limit
|
||||
)
|
||||
) |> Enum.map(fn ref ->
|
||||
Map.update(ref, :url, nil, fn url -> url && URI.parse("http://" <> url).host end)
|
||||
end)
|
||||
end
|
||||
|
||||
def top_referrers(site, query, limit \\ 5, include \\ []) do
|
||||
referrers = Repo.all(from e in base_query(site, query),
|
||||
select: %{name: e.referrer_source, count: count(e.user_id, :distinct)},
|
||||
select: %{name: e.referrer_source, url: min(e.referrer), count: count(e.user_id, :distinct)},
|
||||
group_by: e.referrer_source,
|
||||
where: not is_nil(e.referrer_source),
|
||||
order_by: [desc: 2],
|
||||
order_by: [desc: 3],
|
||||
limit: ^limit
|
||||
)
|
||||
) |> Enum.map(fn ref ->
|
||||
Map.update(ref, :url, nil, fn url -> url && URI.parse("http://" <> url).host end)
|
||||
end)
|
||||
|
||||
if "bounce_rate" in include do
|
||||
bounce_rates = bounce_rates_by_referrer_source(site, query, Enum.map(referrers, fn ref -> ref[:name] end))
|
||||
|
@ -77,7 +77,7 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
site = conn.assigns[:site]
|
||||
query = Stats.Query.from(site.timezone, params)
|
||||
|
||||
json(conn, Stats.top_referrers_for_goal(site, query, params["limit"] || 5))
|
||||
json(conn, Stats.top_referrers_for_goal(site, query, params["limit"] || 9))
|
||||
end
|
||||
|
||||
@google_api Application.fetch_env!(:plausible, :google_api)
|
||||
|
@ -14,8 +14,8 @@ defmodule PlausibleWeb.Api.StatsController.ReferrersTest do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/referrers?period=day&date=2019-01-01")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"name" => "Google", "count" => 2},
|
||||
%{"name" => "Bing", "count" => 1},
|
||||
%{"name" => "Google", "count" => 2, "url" => nil},
|
||||
%{"name" => "Bing", "count" => 1, "url" => nil},
|
||||
]
|
||||
end
|
||||
|
||||
@ -30,8 +30,8 @@ defmodule PlausibleWeb.Api.StatsController.ReferrersTest do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/referrers?period=day&date=2019-01-01&include=bounce_rate")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"name" => "Google", "count" => 2, "bounce_rate" => 50},
|
||||
%{"name" => "Bing", "count" => 1, "bounce_rate" => nil},
|
||||
%{"name" => "Google", "count" => 2, "bounce_rate" => 50, "url" => nil},
|
||||
%{"name" => "Bing", "count" => 1, "bounce_rate" => nil, "url" => nil},
|
||||
]
|
||||
end
|
||||
end
|
||||
@ -48,7 +48,7 @@ defmodule PlausibleWeb.Api.StatsController.ReferrersTest do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/goal/referrers?period=day&date=2019-01-01&filters=#{filters}")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"name" => "Google", "count" => 2},
|
||||
%{"name" => "Google", "count" => 2, "url" => nil},
|
||||
]
|
||||
end
|
||||
|
||||
@ -61,7 +61,7 @@ defmodule PlausibleWeb.Api.StatsController.ReferrersTest do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/goal/referrers?period=day&date=2019-01-01&filters=#{filters}")
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"name" => "Google", "count" => 2},
|
||||
%{"name" => "Google", "count" => 2, "url" => nil},
|
||||
]
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user