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
Improve report icons and add dark mode support (#6673)
Sanne de Vries04ed48c1f6c1
diff --git a/assets/js/dashboard/components/site-icon.tsx b/assets/js/dashboard/components/site-icon.tsxindex eee0d6e4d7..16d3644004 100644--- a/assets/js/dashboard/components/site-icon.tsx+++ b/assets/js/dashboard/components/site-icon.tsx@@ -51,7 +51,7 @@ export const ConsolidatedViewIcon = () => (height="19"rx="4.5"fill="none"- strokeWidth="1.8"+ strokeWidth="1.5"className="stroke-white/15"/><g@@ -60,7 +60,7 @@ export const ConsolidatedViewIcon = () => (stroke="currentColor"strokeLinecap="round"strokeLinejoin="round"- strokeWidth="1.8"+ strokeWidth="1.5"><path d="M22 12H2M12 22c5.714-5.442 5.714-14.558 0-20M12 22C6.286 16.558 6.286 7.442 12 2" /><path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z" />diff --git a/assets/js/dashboard/stats/devices/icons.tsx b/assets/js/dashboard/stats/devices/icons.tsxindex cb2e0bd312..32d3a43810 100644--- a/assets/js/dashboard/stats/devices/icons.tsx+++ b/assets/js/dashboard/stats/devices/icons.tsx@@ -1,4 +1,21 @@-import React, { ReactNode } from 'react'+import React, { ReactElement } from 'react'++const ICON_CLASS = 'shrink-0 inline-block size-4 mr-2'++const SVG_ICON_COLOR_CLASS = 'text-gray-600 dark:text-gray-300'++// The icons that are not brand logos are inlined so that they follow the+// current text color, supporting light and dark mode.+const SHARED_SVG_PROPS = {+ xmlns: 'http://www.w3.org/2000/svg',+ viewBox: '0 0 24 24',+ fill: 'none',+ stroke: 'currentColor',+ strokeWidth: 1.5,+ strokeLinecap: 'round',+ strokeLinejoin: 'round',+ className: `${ICON_CLASS} ${SVG_ICON_COLOR_CLASS}`+} as const// Icons copied from https://github.com/alrra/browser-logosconst BROWSER_ICONS: Record<string, string> = {@@ -22,13 +39,26 @@ const BROWSER_ICONS: Record<string, string> = {'vivo Browser': 'vivo.png'}+const BrowserFallbackIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}>+ <path d="M12 22c2.21 0 4-4.477 4-10S14.21 2 12 2 8 6.477 8 12s1.79 10 4 10Z" />+ <path d="M2 12h20" />+ <path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z" />+ </svg>+)+export const BrowserIcon = ({ dimensionValue }: { dimensionValue: string }) => {- const filename = BROWSER_ICONS[dimensionValue] ?? 'fallback.svg'+ const filename = BROWSER_ICONS[dimensionValue]++ if (!filename) {+ return <BrowserFallbackIconSvg />+ }+return (<imgalt=""src={`/images/icon/browser/${filename}`}- className="inline-block w-4 h-4 mr-2"+ className={ICON_CLASS}/>)}@@ -53,39 +83,34 @@ const OS_ICONS: Record<string, string> = {FreeBSD: 'freebsd.png'}+const OsFallbackIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}>+ <path d="M4 20.818h16a2 2 0 0 0 2-2v-4.73q0-.18-.032-.355l-2.38-9.087A2 2 0 0 0 17.617 3H6.382a2 2 0 0 0-1.968 1.646l-2.381 9.087a2 2 0 0 0-.032.355v4.73a2 2 0 0 0 2 2M22 13.91H2" />+ <path strokeWidth={2.5} d="M6.092 17.328v-.01M10.182 17.328v-.01" />+ </svg>+)+export const OsIcon = ({ dimensionValue }: { dimensionValue: string }) => {- const filename = OS_ICONS[dimensionValue] ?? 'fallback.svg'+ const filename = OS_ICONS[dimensionValue]++ if (!filename) {+ return <OsFallbackIconSvg />+ }+return (- <img- alt=""- src={`/images/icon/os/${filename}`}- className="inline-block w-4 h-4 mr-2"- />+ <img alt="" src={`/images/icon/os/${filename}`} className={ICON_CLASS} />)}-const SHARED_SCREEN_SIZE_SVG_PROPS = {- xmlns: 'http://www.w3.org/2000/svg',- width: 24,- height: 24,- viewBox: '0 0 24 24',- fill: 'none',- stroke: 'currentColor',- strokeWidth: 2,- strokeLinecap: 'round',- strokeLinejoin: 'round',- className: '-mt-px feather inline-block'-} as const--export const MobileScreenIconSvg = () => (- <svg {...SHARED_SCREEN_SIZE_SVG_PROPS}>+const MobileScreenIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}><rect x="5" y="2" width="14" height="20" rx="2" ry="2" />- <line x1="12" y1="18" x2="12" y2="18" />+ <line strokeWidth={2.5} x1="12" y1="18" x2="12" y2="18" /></svg>)-export const TabletScreenIconSvg = () => (- <svg {...SHARED_SCREEN_SIZE_SVG_PROPS}>+const TabletScreenIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}><rectx="4"y="2"@@ -95,42 +120,42 @@ export const TabletScreenIconSvg = () => (ry="2"transform="rotate(180 12 12)"/>- <line x1="12" y1="18" x2="12" y2="18" />+ <line strokeWidth={2.5} x1="12" y1="18" x2="12" y2="18" /></svg>)-export const LaptopScreenIconSvg = () => (- <svg {...SHARED_SCREEN_SIZE_SVG_PROPS}>+const LaptopScreenIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}><rect x="2" y="3" width="20" height="14" rx="2" ry="2" /><line x1="2" y1="20" x2="22" y2="20" /></svg>)-export const DesktopScreenIconSvg = () => (- <svg {...SHARED_SCREEN_SIZE_SVG_PROPS}>+const DesktopScreenIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}><rect x="2" y="3" width="20" height="14" rx="2" ry="2" /><line x1="8" y1="21" x2="16" y2="21" /><line x1="12" y1="17" x2="12" y2="21" /></svg>)-export const UltraWideScreenIconSvg = () => (- <svg {...SHARED_SCREEN_SIZE_SVG_PROPS}>+const UltraWideScreenIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}><rect x="1" y="4" width="22" height="12" rx="2" ry="2" /><line x1="6" y1="20" x2="18" y2="20" /><line x1="12" y1="16" x2="12" y2="20" /></svg>)-export const NotSetScreenIconSvg = () => (- <svg {...SHARED_SCREEN_SIZE_SVG_PROPS}>- <circle cx="12" cy="12" r="10" />- <circle cx="12" cy="17.25" r="1.25" />- <path d="M9.244 8.369c.422-1.608 1.733-2.44 3.201-2.364 1.45.075 2.799.872 2.737 2.722-.089 2.63-2.884 2.273-3.197 4.773h.011" />+const NotSetScreenIconSvg = () => (+ <svg {...SHARED_SVG_PROPS}>+ <path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z" />+ <path d="M9 10a3 3 0 1 1 6 0c0 1.31-.839 2.11-2.008 2.389-.538.128-.992.559-.992 1.111" />+ <path strokeWidth={2.5} d="M12 17.01V17" /></svg>)-const SCREEN_SIZE_SVGS: Record<string, ReactNode> = {+const SCREEN_SIZE_SVGS: Record<string, ReactElement> = {Mobile: <MobileScreenIconSvg />,Tablet: <TabletScreenIconSvg />,Laptop: <LaptopScreenIconSvg />,@@ -143,4 +168,4 @@ export const ScreenSizeIcon = ({dimensionValue}: {dimensionValue: string-}) => <span className="mr-1.5">{SCREEN_SIZE_SVGS[dimensionValue] ?? null}</span>+}) => SCREEN_SIZE_SVGS[dimensionValue] ?? nulldiff --git a/assets/js/dashboard/stats/reports/index-breakdown.tsx b/assets/js/dashboard/stats/reports/index-breakdown.tsxindex d21069ba9a..6afbf8eac3 100644--- a/assets/js/dashboard/stats/reports/index-breakdown.tsx+++ b/assets/js/dashboard/stats/reports/index-breakdown.tsx@@ -587,7 +587,7 @@ export const Bar = ({)}style={{ width: `${barWidthPercent}%` }}></div>- <div className="px-2 py-1.5 text-sm dark:text-gray-300 relative z-9 break-all">+ <div className="px-2 py-1.5 text-sm text-gray-800 dark:text-gray-200 relative z-9 break-all">{children}</div></div>diff --git a/assets/js/dashboard/stats/sources/source-favicon.tsx b/assets/js/dashboard/stats/sources/source-favicon.tsxindex 9c0bdd0082..84e20fa3cd 100644--- a/assets/js/dashboard/stats/sources/source-favicon.tsx+++ b/assets/js/dashboard/stats/sources/source-favicon.tsx@@ -1,5 +1,6 @@import React from 'react'import classNames from 'classnames'+import { useTheme } from '../../theme-context'interface SourceFaviconProps {name: string@@ -7,6 +8,7 @@ interface SourceFaviconProps {}export const SourceFavicon = ({ name, className }: SourceFaviconProps) => {+ const { mode } = useTheme()const sourceName = name.toLowerCase()const needsWhiteBg =sourceName.includes('github') || sourceName.includes('chatgpt.com')@@ -14,7 +16,7 @@ export const SourceFavicon = ({ name, className }: SourceFaviconProps) => {return (<imgalt=""- src={`/favicon/sources/${encodeURIComponent(name)}`}+ src={`/favicon/sources/${encodeURIComponent(name)}?ui-mode=${mode}`}referrerPolicy="no-referrer"className={classNames(className,diff --git a/lib/plausible_web/plugs/favicon.ex b/lib/plausible_web/plugs/favicon.exindex d490d1883a..08173ac65e 100644--- a/lib/plausible_web/plugs/favicon.ex+++ b/lib/plausible_web/plugs/favicon.ex@@ -33,6 +33,10 @@ defmodule PlausibleWeb.Favicon do@source_placeholder_icon File.read!(@source_placeholder_icon_location)@external_resource @source_placeholder_icon_location+ @source_dark_placeholder_icon_location "priv/link_favicon_dark.svg"+ @source_dark_placeholder_icon File.read!(@source_dark_placeholder_icon_location)+ @external_resource @source_dark_placeholder_icon_location+@site_placeholder_icon_location "priv/site_favicon_placeholder.svg"@site_placeholder_icon File.read!(@site_placeholder_icon_location)@external_resource @site_placeholder_icon_location@@ -96,9 +100,11 @@ defmodule PlausibleWeb.Favicon do- `site` is `#{@site_placeholder_icon_location}`, a globe on a rounded greybackground, for the rows that list sites.- `?ui-mode=light|dark` picks the colours and defaults to `light`. An SVG served- as an image cannot see the `dark` class on the page, so the caller must say- which mode it needs.+ `?ui-mode=light|dark` picks the colours and defaults to `light`. Each+ placeholder has its own dark drawing, `#{@source_dark_placeholder_icon_location}`+ and `#{@site_dark_placeholder_icon_location}`. An SVG served as an image+ cannot see the `dark` class on the page, so the caller must say which mode it+ needs.DuckDuckGo favicon service has some issues with [SVG favicons](https://css-tricks.com/svg-favicons-and-all-the-fun-things-we-can-do-with-them/).For some reason, they return them with `content-type=image/x-icon` whereas SVG@@ -166,6 +172,7 @@ defmodule PlausibleWeb.Favicon dodefp placeholder_icon("site", "dark"), do: @site_dark_placeholder_icondefp placeholder_icon("site", _ui_mode), do: @site_placeholder_icon+ defp placeholder_icon(_source, "dark"), do: @source_dark_placeholder_icondefp placeholder_icon(_source, _ui_mode), do: @source_placeholder_icon@forwarded_headers ["content-type", "cache-control", "expires"]diff --git a/priv/link_favicon.svg b/priv/link_favicon.svgindex 7a9008b2ba..7cdb6ec187 100644--- a/priv/link_favicon.svg+++ b/priv/link_favicon.svg@@ -1 +1 @@-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="#71717a"><path d="M12.232 4.232a2.5 2.5 0 0 1 3.536 3.536l-1.225 1.224a.75.75 0 0 0 1.061 1.06l1.224-1.224a4 4 0 0 0-5.656-5.656l-3 3a4 4 0 0 0 .225 5.865.75.75 0 0 0 .977-1.138 2.5 2.5 0 0 1-.142-3.667l3-3Z"></path><path d="M11.603 7.963a.75.75 0 0 0-.977 1.138 2.5 2.5 0 0 1 .142 3.667l-3 3a2.5 2.5 0 0 1-3.536-3.536l1.225-1.224a.75.75 0 0 0-1.061-1.06l-1.224 1.224a4 4 0 1 0 5.656 5.656l3-3a4 4 0 0 0-.225-5.865Z"></path></svg>\ No newline at end of file+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#52525c" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M13.22 8.603a4.615 4.615 0 0 1 1.274 7.43L9.88 20.648a4.616 4.616 0 0 1-6.527-6.527l1.802-1.802m13.692-.638 1.802-1.802a4.616 4.616 0 0 0-6.527-6.527L9.506 7.967a4.615 4.615 0 0 0 1.274 7.43"></path></svg>diff --git a/priv/link_favicon_dark.svg b/priv/link_favicon_dark.svgnew file mode 100644index 0000000000..26e4ff3c10--- /dev/null+++ b/priv/link_favicon_dark.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#d4d4d8" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M13.22 8.603a4.615 4.615 0 0 1 1.274 7.43L9.88 20.648a4.616 4.616 0 0 1-6.527-6.527l1.802-1.802m13.692-.638 1.802-1.802a4.616 4.616 0 0 0-6.527-6.527L9.506 7.967a4.615 4.615 0 0 0 1.274 7.43"></path></svg>diff --git a/priv/site_favicon_placeholder.svg b/priv/site_favicon_placeholder.svgindex a4334cd7a5..2fde208c7f 100644--- a/priv/site_favicon_placeholder.svg+++ b/priv/site_favicon_placeholder.svg@@ -1 +1 @@-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect width="20" height="20" rx="5" fill="#f4f4f5"></rect><rect x=".5" y=".5" width="19" height="19" rx="4.5" fill="none" stroke="#71717b" stroke-width="1.8" stroke-opacity=".1"></rect><g transform="translate(3 3) scale(.5833)" fill="none" stroke="#71717b" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"><path d="M22 12H2M12 22c5.714-5.442 5.714-14.558 0-20M12 22C6.286 16.558 6.286 7.442 12 2"></path><path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z"></path></g></svg>+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect width="20" height="20" rx="5" fill="#f4f4f5"></rect><rect x=".5" y=".5" width="19" height="19" rx="4.5" fill="none" stroke="#71717b" stroke-width="1.5" stroke-opacity=".1"></rect><g transform="translate(3 3) scale(.5833)" fill="none" stroke="#71717b" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M22 12H2M12 22c5.714-5.442 5.714-14.558 0-20M12 22C6.286 16.558 6.286 7.442 12 2"></path><path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z"></path></g></svg>diff --git a/priv/site_favicon_placeholder_dark.svg b/priv/site_favicon_placeholder_dark.svgindex 5aec4931dd..95d7aac63b 100644--- a/priv/site_favicon_placeholder_dark.svg+++ b/priv/site_favicon_placeholder_dark.svg@@ -1 +1 @@-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect width="20" height="20" rx="5" fill="#3f3f47"></rect><rect x=".5" y=".5" width="19" height="19" rx="4.5" fill="none" stroke="#ffffff" stroke-width="1.8" stroke-opacity=".1"></rect><g transform="translate(3 3) scale(.5833)" fill="none" stroke="#D4D4D8" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"><path d="M22 12H2M12 22c5.714-5.442 5.714-14.558 0-20M12 22C6.286 16.558 6.286 7.442 12 2"></path><path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z"></path></g></svg>+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect width="20" height="20" rx="5" fill="#3f3f47"></rect><rect x=".5" y=".5" width="19" height="19" rx="4.5" fill="none" stroke="#ffffff" stroke-width="1.5" stroke-opacity=".1"></rect><g transform="translate(3 3) scale(.5833)" fill="none" stroke="#D4D4D8" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M22 12H2M12 22c5.714-5.442 5.714-14.558 0-20M12 22C6.286 16.558 6.286 7.442 12 2"></path><path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z"></path></g></svg>diff --git a/priv/static/images/icon/browser/fallback.svg b/priv/static/images/icon/browser/fallback.svgdeleted file mode 100644index 4cd3e78e9b..0000000000--- a/priv/static/images/icon/browser/fallback.svg+++ /dev/null@@ -1,3 +0,0 @@-<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="#64748b" class="size-6">- <path stroke-linecap="round" stroke-linejoin="round" d="M12 21a9.004 9.004 0 0 0 8.716-6.747M12 21a9.004 9.004 0 0 1-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 0 1 7.843 4.582M12 3a8.997 8.997 0 0 0-7.843 4.582m15.686 0A11.953 11.953 0 0 1 12 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0 1 21 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0 1 12 16.5c-3.162 0-6.133-.815-8.716-2.247m0 0A9.015 9.015 0 0 1 3 12c0-1.605.42-3.113 1.157-4.418" />-</svg>diff --git a/priv/static/images/icon/os/fallback.svg b/priv/static/images/icon/os/fallback.svgdeleted file mode 100644index fd01eec9e3..0000000000--- a/priv/static/images/icon/os/fallback.svg+++ /dev/null@@ -1,3 +0,0 @@-<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="#64748b" class="size-6">- <path stroke-linecap="round" stroke-linejoin="round" d="M21.75 17.25v-.228a4.5 4.5 0 0 0-.12-1.03l-2.268-9.64a3.375 3.375 0 0 0-3.285-2.602H7.923a3.375 3.375 0 0 0-3.285 2.602l-2.268 9.64a4.5 4.5 0 0 0-.12 1.03v.228m19.5 0a3 3 0 0 1-3 3H5.25a3 3 0 0 1-3-3m19.5 0a3 3 0 0 0-3-3H5.25a3 3 0 0 0-3 3m16.5 0h.008v.008h-.008v-.008Zm-3 0h.008v.008h-.008v-.008Z" />-</svg>diff --git a/test/plausible_web/plugs/favicon_test.exs b/test/plausible_web/plugs/favicon_test.exsindex de5c191282..9a360138cb 100644--- a/test/plausible_web/plugs/favicon_test.exs+++ b/test/plausible_web/plugs/favicon_test.exs@@ -173,6 +173,7 @@ defmodule PlausibleWeb.FaviconTest dodescribe "Fallback to placeholder icon" do@source_placeholder_icon File.read!("priv/link_favicon.svg")+ @source_dark_placeholder_icon File.read!("priv/link_favicon_dark.svg")@site_placeholder_icon File.read!("priv/site_favicon_placeholder.svg")@site_dark_placeholder_icon File.read!("priv/site_favicon_placeholder_dark.svg")@@ -233,6 +234,24 @@ defmodule PlausibleWeb.FaviconTest doassert conn.resp_body == @source_placeholder_iconend+ test "falls back to the dark source placeholder when requested", %{plug_opts: plug_opts} do+ expect(+ Plausible.HTTPClient.Mock,+ :get,+ fn "https://icons.duckduckgo.com/ip3/plausible.io.ico" ->+ {:error, %Finch.TransportError{reason: :closed}}+ end+ )++ conn =+ conn(:get, "/favicon/sources/plausible.io?ui-mode=dark")+ |> Favicon.call(plug_opts)++ assert conn.halted+ assert conn.status == 200+ assert conn.resp_body == @source_dark_placeholder_icon+ end+test "falls back to the site placeholder when requested", %{plug_opts: plug_opts} doexpect(Plausible.HTTPClient.Mock,@@ -299,6 +318,16 @@ defmodule PlausibleWeb.FaviconTest doassert conn.resp_body == @source_placeholder_iconend+ test "serves the dark source placeholder on its own URL", %{plug_opts: plug_opts} do+ conn =+ conn(:get, "/favicon/placeholders/source?ui-mode=dark")+ |> Favicon.call(plug_opts)++ assert conn.halted+ assert conn.status == 200+ assert conn.resp_body == @source_dark_placeholder_icon+ end+test "serves a favicon for a source named placeholder", %{plug_opts: plug_opts} doexpect(Plausible.HTTPClient.Mock,