mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 09:33:19 +03:00
Show last touch referrer for drilldown
This commit is contained in:
parent
bda08df7b5
commit
43b46e7607
@ -18,14 +18,25 @@ class GoogleKeywordsModal extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers/Google`, this.state.query, {limit: 100})
|
||||
.then((res) => this.setState({
|
||||
loading: false,
|
||||
searchTerms: res.search_terms,
|
||||
totalVisitors: res.total_visitors,
|
||||
notConfigured: res.not_configured,
|
||||
isOwner: res.is_owner
|
||||
}))
|
||||
if (this.state.query.filters.goal) {
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/referrers/Google`, this.state.query, {limit: 100})
|
||||
.then((res) => this.setState({
|
||||
loading: false,
|
||||
searchTerms: res.search_terms,
|
||||
totalVisitors: res.total_visitors,
|
||||
notConfigured: res.not_configured,
|
||||
isOwner: res.is_owner
|
||||
}))
|
||||
} else {
|
||||
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers/Google`, this.state.query, {limit: 100})
|
||||
.then((res) => this.setState({
|
||||
loading: false,
|
||||
searchTerms: res.search_terms,
|
||||
totalVisitors: res.total_visitors,
|
||||
notConfigured: res.not_configured,
|
||||
isOwner: res.is_owner
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
renderTerm(term) {
|
||||
@ -92,6 +103,14 @@ class GoogleKeywordsModal extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
renderGoalText() {
|
||||
if (this.state.query.filters.goal) {
|
||||
return (
|
||||
<h1 className="text-xl font-semibold text-gray-500 leading-none">completed {this.state.query.filters.goal}</h1>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
renderBody() {
|
||||
if (this.state.loading) {
|
||||
return (
|
||||
@ -104,8 +123,11 @@ class GoogleKeywordsModal extends React.Component {
|
||||
|
||||
<div className="my-4 border-b border-gray-300"></div>
|
||||
<main className="modal__content">
|
||||
<h1 className="text-xl font-semibold">{this.state.totalVisitors} new visitors from Google</h1>
|
||||
<h1 className="text-xl font-semibold text-gray-700 mt-2" style={{transform: 'translateY(-1rem)'}}>{toHuman(this.state.query)}</h1>
|
||||
<h1 className="text-xl font-semibold mb-0 leading-none">
|
||||
{this.state.totalVisitors} visitors from Google<br />
|
||||
{toHuman(this.state.query)}
|
||||
</h1>
|
||||
{this.renderGoalText()}
|
||||
{ this.renderKeywords() }
|
||||
</main>
|
||||
</React.Fragment>
|
||||
|
File diff suppressed because one or more lines are too long
@ -216,11 +216,19 @@ defmodule Plausible.Stats.Clickhouse do
|
||||
end
|
||||
|
||||
def conversions_from_referrer(site, query, referrer) do
|
||||
[res] = Clickhouse.all(
|
||||
converted_sessions = from(
|
||||
from e in base_query(site, query),
|
||||
select: fragment("uniq(user_id) as visitors"),
|
||||
where: e.initial_referrer_source == ^referrer
|
||||
select: %{session_id: e.session_id}
|
||||
)
|
||||
|
||||
[res] = Plausible.Clickhouse.all(
|
||||
from s in Plausible.ClickhouseSession,
|
||||
join: cs in subquery(converted_sessions),
|
||||
on: s.session_id == cs.session_id,
|
||||
where: s.referrer_source == ^referrer,
|
||||
select: fragment("uniq(user_id) as visitors")
|
||||
)
|
||||
|
||||
res["visitors"]
|
||||
end
|
||||
|
||||
@ -258,11 +266,18 @@ defmodule Plausible.Stats.Clickhouse do
|
||||
end
|
||||
|
||||
def referrer_drilldown_for_goal(site, query, referrer) do
|
||||
Clickhouse.all(
|
||||
converted_sessions = from(
|
||||
from e in base_query(site, query),
|
||||
select: {fragment("? as name", e.initial_referrer), fragment("uniq(user_id) as count")},
|
||||
group_by: e.initial_referrer,
|
||||
where: e.initial_referrer_source == ^referrer,
|
||||
select: %{session_id: e.session_id}
|
||||
)
|
||||
|
||||
Plausible.Clickhouse.all(
|
||||
from s in Plausible.ClickhouseSession,
|
||||
join: cs in subquery(converted_sessions),
|
||||
on: s.session_id == cs.session_id,
|
||||
select: {fragment("? as name", s.referrer), fragment("uniq(user_id) as count")},
|
||||
where: s.referrer_source == ^referrer,
|
||||
group_by: s.referrer,
|
||||
order_by: [desc: fragment("count")],
|
||||
limit: 100
|
||||
)
|
||||
|
@ -32,7 +32,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" => 3, "url" => "google.com"},
|
||||
%{"name" => "10words", "count" => 2, "url" => "10words.com"},
|
||||
]
|
||||
end
|
||||
|
||||
@ -41,7 +41,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, "url" => "google.com"},
|
||||
%{"name" => "10words", "count" => 2, "url" => "10words.com"},
|
||||
]
|
||||
end
|
||||
end
|
||||
@ -102,26 +102,24 @@ defmodule PlausibleWeb.Api.StatsController.ReferrersTest do
|
||||
|
||||
test "returns top referring urls for a custom goal", %{conn: conn, site: site} do
|
||||
filters = Jason.encode!(%{goal: "Signup"})
|
||||
conn = get(conn, "/api/stats/#{site.domain}/goal/referrers/Google?period=day&date=2019-01-01&filters=#{filters}")
|
||||
conn = get(conn, "/api/stats/#{site.domain}/goal/referrers/10words?period=day&date=2019-01-01&filters=#{filters}")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"total_visitors" => 3,
|
||||
"total_visitors" => 2,
|
||||
"referrers" => [
|
||||
%{"name" => "google.com/a", "count" => 2},
|
||||
%{"name" => "google.com/b", "count" => 1}
|
||||
%{"name" => "10words.com/page1", "count" => 2}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "returns top referring urls for a pageview goal", %{conn: conn, site: site} do
|
||||
filters = Jason.encode!(%{goal: "Visit /register"})
|
||||
conn = get(conn, "/api/stats/#{site.domain}/goal/referrers/Google?period=day&date=2019-01-01&filters=#{filters}")
|
||||
conn = get(conn, "/api/stats/#{site.domain}/goal/referrers/10words?period=day&date=2019-01-01&filters=#{filters}")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"total_visitors" => 2,
|
||||
"referrers" => [
|
||||
%{"name" => "google.com/a", "count" => 1},
|
||||
%{"name" => "google.com/b", "count" => 1}
|
||||
%{"name" => "10words.com/page1", "count" => 2},
|
||||
]
|
||||
}
|
||||
end
|
||||
|
@ -67,6 +67,9 @@ defmodule Plausible.Test.ClickhouseSetup do
|
||||
Clickhousex.query(:clickhouse, create, [],log: {Plausible.Clickhouse, :log, []})
|
||||
end
|
||||
|
||||
@conversion_1_session_id 123
|
||||
@conversion_2_session_id 234
|
||||
|
||||
def load_fixtures() do
|
||||
Plausible.TestUtils.create_events([
|
||||
%{name: "pageview", domain: "test-site.com", pathname: "/", country_code: "EE", browser: "Chrome", operating_system: "Mac", screen_size: "Desktop", referrer_source: "10words", referrer: "10words.com/page1", timestamp: ~N[2019-01-01 00:00:00]},
|
||||
@ -75,13 +78,13 @@ defmodule Plausible.Test.ClickhouseSetup do
|
||||
|
||||
%{name: "pageview", domain: "test-site.com", timestamp: ~N[2019-01-31 00:00:00]},
|
||||
|
||||
%{name: "Signup", domain: "test-site.com", initial_referrer_source: "Google", initial_referrer: "google.com/a", timestamp: ~N[2019-01-01 01:00:00]},
|
||||
%{name: "Signup", domain: "test-site.com", initial_referrer_source: "Google", initial_referrer: "google.com/a", timestamp: ~N[2019-01-01 02:00:00]},
|
||||
%{name: "Signup", domain: "test-site.com", initial_referrer_source: "Google", initial_referrer: "google.com/b", timestamp: ~N[2019-01-01 02:00:00]},
|
||||
%{name: "Signup", domain: "test-site.com", session_id: @conversion_1_session_id, timestamp: ~N[2019-01-01 01:00:00]},
|
||||
%{name: "Signup", domain: "test-site.com", session_id: @conversion_1_session_id, timestamp: ~N[2019-01-01 02:00:00]},
|
||||
%{name: "Signup", domain: "test-site.com", session_id: @conversion_2_session_id, timestamp: ~N[2019-01-01 02:00:00]},
|
||||
|
||||
%{name: "pageview", pathname: "/register", domain: "test-site.com", initial_referrer_source: "Google", initial_referrer: "google.com/a", timestamp: ~N[2019-01-01 23:00:00]},
|
||||
%{name: "pageview", pathname: "/register", domain: "test-site.com", initial_referrer_source: "Google", initial_referrer: "google.com/b", timestamp: ~N[2019-01-01 23:00:00]},
|
||||
%{name: "pageview", pathname: "/irrelevant", domain: "test-site.com", initial_referrer_source: "Google", initial_referrer: "google.com/b", timestamp: ~N[2019-01-01 23:00:00]},
|
||||
%{name: "pageview", pathname: "/register", domain: "test-site.com", session_id: @conversion_1_session_id, timestamp: ~N[2019-01-01 23:00:00]},
|
||||
%{name: "pageview", pathname: "/register", domain: "test-site.com", session_id: @conversion_2_session_id, timestamp: ~N[2019-01-01 23:00:00]},
|
||||
%{name: "pageview", pathname: "/irrelevant", domain: "test-site.com", session_id: @conversion_1_session_id, timestamp: ~N[2019-01-01 23:00:00]},
|
||||
|
||||
%{name: "pageview", domain: "test-site.com", referrer_source: "Google", timestamp: ~N[2019-02-01 01:00:00]},
|
||||
%{name: "pageview", domain: "test-site.com", referrer_source: "Google", timestamp: ~N[2019-02-01 02:00:00]},
|
||||
@ -99,8 +102,8 @@ defmodule Plausible.Test.ClickhouseSetup do
|
||||
])
|
||||
|
||||
Plausible.TestUtils.create_sessions([
|
||||
%{domain: "test-site.com", entry_page: "/", exit_page: "/", referrer_source: "10words", referrer: "10words.com/page1", is_bounce: true, start: ~N[2019-01-01 02:00:00]},
|
||||
%{domain: "test-site.com", entry_page: "/", exit_page: "/", referrer_source: "10words", referrer: "10words.com/page1", is_bounce: false, start: ~N[2019-01-01 02:00:00]}
|
||||
%{domain: "test-site.com", entry_page: "/", exit_page: "/", referrer_source: "10words", referrer: "10words.com/page1", session_id: @conversion_1_session_id, is_bounce: true, start: ~N[2019-01-01 02:00:00]},
|
||||
%{domain: "test-site.com", entry_page: "/", exit_page: "/", referrer_source: "10words", referrer: "10words.com/page1", session_id: @conversion_2_session_id, is_bounce: false, start: ~N[2019-01-01 02:00:00]}
|
||||
])
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user