A performance read
Spend, revenue, and ROAS over the last 30 days, through an LDKit lens.
What it is
A component that reads a :KPISnapshot through an LDKit lens. One snapshot is one window and one currency. It
carries :totalSpend, :totalRevenue, and :roas, which is revenue divided by spend. The graph leaves :roas out
when spend is not greater than zero.
useLensFind loads every snapshot of that schema. It does not take a window argument,
so keep the rows whose :window is "last-30d". The schema comes from manta-codegen, which writes it from the
shapes in your datastore.
Import
import { useLensFind, useSparqlOptions } from "@manta-eu/react/ldo-ui";
import { PerformanceSchema } from "./.ldkit/your-namespace";
PerformanceSchema is a placeholder. Use the name manta-codegen generated. useSparqlOptions reads the SPARQL
connection the Manta providers set up, so this only works inside EmbeddedChatProviders.
Example
import { useLensFind, useSparqlOptions } from "@manta-eu/react/ldo-ui";
import { PerformanceSchema } from "./.ldkit/your-namespace";
export function PerformanceRead() {
const options = useSparqlOptions();
const { data = [] } = useLensFind({
schema: PerformanceSchema,
options,
queryKey: ["performance"],
});
return (
<ul>
{data
.filter((row) => row.window === "last-30d")
.map((row) => (
<li key={row.$id}>
{row.totalSpend} spent, {row.totalRevenue} revenue
{row.roas !== undefined && `, ROAS ${row.roas}`}
</li>
))}
</ul>
);
}
Read :window, :totalSpend, :totalRevenue, and :roas under the names manta-codegen gave them. $id is the
entity IRI. Use it as the list key, and do not parse it.
Request
Pass the schema, the options from useSparqlOptions, and a queryKey. The key identifies the query in the cache. It
does not filter the graph.
const options = useSparqlOptions();
useLensFind({
schema: PerformanceSchema,
options,
queryKey: ["performance"],
});
Response
useLensFind returns UseQueryResult<LensEntity<S>[], Error>. Until the read succeeds, data is undefined and
status is "pending", which is why the example defaults data to []. Afterward, data is the array of entities,
each with an $id and the fields the schema declared. The result also carries the rest of the query state, including
isPending and isFetching.
The object below illustrates that success shape. It is not a live payload. The property names stand in for the ones
manta-codegen writes for :window, :totalSpend, :totalRevenue, and :roas.
{
data: [
{
$id: "https://example.com/id/1",
window: "last-30d",
totalSpend: 1000,
totalRevenue: 4000,
roas: 4,
},
{
$id: "https://example.com/id/2",
window: "last-30d",
totalSpend: 0,
totalRevenue: 80,
},
],
error: null,
isSuccess: true,
status: "success",
}
The second entity has no roas. The ratio is omitted when spend is not greater than zero.