From 7db5489a7f16ae65ae6e094bdfb176d67a84c576 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Mon, 18 Nov 2024 11:03:58 +0100 Subject: [PATCH] Plausible analytics fix Signed-off-by: Mihovil Ilakovac --- .../analytics/AnalyticsDashboardPage.tsx.diff | 47 ++++++++++++++++--- .../providers/plausibleAnalyticsUtils.ts.diff | 29 ++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 opensaas-sh/app_diff/src/analytics/providers/plausibleAnalyticsUtils.ts.diff diff --git a/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff b/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff index ab0c5301..96ae364d 100644 --- a/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff +++ b/opensaas-sh/app_diff/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx.diff @@ -1,18 +1,23 @@ --- template/app/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx +++ opensaas-sh/app/src/admin/dashboards/analytics/AnalyticsDashboardPage.tsx @@ -1,4 +1,6 @@ -+import { Link } from "wasp/client/router"; ++import { Link } from 'wasp/client/router'; import { type AuthUser } from 'wasp/auth'; -+import { useState, useEffect } from 'react'; ++import { useState, useEffect, useMemo } from 'react'; import { useQuery, getDailyStats } from 'wasp/client/operations'; import TotalSignupsCard from './TotalSignupsCard'; import TotalPageViewsCard from './TotalPageViewsCard'; -@@ -10,12 +12,45 @@ - import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin' +@@ -7,21 +9,68 @@ + import RevenueAndProfitChart from './RevenueAndProfitChart'; + import SourcesTable from './SourcesTable'; + import DefaultLayout from '../../layout/DefaultLayout'; +-import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin' ++import { useRedirectHomeUnlessUserIsAdmin } from '../../useRedirectHomeUnlessUserIsAdmin'; const Dashboard = ({ user }: { user: AuthUser }) => { +- useRedirectHomeUnlessUserIsAdmin({ user }) + const [isDemoInfoVisible, setIsDemoInfoVisible] = useState(false); - useRedirectHomeUnlessUserIsAdmin({ user }) ++ useRedirectHomeUnlessUserIsAdmin({ user }); const { data: stats, isLoading, error } = useQuery(getDailyStats); @@ -36,6 +41,10 @@ + console.error(error); + } + }; ++ ++ const sortedSources = useMemo(() => { ++ return stats?.dailyStats?.sources?.slice().sort((a, b) => b.visitors - a.visitors); ++ }, [stats?.dailyStats?.sources]); + return ( @@ -43,7 +52,13 @@ + {isDemoInfoVisible && ( +
+
-+ This is actual data from Stripe test purchases.
Try out purchasing a test product!
++ ++ This is actual data from Stripe test purchases.
Try out purchasing a{' '} ++ ++ test product ++ ++ ! ++
+ @@ -53,3 +68,23 @@
+- ++ + + +
+@@ -30,7 +79,7 @@ + + +
+- ++ +
+
+ diff --git a/opensaas-sh/app_diff/src/analytics/providers/plausibleAnalyticsUtils.ts.diff b/opensaas-sh/app_diff/src/analytics/providers/plausibleAnalyticsUtils.ts.diff new file mode 100644 index 00000000..0b05d41f --- /dev/null +++ b/opensaas-sh/app_diff/src/analytics/providers/plausibleAnalyticsUtils.ts.diff @@ -0,0 +1,29 @@ +--- template/app/src/analytics/providers/plausibleAnalyticsUtils.ts ++++ opensaas-sh/app/src/analytics/providers/plausibleAnalyticsUtils.ts +@@ -36,7 +36,7 @@ + + async function getTotalPageViews() { + const response = await fetch( +- `${PLAUSIBLE_BASE_URL}/v1/stats/aggregate?site_id=${PLAUSIBLE_SITE_ID}&metrics=pageviews`, ++ `${PLAUSIBLE_BASE_URL}/v1/stats/aggregate?site_id=${PLAUSIBLE_SITE_ID}&metrics=pageviews&with_imported=true`, + { + method: 'GET', + headers: { +@@ -80,7 +80,7 @@ + } + + async function getPageviewsForDate(date: string) { +- const url = `${PLAUSIBLE_BASE_URL}/v1/stats/aggregate?site_id=${PLAUSIBLE_SITE_ID}&period=day&date=${date}&metrics=pageviews`; ++ const url = `${PLAUSIBLE_BASE_URL}/v1/stats/aggregate?site_id=${PLAUSIBLE_SITE_ID}&period=day&date=${date}&metrics=pageviews&with_imported=true`; + const response = await fetch(url, { + method: 'GET', + headers: headers, +@@ -93,7 +93,7 @@ + } + + export async function getSources() { +- const url = `${PLAUSIBLE_BASE_URL}/v1/stats/breakdown?site_id=${PLAUSIBLE_SITE_ID}&property=visit:source&metrics=visitors`; ++ const url = `${PLAUSIBLE_BASE_URL}/v1/stats/breakdown?site_id=${PLAUSIBLE_SITE_ID}&property=visit:source&metrics=visitors&with_imported=true`; + const response = await fetch(url, { + method: 'GET', + headers: headers,