📈 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
added marketplace extensions integration
Blue Mouse09eedac516fa
diff --git a/public/assets/test_extension.js b/public/assets/test_extension.jsnew file mode 100644index 000000000..2b3b040a6--- /dev/null+++ b/public/assets/test_extension.js@@ -0,0 +1,17 @@+((sdk) => {+ function main(sdk) {+ console.log('Main function called!\n', sdk)+ }++ main(sdk)++ sdk.addExportDataRow('As blahblahblah', () => {+ console.log('blahblahblah')+ })++ sdk.addExportDataRow('As test', () => {+ console.log('test')+ })++ sdk.addPanelTab('test-extension', 'pg', () => {})+})diff --git a/src/pages/Project/View/Panels.jsx b/src/pages/Project/View/Panels.jsxindex ac212e900..1faf2fdc2 100644--- a/src/pages/Project/View/Panels.jsx+++ b/src/pages/Project/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,+ FunnelIcon, MapIcon, Bars4Icon, ArrowsPointingOutIcon, ChartPieIcon, PuzzlePieceIcon,} from '@heroicons/react/24/outline'import cx from 'clsx'import PropTypes from 'prop-types'@@ -31,7 +31,7 @@ const ENTRIES_PER_PANEL = 5// noSwitch - 'previous' and 'next' buttonsconst PanelContainer = ({- name, children, noSwitch, icon, type, openModal, activeFragment, setActiveFragment,+ name, children, noSwitch, icon, type, openModal, activeFragment, setActiveFragment, customTabs,}) => (<divclassName={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', {@@ -49,50 +49,80 @@ const PanelContainer = ({)}{name}</h3>- {/* if it is a Country tab */}- {type === 'cc' && (- <div className='flex'>- <Bars4Icon- className={cx(iconClassName, 'cursor-pointer', {- 'text-blue-500': activeFragment === 0,- 'text-gray-900 dark:text-gray-50': activeFragment === 1,- })}- onClick={() => setActiveFragment(0)}- />- <MapIcon- className={cx(iconClassName, 'ml-2 cursor-pointer', {- 'text-blue-500': activeFragment === 1,- 'text-gray-900 dark:text-gray-50': activeFragment === 0,- })}- onClick={() => setActiveFragment(1)}- />- <ArrowsPointingOutIcon- className={cx(iconClassName, 'ml-2 cursor-pointer text-gray-900 dark:text-gray-50', {- hidden: activeFragment === 0,- })}- onClick={openModal}- />- </div>- )}- {/* if this tab using Circle showing stats panel */}- {(type === 'ce' || type === 'os' || type === 'br' || type === 'dv') && (- <div className='flex'>- <Bars4Icon- className={cx(iconClassName, 'cursor-pointer', {- 'text-blue-500': activeFragment === 0,- 'text-gray-900 dark:text-gray-50': activeFragment === 1,- })}- onClick={() => setActiveFragment(0)}- />- <ChartPieIcon- className={cx(iconClassName, 'ml-2 cursor-pointer', {- 'text-blue-500': activeFragment === 1,- 'text-gray-900 dark:text-gray-50': activeFragment === 0,- })}- onClick={() => setActiveFragment(1)}- />- </div>- )}+ <div className='flex'>+ {/* if it is a Country tab */}+ {type === 'cc' && (+ <>+ <Bars4Icon+ className={cx(iconClassName, 'cursor-pointer', {+ 'text-blue-500': activeFragment === 0,+ 'text-gray-900 dark:text-gray-50': activeFragment === 1,+ })}+ onClick={() => setActiveFragment(0)}+ />+ <MapIcon+ className={cx(iconClassName, 'ml-2 cursor-pointer', {+ 'text-blue-500': activeFragment === 1,+ 'text-gray-900 dark:text-gray-50': activeFragment === 0,+ })}+ onClick={() => setActiveFragment(1)}+ />+ <ArrowsPointingOutIcon+ className={cx(iconClassName, 'ml-2 cursor-pointer text-gray-900 dark:text-gray-50', {+ hidden: activeFragment === 0,+ })}+ onClick={openModal}+ />+ </>+ )}+ {/* if this tab using Circle showing stats panel */}+ {(type === 'ce' || type === 'os' || type === 'br' || type === 'dv') && (+ <>+ <Bars4Icon+ className={cx(iconClassName, 'cursor-pointer', {+ 'text-blue-500': activeFragment === 0,+ 'text-gray-900 dark:text-gray-50': activeFragment === 1,+ })}+ onClick={() => setActiveFragment(0)}+ />+ <ChartPieIcon+ className={cx(iconClassName, 'ml-2 cursor-pointer', {+ 'text-blue-500': activeFragment === 1,+ 'text-gray-900 dark:text-gray-50': activeFragment === 0,+ })}+ onClick={() => setActiveFragment(1)}+ />+ </>+ )}+ {!_isEmpty(customTabs) && type === 'pg' && (+ <>+ {/* {_map(customTabs, (tab, index) => (+ <PuzzlePieceIcon+ key={index}+ className={cx(iconClassName, 'ml-2 cursor-pointer', {+ 'text-blue-500': activeFragment === index + 2,+ 'text-gray-900 dark:text-gray-50': activeFragment !== index + 2,+ })}+ onClick={() => setActiveFragment(index + 2)}+ />+ ))} */}+ <Bars4Icon+ className={cx(iconClassName, 'cursor-pointer', {+ 'text-blue-500': activeFragment === 0,+ 'text-gray-900 dark:text-gray-50': activeFragment !== 0,+ })}+ onClick={() => setActiveFragment(0)}+ />+ <PuzzlePieceIcon+ className={cx(iconClassName, 'ml-2 cursor-pointer', {+ 'text-blue-500': activeFragment === 555,+ 'text-gray-900 dark:text-gray-50': activeFragment === 0,+ })}+ onClick={() => setActiveFragment(555)}+ />+ </>+ )}+ </div></div>{/* for other tabs */}<div className='flex flex-col h-full scroll-auto overflow-auto'>@@ -389,7 +419,7 @@ CustomEvents.propTypes = {}const Panel = ({- name, data, rowMapper, capitalize, linkContent, t, icon, id, hideFilters, onFilter,+ name, data, rowMapper, capitalize, linkContent, t, icon, id, hideFilters, onFilter, customTabs,}) => {const [page, setPage] = useState(0)const currentIndex = page * ENTRIES_PER_PANEL@@ -432,6 +462,7 @@ const Panel = ({activeFragment={activeFragment}setActiveFragment={setActiveFragment}openModal={() => setModal(true)}+ customTabs={customTabs}><InteractiveMapdata={data}@@ -498,6 +529,7 @@ 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'>@@ -514,8 +546,29 @@ const Panel = ({}// 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) && activeFragment === 555 && !_isEmpty(data)) {+ return (+ <PanelContainer+ name={name}+ icon={icon}+ type={id}+ activeFragment={activeFragment}+ setActiveFragment={setActiveFragment}+ openModal={() => setModal(true)}+ customTabs={customTabs}+ >+ <p>+ Custom extension content+ </p>+ </PanelContainer>+ )+ }++ console.log(id)return (- <PanelContainer name={name} icon={icon} type={id} activeFragment={activeFragment} setActiveFragment={setActiveFragment}>+ <PanelContainer name={name} icon={icon} type={id} activeFragment={activeFragment} setActiveFragment={setActiveFragment} customTabs={customTabs}>{_isEmpty(data) ? (<p className='mt-1 text-base text-gray-700 dark:text-gray-300'>{t('project.noParamData')}diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsxindex 747f3a7e8..3b0127b1b 100644--- a/src/pages/Project/View/ViewProject.jsx+++ b/src/pages/Project/View/ViewProject.jsx@@ -28,6 +28,7 @@ import _filter from 'lodash/filter'import _truncate from 'lodash/truncate'import _startsWith from 'lodash/startsWith'import PropTypes from 'prop-types'+import SwetrixSDK from 'swetrix-sdk-test/esnext'import { SWETRIX_PID } from 'utils/analytics'import Title from 'components/Title'@@ -350,6 +351,8 @@ const ViewProject = ({}) => {const { t, i18n: { language } } = useTranslation('common')const [periodPairs, setPeriodPairs] = useState(tbPeriodPairs(t))+ const [customExportTypes, setCustomExportTypes] = useState([])+ const [customPanelTabs, setCustomPanelTabs] = useState([])const dashboardRef = useRef(null)const { id } = useParams()const history = useHistory()@@ -571,6 +574,44 @@ const ViewProject = ({}}, [isLoading, showTotal, chartData, mainChart, t])+ useEffect(() => {+ const sdk = new SwetrixSDK([{+ cdnURL: 'http://localhost:3000/assets/test_extension.js',+ }], {+ debug: true,+ }, {+ onAddExportDataRow: (label, onClick) => {+ setCustomExportTypes((prev) => [+ ...prev,+ {+ label,+ onClick,+ },+ ])+ },+ onRemoveExportDataRow: (label) => {+ setCustomExportTypes((prev) => _filter(prev, (row) => row.label !== label))+ },+ onAddPanelTab: (extensionID, panelID, onClick) => {+ setCustomPanelTabs((prev) => [+ ...prev,+ {+ extensionID,+ panelID,+ onClick,+ },+ ])+ },+ onRemovePanelTab: (extensionID, panelID) => {+ setCustomPanelTabs((prev) => _filter(prev, (row) => row.extensionID !== extensionID && row.panelID !== panelID))+ },+ })++ return () => {+ sdk._destroy()+ }+ }, [])+useEffect(() => {setPeriodPairs(tbPeriodPairs(t))}, [t])@@ -955,7 +996,7 @@ const ViewProject = ({onChange={(e) => setShowTotal(e.target.checked)}/><Dropdown- items={exportTypes}+ items={[...exportTypes, ...customExportTypes]}title={[<ArrowDownTrayIcon key='download-icon' className='w-5 h-5 mr-2' />,<Fragment key='export-data'>@@ -1015,6 +1056,7 @@ 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 (@@ -1026,6 +1068,7 @@ const ViewProject = ({onFilter={filterHandler}name={panelName}data={panelsData.data[type]}+ customTabs={customTabs}rowMapper={(rowName) => (<CCRow rowName={rowName} language={language} />)}@@ -1043,6 +1086,7 @@ const ViewProject = ({onFilter={filterHandler}name={panelName}data={panelsData.data[type]}+ customTabs={customTabs}capitalize/>)@@ -1058,6 +1102,7 @@ const ViewProject = ({onFilter={filterHandler}name={panelName}data={panelsData.data[type]}+ customTabs={customTabs}rowMapper={(rowName) => (<RefRow rowName={rowName} showIcons={showIcons} />)}@@ -1074,6 +1119,7 @@ const ViewProject = ({onFilter={filterHandler}name={panelName}data={panelsData.data[type]}+ customTabs={customTabs}/>)})}