📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Display Impressions, Position and CTR metrics
Blue Mouse315901fe67e2
diff --git a/backend/apps/cloud/src/project/gsc.service.ts b/backend/apps/cloud/src/project/gsc.service.tsindex c4a566997..23d84b8e2 100644--- a/backend/apps/cloud/src/project/gsc.service.ts+++ b/backend/apps/cloud/src/project/gsc.service.ts@@ -230,7 +230,15 @@ export class GSCService {pid: string,from: string,to: string,- ): Promise<{ name: string; count: number }[]> {+ ): Promise<+ {+ name: string+ count: number+ impressions: number+ position: number+ ctr: number+ }[]+ > {const tokens = await this.getStoredTokens(pid)if (_isEmpty(tokens) || _isEmpty(tokens.property_uri)) {throw new BadRequestException(@@ -260,11 +268,17 @@ export class GSCService {const rows = (data.rows || []) as Array<{keys: string[]clicks?: number+ impressions?: number+ ctr?: number+ position?: number}>return rows.map(row => ({name: row.keys?.[0] || '(not set)',count: Math.round(row.clicks || 0),+ impressions: Math.round(row.impressions || 0),+ position: Number(Number(row.position || 0).toFixed(2)),+ ctr: Number(Number((row.ctr || 0) * 100).toFixed(2)), // return CTR in percent})).filter(Boolean)} catch {diff --git a/web/app/api/index.ts b/web/app/api/index.tsindex 1ab6a451f..f3ae6aca4 100644--- a/web/app/api/index.ts+++ b/web/app/api/index.ts@@ -1576,7 +1576,11 @@ export const getGSCKeywords = (.get(`log/keywords?pid=${pid}&period=${period}&from=${from}&to=${to}&timezone=${timezone}`, {headers: { 'x-password': password },})- .then((response): { keywords: { name: string; count: number }[] } => response.data)+ .then(+ (response): {+ keywords: { name: string; count: number; impressions: number; position: number; ctr: number }[]+ } => response.data,+ ).catch((error) => {throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message})diff --git a/web/app/pages/Project/View/Panels.tsx b/web/app/pages/Project/View/Panels.tsxindex 09195ae98..821755656 100644--- a/web/app/pages/Project/View/Panels.tsx+++ b/web/app/pages/Project/View/Panels.tsx@@ -881,6 +881,14 @@ interface PanelProps {highlightColour?: 'blue' | 'red' | 'orange'// When true, rows are non-interactive (no hover state, no filter link/navigation)disableRowClick?: boolean+ // Details modal specific overrides+ hidePercentageInDetails?: boolean+ detailsExtraColumns?: Array<{+ header: string+ render: (entry: Entry) => React.ReactNode+ sortLabel: string+ getSortValue: (entry: Entry) => number+ }>}interface DetailsTableProps@@ -899,6 +907,13 @@ interface DetailsTablePropstotal: numbercloseDetails: () => voiddisableRowClick?: boolean+ hidePercentageInDetails?: boolean+ detailsExtraColumns?: Array<{+ header: string+ render: (entry: Entry) => React.ReactNode+ sortLabel: string+ getSortValue: (entry: Entry) => number+ }>}const DetailsTable = ({@@ -914,6 +929,8 @@ const DetailsTable = ({activeTabId,closeDetails,disableRowClick,+ hidePercentageInDetails,+ detailsExtraColumns,}: DetailsTableProps) => {const {t,@@ -966,40 +983,36 @@ const DetailsTable = ({})const onSortBy = (label: string) => {+ const getValue = (entry: Entry): number | string => {+ if (label === 'quantity') return entry.count+ if (label === 'name') return entry.name+ const extra = detailsExtraColumns?.find((c) => c.sortLabel === label)+ if (extra) return extra.getSortValue(entry)+ return 0+ }+if (sort.sortByAscend) {const newData = [...sortedData].sort((a, b) => {- if (label === 'quantity') return a.count - b.count- return b.name.localeCompare(a.name)+ if (label === 'name') return (getValue(a) as string).localeCompare(getValue(b) as string)+ return (getValue(a) as number) - (getValue(b) as number)})setSortedData(newData)- setSort({- label,- sortByAscend: false,- sortByDescend: true,- })+ setSort({ label, sortByAscend: false, sortByDescend: true })return}if (sort.sortByDescend) {setSortedData([...data])- setSort({- label,- sortByAscend: false,- sortByDescend: false,- })+ setSort({ label, sortByAscend: false, sortByDescend: false })return}const newData = [...sortedData].sort((a, b) => {- if (label === 'quantity') return b.count - a.count- return a.name.localeCompare(b.name)+ if (label === 'name') return (getValue(a) as string).localeCompare(getValue(b) as string)+ return (getValue(b) as number) - (getValue(a) as number)})setSortedData(newData)- setSort({- label,- sortByAscend: true,- sortByDescend: false,- })+ setSort({ label, sortByAscend: true, sortByDescend: false })}useEffect(() => {@@ -1027,7 +1040,8 @@ const DetailsTable = ({<thead className='sticky top-0 z-10 bg-white dark:bg-slate-900'><tr className='text-base text-gray-900 dark:text-gray-50'><th- className='flex w-2/5 cursor-pointer items-center pl-2 text-left hover:opacity-90 sm:w-4/6'+ className='flex cursor-pointer items-center pl-2 text-left hover:opacity-90'+ style={{ width: '40%' }}onClick={() => onSortBy('name')}>{tnMapping[activeTabId as keyof typeof tnMapping]}@@ -1037,23 +1051,54 @@ const DetailsTable = ({sortByDescend={sort.label === 'name' ? sort.sortByDescend : null}/></th>- <th className='w-[30%] sm:w-1/6'>- <p- className='flex cursor-pointer items-center justify-end hover:opacity-90'- onClick={() => onSortBy('quantity')}- >- {valuesHeaderName || t('project.visitors')}- <Sort- className='ml-1'- sortByAscend={sort.label === 'quantity' ? sort.sortByAscend : null}- sortByDescend={sort.label === 'quantity' ? sort.sortByDescend : null}- />- - </p>- </th>- <th className='w-[30%] pr-2 sm:w-1/6'>- <p className='flex items-center justify-end'>{t('project.percentage')}</p>- </th>+ {(() => {+ const numericColsCount = 1 + (detailsExtraColumns?.length || 0) + (!hidePercentageInDetails ? 1 : 0)+ const numericColWidth = `${(60 / numericColsCount).toFixed(3)}%`+ return (+ <th style={{ width: numericColWidth }}>+ <p+ className='flex cursor-pointer items-center justify-end hover:opacity-90'+ onClick={() => onSortBy('quantity')}+ >+ {valuesHeaderName || t('project.visitors')}+ <Sort+ className='ml-1'+ sortByAscend={sort.label === 'quantity' ? sort.sortByAscend : null}+ sortByDescend={sort.label === 'quantity' ? sort.sortByDescend : null}+ />+ + </p>+ </th>+ )+ })()}+ {(() => {+ const numericColsCount = 1 + (detailsExtraColumns?.length || 0) + (!hidePercentageInDetails ? 1 : 0)+ const numericColWidth = `${(60 / numericColsCount).toFixed(3)}%`+ return (+ <>+ {detailsExtraColumns?.map((col, idx) => (+ <th key={`extra-col-${idx}`} style={{ width: numericColWidth }} className='pr-2'>+ <p+ className='flex cursor-pointer items-center justify-end hover:opacity-90'+ onClick={() => onSortBy(col.sortLabel)}+ >+ {col.header}+ <Sort+ className='ml-1'+ sortByAscend={sort.label === col.sortLabel ? sort.sortByAscend : null}+ sortByDescend={sort.label === col.sortLabel ? sort.sortByDescend : null}+ />+ </p>+ </th>+ ))}+ {!hidePercentageInDetails ? (+ <th style={{ width: numericColWidth }} className='pr-2'>+ <p className='flex items-center justify-end'>{t('project.percentage')}</p>+ </th>+ ) : null}+ </>+ )+ })()}</tr></thead>@@ -1077,13 +1122,10 @@ const DetailsTable = ({width: '100%',display: 'flex',}}- className={cx(- 'text-base text-gray-900 even:bg-gray-50 dark:text-gray-50 dark:even:bg-slate-800',- {- 'group cursor-pointer hover:bg-gray-100 hover:dark:bg-slate-700': !disableRowClick,- 'cursor-default': !!disableRowClick,- },- )}+ className={cx('text-base text-gray-900 even:bg-gray-50 dark:text-gray-50 dark:even:bg-slate-800', {+ 'group cursor-pointer hover:bg-gray-100 hover:dark:bg-slate-700': !disableRowClick,+ 'cursor-default': !!disableRowClick,+ })}onClick={() => {if (disableRowClick) returnconst link = getFilterLink(id, entryName)@@ -1093,7 +1135,7 @@ const DetailsTable = ({}}}>- <td className='flex w-2/5 items-center py-1 pl-2 text-left sm:w-4/6'>+ <td className='flex items-center py-1 pl-2 text-left' style={{ width: '40%' }}><spanclassName={cx('scrollbar-thin hover-always-overflow flex items-center whitespace-nowrap', {capitalize,@@ -1123,11 +1165,38 @@ const DetailsTable = ({</>) : null}</td>- <td className='w-[30%] py-1 text-right sm:w-1/6'>- {activeTab === PROJECT_TABS.traffic ? nFormatter(valueData, 1) : valueData}- - </td>- <td className='w-[30%] py-1 pr-2 text-right sm:w-1/6'>{perc}%</td>+ {(() => {+ const numericColsCount = 1 + (detailsExtraColumns?.length || 0) + (!hidePercentageInDetails ? 1 : 0)+ const numericColWidth = `${(60 / numericColsCount).toFixed(3)}%`+ return (+ <td style={{ width: numericColWidth }} className='py-1 text-right'>+ {activeTab === PROJECT_TABS.traffic ? nFormatter(valueData, 1) : valueData}+ + </td>+ )+ })()}+ {(() => {+ const numericColsCount = 1 + (detailsExtraColumns?.length || 0) + (!hidePercentageInDetails ? 1 : 0)+ const numericColWidth = `${(60 / numericColsCount).toFixed(3)}%`+ return (+ <>+ {detailsExtraColumns?.map((col, idx) => (+ <td+ key={`extra-cell-${idx}`}+ style={{ width: numericColWidth }}+ className='py-1 pr-2 text-right'+ >+ {col.render(entry)}+ </td>+ ))}+ {!hidePercentageInDetails ? (+ <td style={{ width: numericColWidth }} className='py-1 pr-2 text-right'>+ {perc}%+ </td>+ ) : null}+ </>+ )+ })()}</tr>)})}@@ -1158,6 +1227,8 @@ const Panel = ({valuesHeaderName,highlightColour = 'blue',disableRowClick = false,+ hidePercentageInDetails,+ detailsExtraColumns,}: PanelProps) => {const { dataLoading, activeTab } = useViewProjectContext()const { t } = useTranslation('common')@@ -1318,7 +1389,9 @@ const Panel = ({{_map(versions, (versionEntry) => {const versionPerc = _round((versionEntry.count / total) * 100, 2)const versionValueData = valueMapper(versionEntry.count)- const versionLink = disableRowClick ? undefined : getVersionFilterLink?.(entryName, versionEntry.name)+ const versionLink = disableRowClick+ ? undefined+ : getVersionFilterLink?.(entryName, versionEntry.name)return (<FilterWrapper@@ -1399,10 +1472,10 @@ const Panel = ({valueMapper={valueMapper}capitalize={capitalize || false}linkContent={linkContent || false}- getFilterLink={(- disableRowClick ? (() => '') : (getFilterLink as (id: string, name: string) => string)- )}+ getFilterLink={disableRowClick ? () => '' : (getFilterLink as (id: string, name: string) => string)}disableRowClick={disableRowClick}+ hidePercentageInDetails={hidePercentageInDetails}+ detailsExtraColumns={detailsExtraColumns}/>}size='large'diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsxindex a0f4ec673..aca7f3ff1 100644--- a/web/app/pages/Project/View/ViewProject.tsx+++ b/web/app/pages/Project/View/ViewProject.tsx@@ -757,9 +757,10 @@ const ViewProjectContent = () => {const [panelsDataPerf, setPanelsDataPerf] = useState<any>({})// GSC Keywords state+ type KeywordEntry = Entry & { impressions: number; position: number; ctr: number }const [keywordsLoading, setKeywordsLoading] = useState<boolean>(false)const [keywordsNotConnected, setKeywordsNotConnected] = useState<boolean>(false)- const [keywords, setKeywords] = useState<Entry[]>([])+ const [keywords, setKeywords] = useState<KeywordEntry[]>([])const timeFormat = useMemo<'12-hour' | '24-hour'>(() => user?.timeFormat || TimeFormat['12-hour'], [user])const [ref, size] = useSize()@@ -2136,10 +2137,15 @@ const ViewProjectContent = () => {}const res = await getGSCKeywords(id, period, from, to, timezone, projectPassword)- const list = (res?.keywords || []).map((k: { name: string; count: number }) => ({- name: k.name,- count: k.count,- }))+ const list = (res?.keywords || []).map(+ (k: { name: string; count: number; impressions: number; position: number; ctr: number }) => ({+ name: k.name,+ count: k.count,+ impressions: k.impressions,+ position: k.position,+ ctr: k.ctr,+ }),+ )setKeywords(list)} catch (error: any) {const message = typeof error === 'string' ? error : error?.message@@ -3968,6 +3974,31 @@ const ViewProjectContent = () => {}rowMapper={getTrafficSourcesRowMapper(panelsActiveTabs.source)}disableRowClick={panelsActiveTabs.source === 'keywords'}+ hidePercentageInDetails={panelsActiveTabs.source === 'keywords'}+ detailsExtraColumns={+ panelsActiveTabs.source === 'keywords'+ ? [+ {+ header: 'Impressions',+ render: (entry: any) => entry.impressions,+ sortLabel: 'impressions',+ getSortValue: (entry: any) => Number(entry.impressions || 0),+ },+ {+ header: 'Position',+ render: (entry: any) => entry.position,+ sortLabel: 'position',+ getSortValue: (entry: any) => Number(entry.position || 0),+ },+ {+ header: 'CTR',+ render: (entry: any) => `${entry.ctr}%`,+ sortLabel: 'ctr',+ getSortValue: (entry: any) => Number(entry.ctr || 0),+ },+ ]+ : undefined+ }customRenderer={panelsActiveTabs.source === 'keywords'? keywordsLoading