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
Use db-ip lite database for countries (#906)
Uku Taht83a759c60a20
diff --git a/.gitignore b/.gitignoreindex 9a60ff83f5..3f5eff64fa 100644--- a/.gitignore+++ b/.gitignore@@ -36,7 +36,7 @@ npm-debug.log# we ignore priv/static. You may want to comment# this depending on your deployment strategy./priv/static/-/priv/geolix/+/priv/geodb/# Files matching config/*.secret.exs pattern contain sensitive# data and you should not commit them into version control.@@ -58,4 +58,4 @@ plausible-report.xml# Dializer/priv/plts/*.plt-/priv/plts/*.plt.hash\ No newline at end of file+/priv/plts/*.plt.hashdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex f16547d067..e3cd89d491 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.- Site switching keybinds (1-9 for respective sites) plausible/analytics#735- Glob (wildcard) based pageview goals plausible/analytics#750- Support for embedding shared links in an iframe plausible/analytics#812+- Include a basic IP-To-Country database by default plausible/analytics#906- Add name/label to shared links plausible/analytics#910### Fixeddiff --git a/assets/js/dashboard/mount.js b/assets/js/dashboard/mount.jsindex c42dbc1996..db86a5b181 100644--- a/assets/js/dashboard/mount.js+++ b/assets/js/dashboard/mount.js@@ -15,7 +15,8 @@ if (container) {hasGoals: container.dataset.hasGoals === 'true',insertedAt: container.dataset.insertedAt,embedded: container.dataset.embedded,- background: container.dataset.background+ background: container.dataset.background,+ selfhosted: container.dataset.selfhosted === 'true'}const loggedIn = container.dataset.loggedIn === 'true'diff --git a/assets/js/dashboard/stats/countries.js b/assets/js/dashboard/stats/countries.jsindex 576a62faca..20dd363d0a 100644--- a/assets/js/dashboard/stats/countries.js+++ b/assets/js/dashboard/stats/countries.js@@ -125,13 +125,22 @@ class Countries extends React.Component {});}+ geolocationDbNotice() {+ if (this.props.site.selfhosted) {+ return (+ <span className="text-xs text-gray-500 absolute bottom-4 right-3">IP Geolocation by <a target="_blank" href="https://db-ip.com" className="text-indigo-600">DB-IP</a></span>+ )+ }+ }+renderBody() {if (this.state.countries) {return (<React.Fragment><h3 className="font-bold dark:text-gray-100">Countries</h3>- <div className="mx-auto mt-6" style={{width: '100%', maxWidth: '475px', height: '320px'}} id="map-container"></div>+ <div className="mx-auto mt-6" style={{width: '100%', maxWidth: '475px', height: '335px'}} id="map-container"></div><MoreLink site={this.props.site} list={this.state.countries} endpoint="countries" />+ { this.geolocationDbNotice() }</React.Fragment>)}diff --git a/config/runtime.exs b/config/runtime.exsindex bdd58fef96..57cdfeec77 100644--- a/config/runtime.exs+++ b/config/runtime.exs@@ -56,7 +56,7 @@ cron_enabled = String.to_existing_atom(System.get_env("CRON_ENABLED", "false"))custom_domain_server_ip = System.get_env("CUSTOM_DOMAIN_SERVER_IP")custom_domain_server_user = System.get_env("CUSTOM_DOMAIN_SERVER_USER")custom_domain_server_password = System.get_env("CUSTOM_DOMAIN_SERVER_PASSWORD")-geolite2_country_db = System.get_env("GEOLITE2_COUNTRY_DB")+geolite2_country_db = System.get_env("EOLITE2_COUNTRY_DB", "priv/geodb/dbip-country.mmdb")disable_auth = String.to_existing_atom(System.get_env("DISABLE_AUTH", "false"))disable_registration = String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false"))hcaptcha_sitekey = System.get_env("HCAPTCHA_SITEKEY")@@ -243,7 +243,7 @@ config :kaffy,]]-if geolite2_country_db do+if config_env() != :test && geolite2_country_db doconfig :geolix,databases: [%{diff --git a/lib/mix/tasks/download_country_database.ex b/lib/mix/tasks/download_country_database.exnew file mode 100644index 0000000000..d6e63e34fd--- /dev/null+++ b/lib/mix/tasks/download_country_database.ex@@ -0,0 +1,38 @@+defmodule Mix.Tasks.DownloadCountryDatabase do+ use Mix.Task+ use Plausible.Repo+ require Logger++ # coveralls-ignore-start++ def run(_) do+ Application.ensure_all_started(:httpoison)+ Application.ensure_all_started(:timex)+ this_month = Timex.today()+ last_month = Timex.shift(this_month, months: -1)+ this_month = this_month |> Date.to_iso8601() |> binary_part(0, 7)+ last_month = last_month |> Date.to_iso8601() |> binary_part(0, 7)+ this_month_url = "https://download.db-ip.com/free/dbip-country-lite-#{this_month}.mmdb.gz"+ last_month_url = "https://download.db-ip.com/free/dbip-country-lite-#{last_month}.mmdb.gz"+ Logger.info("Downloading #{this_month_url}")+ res = HTTPoison.get!(this_month_url)++ res =+ case res.status_code do+ 404 ->+ Logger.info("Got 404 for #{this_month_url}, trying #{last_month_url}")+ HTTPoison.get!(last_month_url)++ _ ->+ res+ end++ if res.status_code == 200 do+ File.mkdir("priv/geodb")+ File.write!("priv/geodb/dbip-country.mmdb", res.body)+ Logger.info("Downloaded and saved the database successfully")+ else+ Logger.error("Unable to download and save the database. Response: #{inspect(res)}")+ end+ end+enddiff --git a/lib/plausible_web/templates/stats/stats.html.eex b/lib/plausible_web/templates/stats/stats.html.eexindex 8fd38ad8fa..f6a9212f1e 100644--- a/lib/plausible_web/templates/stats/stats.html.eex+++ b/lib/plausible_web/templates/stats/stats.html.eex@@ -5,7 +5,7 @@</div><% end %><div class="pt-6"></div>- <div id="stats-react-container" data-domain="<%= @site.domain %>" data-offset="<%= Timex.Timezone.total_offset(Timex.Timezone.get(@site.timezone)) %>" data-has-goals="<%= @has_goals %>" data-logged-in="<%= [email protected][:current_user] %>" data-inserted-at="<%= @site.inserted_at %>" data-shared-link-auth="<%= assigns[:shared_link_auth] %>" data-embedded="<%= @conn.assigns[:embedded] %>" data-background="<%= @conn.assigns[:background] %>"></div>+ <div id="stats-react-container" data-domain="<%= @site.domain %>" data-offset="<%= Timex.Timezone.total_offset(Timex.Timezone.get(@site.timezone)) %>" data-has-goals="<%= @has_goals %>" data-logged-in="<%= [email protected][:current_user] %>" data-inserted-at="<%= @site.inserted_at %>" data-shared-link-auth="<%= assigns[:shared_link_auth] %>" data-embedded="<%= @conn.assigns[:embedded] %>" data-background="<%= @conn.assigns[:background] %>" data-selfhosted="<%= Application.get_env(:plausible, :is_selfhost) %>"></div><div id="modal_root"></div><%= if [email protected][:current_user] && @conn.assigns[:demo] do %><div class="bg-gray-50 dark:bg-gray-850">