📈 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
fix-custom-events
kruzhambusbd2ee195dd76
diff --git a/src/pages/Project/View/ViewProject.helpers.tsx b/src/pages/Project/View/ViewProject.helpers.tsxindex 65159af0f..e6bdfee19 100644--- a/src/pages/Project/View/ViewProject.helpers.tsx+++ b/src/pages/Project/View/ViewProject.helpers.tsx@@ -310,6 +310,7 @@ const getSettings = (const customEventsToArray = customEvents ? _map(_keys(customEvents), (el) => {return [el, ...customEvents[el]]}) : []+ console.log('customEventsToArray', customEventsToArray)if (!_isEmpty(forecasedChartData)) {lines.push({diff --git a/src/pages/Project/View/ViewProject.tsx b/src/pages/Project/View/ViewProject.tsxindex af74106f9..bc96e2224 100644--- a/src/pages/Project/View/ViewProject.tsx+++ b/src/pages/Project/View/ViewProject.tsx@@ -433,11 +433,11 @@ const ViewProject = ({}useEffect(() => {- if (activeTab === PROJECT_TABS.traffic) {+ if (activeTab === PROJECT_TABS.traffic && !_isEmpty(activeChartMetricsCustomEvents)) {loadCustomEvents()}// eslint-disable-next-line react-hooks/exhaustive-deps- }, [activeTab, activeChartMetricsCustomEvents])+ }, [activeChartMetricsCustomEvents])// this function is used for requesting the data from the APIconst loadAnalytics = async (forced = false, newFilters: any[] | null = null) => {@@ -451,6 +451,7 @@ const ViewProject = ({let keylet fromlet to+ let customEventsChart = customEventsChartDataif (dateRange) {from = getFormatDate(dateRange[0])@@ -465,10 +466,16 @@ const ViewProject = ({} else {if (period === 'custom' && dateRange) {data = await getProjectData(id, timeBucket, '', newFilters || filters, from, to, timezone)+ customEventsChart = await getProjectDataCustomEvents(id, timeBucket, '', filters, from, to, timezone, activeChartMetricsCustomEvents)} else {data = await getProjectData(id, timeBucket, period, newFilters || filters, '', '', timezone)+ customEventsChart = await getProjectDataCustomEvents(id, timeBucket, period, filters, '', '', timezone, activeChartMetricsCustomEvents)}+ customEventsChart = customEventsChart?.chart ? customEventsChart.chart.events : customEventsChartData++ setCustomEventsPrefs(id, customEventsChart)+setProjectCache(id, data || {}, key)}@@ -506,7 +513,8 @@ const ViewProject = ({setIsPanelsDataEmpty(true)} else {const applyRegions = !_includes(noRegionPeriods, activePeriod?.period)- const bbSettings = getSettings(chart, timeBucket, activeChartMetrics, applyRegions, timeFormat, forecasedChartData, rotateXAxias, chartType, customEventsChartData)+ console.log('customEventsChart', customEventsChart)+ const bbSettings = getSettings(chart, timeBucket, activeChartMetrics, applyRegions, timeFormat, forecasedChartData, rotateXAxias, chartType, customEventsChart)setChartData(chart)setPanelsData({@@ -854,23 +862,7 @@ const ViewProject = ({})}- if (activeChartMetrics.bounce || activeChartMetrics.sessionDuration || activeChartMetrics.views || activeChartMetrics.unique) {- const applyRegions = !_includes(noRegionPeriods, activePeriod?.period)- const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions, timeFormat, forecasedChartData, rotateXAxias, chartType, customEventsChartData)-- if (!_isEmpty(mainChart)) {- mainChart.destroy()- }-- setMainChart(() => {- // @ts-ignore- const generete = bb.generate(bbSettings)- generete.data.names(dataNames)- return generete- })- }-- if (!activeChartMetrics.bounce || !activeChartMetrics.sessionDuration || activeChartMetrics.views || activeChartMetrics.unique) {+ if (activeChartMetrics.bounce || activeChartMetrics.sessionDuration || activeChartMetrics.views || activeChartMetrics.unique || !activeChartMetrics.bounce || !activeChartMetrics.sessionDuration) {const applyRegions = !_includes(noRegionPeriods, activePeriod?.period)const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions, timeFormat, forecasedChartData, rotateXAxias, chartType, customEventsChartData)@@ -1154,6 +1146,10 @@ const ViewProject = ({}}, [project, period, timeBucket, periodPairs, areFiltersParsed, areTimeBucketParsed, arePeriodParsed, t, activeTab, areFiltersPerfParsed]) // eslint-disable-line+ useEffect(() => {+ setActiveChartMetricsCustomEvents([])+ }, [period, filters]) // eslint-disable-line+useEffect(() => {if (dateRange && arePeriodParsed) {onRangeDateChange(dateRange)@@ -1634,7 +1630,9 @@ const ViewProject = ({)}buttonClassName='group-hover:bg-gray-50 px-4 py-2 dark:group-hover:bg-gray-600 inline-flex w-full rounded-md shadow-sm bg-white text-sm font-medium text-gray-700 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700'keyExtractor={(event) => event.id}- onSelect={(event) => {+ onSelect={(event, e) => {+ e.stopPropagation()+ e.preventDefault()setActiveChartMetricsCustomEvents((prev) => {const newActiveChartMetricsCustomEvents = [...prev]const index = _findIndex(prev, (item) => item === event.id)diff --git a/src/ui/Dropdown.tsx b/src/ui/Dropdown.tsxindex 3cc2f9685..01267290a 100644--- a/src/ui/Dropdown.tsx+++ b/src/ui/Dropdown.tsx@@ -15,7 +15,7 @@ const Dropdown = ({items: any[],labelExtractor: (item: any) => string | number | React.ReactNode,keyExtractor: (item: any) => string | number | React.ReactNode,- onSelect: (item: any) => void | null,+ onSelect: (item: any, e?: any) => void | null,aside?: boolean,buttonClassName?: string,selectItemClassName?: string,@@ -59,7 +59,7 @@ const Dropdown = ({// @ts-ignoretabIndex='-1'id='menu-item-0'- onClick={() => onSelect(item)}+ onClick={(e) => onSelect(item, e)}>{labelExtractor ? labelExtractor(item) : item}</span>