mirror of
https://github.com/plausible/analytics.git
synced 2025-01-02 22:48:25 +03:00
e8f20e67cc
* Load dashboard with react * Rename stast2 to dashboard * Save timeframe on the frontend * Implement current visitors * Implement comparisons * React to route changes * Add modals * Show number of visitors on hover * Show 'Today' for today * Add 30 days * Show referrer drilldown * Arrow keys to go back and forward * Improve comparisons UI * Fix dropdown when clicking on it * Verify API access in a memoized fashion * Test API access * Test stats through controller * Move map formatting from stats controller to stats * Remove unused code * Remove dead code from query * Remove dead code from stats templates * Add stats view test back in * Render modal inside the modal component * Implement google search terms * Add explanation for screen sizes * Separate dashboard JS from the app js
52 lines
1.5 KiB
Elixir
52 lines
1.5 KiB
Elixir
defmodule PlausibleWeb.StatsController do
|
|
use PlausibleWeb, :controller
|
|
use Plausible.Repo
|
|
|
|
def stats(conn, %{"website" => website}) do
|
|
site = Repo.get_by(Plausible.Site, domain: website)
|
|
|
|
if site && current_user_can_access?(conn, site) do
|
|
user = conn.assigns[:current_user]
|
|
if user && Plausible.Billing.needs_to_upgrade?(conn.assigns[:current_user]) do
|
|
redirect(conn, to: "/billing/upgrade")
|
|
else
|
|
if Plausible.Sites.has_pageviews?(site) do
|
|
offer_email_report = get_session(conn, site.domain <> "_offer_email_report")
|
|
|
|
Plausible.Tracking.event(conn, "Site Analytics: Open", %{demo: site.domain == "plausible.io"})
|
|
|
|
has_goals = user && Plausible.Sites.has_goals?(site)
|
|
|
|
conn
|
|
|> assign(:skip_plausible_tracking, !site.public)
|
|
|> put_session(site.domain <> "_offer_email_report", nil)
|
|
|> render("stats.html",
|
|
site: site,
|
|
has_goals: has_goals,
|
|
title: "Plausible · " <> site.domain,
|
|
offer_email_report: offer_email_report
|
|
)
|
|
else
|
|
conn
|
|
|> assign(:skip_plausible_tracking, true)
|
|
|> render("waiting_first_pageview.html", site: site)
|
|
end
|
|
end
|
|
else
|
|
render_error(conn, 404)
|
|
end
|
|
end
|
|
|
|
defp current_user_can_access?(_conn, %Plausible.Site{public: true}) do
|
|
true
|
|
end
|
|
|
|
defp current_user_can_access?(conn, site) do
|
|
case conn.assigns[:current_user] do
|
|
nil -> false
|
|
user -> Plausible.Sites.is_owner?(user.id, site)
|
|
end
|
|
end
|
|
end
|
|
|