@10x-media/analytics 0.1.0-beta.0 → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/README.md +37 -357
- package/dist/adapters/ga4/ga4.d.ts +20 -0
- package/dist/adapters/ga4/ga4.js +177 -0
- package/dist/{fetchJson-DZb2_Puj.js → adapters/http/fetchJson.js} +2 -2
- package/dist/adapters/http/fetchJson.js.map +1 -0
- package/dist/adapters/plausible/plausible.d.ts +15 -0
- package/dist/adapters/plausible/plausible.js +143 -0
- package/dist/adapters/posthog/posthog.d.ts +23 -0
- package/dist/adapters/posthog/posthog.js +121 -0
- package/dist/adapters/posthog/posthog.js.map +1 -0
- package/dist/{series-zytbzPoc.js → adapters/series.js} +2 -2
- package/dist/adapters/series.js.map +1 -0
- package/dist/adapters/umami/umami.d.ts +18 -0
- package/dist/adapters/umami/umami.js +139 -0
- package/dist/binding/resolvePath.js +61 -0
- package/dist/binding/resolvePath.js.map +1 -0
- package/dist/binding/types.d.ts +53 -0
- package/dist/charts/BarList.d.ts +20 -0
- package/dist/charts/BarList.js +73 -0
- package/dist/charts/BarList.js.map +1 -0
- package/dist/charts/TrendChart.d.ts +25 -0
- package/dist/charts/TrendChart.js +186 -0
- package/dist/charts/TrendChart.js.map +1 -0
- package/dist/charts/bars.d.ts +9 -0
- package/dist/charts/bars.js +19 -0
- package/dist/charts/bars.js.map +1 -0
- package/dist/charts/bucket.js +79 -0
- package/dist/charts/bucket.js.map +1 -0
- package/dist/charts/spline.js +84 -0
- package/dist/charts/spline.js.map +1 -0
- package/dist/charts/styles.js +42 -0
- package/dist/charts/styles.js.map +1 -0
- package/dist/core/cacheKey.js +31 -0
- package/dist/core/cacheKey.js.map +1 -0
- package/dist/core/capabilities.d.ts +12 -0
- package/dist/core/capabilities.js +12 -0
- package/dist/core/capabilities.js.map +1 -0
- package/dist/{contract-CWZPKWuR.d.ts → core/contract.d.ts} +30 -4
- package/dist/core/contract.js +10 -0
- package/dist/core/contract.js.map +1 -0
- package/dist/core/granularity.js +17 -0
- package/dist/core/granularity.js.map +1 -0
- package/dist/core/options.d.ts +115 -0
- package/dist/core/options.js +107 -0
- package/dist/core/options.js.map +1 -0
- package/dist/core/registry.js +24 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/scopedRead.js +57 -0
- package/dist/core/scopedRead.js.map +1 -0
- package/dist/exports/adapters/ga4.d.ts +2 -20
- package/dist/exports/adapters/ga4.js +1 -176
- package/dist/exports/adapters/native.d.ts +2 -22
- package/dist/exports/adapters/native.js +1 -848
- package/dist/exports/adapters/plausible.d.ts +2 -15
- package/dist/exports/adapters/plausible.js +1 -142
- package/dist/exports/adapters/posthog.d.ts +2 -17
- package/dist/exports/adapters/posthog.js +1 -118
- package/dist/exports/adapters/umami.d.ts +2 -18
- package/dist/exports/adapters/umami.js +1 -138
- package/dist/exports/client.d.ts +5 -77
- package/dist/exports/client.js +4 -386
- package/dist/exports/geo.d.ts +4 -19
- package/dist/exports/geo.js +3 -1
- package/dist/exports/i18n.d.ts +3 -63
- package/dist/exports/i18n.js +2 -2
- package/dist/exports/next.d.ts +2 -0
- package/dist/exports/next.js +2 -0
- package/dist/exports/rsc.d.ts +13 -120
- package/dist/exports/rsc.js +10 -597
- package/dist/exports/types.d.ts +6 -4
- package/dist/exports/types.js +2 -1
- package/dist/fields/AnalyticsStatField.d.ts +31 -0
- package/dist/fields/AnalyticsStatField.js +93 -0
- package/dist/fields/AnalyticsStatField.js.map +1 -0
- package/dist/fields/dateRange/field.js +55 -0
- package/dist/fields/dateRange/field.js.map +1 -0
- package/dist/fields/dateRange/styles.js +23 -0
- package/dist/fields/dateRange/styles.js.map +1 -0
- package/dist/fields/dateRange/types.d.ts +11 -0
- package/dist/fields/dateRange/ui.d.ts +9 -0
- package/dist/fields/dateRange/ui.js +373 -0
- package/dist/fields/dateRange/ui.js.map +1 -0
- package/dist/fields/factories.d.ts +52 -0
- package/dist/fields/factories.js +65 -0
- package/dist/fields/factories.js.map +1 -0
- package/dist/fields/format.d.ts +7 -0
- package/dist/fields/format.js +22 -0
- package/dist/fields/format.js.map +1 -0
- package/dist/fields/readForDocument.js +107 -0
- package/dist/fields/readForDocument.js.map +1 -0
- package/dist/index.d.ts +18 -3
- package/dist/index.js +55 -1025
- package/dist/index.js.map +1 -1
- package/dist/native/collections/events.js +101 -0
- package/dist/native/collections/events.js.map +1 -0
- package/dist/native/collections/rollups.js +115 -0
- package/dist/native/collections/rollups.js.map +1 -0
- package/dist/native/collections/seen.js +47 -0
- package/dist/native/collections/seen.js.map +1 -0
- package/dist/native/geo/composeGeoResolvers.d.ts +7 -0
- package/dist/native/geo/composeGeoResolvers.js +14 -0
- package/dist/native/geo/composeGeoResolvers.js.map +1 -0
- package/dist/{geoResolver-CasIa4T9.d.ts → native/geo/geoResolver.d.ts} +2 -2
- package/dist/native/geo/geoResolver.js +11 -0
- package/dist/native/geo/geoResolver.js.map +1 -0
- package/dist/native/geo/maxmindResolver.d.ts +16 -0
- package/dist/native/geo/maxmindResolver.js +55 -0
- package/dist/native/geo/maxmindResolver.js.map +1 -0
- package/dist/native/ingest/device.js +15 -0
- package/dist/native/ingest/device.js.map +1 -0
- package/dist/native/ingest/endpoint.js +27 -0
- package/dist/native/ingest/endpoint.js.map +1 -0
- package/dist/native/ingest/flushBatch.js +69 -0
- package/dist/native/ingest/flushBatch.js.map +1 -0
- package/dist/native/ingest/normalizeEvent.js +38 -0
- package/dist/native/ingest/normalizeEvent.js.map +1 -0
- package/dist/native/ingest/salt.js +14 -0
- package/dist/native/ingest/salt.js.map +1 -0
- package/dist/native/ingest/source.js +22 -0
- package/dist/native/ingest/source.js.map +1 -0
- package/dist/native/ingest/visitorHash.js +12 -0
- package/dist/native/ingest/visitorHash.js.map +1 -0
- package/dist/native/ingest/writeBuffer.js +55 -0
- package/dist/native/ingest/writeBuffer.js.map +1 -0
- package/dist/native/ingest/writeEvent.js +13 -0
- package/dist/native/ingest/writeEvent.js.map +1 -0
- package/dist/native/nativeAdapter.d.ts +22 -0
- package/dist/native/nativeAdapter.js +213 -0
- package/dist/native/nativeAdapter.js.map +1 -0
- package/dist/native/realtime/buildRealtime.js +53 -0
- package/dist/native/realtime/buildRealtime.js.map +1 -0
- package/dist/native/retention/pruneTask.js +29 -0
- package/dist/native/retention/pruneTask.js.map +1 -0
- package/dist/native/rollupAcc.js +50 -0
- package/dist/native/rollupAcc.js.map +1 -0
- package/dist/native/rollups/applyDistinctDeltas.js +9 -0
- package/dist/native/rollups/applyDistinctDeltas.js.map +1 -0
- package/dist/native/rollups/bumpRollup.js +52 -0
- package/dist/native/rollups/bumpRollup.js.map +1 -0
- package/dist/native/rollups/deltas.js +31 -0
- package/dist/native/rollups/deltas.js.map +1 -0
- package/dist/native/rollups/insertIfNew.js +19 -0
- package/dist/native/rollups/insertIfNew.js.map +1 -0
- package/dist/next/posthogProxyRewrites.d.ts +36 -0
- package/dist/next/posthogProxyRewrites.js +50 -0
- package/dist/next/posthogProxyRewrites.js.map +1 -0
- package/dist/plugin/realtimeEndpoint.js +36 -0
- package/dist/plugin/realtimeEndpoint.js.map +1 -0
- package/dist/plugin/registerTranslations.js +19 -0
- package/dist/plugin/registerTranslations.js.map +1 -0
- package/dist/plugin/runtime.js +20 -0
- package/dist/plugin/runtime.js.map +1 -0
- package/dist/plugin/warmTask.js +165 -0
- package/dist/plugin/warmTask.js.map +1 -0
- package/dist/providers/collection.js +159 -0
- package/dist/providers/collection.js.map +1 -0
- package/dist/providers/factory.js +62 -0
- package/dist/providers/factory.js.map +1 -0
- package/dist/providers/resolver.js +67 -0
- package/dist/providers/resolver.js.map +1 -0
- package/dist/providers/secrets.js +27 -0
- package/dist/providers/secrets.js.map +1 -0
- package/dist/surfacing/cacheStore.js +26 -0
- package/dist/surfacing/cacheStore.js.map +1 -0
- package/dist/surfacing/coalesce.js +15 -0
- package/dist/surfacing/coalesce.js.map +1 -0
- package/dist/surfacing/engine.js +63 -0
- package/dist/surfacing/engine.js.map +1 -0
- package/dist/surfacing/queue.js +44 -0
- package/dist/surfacing/queue.js.map +1 -0
- package/dist/sync/collection.js +65 -0
- package/dist/sync/collection.js.map +1 -0
- package/dist/sync/syncTask.js +123 -0
- package/dist/sync/syncTask.js.map +1 -0
- package/dist/testing/memoryAdapter.d.ts +1 -1
- package/dist/timeframe/presets.d.ts +6 -0
- package/dist/timeframe/presets.js +63 -0
- package/dist/timeframe/presets.js.map +1 -0
- package/dist/{translations-keiKtSjF.js → translations/en.js} +25 -23
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +14 -0
- package/dist/translations/index.js +26 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/keys.d.ts +78 -0
- package/dist/{keys-DEqL4LOT.js → translations/keys.js} +24 -3
- package/dist/translations/keys.js.map +1 -0
- package/dist/translations/metricKeys.js +30 -0
- package/dist/translations/metricKeys.js.map +1 -0
- package/dist/translations/server.js +13 -0
- package/dist/translations/server.js.map +1 -0
- package/dist/translations/useTranslation.js +12 -0
- package/dist/translations/useTranslation.js.map +1 -0
- package/dist/widgets/AnalyticsBreakdownWidget.d.ts +7 -0
- package/dist/widgets/AnalyticsBreakdownWidget.js +85 -0
- package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -0
- package/dist/widgets/AnalyticsMetricWidget.d.ts +7 -0
- package/dist/widgets/AnalyticsMetricWidget.js +81 -0
- package/dist/widgets/AnalyticsMetricWidget.js.map +1 -0
- package/dist/widgets/AnalyticsRealtimeWidget.d.ts +7 -0
- package/dist/widgets/AnalyticsRealtimeWidget.js +64 -0
- package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -0
- package/dist/widgets/AnalyticsTrendWidget.d.ts +7 -0
- package/dist/widgets/AnalyticsTrendWidget.js +91 -0
- package/dist/widgets/AnalyticsTrendWidget.js.map +1 -0
- package/dist/widgets/RealtimeCounter.d.ts +19 -0
- package/dist/widgets/RealtimeCounter.js +76 -0
- package/dist/widgets/RealtimeCounter.js.map +1 -0
- package/dist/widgets/breakdownTypes.js +29 -0
- package/dist/widgets/breakdownTypes.js.map +1 -0
- package/dist/widgets/cardChrome.js +22 -0
- package/dist/widgets/cardChrome.js.map +1 -0
- package/dist/widgets/customWidget.d.ts +20 -0
- package/dist/widgets/customWidget.js +30 -0
- package/dist/widgets/customWidget.js.map +1 -0
- package/dist/widgets/defaults.d.ts +12 -0
- package/dist/widgets/defaults.js +72 -0
- package/dist/widgets/defaults.js.map +1 -0
- package/dist/widgets/range.js +28 -0
- package/dist/widgets/range.js.map +1 -0
- package/dist/widgets/readForWidget.d.ts +27 -0
- package/dist/widgets/readForWidget.js +57 -0
- package/dist/widgets/readForWidget.js.map +1 -0
- package/dist/widgets/readForWidgetBreakdown.d.ts +38 -0
- package/dist/widgets/readForWidgetBreakdown.js +75 -0
- package/dist/widgets/readForWidgetBreakdown.js.map +1 -0
- package/dist/{readForWidgetRealtime-D1BD37ST.d.ts → widgets/readForWidgetRealtime.d.ts} +5 -3
- package/dist/widgets/readForWidgetRealtime.js +63 -0
- package/dist/widgets/readForWidgetRealtime.js.map +1 -0
- package/dist/widgets/readForWidgetSeries.d.ts +38 -0
- package/dist/widgets/readForWidgetSeries.js +97 -0
- package/dist/widgets/readForWidgetSeries.js.map +1 -0
- package/dist/widgets/realtimePoll.js +26 -0
- package/dist/widgets/realtimePoll.js.map +1 -0
- package/dist/widgets/registerWidgets.js +249 -0
- package/dist/widgets/registerWidgets.js.map +1 -0
- package/dist/widgets/types.js +13 -0
- package/dist/widgets/types.js.map +1 -0
- package/package.json +16 -2
- package/dist/RealtimeCounter-BJrjMPSa.js +0 -473
- package/dist/RealtimeCounter-BJrjMPSa.js.map +0 -1
- package/dist/dist-B6HruP5v.js +0 -4731
- package/dist/dist-B6HruP5v.js.map +0 -1
- package/dist/exports/adapters/native.js.map +0 -1
- package/dist/exports/adapters/posthog.js.map +0 -1
- package/dist/exports/client.js.map +0 -1
- package/dist/exports/rsc.js.map +0 -1
- package/dist/fetchJson-DZb2_Puj.js.map +0 -1
- package/dist/index-CZdCT0WJ.d.ts +0 -98
- package/dist/keys-DEqL4LOT.js.map +0 -1
- package/dist/lib-CE5x1zLQ.js +0 -1058
- package/dist/lib-CE5x1zLQ.js.map +0 -1
- package/dist/maxmindResolver-CXYXXdul.js +0 -99
- package/dist/maxmindResolver-CXYXXdul.js.map +0 -1
- package/dist/presets-CBfq_uJX.d.ts +0 -38
- package/dist/series-zytbzPoc.js.map +0 -1
- package/dist/server-Cuvhgz-S.js +0 -492
- package/dist/server-Cuvhgz-S.js.map +0 -1
- package/dist/translations-keiKtSjF.js.map +0 -1
- /package/dist/{exports/adapters → adapters/ga4}/ga4.js.map +0 -0
- /package/dist/{exports/adapters → adapters/plausible}/plausible.js.map +0 -0
- /package/dist/{exports/adapters → adapters/umami}/umami.js.map +0 -0
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/adapters/plausible/plausible.d.ts
|
|
4
|
-
interface PlausibleConfig {
|
|
5
|
-
siteId: string;
|
|
6
|
-
apiKey: string;
|
|
7
|
-
/** Base URL for self-hosted CE. Defaults to Plausible Cloud. */
|
|
8
|
-
host?: string;
|
|
9
|
-
/** Maximum days of historical data. Defaults to 730. Pass null to disable clamping. */
|
|
10
|
-
maxLookbackDays?: number | null;
|
|
11
|
-
}
|
|
12
|
-
declare function plausible(config: PlausibleConfig): AnalyticsAdapter;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { type PlausibleConfig, plausible };
|
|
15
|
-
//# sourceMappingURL=plausible.d.ts.map
|
|
1
|
+
import { PlausibleConfig, plausible } from "../../adapters/plausible/plausible.js";
|
|
2
|
+
export { type PlausibleConfig, plausible };
|
|
@@ -1,143 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as dayIso } from "../../series-zytbzPoc.js";
|
|
3
|
-
//#region src/adapters/plausible/plausible.ts
|
|
4
|
-
const METRIC_MAP = {
|
|
5
|
-
pageviews: "pageviews",
|
|
6
|
-
visitors: "visitors",
|
|
7
|
-
visits: "visits",
|
|
8
|
-
sessions: "visits",
|
|
9
|
-
bounceRate: "bounce_rate",
|
|
10
|
-
avgDuration: "visit_duration",
|
|
11
|
-
events: "events",
|
|
12
|
-
scrollDepth: "scroll_depth",
|
|
13
|
-
revenue: "total_revenue"
|
|
14
|
-
};
|
|
15
|
-
const DIMENSION_MAP = {
|
|
16
|
-
page: "event:page",
|
|
17
|
-
source: "visit:source",
|
|
18
|
-
referrer: "visit:referrer",
|
|
19
|
-
device: "visit:device",
|
|
20
|
-
browser: "visit:browser",
|
|
21
|
-
os: "visit:os",
|
|
22
|
-
country: "visit:country",
|
|
23
|
-
region: "visit:region",
|
|
24
|
-
city: "visit:city",
|
|
25
|
-
utmSource: "visit:utm_source",
|
|
26
|
-
utmMedium: "visit:utm_medium",
|
|
27
|
-
utmCampaign: "visit:utm_campaign"
|
|
28
|
-
};
|
|
29
|
-
const plausibleMetrics = new Set(Object.keys(METRIC_MAP));
|
|
30
|
-
const plausibleDimensions = new Set(Object.keys(DIMENSION_MAP));
|
|
31
|
-
const toContractValue = (metric, raw) => metric === "avgDuration" ? Math.round(raw * 1e3) : raw;
|
|
32
|
-
function plausible(config) {
|
|
33
|
-
const host = config.host ?? "https://plausible.io";
|
|
34
|
-
return {
|
|
35
|
-
id: "plausible",
|
|
36
|
-
label: "Plausible",
|
|
37
|
-
capabilities: {
|
|
38
|
-
perPageQuery: true,
|
|
39
|
-
realtime: false,
|
|
40
|
-
comparison: false,
|
|
41
|
-
minGranularity: "day",
|
|
42
|
-
maxLookbackDays: config.maxLookbackDays !== void 0 ? config.maxLookbackDays : 730,
|
|
43
|
-
metrics: plausibleMetrics,
|
|
44
|
-
dimensions: plausibleDimensions,
|
|
45
|
-
batchPageReport: true,
|
|
46
|
-
rateLimit: { requestsPerHour: 600 },
|
|
47
|
-
recommendedTtl: {
|
|
48
|
-
realtime: 300,
|
|
49
|
-
aggregate: 3600
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
isConfigured: () => Boolean(config.siteId && config.apiKey),
|
|
53
|
-
async query(q, ctx) {
|
|
54
|
-
const fetchedAt = q.dateRange.end.toISOString();
|
|
55
|
-
const wanted = q.metrics.filter((m) => METRIC_MAP[m]);
|
|
56
|
-
const providerMetrics = [...new Set(wanted.map((m) => METRIC_MAP[m]))];
|
|
57
|
-
const dims = (q.dimensions ?? []).filter((d) => DIMENSION_MAP[d]);
|
|
58
|
-
const filters = [];
|
|
59
|
-
if (q.path) filters.push([
|
|
60
|
-
"is",
|
|
61
|
-
"event:page",
|
|
62
|
-
[q.path]
|
|
63
|
-
]);
|
|
64
|
-
const readRow = (row) => {
|
|
65
|
-
const out = {};
|
|
66
|
-
for (const m of wanted) {
|
|
67
|
-
const idx = providerMetrics.indexOf(METRIC_MAP[m]);
|
|
68
|
-
out[m] = toContractValue(m, row.metrics[idx] ?? 0);
|
|
69
|
-
}
|
|
70
|
-
return out;
|
|
71
|
-
};
|
|
72
|
-
const postQuery = (extra) => fetchJson(`${host}/api/v2/query`, {
|
|
73
|
-
method: "POST",
|
|
74
|
-
headers: { authorization: `Bearer ${config.apiKey}` },
|
|
75
|
-
body: {
|
|
76
|
-
site_id: config.siteId,
|
|
77
|
-
metrics: providerMetrics,
|
|
78
|
-
date_range: [q.dateRange.start.toISOString().slice(0, 10), q.dateRange.end.toISOString().slice(0, 10)],
|
|
79
|
-
...filters.length ? { filters } : {},
|
|
80
|
-
...extra
|
|
81
|
-
},
|
|
82
|
-
signal: ctx.signal,
|
|
83
|
-
provider: "plausible"
|
|
84
|
-
});
|
|
85
|
-
const fetchTotals = async () => {
|
|
86
|
-
const data = await postQuery({});
|
|
87
|
-
return data.results[0] ? readRow(data.results[0]) : {};
|
|
88
|
-
};
|
|
89
|
-
if (q.granularity === "day" && !dims.length) {
|
|
90
|
-
const [seriesData, totals] = await Promise.all([postQuery({ dimensions: ["time:day"] }), fetchTotals()]);
|
|
91
|
-
const rows = [];
|
|
92
|
-
for (const row of seriesData.results) {
|
|
93
|
-
const ts = dayIso(row.dimensions[0] ?? "");
|
|
94
|
-
if (ts) rows.push({
|
|
95
|
-
timestamp: ts,
|
|
96
|
-
metrics: readRow(row)
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
rows,
|
|
101
|
-
totals,
|
|
102
|
-
meta: {
|
|
103
|
-
provider: "plausible",
|
|
104
|
-
fetchedAt
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
if (!dims.length) {
|
|
109
|
-
const totals = await fetchTotals();
|
|
110
|
-
return {
|
|
111
|
-
rows: [{ metrics: totals }],
|
|
112
|
-
totals,
|
|
113
|
-
meta: {
|
|
114
|
-
provider: "plausible",
|
|
115
|
-
fetchedAt
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
rows: (await postQuery({ dimensions: dims.map((d) => DIMENSION_MAP[d]) })).results.map((row) => {
|
|
121
|
-
const dimValues = {};
|
|
122
|
-
for (let i = 0; i < dims.length; i++) {
|
|
123
|
-
const d = dims[i];
|
|
124
|
-
if (d !== void 0) dimValues[d] = row.dimensions[i] ?? "";
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
dimensions: dimValues,
|
|
128
|
-
metrics: readRow(row)
|
|
129
|
-
};
|
|
130
|
-
}),
|
|
131
|
-
totals: void 0,
|
|
132
|
-
meta: {
|
|
133
|
-
provider: "plausible",
|
|
134
|
-
fetchedAt
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
1
|
+
import { plausible } from "../../adapters/plausible/plausible.js";
|
|
141
2
|
export { plausible };
|
|
142
|
-
|
|
143
|
-
//# sourceMappingURL=plausible.js.map
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/adapters/posthog/posthog.d.ts
|
|
4
|
-
interface PosthogConfig {
|
|
5
|
-
/** PostHog project id (numeric). */
|
|
6
|
-
projectId: string;
|
|
7
|
-
/** Personal API key with the "Query Read" scope (phx_...). */
|
|
8
|
-
apiKey: string;
|
|
9
|
-
/** API host. Defaults to US Cloud; EU is https://eu.posthog.com, self-host is your instance URL. */
|
|
10
|
-
host?: string;
|
|
11
|
-
/** Maximum days of historical data. Defaults to 730. Pass null to disable clamping. */
|
|
12
|
-
maxLookbackDays?: number | null;
|
|
13
|
-
}
|
|
14
|
-
declare function posthog(config: PosthogConfig): AnalyticsAdapter;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { type PosthogConfig, posthog };
|
|
17
|
-
//# sourceMappingURL=posthog.d.ts.map
|
|
1
|
+
import { PosthogConfig, posthog } from "../../adapters/posthog/posthog.js";
|
|
2
|
+
export { type PosthogConfig, posthog };
|
|
@@ -1,119 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as dayIso } from "../../series-zytbzPoc.js";
|
|
3
|
-
//#region src/adapters/posthog/posthog.ts
|
|
4
|
-
const US_CLOUD = "https://us.posthog.com";
|
|
5
|
-
const METRIC_SQL = {
|
|
6
|
-
pageviews: "count()",
|
|
7
|
-
visitors: "count(DISTINCT person_id)",
|
|
8
|
-
visits: "count(DISTINCT properties.$session_id)",
|
|
9
|
-
sessions: "count(DISTINCT properties.$session_id)"
|
|
10
|
-
};
|
|
11
|
-
const posthogMetrics = new Set(Object.keys(METRIC_SQL));
|
|
12
|
-
const posthogDimensions = new Set(["page"]);
|
|
13
|
-
const sqlString = (value) => `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
14
|
-
const sqlDateTimeLiteral = (d) => sqlString(d.toISOString().slice(0, 19).replace("T", " "));
|
|
15
|
-
function posthog(config) {
|
|
16
|
-
const host = config.host ?? US_CLOUD;
|
|
17
|
-
return {
|
|
18
|
-
id: "posthog",
|
|
19
|
-
label: "PostHog",
|
|
20
|
-
capabilities: {
|
|
21
|
-
perPageQuery: true,
|
|
22
|
-
realtime: false,
|
|
23
|
-
comparison: false,
|
|
24
|
-
minGranularity: "day",
|
|
25
|
-
maxLookbackDays: config.maxLookbackDays !== void 0 ? config.maxLookbackDays : 730,
|
|
26
|
-
metrics: posthogMetrics,
|
|
27
|
-
dimensions: posthogDimensions,
|
|
28
|
-
batchPageReport: true,
|
|
29
|
-
rateLimit: {
|
|
30
|
-
requestsPerMinute: 240,
|
|
31
|
-
requestsPerHour: 2400
|
|
32
|
-
},
|
|
33
|
-
recommendedTtl: {
|
|
34
|
-
realtime: 300,
|
|
35
|
-
aggregate: 3600
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
isConfigured: () => Boolean(config.projectId && config.apiKey),
|
|
39
|
-
async query(q, ctx) {
|
|
40
|
-
const fetchedAt = q.dateRange.end.toISOString();
|
|
41
|
-
const wanted = q.metrics.filter((m) => METRIC_SQL[m]);
|
|
42
|
-
const exprs = [...new Set(wanted.map((m) => METRIC_SQL[m]))];
|
|
43
|
-
const wantsPageBreakdown = (q.dimensions ?? []).includes("page");
|
|
44
|
-
const where = [
|
|
45
|
-
"event = '$pageview'",
|
|
46
|
-
`timestamp >= toDateTime(${sqlDateTimeLiteral(q.dateRange.start)})`,
|
|
47
|
-
`timestamp <= toDateTime(${sqlDateTimeLiteral(q.dateRange.end)})`
|
|
48
|
-
];
|
|
49
|
-
if (q.path) where.push(`properties.$pathname = ${sqlString(q.path)}`);
|
|
50
|
-
const selectMetrics = exprs.map((expr, i) => `${expr} AS m${i}`);
|
|
51
|
-
const runSql = (sql) => fetchJson(`${host}/api/projects/${config.projectId}/query/`, {
|
|
52
|
-
method: "POST",
|
|
53
|
-
headers: { authorization: `Bearer ${config.apiKey}` },
|
|
54
|
-
body: { query: {
|
|
55
|
-
kind: "HogQLQuery",
|
|
56
|
-
query: sql
|
|
57
|
-
} },
|
|
58
|
-
signal: ctx.signal,
|
|
59
|
-
provider: "posthog"
|
|
60
|
-
});
|
|
61
|
-
const readRow = (row, offset) => {
|
|
62
|
-
const out = {};
|
|
63
|
-
for (const m of wanted) {
|
|
64
|
-
const idx = exprs.indexOf(METRIC_SQL[m]);
|
|
65
|
-
out[m] = Number(row[offset + idx] ?? 0);
|
|
66
|
-
}
|
|
67
|
-
return out;
|
|
68
|
-
};
|
|
69
|
-
const fetchTotals = async () => {
|
|
70
|
-
const row = (await runSql(`SELECT ${selectMetrics.join(", ")} FROM events WHERE ${where.join(" AND ")}`)).results[0];
|
|
71
|
-
return row ? readRow(row, 0) : {};
|
|
72
|
-
};
|
|
73
|
-
if (q.granularity === "day" && !wantsPageBreakdown) {
|
|
74
|
-
const seriesSql = `SELECT toStartOfDay(timestamp) AS day, ${selectMetrics.join(", ")} FROM events WHERE ${where.join(" AND ")} GROUP BY day ORDER BY day`;
|
|
75
|
-
const [seriesData, totals] = await Promise.all([runSql(seriesSql), fetchTotals()]);
|
|
76
|
-
const rows = [];
|
|
77
|
-
for (const row of seriesData.results) {
|
|
78
|
-
const ts = dayIso(String(row[0] ?? ""));
|
|
79
|
-
if (ts) rows.push({
|
|
80
|
-
timestamp: ts,
|
|
81
|
-
metrics: readRow(row, 1)
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
rows,
|
|
86
|
-
totals,
|
|
87
|
-
meta: {
|
|
88
|
-
provider: "posthog",
|
|
89
|
-
fetchedAt
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (wantsPageBreakdown) return {
|
|
94
|
-
rows: (await runSql(`SELECT properties.$pathname AS path, ${selectMetrics.join(", ")} FROM events WHERE ${where.join(" AND ")} GROUP BY path ORDER BY m0 DESC LIMIT ${q.limit ?? 100}`)).results.map((row) => ({
|
|
95
|
-
dimensions: { page: String(row[0] ?? "") },
|
|
96
|
-
metrics: readRow(row, 1)
|
|
97
|
-
})),
|
|
98
|
-
totals: void 0,
|
|
99
|
-
meta: {
|
|
100
|
-
provider: "posthog",
|
|
101
|
-
fetchedAt
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const totals = await fetchTotals();
|
|
105
|
-
return {
|
|
106
|
-
rows: [{ metrics: totals }],
|
|
107
|
-
totals,
|
|
108
|
-
meta: {
|
|
109
|
-
provider: "posthog",
|
|
110
|
-
fetchedAt
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
//#endregion
|
|
1
|
+
import { posthog } from "../../adapters/posthog/posthog.js";
|
|
117
2
|
export { posthog };
|
|
118
|
-
|
|
119
|
-
//# sourceMappingURL=posthog.js.map
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/adapters/umami/umami.d.ts
|
|
4
|
-
interface UmamiConfig {
|
|
5
|
-
websiteId: string;
|
|
6
|
-
/** Umami Cloud API key (sent as x-umami-api-key). */
|
|
7
|
-
apiKey?: string;
|
|
8
|
-
/** Self-hosted bearer token (from POST /api/auth/login). */
|
|
9
|
-
token?: string;
|
|
10
|
-
/** API base URL. Defaults to Umami Cloud (https://api.umami.is/v1). Self-hosted is e.g. https://site/api. */
|
|
11
|
-
host?: string;
|
|
12
|
-
/** Maximum days of historical data. Defaults to 730. Pass null to disable clamping. */
|
|
13
|
-
maxLookbackDays?: number | null;
|
|
14
|
-
}
|
|
15
|
-
declare function umami(config: UmamiConfig): AnalyticsAdapter;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { type UmamiConfig, umami };
|
|
18
|
-
//# sourceMappingURL=umami.d.ts.map
|
|
1
|
+
import { UmamiConfig, umami } from "../../adapters/umami/umami.js";
|
|
2
|
+
export { type UmamiConfig, umami };
|
|
@@ -1,139 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as dayIso } from "../../series-zytbzPoc.js";
|
|
3
|
-
//#region src/adapters/umami/umami.ts
|
|
4
|
-
const CLOUD_BASE = "https://api.umami.is/v1";
|
|
5
|
-
const umamiMetrics = new Set([
|
|
6
|
-
"pageviews",
|
|
7
|
-
"visitors",
|
|
8
|
-
"visits",
|
|
9
|
-
"sessions",
|
|
10
|
-
"bounceRate",
|
|
11
|
-
"avgDuration"
|
|
12
|
-
]);
|
|
13
|
-
const umamiDimensions = new Set(["page"]);
|
|
14
|
-
function umami(config) {
|
|
15
|
-
const base = config.host ?? CLOUD_BASE;
|
|
16
|
-
const capabilities = {
|
|
17
|
-
perPageQuery: true,
|
|
18
|
-
realtime: false,
|
|
19
|
-
comparison: false,
|
|
20
|
-
minGranularity: "day",
|
|
21
|
-
maxLookbackDays: config.maxLookbackDays !== void 0 ? config.maxLookbackDays : 730,
|
|
22
|
-
metrics: umamiMetrics,
|
|
23
|
-
dimensions: umamiDimensions,
|
|
24
|
-
batchPageReport: true,
|
|
25
|
-
rateLimit: null,
|
|
26
|
-
recommendedTtl: {
|
|
27
|
-
realtime: 300,
|
|
28
|
-
aggregate: 3600
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const authHeaders = () => config.apiKey ? { "x-umami-api-key": config.apiKey } : config.token ? { authorization: `Bearer ${config.token}` } : {};
|
|
32
|
-
const params = (q) => {
|
|
33
|
-
const p = new URLSearchParams({
|
|
34
|
-
startAt: String(q.dateRange.start.getTime()),
|
|
35
|
-
endAt: String(q.dateRange.end.getTime())
|
|
36
|
-
});
|
|
37
|
-
if (q.path) p.set("path", q.path);
|
|
38
|
-
return p;
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
id: "umami",
|
|
42
|
-
label: "Umami",
|
|
43
|
-
capabilities,
|
|
44
|
-
isConfigured: () => Boolean(config.websiteId && (config.apiKey || config.token)),
|
|
45
|
-
async query(q, ctx) {
|
|
46
|
-
const fetchedAt = q.dateRange.end.toISOString();
|
|
47
|
-
const headers = authHeaders();
|
|
48
|
-
if ((q.dimensions ?? []).includes("page")) {
|
|
49
|
-
const p = params(q);
|
|
50
|
-
p.set("type", "url");
|
|
51
|
-
const data = await fetchJson(`${base}/websites/${config.websiteId}/metrics?${p.toString()}`, {
|
|
52
|
-
headers,
|
|
53
|
-
signal: ctx.signal,
|
|
54
|
-
provider: "umami"
|
|
55
|
-
});
|
|
56
|
-
const metric = q.metrics.includes("pageviews") ? "pageviews" : "visitors";
|
|
57
|
-
return {
|
|
58
|
-
rows: data.map((row) => ({
|
|
59
|
-
dimensions: { page: row.x },
|
|
60
|
-
metrics: { [metric]: row.y }
|
|
61
|
-
})),
|
|
62
|
-
totals: void 0,
|
|
63
|
-
meta: {
|
|
64
|
-
provider: "umami",
|
|
65
|
-
fetchedAt
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
const fetchTotals = async () => {
|
|
70
|
-
const stats = await fetchJson(`${base}/websites/${config.websiteId}/stats?${params(q).toString()}`, {
|
|
71
|
-
headers,
|
|
72
|
-
signal: ctx.signal,
|
|
73
|
-
provider: "umami"
|
|
74
|
-
});
|
|
75
|
-
const all = {
|
|
76
|
-
pageviews: stats.pageviews,
|
|
77
|
-
visitors: stats.visitors,
|
|
78
|
-
visits: stats.visits,
|
|
79
|
-
sessions: stats.visits,
|
|
80
|
-
bounceRate: stats.visits > 0 ? Math.round(stats.bounces / stats.visits * 100) : void 0,
|
|
81
|
-
avgDuration: stats.visits > 0 ? Math.round(stats.totaltime / stats.visits * 1e3) : void 0
|
|
82
|
-
};
|
|
83
|
-
const totals = {};
|
|
84
|
-
for (const m of q.metrics) if (all[m] !== void 0) totals[m] = all[m];
|
|
85
|
-
return totals;
|
|
86
|
-
};
|
|
87
|
-
if (q.granularity === "day") {
|
|
88
|
-
const p = params(q);
|
|
89
|
-
p.set("unit", "day");
|
|
90
|
-
p.set("timezone", "UTC");
|
|
91
|
-
const fetchSeries = () => fetchJson(`${base}/websites/${config.websiteId}/pageviews?${p.toString()}`, {
|
|
92
|
-
headers,
|
|
93
|
-
signal: ctx.signal,
|
|
94
|
-
provider: "umami"
|
|
95
|
-
});
|
|
96
|
-
const [series, totals] = await Promise.all([fetchSeries(), fetchTotals()]);
|
|
97
|
-
const sessionsByX = new Map(series.sessions.map((s) => [s.x, s.y]));
|
|
98
|
-
const rows = [];
|
|
99
|
-
for (const pv of series.pageviews) {
|
|
100
|
-
const ts = dayIso(pv.x);
|
|
101
|
-
if (!ts) continue;
|
|
102
|
-
const dayMetrics = sessionsByX.get(pv.x) ?? 0;
|
|
103
|
-
const all = {
|
|
104
|
-
pageviews: pv.y,
|
|
105
|
-
visits: dayMetrics,
|
|
106
|
-
sessions: dayMetrics
|
|
107
|
-
};
|
|
108
|
-
const metrics = {};
|
|
109
|
-
for (const m of q.metrics) if (all[m] !== void 0) metrics[m] = all[m];
|
|
110
|
-
rows.push({
|
|
111
|
-
timestamp: ts,
|
|
112
|
-
metrics
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
rows,
|
|
117
|
-
totals,
|
|
118
|
-
meta: {
|
|
119
|
-
provider: "umami",
|
|
120
|
-
fetchedAt
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const totals = await fetchTotals();
|
|
125
|
-
return {
|
|
126
|
-
rows: [{ metrics: totals }],
|
|
127
|
-
totals,
|
|
128
|
-
meta: {
|
|
129
|
-
provider: "umami",
|
|
130
|
-
fetchedAt
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
//#endregion
|
|
1
|
+
import { umami } from "../../adapters/umami/umami.js";
|
|
137
2
|
export { umami };
|
|
138
|
-
|
|
139
|
-
//# sourceMappingURL=umami.js.map
|
package/dist/exports/client.d.ts
CHANGED
|
@@ -1,77 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
label: string;
|
|
7
|
-
value: number;
|
|
8
|
-
display?: string;
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/charts/BarList.d.ts
|
|
12
|
-
interface BarListProps {
|
|
13
|
-
data: BarDatum[];
|
|
14
|
-
emptyLabel: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Ranked horizontal bar list (shadcn "custom label" style): each row is a filled,
|
|
18
|
-
* proportional bar with the label inside and the value outside; hovering a row lifts
|
|
19
|
-
* it and shows a tooltip with the full label and value (useful when the label is
|
|
20
|
-
* truncated). Dependency-free; styling comes from the shared chart stylesheet.
|
|
21
|
-
*/
|
|
22
|
-
declare function BarList({
|
|
23
|
-
data,
|
|
24
|
-
emptyLabel
|
|
25
|
-
}: BarListProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/charts/TrendChart.d.ts
|
|
28
|
-
interface TrendPoint {
|
|
29
|
-
label: string;
|
|
30
|
-
value: number;
|
|
31
|
-
display: string;
|
|
32
|
-
}
|
|
33
|
-
interface TrendChartProps {
|
|
34
|
-
buckets: TrendPoint[];
|
|
35
|
-
ariaLabel: string;
|
|
36
|
-
minHeight?: number;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Gradient area trend chart: a monotone-cubic line over a themed gradient fill, with
|
|
40
|
-
* gridlines, dots (when sparse), timeframe-aware x-axis labels, and a pointer-tracked
|
|
41
|
-
* tooltip. Dependency-free; sizes to its container via a ResizeObserver so dots and
|
|
42
|
-
* labels stay crisp (no aspect-ratio distortion).
|
|
43
|
-
*/
|
|
44
|
-
declare function TrendChart({
|
|
45
|
-
buckets,
|
|
46
|
-
ariaLabel,
|
|
47
|
-
minHeight
|
|
48
|
-
}: TrendChartProps): import("react/jsx-runtime").JSX.Element;
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/fields/dateRange/types.d.ts
|
|
51
|
-
type DateRangePickerAppearance = 'default' | 'dayOnly' | 'monthOnly';
|
|
52
|
-
interface DateRangeFieldOptions {
|
|
53
|
-
pickerAppearance?: DateRangePickerAppearance;
|
|
54
|
-
timezone?: boolean;
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/fields/dateRange/ui.d.ts
|
|
58
|
-
type DateRangeFieldComponentProps = GroupFieldClientProps & DateRangeFieldOptions;
|
|
59
|
-
declare const DateRangeField: import("react").FC<DateRangeFieldComponentProps>;
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/widgets/RealtimeCounter.d.ts
|
|
62
|
-
interface RealtimeCounterProps {
|
|
63
|
-
endpoint: string;
|
|
64
|
-
intervalMs: number;
|
|
65
|
-
metric: string;
|
|
66
|
-
windowMinutes: number;
|
|
67
|
-
dataSource?: string;
|
|
68
|
-
initialActiveNow: number;
|
|
69
|
-
initialSeries: RealtimePoint[];
|
|
70
|
-
locale: string;
|
|
71
|
-
caption: string;
|
|
72
|
-
pausedLabel: string;
|
|
73
|
-
}
|
|
74
|
-
declare function RealtimeCounter(props: RealtimeCounterProps): import("react/jsx-runtime").JSX.Element;
|
|
75
|
-
//#endregion
|
|
76
|
-
export { BarList, type BarListProps, DateRangeField, RealtimeCounter, TrendChart, type TrendChartProps };
|
|
77
|
-
//# sourceMappingURL=client.d.ts.map
|
|
1
|
+
import { BarList, BarListProps } from "../charts/BarList.js";
|
|
2
|
+
import { TrendChart, TrendChartProps } from "../charts/TrendChart.js";
|
|
3
|
+
import { DateRangeField } from "../fields/dateRange/ui.js";
|
|
4
|
+
import { RealtimeCounter } from "../widgets/RealtimeCounter.js";
|
|
5
|
+
export { BarList, type BarListProps, DateRangeField, RealtimeCounter, TrendChart, type TrendChartProps };
|