MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / fetchPathPageviewCounts

Function fetchPathPageviewCounts

server/src/services/posthog-query.ts:260–345  ·  view source on GitHub ↗
(
  pathnames: string[],
  days = 30
)

Source from the content-addressed store, hash-verified

258}
259
260export async function fetchPathPageviewCounts(
261 pathnames: string[],
262 days = 30
263): Promise<PathPageviewCounts | null> {
264 const uniquePathnames = Array.from(
265 new Set(
266 pathnames
267 .filter((pathname): pathname is string => typeof pathname === "string" && pathname.trim().length > 0)
268 .map((pathname) => pathname.trim())
269 )
270 );
271
272 if (uniquePathnames.length === 0) {
273 return {};
274 }
275
276 const cacheKey = `${days}:${uniquePathnames.join("|")}`;
277 const cached = pathPageviewCache.get(cacheKey);
278 if (cached && Date.now() - cached.timestamp < PATH_PAGEVIEW_CACHE_TTL_MS) {
279 return cached.data;
280 }
281
282 const config = getPostHogQueryConfig();
283 if (!config) return null;
284
285 const regex = `^(?:${uniquePathnames.map(escapeRegExp).join("|")})$`;
286
287 try {
288 const query = {
289 kind: "InsightVizNode",
290 source: {
291 kind: "TrendsQuery",
292 dateRange: { date_from: `-${days}d` },
293 series: [
294 {
295 kind: "EventsNode",
296 event: "$pageview",
297 custom_name: "Perspective pageviews",
298 properties: [
299 {
300 key: "$pathname",
301 type: "event",
302 operator: "regex",
303 value: regex,
304 },
305 ],
306 },
307 ],
308 breakdownFilter: {
309 breakdown: "$pathname",
310 breakdown_type: "event",
311 breakdown_limit: uniquePathnames.length,
312 },
313 trendsFilter: { display: "ActionsBarValue" },
314 },
315 };
316
317 const result = await queryPostHog(config, query);

Callers 1

createMyContentRouterFunction · 0.85

Calls 7

getPostHogQueryConfigFunction · 0.85
queryPostHogFunction · 0.85
getResultsArrayFunction · 0.85
nowMethod · 0.80
trimMethod · 0.65
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected