Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: update tinybird pipe to select from pm_click datasource with fallback
Marc Seitz76f3df3acd7c
diff --git a/lib/tinybird/endpoints/get_useragent_per_view.pipe b/lib/tinybird/endpoints/get_useragent_per_view.pipeindex ffd1e8fe..9b0af88f 100644--- a/lib/tinybird/endpoints/get_useragent_per_view.pipe+++ b/lib/tinybird/endpoints/get_useragent_per_view.pipe@@ -1,4 +1,4 @@-VERSION 1+VERSION 3NODE endpointSQL >@@ -10,11 +10,7 @@ SQL >os,deviceFROM- page_views__v3+ pm_click_events__v1WHERE- documentId = {{ String(documentId, required=True) }}- AND viewId = {{ String(viewId, required=True) }}- AND time >= {{ Int64(since, required=True) }}- ORDER BY- viewId, time ASC+ viewId = {{ String(viewId, required=True) }}LIMIT 1diff --git a/pages/api/teams/[teamId]/datarooms/[id]/export-visits.ts b/pages/api/teams/[teamId]/datarooms/[id]/export-visits.tsindex e1f97427..36b18a61 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/export-visits.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/export-visits.ts@@ -4,7 +4,11 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";import { getServerSession } from "next-auth/next";import prisma from "@/lib/prisma";-import { getViewPageDuration, getViewUserAgent } from "@/lib/tinybird";+import {+ getViewPageDuration,+ getViewUserAgent,+ getViewUserAgent_v2,+} from "@/lib/tinybird";import { CustomUser } from "@/lib/types";export default async function handler(@@ -245,13 +249,21 @@ export default async function handler(// Get user agent data for all viewsconst userAgentData = await Promise.all(- documentViews.map((view) =>- getViewUserAgent({- documentId: view.document?.id!,+ documentViews.map(async (view) => {+ const result = await getViewUserAgent({viewId: view.id,- since: 0,- }),- ),+ });++ if (!result || result.rows === 0) {+ return getViewUserAgent_v2({+ documentId: view.document?.id!,+ viewId: view.id,+ since: 0,+ });+ }++ return result;+ }),);// Process each view and add to CSV rowsdiff --git a/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/export-visits.ts b/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/export-visits.tsindex 7e16fb5c..4c154743 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/export-visits.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/groups/[groupId]/export-visits.ts@@ -4,7 +4,11 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";import { getServerSession } from "next-auth/next";import prisma from "@/lib/prisma";-import { getViewPageDuration, getViewUserAgent } from "@/lib/tinybird";+import {+ getViewPageDuration,+ getViewUserAgent,+ getViewUserAgent_v2,+} from "@/lib/tinybird";import { CustomUser } from "@/lib/types";export default async function handler(@@ -251,13 +255,21 @@ export default async function handler(// Get user agent data for all viewsconst userAgentData = await Promise.all(- documentViews.map((view) =>- getViewUserAgent({- documentId: view.document?.id!,+ documentViews.map(async (view) => {+ const result = await getViewUserAgent({viewId: view.id,- since: 0,- }),- ),+ });++ if (!result || result.rows === 0) {+ return getViewUserAgent_v2({+ documentId: view.document?.id!,+ viewId: view.id,+ since: 0,+ });+ }++ return result;+ }),);// Process each view and add to CSV rowsdiff --git a/pages/api/teams/[teamId]/documents/[id]/export-visits.ts b/pages/api/teams/[teamId]/documents/[id]/export-visits.tsindex b7761297..6133cc41 100644--- a/pages/api/teams/[teamId]/documents/[id]/export-visits.ts+++ b/pages/api/teams/[teamId]/documents/[id]/export-visits.ts@@ -4,7 +4,11 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";import { getServerSession } from "next-auth/next";import prisma from "@/lib/prisma";-import { getViewPageDuration, getViewUserAgent } from "@/lib/tinybird";+import {+ getViewPageDuration,+ getViewUserAgent,+ getViewUserAgent_v2,+} from "@/lib/tinybird";import { CustomUser } from "@/lib/types";export default async function handler(@@ -145,13 +149,21 @@ export default async function handler();const userAgentData = await Promise.all(- views.map((view) =>- getViewUserAgent({- documentId: docId,+ views.map(async (view) => {+ const result = await getViewUserAgent({viewId: view.id,- since: 0,- }),- ),+ });++ if (!result || result.rows === 0) {+ return getViewUserAgent_v2({+ documentId: docId,+ viewId: view.id,+ since: 0,+ });+ }++ return result;+ }),);// Process each view and add to CSV rowsviews.forEach((view, index) => {diff --git a/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/user-agent.ts b/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/user-agent.tsindex 87733eeb..197f0615 100644--- a/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/user-agent.ts+++ b/pages/api/teams/[teamId]/documents/[id]/views/[viewId]/user-agent.ts@@ -5,7 +5,7 @@ import { getServerSession } from "next-auth/next";import { errorhandler } from "@/lib/errorHandler";import prisma from "@/lib/prisma";-import { getViewUserAgent } from "@/lib/tinybird";+import { getViewUserAgent, getViewUserAgent_v2 } from "@/lib/tinybird";import { CustomUser } from "@/lib/types";export default async function handle(@@ -55,12 +55,29 @@ export default async function handle(return res.status(403).end("Forbidden");}- const userAgent = await getViewUserAgent({- documentId: docId,+ let userAgent: {+ rows?: number | undefined;+ data: {+ country: string;+ city: string;+ browser: string;+ os: string;+ device: string;+ }[];+ };++ userAgent = await getViewUserAgent({viewId: viewId,- since: 0,});+ if (!userAgent || userAgent.rows === 0) {+ userAgent = await getViewUserAgent_v2({+ documentId: docId,+ viewId: viewId,+ since: 0,+ });+ }+const userAgentData = userAgent.data[0];// Include country and city for business and datarooms plansif (team.plan.includes("business") || team.plan.includes("datarooms")) {