Skip to content

📈 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!

remove: extensions, sdk, livestats, timezone

kruzhambusa0ed6f3be79e
diff --git a/src/pages/Captcha/View/Panels.jsx b/src/pages/Captcha/View/Panels.jsx
index 2ee44bec6..6ebaeba33 100644
--- a/src/pages/Captcha/View/Panels.jsx
+++ b/src/pages/Captcha/View/Panels.jsx
@@ -3,7 +3,7 @@ import React, {
} from 'react'
import { ArrowSmallUpIcon, ArrowSmallDownIcon } from '@heroicons/react/24/solid'
import {
- FunnelIcon, MapIcon, Bars4Icon, ArrowsPointingOutIcon, ChartPieIcon, PuzzlePieceIcon,
+ FunnelIcon, MapIcon, Bars4Icon, ArrowsPointingOutIcon, ChartPieIcon,
} from '@heroicons/react/24/outline'
import cx from 'clsx'
import PropTypes from 'prop-types'
@@ -15,7 +15,6 @@ import _isEmpty from 'lodash/isEmpty'
import _isFunction from 'lodash/isFunction'
import _reduce from 'lodash/reduce'
import _round from 'lodash/round'
-import _find from 'lodash/find'
import _includes from 'lodash/includes'
import _floor from 'lodash/floor'
import _size from 'lodash/size'
@@ -34,20 +33,13 @@ const ENTRIES_PER_PANEL = 5
const panelsWithBars = ['cc', 'ce', 'os', 'br', 'dv']
-// function that checks if there are custom tabs for a specific type
-const checkCustomTabs = (panelID, customTabs) => {
- if (_isEmpty(customTabs)) return false
-
- return Boolean(_find(customTabs, (el) => el.panelID === panelID))
-}
-
const checkIfBarsNeeded = (panelID) => {
return _includes(panelsWithBars, panelID)
}
// noSwitch - 'previous' and 'next' buttons
const PanelContainer = ({
- name, children, noSwitch, icon, type, openModal, activeFragment, setActiveFragment, customTabs,
+ name, children, noSwitch, icon, type, openModal, activeFragment, setActiveFragment,
}) => (
<div
className={cx('relative bg-white dark:bg-gray-750 pt-5 px-4 min-h-72 sm:pt-6 sm:px-6 shadow rounded-lg overflow-hidden', {
@@ -66,7 +58,7 @@ const PanelContainer = ({
{name}
</h3>
<div className='flex'>
- {(checkIfBarsNeeded(type) || checkCustomTabs(type, customTabs)) && (
+ {(checkIfBarsNeeded(type)) && (
<Bars4Icon
className={cx(iconClassName, 'cursor-pointer', {
'text-blue-500': activeFragment === 0,
@@ -104,20 +96,6 @@ const PanelContainer = ({
onClick={() => setActiveFragment(1)}
/>
)}
- {checkCustomTabs(type, customTabs) && (
- <>
- {_map(customTabs, ({ extensionID, panelID }) => (
- <PuzzlePieceIcon
- key={`${extensionID}-${panelID}`}
- className={cx(iconClassName, 'ml-2 cursor-pointer', {
- 'text-blue-500': activeFragment === extensionID,
- 'text-gray-900 dark:text-gray-50': activeFragment === 0,
- })}
- onClick={() => setActiveFragment(extensionID)}
- />
- ))}
- </>
- )}
</div>
</div>
{/* for other tabs */}
@@ -432,7 +410,7 @@ CustomEvents.propTypes = {
}
const Panel = ({
- name, data, rowMapper, valueMapper, capitalize, linkContent, t, icon, id, hideFilters, onFilter, customTabs,
+ name, data, rowMapper, valueMapper, capitalize, linkContent, t, icon, id, hideFilters, onFilter,
}) => {
const [page, setPage] = useState(0)
const currentIndex = page * ENTRIES_PER_PANEL
@@ -479,7 +457,6 @@ const Panel = ({
activeFragment={activeFragment}
setActiveFragment={setActiveFragment}
openModal={() => setModal(true)}
- customTabs={customTabs}
>
<InteractiveMap
data={data}
@@ -547,7 +524,6 @@ const Panel = ({
type={id}
setActiveFragment={setActiveFragment}
activeFragment={activeFragment}
- customTabs={customTabs}
>
{_isEmpty(data) ? (
<p className='mt-1 text-base text-gray-700 dark:text-gray-300'>
@@ -562,31 +538,9 @@ const Panel = ({
</PanelContainer>
)
}
- // Showing chart of stats a data (end if)
-
- // Showing custom tabs (Extensions Marketplace)
- // todo: check activeFragment for being equal to customTabs -> extensionID + panelID
- if (!_isEmpty(customTabs) && typeof activeFragment === 'string' && !_isEmpty(data)) {
- const content = _find(customTabs, (tab) => tab.extensionID === activeFragment).tabContent
-
- return (
- <PanelContainer
- name={name}
- icon={icon}
- type={id}
- activeFragment={activeFragment}
- setActiveFragment={setActiveFragment}
- openModal={() => setModal(true)}
- customTabs={customTabs}
- >
- {/* eslint-disable-next-line react/no-danger */}
- <div dangerouslySetInnerHTML={{ __html: content }} />
- </PanelContainer>
- )
- }
return (
- <PanelContainer name={name} icon={icon} type={id} activeFragment={activeFragment} setActiveFragment={setActiveFragment} customTabs={customTabs}>
+ <PanelContainer name={name} icon={icon} type={id} activeFragment={activeFragment} setActiveFragment={setActiveFragment}>
{_isEmpty(data) ? (
<p className='mt-1 text-base text-gray-700 dark:text-gray-300'>
{t('project.noParamData')}
diff --git a/src/pages/Captcha/View/ViewCaptcha.jsx b/src/pages/Captcha/View/ViewCaptcha.jsx
index a92b7041d..4874a4db7 100644
--- a/src/pages/Captcha/View/ViewCaptcha.jsx
+++ b/src/pages/Captcha/View/ViewCaptcha.jsx
@@ -25,7 +25,6 @@ import _startsWith from 'lodash/startsWith'
import _debounce from 'lodash/debounce'
import _some from 'lodash/some'
import PropTypes from 'prop-types'
-import * as SwetrixSDK from '@swetrix/sdk'
import { SWETRIX_PID } from 'utils/analytics'
import { getTimeFromSeconds, getStringFromTime } from 'utils/generic'
@@ -33,8 +32,8 @@ import { getItem, setItem } from 'utils/localstorage'
import Title from 'components/Title'
import EventsRunningOutBanner from 'components/EventsRunningOutBanner'
import {
- tbPeriodPairs, getProjectCacheKey, LIVE_VISITORS_UPDATE_INTERVAL, DEFAULT_TIMEZONE, CDN_URL, isDevelopment,
- timeBucketToDays, getProjectCacheCustomKey, roleViewer, MAX_MONTHS_IN_PAST, MAX_MONTHS_IN_PAST_FREE, TimeFormat, chartTypes,
+ tbPeriodPairs, getProjectCacheKey, timeBucketToDays, getProjectCacheCustomKey, roleViewer,
+ MAX_MONTHS_IN_PAST, MAX_MONTHS_IN_PAST_FREE, TimeFormat, chartTypes,
} from 'redux/constants'
import Button from 'ui/Button'
import Loader from 'ui/Loader'
@@ -60,14 +59,10 @@ import Filters from './components/Filters'
import './styles.css'
const ViewProject = ({
- projects, isLoading: _isLoading, showError, cache, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,
- setLiveStatsForProject, authenticated, timezone, user, isPaidTierUsed, extensions, generateAlert, setProjects,
+ projects, isLoading: _isLoading, showError, cache, setProjectCache, projectViewPrefs, setProjectViewPrefs, authenticated, user, isPaidTierUsed, generateAlert, setProjects,
}) => {
const { t, i18n: { language } } = useTranslation('common')
const [periodPairs, setPeriodPairs] = useState(tbPeriodPairs(t))
- const [customExportTypes, setCustomExportTypes] = useState([])
- const [customPanelTabs, setCustomPanelTabs] = useState([])
- const [sdkInstance, setSdkInstance] = useState(null)
const dashboardRef = useRef(null)
const { id } = useParams()
const history = useHistory()
@@ -198,36 +193,24 @@ const ViewProject = ({
data = cache[id][key]
} else {
if (period === 'custom' && dateRange) {
- data = await getProjectData(id, timeBucket, '', newFilters || filters, from, to, timezone)
+ data = await getProjectData(id, timeBucket, '', newFilters || filters, from, to)
} else {
- data = await getProjectData(id, timeBucket, period, newFilters || filters, '', '', timezone)
+ data = await getProjectData(id, timeBucket, period, newFilters || filters, '', '')
}
setProjectCache(id, data || {}, key)
}
- const sdkData = {
- ...(data || {}),
- filters: newFilters || filters,
- timezone,
- timeBucket,
- period,
- from,
- to,
- }
-
if (_isEmpty(data)) {
setAnalyticsLoading(false)
setDataLoading(false)
setIsPanelsDataEmpty(true)
- sdkInstance?._emitEvent('load', sdkData)
return
}
const {
chart, params, customs, appliedFilters, avgSdur,
} = data
- sdkInstance?._emitEvent('load', sdkData)
const processedSdur = getTimeFromSeconds(avgSdur)
setSessionDurationAVG(getStringFromTime(processedSdur))
@@ -316,7 +299,6 @@ const ViewProject = ({
})
}
- sdkInstance?._emitEvent('filtersupdate', newFilters)
loadAnalytics(true, newFilters)
}
@@ -349,7 +331,6 @@ const ViewProject = ({
scrollToTopDisable: true,
},
})
- sdkInstance?._emitEvent('filtersupdate', newFilters)
}
const refreshStats = () => {
@@ -416,82 +397,6 @@ const ViewProject = ({
}
}, [isLoading, activeChartMetrics, chartData]) // eslint-disable-line
- // Initialising Swetrix SDK instance
- useEffect(() => {
- let sdk = null
- if (!_isEmpty(extensions)) {
- const processedExtensions = _map(extensions, (ext) => {
- const { id: extId, fileURL } = ext
- return {
- id: extId,
- cdnURL: `${CDN_URL}file/${fileURL}`,
- }
- })
-
- sdk = new SwetrixSDK(processedExtensions, {
- debug: isDevelopment,
- }, {
- onAddExportDataRow: (label, onClick) => {
- setCustomExportTypes((prev) => [
- ...prev,
- {
- label,
- onClick,
- },
- ])
- },
- onRemoveExportDataRow: (label) => {
- setCustomExportTypes((prev) => _filter(prev, (row) => row.label !== label))
- },
- onAddPanelTab: (extensionID, panelID, tabContent, onOpen) => {
- setCustomPanelTabs((prev) => [
- ...prev,
- {
- extensionID,
- panelID,
- tabContent,
- onOpen,
- },
- ])
- },
- onRemovePanelTab: (extensionID, panelID) => {
- setCustomPanelTabs((prev) => _filter(prev, (row) => row.extensionID !== extensionID && row.panelID !== panelID))
- },
- })
- setSdkInstance(sdk)
- }
-
- return () => {
- if (sdk) {
- sdk._destroy()
- }
- }
- }, [extensions])
-
- // Supplying 'timeupdate' event to the SDK after loading
- useEffect(() => {
- sdkInstance?._emitEvent('timeupdate', {
- period,
- timeBucket,
- dateRange: period === 'custom' ? dateRange : null,
- })
- }, [sdkInstance]) // eslint-disable-line
-
- // Supplying 'projectinfo' event to the SDK after loading
- useEffect(() => {
- if (_isEmpty(project)) {
- return
- }
-
- const {
- active: isActive, created, public: isPublic,
- } = project
-
- sdkInstance?._emitEvent('projectinfo', {
- id, name, isActive, created, isPublic,
- })
- }, [sdkInstance, name]) // eslint-disable-line
-
useEffect(() => {
setPeriodPairs(tbPeriodPairs(t))
}, [t])
@@ -590,12 +495,6 @@ const ViewProject = ({
setPeriod('custom')
setProjectViewPrefs(id, 'custom', timeBucketToDays[index].tb[0], dates)
- sdkInstance?._emitEvent('timeupdate', {
- period: 'custom',
- timeBucket: eventEmitTimeBucket,
- dateRange: dates,
- })
-
break
}
}
@@ -613,64 +512,26 @@ const ViewProject = ({
}
}, [dateRange, t, arePeriodParsed]) // eslint-disable-line
- useEffect(() => {
- const updateLiveVisitors = async () => {
- const { id: pid } = project
- const result = await getLiveVisitors([pid])
-
- setLiveStatsForProject(pid, result[pid])
- }
-
- let interval
- if (project.uiHidden) {
- updateLiveVisitors()
- interval = setInterval(async () => {
- await updateLiveVisitors()
- }, LIVE_VISITORS_UPDATE_INTERVAL)
- }
-
- return () => clearInterval(interval)
- }, [project.id, setLiveStatsForProject]) // eslint-disable-line react-hooks/exhaustive-deps
-
useEffect(() => {
if (!isLoading && _isEmpty(project)) {
getProject(id)
.then(projectRes => {
if (!_isEmpty(projectRes)) {
- if (projectRes.isPublic && !projectRes.isOwner) {
- getOverallStats([id])
- .then(res => {
- setPublicProject({
- ...projectRes,
- overall: res[id],
- live: 'N/A',
- isPublicVisitors: true,
- })
- })
- .catch(e => {
- console.error(e)
- onErrorLoading()
- })
- } else {
- getOverallStats([id])
- .then(res => {
- setProjects([...projects, {
- ...projectRes,
- overall: res[id],
- live: 'N/A',
- }])
- })
- .then(() => {
- return getLiveVisitors([id])
- })
- .then(res => {
- setLiveStatsForProject(id, res[id])
- })
- .catch(e => {
- console.error(e)
- onErrorLoading()
- })
- }
+ getOverallStats([id])
+ .then(res => {
+ setProjects([...projects, {
+ ...projectRes,
+ overall: res[id],
+ live: 'N/A',
+ }])
+ })
+ .then(() => {
+ return getLiveVisitors([id])
+ })
+ .catch(e => {
+ console.error(e)
+ onErrorLoading()
+ })
} else {
onErrorLoading()
}
@@ -712,11 +573,6 @@ const ViewProject = ({
scrollToTopDisable: true,
},
})
- sdkInstance?._emitEvent('timeupdate', {
- period: newPeriod.period,
- timeBucket: tb,
- dateRange: newPeriod.period === 'custom' ? dateRange : null,
- })
}
const updateTimebucket = (newTimebucket) => {
@@ -733,11 +589,6 @@ const ViewProject = ({
})
setTimebucket(newTimebucket)
setProjectViewPrefs(id, period, newTimebucket, dateRange)
- sdkInstance?._emitEvent('timeupdate', {
- period,
- timeBucket: newTimebucket,
- dateRange,
- })
}
const openSettingsHandler = () => {
@@ -971,7 +822,7 @@ const ViewProject = ({
/>
)}
<Dropdown
- items={[...exportTypes, ...customExportTypes]}
+ items={exportTypes}
title={[
<ArrowDownTrayIcon key='download-icon' className='w-5 h-5 mr-2' />,
<Fragment key='export-data'>
@@ -1073,7 +924,6 @@ const ViewProject = ({
{_map(panelsData.types, (type) => {
const panelName = tnMapping[type]
const panelIcon = panelIconMapping[type]
- const customTabs = _filter(customPanelTabs, tab => tab.panelID === type)
if (type === 'cc') {
return (
@@ -1085,7 +935,6 @@ const ViewProject = ({
onFilter={filterHandler}
name={panelName}
data={panelsData.data[type]}
- customTabs={customTabs}
rowMapper={(rowName) => (
<CCRow rowName={rowName} language={language} />
)}
@@ -1103,7 +952,6 @@ const ViewProject = ({
onFilter={filterHandler}
name={panelName}
data={panelsData.data[type]}
- customTabs={customTabs}
capitalize
/>
)
@@ -1119,7 +967,6 @@ const ViewProject = ({
onFilter={filterHandler}
name={panelName}
data={panelsData.data[type]}
- customTabs={customTabs}
rowMapper={(rowName) => (
<RefRow rowName={rowName} showIcons={showIcons} />
)}
@@ -1136,7 +983,6 @@ const ViewProject = ({
onFilter={filterHandler}
name={panelName}
data={panelsData.data[type]}
- customTabs={customTabs}
/>
)
})}
@@ -1204,16 +1050,8 @@ ViewProject.propTypes = {
setProjectCache: PropTypes.func.isRequired,
setProjectViewPrefs: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
- setPublicProject: PropTypes.func.isRequired,
- setLiveStatsForProject: PropTypes.func.isRequired,
authenticated: PropTypes.bool.isRequired,
- extensions: PropTypes.arrayOf(PropTypes.object).isRequired,
isPaidTierUsed: PropTypes.bool.isRequired,
- timezone: PropTypes.string,
-}
-
-ViewProject.defaultProps = {
- timezone: DEFAULT_TIMEZONE,
}
export default memo(ViewProject)