getEvents
A query method to retrieve your events stored in BaseHub.
import { getEvents } from 'basehub/events'
Parameters
Table Query
Time-series Query
Be wary of exposing the adminKey
in the client. Anyone with this key will be able to read and update existing events from that specific block.
Examples
import { getEvents } from "basehub/events"
// Table query
const tableData = await getEvents("analytics:pageviews", {
type: "table",
first: 10,
skip: 0,
})
// Time-series query
const timeSeriesData = await getEvents("analytics:pageviews", {
type: "time-series",
range: "month",
})
import { getEvents } from "basehub/events"
import { IncrementViews } from "./increment-views"
import { unstable_noStore } from "next/cache"
import { draftMode } from "next/headers"
import type { PageViews } from "~/.basehub/schema"
export const ViewsFragment = async ({
adminKey,
ingestKey,
increment,
}: {
adminKey: PageViews["adminKey"]
ingestKey: PageViews["ingestKey"]
increment?: boolean
}) => {
unstable_noStore()
const { isEnabled: isDraftMode } = draftMode()
const { data: views } = await getEvents(adminKey, {
type: "time-series",
range: "all-time",
})
return (
<>
{views || "0"}
{increment && !isDraftMode && (
<IncrementViews ingestKey={ingestKey} />
)}
</>
)
}