diff --git a/assets/js/dashboard/stats/browsers.js b/assets/js/dashboard/stats/browsers.js index ac8ff2e29..0288e9007 100644 --- a/assets/js/dashboard/stats/browsers.js +++ b/assets/js/dashboard/stats/browsers.js @@ -22,7 +22,7 @@ export default class Browsers extends React.Component { } fetchBrowsers() { - api.get(`/api/stats/${this.props.site.domain}/browsers`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/browsers`, this.props.query) .then((res) => this.setState({loading: false, browsers: res})) } diff --git a/assets/js/dashboard/stats/conversions.js b/assets/js/dashboard/stats/conversions.js index ec269e897..e8d759ece 100644 --- a/assets/js/dashboard/stats/conversions.js +++ b/assets/js/dashboard/stats/conversions.js @@ -24,7 +24,7 @@ export default class Conversions extends React.Component { } fetchConversions() { - api.get(`/api/stats/${this.props.site.domain}/conversions`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/conversions`, this.props.query) .then((res) => this.setState({loading: false, goals: res})) } diff --git a/assets/js/dashboard/stats/countries.js b/assets/js/dashboard/stats/countries.js index 7cac97873..b81734b8b 100644 --- a/assets/js/dashboard/stats/countries.js +++ b/assets/js/dashboard/stats/countries.js @@ -24,7 +24,7 @@ export default class Countries extends React.Component { } fetchCountries() { - api.get(`/api/stats/${this.props.site.domain}/countries`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/countries`, this.props.query) .then((res) => this.setState({loading: false, countries: res})) } diff --git a/assets/js/dashboard/stats/current-visitors.js b/assets/js/dashboard/stats/current-visitors.js index e1b1c6418..c944549fe 100644 --- a/assets/js/dashboard/stats/current-visitors.js +++ b/assets/js/dashboard/stats/current-visitors.js @@ -19,7 +19,7 @@ export default class CurrentVisitors extends React.Component { } updateCount() { - return fetch(`/api/stats/${this.props.site.domain}/current-visitors`) + return fetch(`/api/stats/${encodeURIComponent(this.props.site.domain)}/current-visitors`) .then(res => res.json()) .then((res) => this.setState({currentVisitors: res})) } diff --git a/assets/js/dashboard/stats/modals/browsers.js b/assets/js/dashboard/stats/modals/browsers.js index 5058d2a75..d9ae04f47 100644 --- a/assets/js/dashboard/stats/modals/browsers.js +++ b/assets/js/dashboard/stats/modals/browsers.js @@ -16,7 +16,7 @@ class BrowsersModal extends React.Component { componentDidMount() { const query = parseQuery(this.props.location.search, this.props.site) - api.get(`/api/stats/${this.props.site.domain}/browsers`, query, {limit: 100}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/browsers`, query, {limit: 100}) .then((res) => this.setState({loading: false, browsers: res})) } diff --git a/assets/js/dashboard/stats/modals/countries.js b/assets/js/dashboard/stats/modals/countries.js index b5918e5bf..030e28f17 100644 --- a/assets/js/dashboard/stats/modals/countries.js +++ b/assets/js/dashboard/stats/modals/countries.js @@ -16,7 +16,7 @@ class CountriesModal extends React.Component { componentDidMount() { const query = parseQuery(this.props.location.search, this.props.site) - api.get(`/api/stats/${this.props.site.domain}/countries`, query, {limit: 100}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/countries`, query, {limit: 100}) .then((res) => this.setState({loading: false, countries: res})) } diff --git a/assets/js/dashboard/stats/modals/google-keywords.js b/assets/js/dashboard/stats/modals/google-keywords.js index f2682167e..1616a41c5 100644 --- a/assets/js/dashboard/stats/modals/google-keywords.js +++ b/assets/js/dashboard/stats/modals/google-keywords.js @@ -18,7 +18,7 @@ class GoogleKeywordsModal extends React.Component { } componentDidMount() { - api.get(`/api/stats/${this.props.site.domain}/referrers/Google`, this.state.query, {limit: 100}) + 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, @@ -56,7 +56,7 @@ class GoogleKeywordsModal extends React.Component {
The site is not connected to Google Search Keywords
Configure the integration to view search terms
- Connect with Google + Connect with Google ) } else { @@ -93,7 +93,7 @@ class GoogleKeywordsModal extends React.Component { return (
- ← All referrers + ← All referrers
diff --git a/assets/js/dashboard/stats/modals/modal.js b/assets/js/dashboard/stats/modals/modal.js index 5a81f3a9a..9048980d9 100644 --- a/assets/js/dashboard/stats/modals/modal.js +++ b/assets/js/dashboard/stats/modals/modal.js @@ -39,7 +39,7 @@ class Modal extends React.Component { } close() { - this.props.history.push(`/${this.props.site.domain}${this.props.location.search}`) + this.props.history.push(`/${encodeURIComponent(this.props.site.domain)}${this.props.location.search}`) } render() { diff --git a/assets/js/dashboard/stats/modals/operating-systems.js b/assets/js/dashboard/stats/modals/operating-systems.js index 2a097cb6e..e3a123fdd 100644 --- a/assets/js/dashboard/stats/modals/operating-systems.js +++ b/assets/js/dashboard/stats/modals/operating-systems.js @@ -16,7 +16,7 @@ class OperatingSystemsModal extends React.Component { componentDidMount() { const query = parseQuery(this.props.location.search, this.props.site) - api.get(`/api/stats/${this.props.site.domain}/operating-systems`, query, {limit: 100}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/operating-systems`, query, {limit: 100}) .then((res) => this.setState({loading: false, systems: res})) } diff --git a/assets/js/dashboard/stats/modals/pages.js b/assets/js/dashboard/stats/modals/pages.js index 2a45eacb9..018fcafc4 100644 --- a/assets/js/dashboard/stats/modals/pages.js +++ b/assets/js/dashboard/stats/modals/pages.js @@ -18,7 +18,7 @@ class PagesModal extends React.Component { componentDidMount() { const include = this.showBounceRate() ? 'bounce_rate' : null - api.get(`/api/stats/${this.props.site.domain}/pages`, this.state.query, {limit: 100, include: include}) + 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})) } diff --git a/assets/js/dashboard/stats/modals/referrer-drilldown.js b/assets/js/dashboard/stats/modals/referrer-drilldown.js index db0132787..e0f91d599 100644 --- a/assets/js/dashboard/stats/modals/referrer-drilldown.js +++ b/assets/js/dashboard/stats/modals/referrer-drilldown.js @@ -17,12 +17,12 @@ class ReferrerDrilldownModal extends React.Component { componentDidMount() { if (this.state.query.filters.goal) { - api.get(`/api/stats/${this.props.site.domain}/goal/referrers/${this.props.match.params.referrer}`, this.state.query, {limit: 100}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/referrers/${this.props.match.params.referrer}`, this.state.query, {limit: 100}) .then((res) => this.setState({loading: false, referrers: res.referrers, totalVisitors: res.total_visitors})) } else { const include = this.showBounceRate() ? 'bounce_rate' : null - api.get(`/api/stats/${this.props.site.domain}/referrers/${this.props.match.params.referrer}`, this.state.query, {limit: 100, include: include}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers/${this.props.match.params.referrer}`, this.state.query, {limit: 100, include: include}) .then((res) => this.setState({loading: false, referrers: res.referrers, totalVisitors: res.total_visitors})) } } @@ -119,7 +119,7 @@ class ReferrerDrilldownModal extends React.Component { return (
- ← All referrers + ← All referrers
diff --git a/assets/js/dashboard/stats/modals/referrers.js b/assets/js/dashboard/stats/modals/referrers.js index 7d4320461..e91946d42 100644 --- a/assets/js/dashboard/stats/modals/referrers.js +++ b/assets/js/dashboard/stats/modals/referrers.js @@ -17,12 +17,12 @@ class ReferrersModal extends React.Component { componentDidMount() { if (this.state.query.filters.goal) { - api.get(`/api/stats/${this.props.site.domain}/goal/referrers`, this.state.query, {limit: 100}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/referrers`, this.state.query, {limit: 100}) .then((res) => this.setState({loading: false, referrers: res})) } else { const include = this.showBounceRate() ? 'bounce_rate' : null - api.get(`/api/stats/${this.props.site.domain}/referrers`, this.state.query, {limit: 100, include: include}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers`, this.state.query, {limit: 100, include: include}) .then((res) => this.setState({loading: false, referrers: res})) } } @@ -43,7 +43,7 @@ class ReferrersModal extends React.Component { return ( - { referrer.name } + { referrer.name } {numberFormatter(referrer.count)} {this.showBounceRate() && {this.formatBounceRate(referrer)} } diff --git a/assets/js/dashboard/stats/more-link.js b/assets/js/dashboard/stats/more-link.js index 5658fc87b..668a72410 100644 --- a/assets/js/dashboard/stats/more-link.js +++ b/assets/js/dashboard/stats/more-link.js @@ -4,7 +4,7 @@ import { Link } from 'react-router-dom' export default function MoreLink({site, endpoint}) { return (
- + MORE diff --git a/assets/js/dashboard/stats/operating-systems.js b/assets/js/dashboard/stats/operating-systems.js index b77039923..37e9f0240 100644 --- a/assets/js/dashboard/stats/operating-systems.js +++ b/assets/js/dashboard/stats/operating-systems.js @@ -22,7 +22,7 @@ export default class OperatingSystems extends React.Component { } fetchOperatingSystems() { - api.get(`/api/stats/${this.props.site.domain}/operating-systems`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/operating-systems`, this.props.query) .then((res) => this.setState({loading: false, systems: res})) } diff --git a/assets/js/dashboard/stats/pages.js b/assets/js/dashboard/stats/pages.js index 062da4770..d918dc655 100644 --- a/assets/js/dashboard/stats/pages.js +++ b/assets/js/dashboard/stats/pages.js @@ -26,7 +26,7 @@ export default class Pages extends React.Component { } fetchPages() { - api.get(`/api/stats/${this.props.site.domain}/pages`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/pages`, this.props.query) .then((res) => this.setState({loading: false, pages: res})) } diff --git a/assets/js/dashboard/stats/referrers.js b/assets/js/dashboard/stats/referrers.js index e607182d3..0ddbe5846 100644 --- a/assets/js/dashboard/stats/referrers.js +++ b/assets/js/dashboard/stats/referrers.js @@ -25,10 +25,10 @@ export default class Referrers extends React.Component { fetchReferrers() { if (this.props.query.filters.goal) { - api.get(`/api/stats/${this.props.site.domain}/goal/referrers`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/referrers`, this.props.query) .then((res) => this.setState({loading: false, referrers: res})) } else { - api.get(`/api/stats/${this.props.site.domain}/referrers`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers`, this.props.query) .then((res) => this.setState({loading: false, referrers: res})) } } @@ -37,7 +37,7 @@ export default class Referrers extends React.Component { return (
- { referrer.name } + { referrer.name } {numberFormatter(referrer.count)}
diff --git a/assets/js/dashboard/stats/screen-sizes.js b/assets/js/dashboard/stats/screen-sizes.js index 075cfbb3d..03f9acd56 100644 --- a/assets/js/dashboard/stats/screen-sizes.js +++ b/assets/js/dashboard/stats/screen-sizes.js @@ -48,7 +48,7 @@ export default class ScreenSizes extends React.Component { } fetchScreenSizes() { - api.get(`/api/stats/${this.props.site.domain}/screen-sizes`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/screen-sizes`, this.props.query) .then((res) => this.setState({loading: false, sizes: res})) } diff --git a/assets/js/dashboard/stats/visitor-graph.js b/assets/js/dashboard/stats/visitor-graph.js index 9e6ecf2ac..43500eca9 100644 --- a/assets/js/dashboard/stats/visitor-graph.js +++ b/assets/js/dashboard/stats/visitor-graph.js @@ -289,7 +289,7 @@ class LineGraph extends React.Component { } downloadLink() { - const endpoint = `/${this.props.site.domain}/visitors.csv${api.serializeQuery(this.props.query)}` + const endpoint = `/${encodeURIComponent(this.props.site.domain)}/visitors.csv${api.serializeQuery(this.props.query)}` return ( @@ -337,7 +337,7 @@ export default class VisitorGraph extends React.Component { } fetchGraphData() { - api.get(`/api/stats/${this.props.site.domain}/main-graph`, this.props.query) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/main-graph`, this.props.query) .then((res) => { this.setState({loading: false, graphData: res}) return res diff --git a/assets/js/p.js b/assets/js/p.js index 3e9dadf3c..929b79a7d 100644 --- a/assets/js/p.js +++ b/assets/js/p.js @@ -2,6 +2,10 @@ 'use strict'; try { + const CONFIG = { + domain: window.location.hostname + } + function setCookie(name,value) { var date = new Date(); date.setTime(date.getTime() + (3*365*24*60*60*1000)); // 3 YEARS @@ -76,6 +80,7 @@ var payload = getUserData() payload.name = eventName payload.url = getUrl() + payload.domain = CONFIG['domain'] var request = new XMLHttpRequest(); request.open('POST', plausibleHost + '/api/event', true); @@ -113,10 +118,15 @@ } } + function configure(key, val) { + CONFIG[key] = val + } + const functions = { page: page, trigger: trigger, - trackPushState: trackPushState + trackPushState: trackPushState, + configure: configure } const queue = window.plausible.q || [] diff --git a/lib/mix/tasks/send_email_reports.ex b/lib/mix/tasks/send_email_reports.ex index 660e67157..ef5edb1c2 100644 --- a/lib/mix/tasks/send_email_reports.ex +++ b/lib/mix/tasks/send_email_reports.ex @@ -33,8 +33,8 @@ defmodule Mix.Tasks.SendEmailReports do query = Stats.Query.from(site.timezone, %{"period" => "7d"}) for email <- site.weekly_report.recipients do - Logger.info("Sending weekly report for #{site.domain} to #{email}") - unsubscribe_link = PlausibleWeb.Endpoint.url() <> "/sites/#{site.domain}/weekly-report/unsubscribe?email=#{email}" + Logger.info("Sending weekly report for #{URI.encode_www_form(site.domain)} to #{email}") + unsubscribe_link = PlausibleWeb.Endpoint.url() <> "/sites/#{URI.encode_www_form(site.domain)}/weekly-report/unsubscribe?email=#{email}" send_report(email, site, "Weekly", unsubscribe_link, query) end @@ -59,7 +59,7 @@ defmodule Mix.Tasks.SendEmailReports do for email <- site.monthly_report.recipients do Logger.info("Sending monthly report for #{site.domain} to #{email}") - unsubscribe_link = PlausibleWeb.Endpoint.url() <> "/sites/#{site.domain}/monthly-report/unsubscribe?email=#{email}" + unsubscribe_link = PlausibleWeb.Endpoint.url() <> "/sites/#{URI.encode_www_form(site.domain)}/monthly-report/unsubscribe?email=#{email}" send_report(email, site, Timex.format!(last_month, "{Mfull}"), unsubscribe_link, query) end @@ -115,11 +115,11 @@ defmodule Mix.Tasks.SendEmailReports do end defp view_link(site, %Plausible.Stats.Query{period: "7d"}) do - PlausibleWeb.Endpoint.url() <> "/#{site.domain}?period=7d" + PlausibleWeb.Endpoint.url() <> "/#{URI.encode_www_form(site.domain)}?period=7d" end defp view_link(site, %Plausible.Stats.Query{period: "month", date_range: range}) do month = Timex.format!(range.first, "{ISOdate}") - PlausibleWeb.Endpoint.url() <> "/#{site.domain}?period=month&date=#{month}" + PlausibleWeb.Endpoint.url() <> "/#{URI.encode_www_form(site.domain)}?period=month&date=#{month}" end end diff --git a/lib/mix/tasks/send_trial_notifications.ex b/lib/mix/tasks/send_trial_notifications.ex index 67cbf0e22..c3c8bc176 100644 --- a/lib/mix/tasks/send_trial_notifications.ex +++ b/lib/mix/tasks/send_trial_notifications.ex @@ -44,42 +44,6 @@ defmodule Mix.Tasks.SendTrialNotifications do nil end end - - #two_weeks_left = from( - # u in base_query, - # where: type(u.inserted_at, :date) == fragment("now()::date - '14 days'::interval") - #) - - #tomorrow = from( - # u in base_query, - # where: type(u.inserted_at, :date) == fragment("now()::date - '29 days'::interval") - #) - - #today = from( - # u in base_query, - # where: type(u.inserted_at, :date) == fragment("now()::date - '30 days'::interval") - #) - - #yesterday = from( - # u in base_query, - # where: type(u.inserted_at, :date) == fragment("now()::date - '31 days'::interval") - #) - - #for user <- Repo.all(two_weeks_left) do - # if Plausible.Auth.user_completed_setup?(user), do: send_two_week_reminder(args, user) - #end - - #for user <- Repo.all(tomorrow) do - # if Plausible.Auth.user_completed_setup?(user), do: send_tomorrow_reminder(args, user) - #end - - #for user <- Repo.all(today) do - # if Plausible.Auth.user_completed_setup?(user), do: send_today_reminder(args, user) - #end - - #for user <- Repo.all(yesterday) do - # if Plausible.Auth.user_completed_setup?(user), do: send_over_reminder(args, user) - #end end defp send_two_week_reminder(["--dry-run"], user) do diff --git a/lib/plausible/auth/auth.ex b/lib/plausible/auth/auth.ex index 5c67f89df..45d292a27 100644 --- a/lib/plausible/auth/auth.ex +++ b/lib/plausible/auth/auth.ex @@ -17,7 +17,7 @@ defmodule Plausible.Auth do from( e in Plausible.Event, join: s in Plausible.Site, - on: s.domain == e.hostname, + on: s.domain == e.domain, join: sm in Plausible.Site.Membership, on: sm.site_id == s.id, join: u in Plausible.Auth.User, diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex index b63a41129..283f85c30 100644 --- a/lib/plausible/billing/billing.ex +++ b/lib/plausible/billing/billing.ex @@ -101,7 +101,7 @@ defmodule Plausible.Billing do defp site_usage(site) do Repo.aggregate(from( e in Plausible.Event, - where: e.hostname == ^site.domain, + where: e.domain == ^site.domain, where: e.timestamp >= fragment("now() - '30 days'::interval") ), :count, :id) end diff --git a/lib/plausible/event/schema.ex b/lib/plausible/event/schema.ex index 0fbfaf6b9..e98c08516 100644 --- a/lib/plausible/event/schema.ex +++ b/lib/plausible/event/schema.ex @@ -4,6 +4,7 @@ defmodule Plausible.Event do schema "events" do field :name, :string + field :domain, :string field :hostname, :string field :pathname, :string field :new_visitor, :boolean @@ -21,7 +22,7 @@ defmodule Plausible.Event do def changeset(pageview, attrs) do pageview - |> cast(attrs, [:name, :hostname, :pathname, :referrer, :new_visitor, :user_id, :operating_system, :browser, :referrer_source, :country_code, :screen_size]) - |> validate_required([:name, :hostname, :pathname, :new_visitor, :user_id]) + |> cast(attrs, [:name, :domain, :hostname, :pathname, :referrer, :new_visitor, :user_id, :operating_system, :browser, :referrer_source, :country_code, :screen_size]) + |> validate_required([:name, :domain, :hostname, :pathname, :new_visitor, :user_id]) end end diff --git a/lib/plausible/ingest/session.ex b/lib/plausible/ingest/session.ex index cbc9dbb64..8394a1df1 100644 --- a/lib/plausible/ingest/session.ex +++ b/lib/plausible/ingest/session.ex @@ -48,6 +48,7 @@ defmodule Plausible.Ingest.Session do Plausible.Session.changeset(%Plausible.Session{}, %{ hostname: first_event.hostname, + domain: first_event.domain, user_id: first_event.user_id, new_visitor: first_event.new_visitor, entry_page: first_event.pathname, diff --git a/lib/plausible/session/schema.ex b/lib/plausible/session/schema.ex index ce2d108f2..858941ce0 100644 --- a/lib/plausible/session/schema.ex +++ b/lib/plausible/session/schema.ex @@ -4,6 +4,7 @@ defmodule Plausible.Session do schema "sessions" do field :hostname, :string + field :domain, :string field :new_visitor, :boolean field :user_id, :binary_id @@ -25,7 +26,7 @@ defmodule Plausible.Session do def changeset(session, attrs) do session - |> cast(attrs, [:hostname, :entry_page, :exit_page, :referrer, :new_visitor, :user_id, :start, :length, :is_bounce, :operating_system, :browser, :referrer_source, :country_code, :screen_size]) - |> validate_required([:hostname, :new_visitor, :user_id, :is_bounce, :start]) + |> cast(attrs, [:hostname, :domain, :entry_page, :exit_page, :referrer, :new_visitor, :user_id, :start, :length, :is_bounce, :operating_system, :browser, :referrer_source, :country_code, :screen_size]) + |> validate_required([:hostname, :domain, :new_visitor, :user_id, :is_bounce, :start]) end end diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.ex index 6ecf74818..f64cd19ed 100644 --- a/lib/plausible/sites.ex +++ b/lib/plausible/sites.ex @@ -14,7 +14,7 @@ defmodule Plausible.Sites do def has_pageviews?(site) do Repo.exists?( from e in Plausible.Event, - where: e.hostname == ^site.domain + where: e.domain == ^site.domain ) end diff --git a/lib/plausible/stats/stats.ex b/lib/plausible/stats/stats.ex index 6051455ea..7e7570d61 100644 --- a/lib/plausible/stats/stats.ex +++ b/lib/plausible/stats/stats.ex @@ -126,7 +126,7 @@ defmodule Plausible.Stats do {first_datetime, last_datetime} = date_range_utc_boundaries(query.date_range, site.timezone) sessions_query = from(s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.new_visitor, where: s.start >= ^first_datetime and s.start < ^last_datetime ) @@ -143,7 +143,7 @@ defmodule Plausible.Stats do {first_datetime, last_datetime} = date_range_utc_boundaries(query.date_range, site.timezone) Repo.one(from s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.start >= ^first_datetime and s.start < ^last_datetime, select: coalesce(avg(s.length), 0) ) |> Decimal.round |> Decimal.to_integer @@ -199,7 +199,7 @@ defmodule Plausible.Stats do total_sessions_by_referrer = Repo.all( from s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.new_visitor, where: s.start >= ^first_datetime and s.start < ^last_datetime, where: s.referrer_source in ^referrers, @@ -209,7 +209,7 @@ defmodule Plausible.Stats do bounced_sessions_by_referrer = Repo.all( from s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.new_visitor, where: s.start >= ^first_datetime and s.start < ^last_datetime, where: s.is_bounce, @@ -300,7 +300,7 @@ defmodule Plausible.Stats do total_sessions_by_url = Repo.all( from s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.new_visitor, where: s.start >= ^first_datetime and s.start < ^last_datetime, where: s.referrer in ^referring_urls, @@ -310,7 +310,7 @@ defmodule Plausible.Stats do bounced_sessions_by_url = Repo.all( from s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.new_visitor, where: s.start >= ^first_datetime and s.start < ^last_datetime, where: s.is_bounce, @@ -355,7 +355,7 @@ defmodule Plausible.Stats do total_sessions_by_url = Repo.all( from s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.new_visitor, where: s.start >= ^first_datetime and s.start < ^last_datetime, where: s.entry_page in ^page_urls, @@ -365,7 +365,7 @@ defmodule Plausible.Stats do bounced_sessions_by_url = Repo.all( from s in Plausible.Session, - where: s.hostname == ^site.domain, + where: s.domain == ^site.domain, where: s.new_visitor, where: s.start >= ^first_datetime and s.start < ^last_datetime, where: s.is_bounce, @@ -453,7 +453,7 @@ defmodule Plausible.Stats do Repo.one( from e in Plausible.Event, where: e.timestamp >= fragment("(now() at time zone 'utc') - '5 minutes'::interval"), - where: e.hostname == ^site.domain, + where: e.domain == ^site.domain, select: count(e.user_id, :distinct) ) end @@ -513,7 +513,7 @@ defmodule Plausible.Stats do {goal_event, path} = event_name_for_goal(query) q = from(e in Plausible.Event, - where: e.hostname == ^site.domain, + where: e.domain == ^site.domain, where: e.timestamp >= ^first_datetime and e.timestamp < ^last_datetime ) diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex index e37f49b65..6ae37ec63 100644 --- a/lib/plausible_web/controllers/api/external_controller.ex +++ b/lib/plausible_web/controllers/api/external_controller.ex @@ -50,6 +50,7 @@ defmodule PlausibleWeb.Api.ExternalController do event_attrs = %{ name: params["name"], hostname: strip_www(uri.host), + domain: params["domain"] || strip_www(uri.host), pathname: uri.path, new_visitor: params["new_visitor"], country_code: country_code, diff --git a/lib/plausible_web/controllers/api/internal_controller.ex b/lib/plausible_web/controllers/api/internal_controller.ex index 14c43cd7d..f4e3785f3 100644 --- a/lib/plausible_web/controllers/api/internal_controller.ex +++ b/lib/plausible_web/controllers/api/internal_controller.ex @@ -5,7 +5,7 @@ defmodule PlausibleWeb.Api.InternalController do def domain_status(conn, %{"domain" => domain}) do has_pageviews = Repo.exists?( from e in Plausible.Event, - where: e.hostname == ^domain + where: e.domain == ^domain ) if has_pageviews do diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 826b7c20d..029b3956c 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -208,6 +208,6 @@ defmodule PlausibleWeb.AuthController do site = Repo.get(Plausible.Site, site_id) - redirect(conn, to: "/#{site.domain}/settings#google-auth") + redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings#google-auth") end end diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index caa81e049..4a163c2f9 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -19,7 +19,7 @@ defmodule PlausibleWeb.SiteController do Plausible.Slack.notify("#{user.name} created #{site.domain}") conn |> put_session(site.domain <> "_offer_email_report", true) - |> redirect(to: "/#{site.domain}/snippet") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/snippet") {:error, :site, changeset, _} -> render(conn, "new.html", changeset: changeset) end @@ -52,7 +52,7 @@ defmodule PlausibleWeb.SiteController do {:ok, _} -> conn |> put_flash(:success, "Goal created succesfully") - |> redirect(to: "/#{website}/settings") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings") {:error, :goal, changeset, _} -> conn |> assign(:skip_plausible_tracking, true) @@ -69,7 +69,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Goal deleted succesfully") - |> redirect(to: "/#{website}/settings") + |> redirect(to: "/#{URI.encode_www_form(website)}/settings") end def settings(conn, %{"website" => website}) do @@ -107,7 +107,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Google integration saved succesfully") - |> redirect(to: "/#{site.domain}/settings") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#google-auth") end def update_settings(conn, %{"website" => website, "site" => site_params}) do @@ -122,7 +122,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_session(site_session_key, nil) |> put_flash(:success, "Site settings saved succesfully") - |> redirect(to: "/#{site.domain}/settings") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings") {:error, changeset} -> render("settings.html", site: site, changeset: changeset) end @@ -134,7 +134,7 @@ defmodule PlausibleWeb.SiteController do |> Repo.preload(:google_auth) Repo.delete_all(from sm in "site_memberships", where: sm.site_id == ^site.id) - Repo.delete_all(from e in "events", where: e.hostname == ^site.domain) + Repo.delete_all(from e in "events", where: e.domain == ^site.domain) if site.google_auth do Repo.delete!(site.google_auth) @@ -153,7 +153,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Congrats! Stats for #{site.domain} are now public.") - |> redirect(to: "/" <> site.domain <> "/settings") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings") end def make_private(conn, %{"website" => website}) do @@ -163,7 +163,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Stats for #{site.domain} are now private.") - |> redirect(to: "/" <> site.domain <> "/settings") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings") end def enable_weekly_report(conn, %{"website" => website}) do @@ -177,7 +177,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Success! You will receive an email report every Monday going forward") - |> redirect(to: "/" <> site.domain <> "/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def disable_weekly_report(conn, %{"website" => website}) do @@ -186,7 +186,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Success! You will not receive weekly email reports going forward") - |> redirect(to: "/" <> site.domain <> "/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def add_weekly_report_recipient(conn, %{"website" => website, "recipient" => recipient}) do @@ -198,7 +198,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Succesfully added #{recipient} as a recipient for the weekly report") - |> redirect(to: "/#{site.domain}/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def remove_weekly_report_recipient(conn, %{"website" => website, "recipient" => recipient}) do @@ -210,7 +210,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Succesfully removed #{recipient} as a recipient for the weekly report") - |> redirect(to: "/#{site.domain}/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def enable_monthly_report(conn, %{"website" => website}) do @@ -224,7 +224,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Success! You will receive an email report every month going forward") - |> redirect(to: "/" <> site.domain <> "/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def disable_monthly_report(conn, %{"website" => website}) do @@ -233,7 +233,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Success! You will not receive monthly email reports going forward") - |> redirect(to: "/" <> site.domain <> "/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def add_monthly_report_recipient(conn, %{"website" => website, "recipient" => recipient}) do @@ -245,7 +245,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Succesfully added #{recipient} as a recipient for the monthly report") - |> redirect(to: "/#{site.domain}/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def remove_monthly_report_recipient(conn, %{"website" => website, "recipient" => recipient}) do @@ -257,7 +257,7 @@ defmodule PlausibleWeb.SiteController do conn |> put_flash(:success, "Succesfully removed #{recipient} as a recipient for the monthly report") - |> redirect(to: "/#{site.domain}/settings#email-reports") + |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#email-reports") end def new_shared_link(conn, %{"website" => website}) do @@ -276,17 +276,18 @@ defmodule PlausibleWeb.SiteController do case Repo.insert(changes) do {:ok, _created} -> - redirect(conn, to: "/#{site.domain}/settings#visibility") + redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings#visibility") {:error, changeset} -> render(conn, "new_shared_link.html", site: site, changeset: changeset, layout: {PlausibleWeb.LayoutView, "focus.html"}) end end def delete_shared_link(conn, %{"website" => website, "slug" => slug}) do + site = Sites.get_for_user!(conn.assigns[:current_user].id, website) Repo.get_by(Plausible.Site.SharedLink, slug: slug) |> Repo.delete! - redirect(conn, to: "/#{website}/settings#visibility") + redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings#visibility") end defp insert_site(user_id, params) do diff --git a/lib/plausible_web/templates/page/sites.html.eex b/lib/plausible_web/templates/page/sites.html.eex index cc70bbc2b..87ac9d7db 100644 --- a/lib/plausible_web/templates/page/sites.html.eex +++ b/lib/plausible_web/templates/page/sites.html.eex @@ -7,10 +7,10 @@
<%= for site <- @sites do %>
- +

<%= site.domain %>

- <%= link(to: "/#{site.domain}/settings", class: "flex absolute hover:bg-grey-lighter transition rounded py-3 px-5", style: "top: 6px; right: 6px;") do %> + <%= link(to: "/#{URI.encode_www_form(site.domain)}/settings", class: "flex absolute hover:bg-grey-lighter transition rounded py-3 px-5", style: "top: 6px; right: 6px;") do %>
diff --git a/lib/plausible_web/templates/site/new_goal.html.eex b/lib/plausible_web/templates/site/new_goal.html.eex index cca8366fc..1186b2c66 100644 --- a/lib/plausible_web/templates/site/new_goal.html.eex +++ b/lib/plausible_web/templates/site/new_goal.html.eex @@ -1,4 +1,4 @@ -<%= form_for @changeset, "/#{@site.domain}/goals", [class: "max-w-sm w-full mx-auto bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %> +<%= form_for @changeset, "/#{URI.encode_www_form(@site.domain)}/goals", [class: "max-w-sm w-full mx-auto bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %>

Add goal for <%= @site.domain %>

Goal trigger
diff --git a/lib/plausible_web/templates/site/new_shared_link.html.eex b/lib/plausible_web/templates/site/new_shared_link.html.eex index f9146fd67..336335b70 100644 --- a/lib/plausible_web/templates/site/new_shared_link.html.eex +++ b/lib/plausible_web/templates/site/new_shared_link.html.eex @@ -1,4 +1,4 @@ -<%= form_for @changeset, "/sites/#{@site.domain}/shared-links", [class: "max-w-sm w-full mx-auto bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %> +<%= form_for @changeset, "/sites/#{URI.encode_www_form(@site.domain)}/shared-links", [class: "max-w-sm w-full mx-auto bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %>

New shared link

Add a password or leave it blank so anyone with the link can see the stats. diff --git a/lib/plausible_web/templates/site/settings.html.eex b/lib/plausible_web/templates/site/settings.html.eex index fdf2d3d16..d15b0ed47 100644 --- a/lib/plausible_web/templates/site/settings.html.eex +++ b/lib/plausible_web/templates/site/settings.html.eex @@ -1,6 +1,6 @@
@@ -9,7 +9,7 @@
- <%= form_for @changeset, "/#{@site.domain}/settings", [class: "max-w-xs"], fn f -> %> + <%= form_for @changeset, "/#{URI.encode_www_form(@site.domain)}/settings", [class: "max-w-xs"], fn f -> %>
<%= label f, :domain, class: "block text-grey-darker text-sm font-bold mb-2" %> <%= text_input f, :domain, class: "transition bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 text-grey-darker leading-normal appearance-none focus:outline-none focus:border-grey-light ", disabled: "disabled" %> @@ -37,18 +37,18 @@ <%= if @site.public do %> Stats for <%= @site.domain %> are currently public. Anyone with the following link can view the stats:
- +
- <%= button("Make stats private", to: "/sites/#{@site.domain}/make-private", method: "POST", class: "button mt-8") %> + <%= button("Make stats private", to: "/sites/#{URI.encode_www_form(@site.domain)}/make-private", method: "POST", class: "button mt-8") %> <% else %>
Stats for <%= @site.domain %> are currently private. You are the only person who can see them. If you choose to make your stats public, anyone with the link will be able to view them.
- <%= button("Make stats public", to: "/sites/#{@site.domain}/make-public", method: "POST", class: "button mt-8") %> + <%= button("Make stats public", to: "/sites/#{URI.encode_www_form(@site.domain)}/make-public", method: "POST", class: "button mt-8") %> <% end %>
@@ -67,14 +67,14 @@ - <%= button(to: "/sites/#{@site.domain}/shared-links/#{link.slug}", method: :delete, class: "py-2 px-4 bg-grey-lighter text-red-dark rounded-l-none", data: [confirm: "Are you sure you want to delete this shared link? The stats will not be accessible with this link anymore."]) do %> + <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/shared-links/#{link.slug}", method: :delete, class: "py-2 px-4 bg-grey-lighter text-red-dark rounded-l-none", data: [confirm: "Are you sure you want to delete this shared link? The stats will not be accessible with this link anymore."]) do %> <% end %>
<% end %>
- <%= link("+ New link", to: "/sites/#{@site.domain}/shared-links/new", class: "button mt-4") %> + <%= link("+ New link", to: "/sites/#{URI.encode_www_form(@site.domain)}/shared-links/new", class: "button mt-4") %>
@@ -85,7 +85,7 @@ <%= for goal <- @goals do %>
<%= goal_name(goal) %> - <%= button("❌", to: "/#{@site.domain}/goals/#{goal.id}", method: :delete, class: "text-sm", data: [confirm: "Are you sure you want to remove goal #{goal_name(goal)}? This will just affect the UI, all of your analytics data will stay intact."]) %> + <%= button("❌", to: "/#{URI.encode_www_form(@site.domain)}/goals/#{goal.id}", method: :delete, class: "text-sm", data: [confirm: "Are you sure you want to remove goal #{goal_name(goal)}? This will just affect the UI, all of your analytics data will stay intact."]) %>
<% end %> <% else %> @@ -93,7 +93,7 @@ <% end %>
- <%= link("+ Add goal", to: "/#{@site.domain}/goals/new", class: "button mt-6") %> + <%= link("+ Add goal", to: "/#{URI.encode_www_form(@site.domain)}/goals/new", class: "button mt-6") %>
@@ -120,7 +120,7 @@

<% end %> - <%= form_for Plausible.Site.GoogleAuth.changeset(@site.google_auth), "/#{@site.domain}/settings/google", [class: "max-w-xs"], fn f -> %> + <%= form_for Plausible.Site.GoogleAuth.changeset(@site.google_auth), "/#{URI.encode_www_form(@site.domain)}/settings/google", [class: "max-w-xs"], fn f -> %>
<%= select f, :property, @search_console_domains, prompt: "(Choose property)", class: "block appearance-none w-full bg-grey-lighter text-grey-darker cursor-pointer hover:border-grey p-2 pr-8 rounded leading-normal focus:outline-none" %> @@ -148,11 +148,11 @@
<%= if @weekly_report do %> - <%= button(to: "/sites/#{@site.domain}/weekly-report/disable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 bg-green justify-end") do %> + <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/weekly-report/disable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 bg-green justify-end") do %> <% end %> <% else %> - <%= button(to: "/sites/#{@site.domain}/weekly-report/enable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 justify-start") do %> + <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/weekly-report/enable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 justify-start") do %> <% end %> <% end %> @@ -164,10 +164,10 @@ <%= for recipient <- @weekly_report.recipients do %>
<%= recipient %> - <%= button("❌", to: "/sites/#{@site.domain}/weekly-report/recipients/#{recipient}", method: :delete) %> + <%= button("❌", to: "/sites/#{URI.encode_www_form(@site.domain)}/weekly-report/recipients/#{recipient}", method: :delete) %>
<% end %> - <%= form_for @conn, "/sites/#{@site.domain}/weekly-report/recipients", fn f -> %> + <%= form_for @conn, "/sites/#{URI.encode_www_form(@site.domain)}/weekly-report/recipients", fn f -> %>
<%= email_input f, :recipient, class: "transition bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 text-grey-darker leading-normal appearance-none focus:outline-none focus:border-grey-light", style: "flex-grow: 2", placeholder: "recipient@example.com" %> <%= submit "Add recipient", class: "button rounded-l-none whitespace-no-wrap" %> @@ -178,11 +178,11 @@
<%= if @monthly_report do %> - <%= button(to: "/sites/#{@site.domain}/monthly-report/disable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 bg-green justify-end") do %> + <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/monthly-report/disable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 bg-green justify-end") do %> <% end %> <% else %> - <%= button(to: "/sites/#{@site.domain}/monthly-report/enable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 justify-start") do %> + <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/monthly-report/enable", method: :post, class: "border rounded-full border-grey flex items-center cursor-pointer w-8 justify-start") do %> <% end %> <% end %> @@ -194,10 +194,10 @@ <%= for recipient <- @monthly_report.recipients do %>
<%= recipient %> - <%= button("❌", to: "/sites/#{@site.domain}/monthly-report/recipients/#{recipient}", method: :delete) %> + <%= button("❌", to: "/sites/#{URI.encode_www_form(@site.domain)}/monthly-report/recipients/#{recipient}", method: :delete) %>
<% end %> - <%= form_for @conn, "/sites/#{@site.domain}/monthly-report/recipients", fn f -> %> + <%= form_for @conn, "/sites/#{URI.encode_www_form(@site.domain)}/monthly-report/recipients", fn f -> %>
<%= email_input f, :recipient, class: "transition bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 text-grey-darker leading-normal appearance-none focus:outline-none focus:border-grey-light", style: "flex-grow: 2", placeholder: "recipient@example.com" %> <%= submit "Add recipient", class: "button rounded-l-none whitespace-no-wrap" %> @@ -234,5 +234,5 @@

Deleting the site removes all stats you've collected

- <%= link "Delete #{@site.domain}", to: "/#{@site.domain}", method: :delete, class: "button bg-red-dark mt-4", data: [confirm: "Deleting the site data cannot be reversed. Are you sure?"] %> + <%= link "Delete #{@site.domain}", to: "/#{URI.encode_www_form(@site.domain)}", method: :delete, class: "button bg-red-dark mt-4", data: [confirm: "Deleting the site data cannot be reversed. Are you sure?"] %>
diff --git a/lib/plausible_web/templates/site/snippet.html.eex b/lib/plausible_web/templates/site/snippet.html.eex index 5d02fe4a5..489e29bd8 100644 --- a/lib/plausible_web/templates/site/snippet.html.eex +++ b/lib/plausible_web/templates/site/snippet.html.eex @@ -15,5 +15,5 @@ <%= link("Read the docs", class: "text-indigo hover:underline", to: "https://docs.plausible.io/single-page-application-support", target: "_blank") %>
- <%= link("Start collecting data →", class: "button mt-4 w-full", to: "/#{@site.domain}") %> + <%= link("Start collecting data →", class: "button mt-4 w-full", to: "/#{URI.encode_www_form(@site.domain)}") %> <% end %> diff --git a/lib/plausible_web/templates/stats/stats.html.eex b/lib/plausible_web/templates/stats/stats.html.eex index bc63fd612..fb05abf9a 100644 --- a/lib/plausible_web/templates/stats/stats.html.eex +++ b/lib/plausible_web/templates/stats/stats.html.eex @@ -1,7 +1,7 @@
<%= if @offer_email_report do %> <% end %>
diff --git a/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex b/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex index 16d42bd40..f2a53b00a 100644 --- a/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex +++ b/lib/plausible_web/templates/stats/waiting_first_pageview.html.eex @@ -1,7 +1,7 @@