Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Adds "Load More" functionality to pages modal (#480)
Vignesh Joglekard3f7c94ebeca
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5048fab9ad..5e1425a83f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.- Collect and display browser & OS versions plausible/analytics#397- Simple notifications around traffic spikes plausible/analytics#453- Dark theme option/system setting follow plausible/analytics#467+- "Load More" capability to pages modal plausible/analytics#480### Changed- Use alpine as base image to decrease Docker image size plausible/analytics#353diff --git a/assets/js/dashboard/stats/modals/pages.js b/assets/js/dashboard/stats/modals/pages.jsindex 3850995d78..e4f180da9c 100644--- a/assets/js/dashboard/stats/modals/pages.js+++ b/assets/js/dashboard/stats/modals/pages.js@@ -12,23 +12,35 @@ class PagesModal extends React.Component {super(props)this.state = {loading: true,- query: parseQuery(props.location.search, props.site)+ query: parseQuery(props.location.search, props.site),+ pages: [],+ page: 1,+ moreResultsAvailable: false}}componentDidMount() {+ this.loadPages();+ }++ loadPages() {const include = this.showBounceRate() ? 'bounce_rate' : null+ const {query, page, pages} = this.state;- const {filters} = this.state.query+ const {filters} = queryif (filters.source || filters.referrer) {- api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/entry-pages`, this.state.query, {limit: 100, include: include})- .then((res) => this.setState({loading: false, pages: res}))+ api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/entry-pages`, query, {limit: 100, page, include})+ .then((res) => this.setState((state) => ({loading: false, pages: state.pages.concat(res), moreResultsAvailable: res.length === 100})))} else {- api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/pages`, this.state.query, {limit: 100, include: include})- .then((res) => this.setState({loading: false, pages: res}))+ api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/pages`, query, {limit: 100, page, include})+ .then((res) => this.setState((state) => ({loading: false, pages: state.pages.concat(res), moreResultsAvailable: res.length === 100})))}}+ loadMore() {+ this.setState({loading: true, page: this.state.page + 1}, this.loadPages.bind(this))+ }+showBounceRate() {return this.state.query.period !== 'realtime' && !this.state.query.filters.goal}@@ -71,12 +83,22 @@ class PagesModal extends React.Component {return (filters.source || filters.referrer) ? 'Entry Pages' : 'Top Pages'}- renderBody() {+ renderLoading() {if (this.state.loading) {+ return <div className="loading my-16 mx-auto"><div></div></div>+ } else if (this.state.moreResultsAvailable) {return (- <div className="loading mt-32 mx-auto"><div></div></div>+ <div className="w-full text-center my-4">+ <button onClick={this.loadMore.bind(this)} type="button" className="button">+ Load more+ </button>+ </div>)- } else if (this.state.pages) {+ }+ }++ renderBody() {+ if (this.state.pages) {return (<React.Fragment><h1 className="text-xl font-bold dark:text-gray-100">{this.title()}</h1>@@ -106,6 +128,7 @@ class PagesModal extends React.Component {return (<Modal site={this.props.site}>{ this.renderBody() }+ { this.renderLoading() }</Modal>)}diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.exindex 2142885d2d..e5271f4098 100644--- a/lib/plausible/stats/clickhouse.ex+++ b/lib/plausible/stats/clickhouse.ex@@ -456,13 +456,16 @@ defmodule Plausible.Stats.Clickhouse do)end- def entry_pages(site, query, limit, include) do+ def entry_pages(site, query, limit, page \\ 1, include) do+ offset = (page - 1) * limit+q =from(s in base_session_query(site, query),group_by: s.entry_page,order_by: [desc: fragment("count")],limit: ^limit,+ offset: ^offset,select: %{name: s.entry_page,count: fragment("uniq(?) as count", s.user_id)@@ -487,12 +490,15 @@ defmodule Plausible.Stats.Clickhouse doendend- def top_pages(site, %Query{period: "realtime"} = query, limit, _include) do+ def top_pages(site, %Query{period: "realtime"} = query, limit, page, _include) do+ offset = (page - 1) * limit+ClickhouseRepo.all(from s in base_session_query(site, query),group_by: s.exit_page,order_by: [desc: fragment("count")],limit: ^limit,+ offset: ^offset,select: %{name: fragment("? as name", s.exit_page),count: fragment("uniq(?) as count", s.user_id)@@ -500,13 +506,16 @@ defmodule Plausible.Stats.Clickhouse do)end- def top_pages(site, query, limit, include) do+ def top_pages(site, query, limit, page, include) do+ offset = (page - 1) * limit+q =from(e in base_query(site, query),group_by: e.pathname,order_by: [desc: fragment("count")],limit: ^limit,+ offset: ^offset,select: %{name: fragment("? as name", e.pathname),count: fragment("uniq(?) as count", e.user_id),diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.exindex cb4ec2e106..c48b2f3bd5 100644--- a/lib/plausible_web/controllers/api/stats_controller.ex+++ b/lib/plausible_web/controllers/api/stats_controller.ex@@ -212,8 +212,9 @@ defmodule PlausibleWeb.Api.StatsController doquery = Query.from(site.timezone, params)include = if params["include"], do: String.split(params["include"], ","), else: []limit = if params["limit"], do: String.to_integer(params["limit"])+ page = if params["page"], do: String.to_integer(params["page"])- json(conn, Stats.top_pages(site, query, limit || 9, include))+ json(conn, Stats.top_pages(site, query, limit || 9, page || 1, include))enddef entry_pages(conn, params) do@@ -221,8 +222,9 @@ defmodule PlausibleWeb.Api.StatsController doquery = Query.from(site.timezone, params)include = if params["include"], do: String.split(params["include"], ","), else: []limit = if params["limit"], do: String.to_integer(params["limit"])+ page = if params["page"], do: String.to_integer(params["page"])- json(conn, Stats.entry_pages(site, query, limit || 9, include))+ json(conn, Stats.entry_pages(site, query, limit || 9, page || 1, include))enddef countries(conn, params) dodiff --git a/lib/workers/send_email_report.ex b/lib/workers/send_email_report.exindex b3896b6b21..8b478c63c7 100644--- a/lib/workers/send_email_report.ex+++ b/lib/workers/send_email_report.ex@@ -56,7 +56,7 @@ defmodule Plausible.Workers.SendEmailReport doprev_bounce_rate = Stats.bounce_rate(site, Query.shift_back(query))change_bounce_rate = if prev_bounce_rate > 0, do: bounce_rate - prev_bounce_ratereferrers = Stats.top_sources(site, query, 5, 1, [])- pages = Stats.top_pages(site, query, 5, [])+ pages = Stats.top_pages(site, query, 5, 1, [])user = Plausible.Auth.find_user_by(email: email)login_link = user && Plausible.Sites.is_owner?(user.id, site)