📈 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
(feature) Embedded param (#367)
Andrii Romasiunce49db1ad7c0
diff --git a/app/App.tsx b/app/App.tsxindex 70b9ddf1c..089f221df 100644--- a/app/App.tsx+++ b/app/App.tsx@@ -137,11 +137,12 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {const isMinimalFooter = _some(minimalFooterPages, (page) => _includes(pathname, page))const isReferralPage = _startsWith(pathname, '/ref/')+ const isProjectPage = _startsWith(pathname, '/projects/')return (// eslint-disable-next-line react/jsx-no-useless-fragment<Suspense fallback={<></>}>- {pathname !== routesPath.main && !isReferralPage && (+ {pathname !== routesPath.main && !isReferralPage && !isProjectPage && (<Header ssrTheme={ssrTheme} authenticated={authenticated} />)}{/* @ts-ignore */}@@ -150,7 +151,7 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {<Outlet /></Suspense></ScrollToTop>- {!isReferralPage && (+ {!isReferralPage && !isProjectPage && (<Footer minimal={isMinimalFooter} authenticated={authenticated} />)}</Suspense>diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsxindex c806fe6d1..80a2dbf05 100644--- a/app/pages/Project/View/ViewProject.tsx+++ b/app/pages/Project/View/ViewProject.tsx@@ -62,6 +62,8 @@ import FlatPicker from 'ui/Flatpicker'import Robot from 'ui/icons/Robot'import Forecast from 'modals/Forecast'import routes from 'routesPath'+import Header from 'components/Header'+import Footer from 'components/Footer'import {getProjectData, getProject, getOverallStats, getLiveVisitors, getPerfData, getProjectDataCustomEvents, getProjectCompareData, checkPassword,} from 'api'@@ -122,14 +124,18 @@ interface IViewProject {},theme: 'dark' | 'light',ssrTheme: 'dark' | 'light',+ embedded: boolean,+ ssrAuthenticated: boolean,}const ViewProject = ({projects, isLoading: _isLoading, showError, cache, cachePerf, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,- setLiveStatsForProject, authenticated, timezone, user, sharedProjects, extensions, generateAlert, setProjectCachePerf,+ setLiveStatsForProject, authenticated: csrAuthenticated, timezone, user, sharedProjects, extensions, generateAlert, setProjectCachePerf,projectTab, setProjectTab, setProjects, setProjectForcastCache, customEventsPrefs, setCustomEventsPrefs, liveStats, password, theme,- ssrTheme,+ ssrTheme, embedded, ssrAuthenticated,}: IViewProject) => {+ const authenticated = isBrowser ? csrAuthenticated : ssrAuthenticated+// t is used for translationconst { t, i18n: { language } }: {t: (key: string, options?: {@@ -1606,7 +1612,7 @@ const ViewProject = ({loadAnalyticsPerf()}}- // eslint-disable-next-line react-hooks/exhaustive-deps+ // eslint-disable-next-line react-hooks/exhaustive-deps}, [project, period, chartType, filters, forecasedChartData, areFiltersParsed, areTimeBucketParsed, arePeriodParsed, activeTab, areFiltersPerfParsed])// using this for fix some bugs with update custom events data for chart@@ -1880,14 +1886,23 @@ const ViewProject = ({if (!isLoading) {return (<>+ {!embedded && (+ <Header ssrTheme={ssrTheme} authenticated={authenticated} />+ )}<EventsRunningOutBanner />- <div ref={ref} className='bg-gray-50 dark:bg-slate-900'>+ <div+ ref={ref}+ className={cx('bg-gray-50 dark:bg-slate-900', {+ 'min-h-[100vh]': analyticsLoading && embedded,+ })}+ ><divclassName={cx('max-w-[1584px] w-full mx-auto py-6 px-2 sm:px-4 lg:px-8',{- 'min-h-min-footer': authenticated || activeTab === PROJECT_TABS.alerts,- 'min-h-min-footer-ad': !authenticated && activeTab !== PROJECT_TABS.alerts,+ 'min-h-min-footer': (authenticated || activeTab === PROJECT_TABS.alerts) && !embedded,+ 'min-h-min-footer-ad': (!authenticated && activeTab !== PROJECT_TABS.alerts) && !embedded,+ 'min-h-[100vh]': embedded,},)}ref={dashboardRef}@@ -2616,7 +2631,7 @@ const ViewProject = ({)}</div></div>- {!authenticated && activeTab !== PROJECT_TABS.alerts && (+ {!authenticated && activeTab !== PROJECT_TABS.alerts && !embedded && (<div className='bg-indigo-600'><div className='w-11/12 mx-auto pb-16 pt-12 px-4 sm:px-6 lg:px-8 lg:flex lg:items-center lg:justify-between'><h2 className='text-3xl sm:text-4xl font-bold tracking-tight text-gray-900'>@@ -2658,14 +2673,30 @@ const ViewProject = ({pid={id}language={language}/>+ {!embedded && (+ <Footer authenticated={authenticated} minimal />+ )}</>)}return (- <div className='min-h-min-footer bg-gray-50 dark:bg-slate-900'>- <Loader />- </div>+ <>+ {!embedded && (+ <Header ssrTheme={ssrTheme} authenticated={authenticated} />+ )}+ <div+ className={cx('min-h-min-footer bg-gray-50 dark:bg-slate-900', {+ 'min-h-min-footer': !embedded,+ 'min-h-[100vh]': embedded,+ })}+ >+ <Loader />+ </div>+ {!embedded && (+ <Footer authenticated={authenticated} minimal />+ )}+ </>)}@@ -2682,6 +2713,8 @@ ViewProject.propTypes = {authenticated: PropTypes.bool.isRequired,extensions: PropTypes.arrayOf(PropTypes.object).isRequired,timezone: PropTypes.string,+ embedded: PropTypes.bool.isRequired,+ ssrAuthenticated: PropTypes.bool.isRequired,}ViewProject.defaultProps = {diff --git a/app/routes/projects.$id.tsx b/app/routes/projects.$id.tsxindex 3724531a9..7f57241aa 100644--- a/app/routes/projects.$id.tsx+++ b/app/routes/projects.$id.tsx@@ -5,7 +5,7 @@ import { json } from '@remix-run/node'import _split from 'lodash/split'import { API_URL } from 'redux/constants'-import { detectTheme } from 'utils/server'+import { detectTheme, isEmbedded, isAuthenticated } from 'utils/server'import ProjectViewStyle from 'styles/ProjectViewStyle.css'export const links: LinksFunction = () => [@@ -24,15 +24,17 @@ export const meta: V2_MetaFunction = ({ location }) => {}export async function loader({ request }: LoaderArgs) {+ const embedded = isEmbedded(request)const [theme] = detectTheme(request)+ const isAuth = isAuthenticated(request)- return json({ theme })+ return json({ theme, embedded, isAuth })}export default function Index() {const {- theme,+ theme, embedded, isAuth,} = useLoaderData<typeof loader>()- return <ViewProject ssrTheme={theme} />+ return <ViewProject ssrTheme={theme} ssrAuthenticated={isAuth} embedded={embedded} />}diff --git a/app/utils/server.ts b/app/utils/server.tsindex 22f77b8c3..4dff8c955 100644--- a/app/utils/server.ts+++ b/app/utils/server.ts@@ -37,6 +37,17 @@ export function detectTheme(request: Request): [ThemeType, boolean] {return ['light', false]}++/**+ * Function detects theme based on user's browser hints and cookies+ *+ * @param request+ * @returns boolean+ */+export function isEmbedded(request: Request): boolean {+ return new URL(request.url).searchParams.get('embedded') === 'true'+}+export function getAccessToken(request: Request): string | null {const cookie = request.headers.get('Cookie')const accessToken = cookie?.match(/(?<=access_token=)[^;]*/)?.[0]