Show total conversions in addition to uniques (#294)

This commit is contained in:
Uku Taht 2020-08-20 14:57:49 +03:00 committed by GitHub
parent a7f3aa430e
commit 76896f7cee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 12 deletions

View File

@ -46,11 +46,14 @@ export default class Conversions extends React.Component {
renderGoal(goal) {
return (
<div className="flex items-center justify-between my-2 text-sm" key={goal.name}>
<div className="w-full h-8" style={{maxWidth: 'calc(100% - 6rem)'}}>
<div className="w-full h-8" style={{maxWidth: 'calc(100% - 14rem)'}}>
<Bar count={goal.count} all={this.state.goals} bg="bg-red-50" />
{this.renderGoalText(goal.name)}
</div>
<span className="font-medium">{numberFormatter(goal.count)}</span>
<div>
<span className="font-medium inline-block w-20 text-right">{numberFormatter(goal.count)}</span>
<span className="font-medium inline-block w-36 text-right">{numberFormatter(goal.total_count)}</span>
</div>
</div>
)
}
@ -68,7 +71,10 @@ export default class Conversions extends React.Component {
<h3 className="font-bold">{this.props.title || "Goal Conversions"}</h3>
<div className="flex items-center mt-3 mb-2 justify-between text-gray-500 text-xs font-bold tracking-wide">
<span>Goal</span>
<span>Conversions</span>
<div className="text-right">
<span className="inline-block w-20">Uniques</span>
<span className="inline-block w-36">Total conversions</span>
</div>
</div>
{ this.state.goals.map(this.renderGoal.bind(this)) }

View File

@ -530,11 +530,10 @@ defmodule Plausible.Stats.Clickhouse do
def goal_conversions(site, %Query{filters: %{"goal" => goal}} = query) when is_binary(goal) do
Clickhouse.all(
from e in base_query(site, query),
select: {e.name, fragment("uniq(user_id) as count")},
select: {e.name, fragment("uniq(user_id) as count"), fragment("count(*) as total_count")},
group_by: e.name,
order_by: [desc: fragment("count")]
)
|> Enum.map(fn row -> %{"name" => goal, "count" => row["count"]} end)
end
def goal_conversions(site, query) do
@ -560,7 +559,7 @@ defmodule Plausible.Stats.Clickhouse do
where: e.domain == ^site.domain,
where: e.timestamp >= ^first_datetime and e.timestamp < ^last_datetime,
where: fragment("? IN tuple(?)", e.name, ^events),
select: {e.name, fragment("uniq(user_id) as count")},
select: {e.name, fragment("uniq(user_id) as count"), fragment("count(*) as total_count")},
group_by: e.name
)
@ -609,7 +608,8 @@ defmodule Plausible.Stats.Clickhouse do
group_by: e.pathname,
select:
{fragment("concat('Visit ', ?) as name", e.pathname),
fragment("uniq(user_id) as count")}
fragment("uniq(user_id) as count"),
fragment("count(*) as total_count") }
)
q =

View File

@ -41,6 +41,8 @@ defmodule PlausibleWeb.Api.StatsController do
prev_unique_visitors = Stats.unique_visitors(site, %{prev_query | filters: %{}})
converted_visitors = Stats.unique_visitors(site, query)
prev_converted_visitors = Stats.unique_visitors(site, prev_query)
completions = Stats.total_events(site, query)
prev_completions = Stats.total_events(site, prev_query)
conversion_rate =
if unique_visitors > 0,
@ -59,10 +61,15 @@ defmodule PlausibleWeb.Api.StatsController do
change: percent_change(prev_unique_visitors, unique_visitors)
},
%{
name: "Converted visitors",
name: "Unique conversions",
count: converted_visitors,
change: percent_change(prev_converted_visitors, converted_visitors)
},
%{
name: "Total conversions",
count: completions,
change: percent_change(prev_completions, completions)
},
%{
name: "Conversion rate",
percentage: conversion_rate,

View File

@ -12,8 +12,8 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day&date=2019-01-01")
assert json_response(conn, 200) == [
%{"name" => "Signup", "count" => 3},
%{"name" => "Visit /register", "count" => 2}
%{"name" => "Signup", "count" => 3, "total_count" => 3},
%{"name" => "Visit /register", "count" => 2, "total_count" => 2}
]
end
end
@ -34,7 +34,7 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
)
assert json_response(conn, 200) == [
%{"name" => "Signup", "count" => 3}
%{"name" => "Signup", "count" => 3, "total_count" => 3}
]
end
end

View File

@ -134,7 +134,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
)
res = json_response(conn, 200)
assert %{"name" => "Converted visitors", "count" => 3, "change" => 100} in res["top_stats"]
assert %{"name" => "Unique conversions", "count" => 3, "change" => 100} in res["top_stats"]
end
test "returns conversion rate", %{conn: conn, site: site} do