diff --git a/assets/js/dashboard/number-formatter.js b/assets/js/dashboard/number-formatter.js
index 0ecc4373f..c724525ef 100644
--- a/assets/js/dashboard/number-formatter.js
+++ b/assets/js/dashboard/number-formatter.js
@@ -3,6 +3,8 @@ const HUNDRED_THOUSAND = 100000
const MILLION = 1000000
const HUNDRED_MILLION = 100000000
const BILLION = 1000000000
+const HUNDRED_BILLION = 100000000000
+const TRILLION = 1000000000000
export default function numberFormatter(num) {
if (num >= THOUSAND && num < MILLION) {
@@ -19,6 +21,13 @@ export default function numberFormatter(num) {
} else {
return (Math.floor(millions * 10) / 10) + 'M'
}
+ } else if (num >= BILLION && num < TRILLION) {
+ const billions = num / BILLION
+ if (billions === Math.floor(billions) || num >= HUNDRED_BILLION) {
+ return Math.floor(billions) + 'B'
+ } else {
+ return (Math.floor(billions * 10) / 10) + 'B'
+ }
} else {
return num
}
diff --git a/assets/js/dashboard/stats/visitor-graph.js b/assets/js/dashboard/stats/visitor-graph.js
index 2bae9afca..bf2fcb50f 100644
--- a/assets/js/dashboard/stats/visitor-graph.js
+++ b/assets/js/dashboard/stats/visitor-graph.js
@@ -246,9 +246,9 @@ class LineGraph extends React.Component {
}
}
- renderTopStatNumber(stat) {
- if (stat.name === 'Visit duration') {
- return durationFormatter(stat.count)
+ topStatNumberShort(stat) {
+ if (typeof(stat.duration) == 'number') {
+ return durationFormatter(stat.duration)
} else if (typeof(stat.count) == 'number') {
return numberFormatter(stat.count)
} else {
@@ -256,6 +256,12 @@ class LineGraph extends React.Component {
}
}
+ topStatTooltip(stat) {
+ if (typeof(stat.count) == 'number') {
+ return stat.count.toLocaleString() + ' ' + stat.name
+ }
+ }
+
renderTopStats() {
const {graphData} = this.props
const stats = this.props.graphData.top_stats.map((stat, index) => {
@@ -266,7 +272,7 @@ class LineGraph extends React.Component {
{stat.name}
- { this.renderTopStatNumber(stat) }
+ { this.topStatNumberShort(stat) }
{this.renderComparison(stat.name, stat.change)}
diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex
index 28ee9f324..33ee45e40 100644
--- a/lib/plausible_web/controllers/api/stats_controller.ex
+++ b/lib/plausible_web/controllers/api/stats_controller.ex
@@ -98,7 +98,7 @@ defmodule PlausibleWeb.Api.StatsController do
%{
name: "Visit duration",
- count: duration,
+ duration: duration,
change: percent_change(prev_duration, duration)
}
end
diff --git a/lib/plausible_web/views/stats_view.ex b/lib/plausible_web/views/stats_view.ex
index 7ef8780f7..0f33dd723 100644
--- a/lib/plausible_web/views/stats_view.ex
+++ b/lib/plausible_web/views/stats_view.ex
@@ -28,9 +28,18 @@ defmodule PlausibleWeb.StatsView do
millions = trunc(n / 100_000) / 10
if millions == trunc(millions) || n > 100_000_000 do
- "#{trunc(millions)}m"
+ "#{trunc(millions)}M"
else
- "#{millions}m"
+ "#{millions}M"
+ end
+
+ n >= 1_000_000_000 && n < 1_000_000_000_000 ->
+ billions = trunc(n / 100_000_000) / 10
+
+ if billions == trunc(billions) || n > 100_000_000_000 do
+ "#{trunc(billions)}B"
+ else
+ "#{billions}B"
end
true ->
diff --git a/test/plausible_web/controllers/api/stats_controller/main_graph_test.exs b/test/plausible_web/controllers/api/stats_controller/main_graph_test.exs
index d431b7c66..83940b915 100644
--- a/test/plausible_web/controllers/api/stats_controller/main_graph_test.exs
+++ b/test/plausible_web/controllers/api/stats_controller/main_graph_test.exs
@@ -104,7 +104,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-01")
res = json_response(conn, 200)
- assert %{"name" => "Visit duration", "count" => 67, "change" => 100} in res["top_stats"]
+ assert %{"name" => "Visit duration", "duration" => 67, "change" => 100} in res["top_stats"]
end
end
diff --git a/test/plausible_web/views/stats_view_test.exs b/test/plausible_web/views/stats_view_test.exs
index 908f22b6a..1ca44adca 100644
--- a/test/plausible_web/views/stats_view_test.exs
+++ b/test/plausible_web/views/stats_view_test.exs
@@ -32,19 +32,31 @@ defmodule PlausibleWeb.StatsView.Test do
end
test "1_000_000 becomes 1m" do
- assert StatsView.large_number_format(1_000_000) == "1m"
+ assert StatsView.large_number_format(1_000_000) == "1M"
end
test "2_590_000 becomes 2.5m" do
- assert StatsView.large_number_format(2_590_000) == "2.5m"
+ assert StatsView.large_number_format(2_590_000) == "2.5M"
end
test "99_999_999 becomes 99.9m" do
- assert StatsView.large_number_format(99_999_999) == "99.9m"
+ assert StatsView.large_number_format(99_999_999) == "99.9M"
end
test "101_000_000 becomes 101m" do
- assert StatsView.large_number_format(101_000_000) == "101m"
+ assert StatsView.large_number_format(101_000_000) == "101M"
+ end
+
+ test "2_500_000_000 becomes 2.5bn" do
+ assert StatsView.large_number_format(2_500_000_000) == "2.5B"
+ end
+
+ test "25_500_000_000 becomes 25bn" do
+ assert StatsView.large_number_format(25_500_000_000) == "25.5B"
+ end
+
+ test "250_500_000_000 becomes 250bn" do
+ assert StatsView.large_number_format(250_500_000_000) == "250B"
end
end
end
diff --git a/test/workers/send_trial_notifications_test.exs b/test/workers/send_trial_notifications_test.exs
index 2c4065af7..5035487ee 100644
--- a/test/workers/send_trial_notifications_test.exs
+++ b/test/workers/send_trial_notifications_test.exs
@@ -117,35 +117,35 @@ defmodule Plausible.Workers.SendTrialNotificationsTest do
user = insert(:user)
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {900_000, 0})
- assert email.html_body =~ "we recommend you select the 1m/mo plan which runs at $48/mo."
+ assert email.html_body =~ "we recommend you select the 1M/mo plan which runs at $48/mo."
end
test "suggests 2m/mo plan" do
user = insert(:user)
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {1_800_000, 0})
- assert email.html_body =~ "we recommend you select the 2m/mo plan which runs at $69/mo."
+ assert email.html_body =~ "we recommend you select the 2M/mo plan which runs at $69/mo."
end
test "suggests 5m/mo plan" do
user = insert(:user)
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {4_500_000, 0})
- assert email.html_body =~ "we recommend you select the 5m/mo plan which runs at $99/mo."
+ assert email.html_body =~ "we recommend you select the 5M/mo plan which runs at $99/mo."
end
test "suggests 10m/mo plan" do
user = insert(:user)
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000_000, 0})
- assert email.html_body =~ "we recommend you select the 10m/mo plan which runs at $150/mo."
+ assert email.html_body =~ "we recommend you select the 10M/mo plan which runs at $150/mo."
end
test "suggests 20m/mo plan" do
user = insert(:user)
email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {19_000_000, 0})
- assert email.html_body =~ "we recommend you select the 20m/mo plan which runs at $225/mo."
+ assert email.html_body =~ "we recommend you select the 20M/mo plan which runs at $225/mo."
end
test "does not suggest a plan above that" do