📈 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
Merge branch 'main' into feature/seo-view-improvements
Blue Mouse0f1c8174558b
diff --cc web/app/pages/Project/tabs/SEO/SEOView.tsxindex 5d0ee4ee6,c5906d063..023e79137--- a/web/app/pages/Project/tabs/SEO/SEOView.tsx+++ b/web/app/pages/Project/tabs/SEO/SEOView.tsx@@@ -491,21 -373,11 +492,23 @@@ const SEOViewInner = ({ projectId, tnMabuildMainChartOptions(aggregatedSeries,activeMetrics,- timeBucket,+ seoTimeBucket,t,+ !noRegionPeriods.includes(period),+ isActiveCompare && compareEnabled && aggregatedCompareSeries.length+ ? aggregatedCompareSeries+ : undefined,),- [aggregatedSeries, activeMetrics, timeBucket, t, period],+ [+ aggregatedSeries,+ activeMetrics,+ seoTimeBucket,+ t,+ isActiveCompare,+ compareEnabled,+ aggregatedCompareSeries,++ period,+ ],)const detailsExtraColumns = useMemo(@@@ -835,10 -708,10 +838,11 @@@className='h-80 [&_svg]:overflow-visible!'deps={[aggregatedSeries,+ aggregatedCompareSeries,activeMetrics,- timeBucket,+ seoTimeBucket,timeFormat,+ period,]}/>) : null}diff --cc web/app/pages/Project/tabs/SEO/seo-chart-options.tsindex b118c31f5,1156c94a6..06e92d8fc--- a/web/app/pages/Project/tabs/SEO/seo-chart-options.ts+++ b/web/app/pages/Project/tabs/SEO/seo-chart-options.ts@@@ -1,6 -1,7 +1,7 @@@import type { ChartOptions } from 'billboard.js'-import { area, donut, scatter } from 'billboard.js'+import { area, bar, donut, line, scatter } from 'billboard.js'import * as d3 from 'd3'+ import dayjs from 'dayjs'import _round from 'lodash/round'import type { TFunction } from 'i18next'@@@ -50,7 -13,7 +51,8 @@@ export function buildMainChartOptionsactiveMetrics: Record<SEOMetricKey, boolean>,timeBucket: string,t: TFunction,+ applyRegions: boolean,+ compareSeries?: DateSeriesEntry[],): ChartOptions {if (!series.length) return {}@@@ -58,66 -21,48 +60,68 @@@const columns: any[] = [['x', ...dates]]const colors: Record<string, string> = {}const axes: Record<string, string> = {}+ const activeSeries: string[] = []+ const names: Record<string, string> = {}+ const types: Record<string, any> = {}+ const compareIds: string[] = []let needsY2 = false-- if (activeMetrics.clicks) {- const label = t('project.seo.clicks')- columns.push([label, ...series.map((d) => d.clicks)])- colors[label] = '#3b82f6'- activeSeries.push(label)+ const hasCompareSeries = !!compareSeries?.length+ const metricLabels: Record<SEOMetricKey, string> = {+ clicks: t('project.seo.clicks'),+ impressions: t('project.seo.impressions'),+ position: t('project.seo.avgPosition'),+ ctr: t('project.seo.avgCTR'),}- if (activeMetrics.impressions) {- const label = t('project.seo.impressions')- columns.push([label, ...series.map((d) => d.impressions)])- colors[label] = '#5b21b6'- activeSeries.push(label)- if (activeMetrics.clicks) {- axes[label] = 'y2'- needsY2 = true+ const metricUsesSecondaryAxis = (metric: SEOMetricKey) => {+ if (metric === SEO_METRICS.impressions) {+ return activeMetrics.clicks}- }- if (activeMetrics.position) {- const label = t('project.seo.avgPosition')- columns.push([label, ...series.map((d) => d.position)])- colors[label] = '#d97706'- activeSeries.push(label)- if (activeMetrics.clicks || activeMetrics.impressions) {- axes[label] = 'y2'- needsY2 = true+ if (metric === SEO_METRICS.position || metric === SEO_METRICS.ctr) {+ return activeMetrics.clicks || activeMetrics.impressions}++ return false}- if (activeMetrics.ctr) {- const label = t('project.seo.avgCTR')- columns.push([label, ...series.map((d) => d.ctr)])- colors[label] = '#0d9488'- activeSeries.push(label)- if (activeMetrics.clicks || activeMetrics.impressions) {- axes[label] = 'y2'+ const metricKeys = Object.keys(SEO_METRICS) as SEOMetricKey[]++ metricKeys.forEach((metric: SEOMetricKey) => {+ if (!activeMetrics[metric]) return++ const compareId = `${metric}Compare`+ const usesY2 = metricUsesSecondaryAxis(metric)++ columns.push([metric, ...series.map((d) => getSEOMetricValue(d, metric))])+ colors[metric] = SEO_MAIN_METRIC_COLORS[metric]+ names[metric] = metricLabels[metric]+ types[metric] = area()++ activeSeries.push(metric)++ if (usesY2) {+ axes[metric] = 'y2'needsY2 = true}- }++ if (hasCompareSeries) {+ columns.push([+ compareId,+ ...dates.map((_, index) => {+ const entry = compareSeries?.[index]+ return entry ? getSEOMetricValue(entry, metric) : null+ }),+ ])+ colors[compareId] = SEO_MAIN_METRIC_COMPARE_COLORS[metric]+ names[compareId] = metricLabels[metric]+ types[compareId] = line()+ compareIds.push(compareId)++ if (usesY2) {+ axes[compareId] = 'y2'+ }+ }+ })const tickFormatMap: Record<string, string> = {hour: '%b %d %H:%M',@@@ -128,17 -73,35 +132,37 @@@year: '%Y',}const tickFormat = tickFormatMap[timeBucket] || '%b %d'+ const xFormat = timeBucket === 'hour' ? '%Y-%m-%d %H:%M:%S' : '%Y-%m-%d'+ const regionStart =+ dates.length > 1+ ? dayjs(dates[dates.length - 2]).toDate()+ : dayjs(dates[dates.length - 1]).toDate()+ const regions: any = applyRegions+ ? Object.fromEntries(+ activeSeries.map((label) => [+ label,+ [+ {+ start: regionStart,+ style: {+ dasharray: '6 2',+ },+ },+ ],+ ]),+ )+ : undefinedreturn {data: {x: 'x',- xFormat: timeBucket === 'hour' ? '%Y-%m-%d %H:%M:%S' : '%Y-%m-%d',+ xFormat,columns,- type: area(),+ types,axes,colors,+ names,+ regions,},area: {linearGradient: true,