Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

add total view duration to stats element

Marc Seitz4d882522b81b
diff --git a/components/documents/stats-card.tsx b/components/documents/stats-card.tsx
index b0825b06..b57cae1f 100644
--- a/components/documents/stats-card.tsx
+++ b/components/documents/stats-card.tsx
@@ -22,10 +22,19 @@ export default function StatsCard() {
active: true,
},
{
- name: "Average view duration",
- value: Math.round(stats?.total_duration / 1000),
- unit: "seconds",
- active: true,
+ name: "Total view duration",
+ value:
+ stats?.total_duration == null
+ ? "46"
+ : stats?.total_duration < 60000
+ ? Math.round(stats?.total_duration / 1000)
+ : `${Math.floor(stats?.total_duration / 60000)}:${
+ Math.round((stats?.total_duration % 60000) / 1000) < 10
+ ? `0${Math.round((stats?.total_duration % 60000) / 1000)}`
+ : Math.round((stats?.total_duration % 60000) / 1000)
+ }`,
+ unit: stats?.total_duration! < 60000 ? "seconds" : "minutes",
+ active: stats?.total_duration ? true : false,
},
{ name: "TBD", value: "98.5%", active: false },
];
diff --git a/components/documents/stats-element.tsx b/components/documents/stats-element.tsx
index dba3eb7e..d825b998 100644
--- a/components/documents/stats-element.tsx
+++ b/components/documents/stats-element.tsx
@@ -14,7 +14,7 @@ interface StatsElementProps {
export default function StatsElement({ stat, statIdx }: StatsElementProps) {
return (
<div
- key={stat.name}
+ key={statIdx}
className={classNames(
statIdx % 2 === 1 ? "sm:border-l" : statIdx === 2 ? "lg:border-l" : "",
"border-t border-white/5 py-6 px-4 sm:px-6 lg:px-8"
diff --git a/lib/swr/use-stats.ts b/lib/swr/use-stats.ts
index 385fcc08..d2920b41 100644
--- a/lib/swr/use-stats.ts
+++ b/lib/swr/use-stats.ts
@@ -11,6 +11,10 @@ interface GroupedView {
interface StatsData {
views: View[];
groupedViews: GroupedView[];
+ duration: {
+ data: { pageNumber: string; avg_duration: number }[];
+ };
+ total_duration: number;
}
export function useStats() {