@10x-media/analytics 0.1.0-beta.5 → 1.0.0-beta.11
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 +277 -0
- package/README.md +15 -4
- package/dist/adapters/ga4/disableKey.d.ts +9 -0
- package/dist/adapters/ga4/disableKey.js +21 -0
- package/dist/adapters/ga4/disableKey.js.map +1 -0
- package/dist/adapters/ga4/eventName.d.ts +15 -0
- package/dist/adapters/ga4/eventName.js +19 -0
- package/dist/adapters/ga4/eventName.js.map +1 -0
- package/dist/adapters/ga4/ga4.d.ts +5 -0
- package/dist/adapters/ga4/ga4.js +186 -58
- package/dist/adapters/ga4/ga4.js.map +1 -1
- package/dist/adapters/ga4/measurementId.js +15 -0
- package/dist/adapters/ga4/measurementId.js.map +1 -0
- package/dist/adapters/goalRead.js +126 -0
- package/dist/adapters/goalRead.js.map +1 -0
- package/dist/adapters/http/fetchJson.js +1 -1
- package/dist/adapters/plausible/plausible.d.ts +25 -0
- package/dist/adapters/plausible/plausible.js +159 -38
- package/dist/adapters/plausible/plausible.js.map +1 -1
- package/dist/adapters/posthog/posthog.d.ts +10 -1
- package/dist/adapters/posthog/posthog.js +130 -21
- package/dist/adapters/posthog/posthog.js.map +1 -1
- package/dist/adapters/series.js +11 -1
- package/dist/adapters/series.js.map +1 -1
- package/dist/adapters/umami/umami.d.ts +13 -1
- package/dist/adapters/umami/umami.js +278 -26
- package/dist/adapters/umami/umami.js.map +1 -1
- package/dist/binding/resolvePath.js +18 -2
- package/dist/binding/resolvePath.js.map +1 -1
- package/dist/capture/getTrackerConfig.d.ts +20 -0
- package/dist/capture/getTrackerConfig.js +31 -0
- package/dist/capture/getTrackerConfig.js.map +1 -0
- package/dist/capture/mountPath.js +14 -0
- package/dist/capture/mountPath.js.map +1 -0
- package/dist/capture/proxyEndpoint.js +127 -0
- package/dist/capture/proxyEndpoint.js.map +1 -0
- package/dist/capture/proxyRoutes.js +108 -0
- package/dist/capture/proxyRoutes.js.map +1 -0
- package/dist/capture/requestBody.js +68 -0
- package/dist/capture/requestBody.js.map +1 -0
- package/dist/capture/slots.d.ts +8 -0
- package/dist/capture/slots.js +54 -0
- package/dist/capture/slots.js.map +1 -0
- package/dist/capture/trackerConfig.d.ts +33 -0
- package/dist/capture/trackerConfig.js +95 -0
- package/dist/capture/trackerConfig.js.map +1 -0
- package/dist/capture/trackerEndpoint.js +35 -0
- package/dist/capture/trackerEndpoint.js.map +1 -0
- package/dist/charts/BarList.d.ts +16 -1
- package/dist/charts/BarList.js +41 -19
- package/dist/charts/BarList.js.map +1 -1
- package/dist/charts/TrendChart.d.ts +16 -3
- package/dist/charts/TrendChart.js +172 -106
- package/dist/charts/TrendChart.js.map +1 -1
- package/dist/charts/bars.d.ts +4 -0
- package/dist/charts/bars.js +3 -1
- package/dist/charts/bars.js.map +1 -1
- package/dist/charts/bucket.js +10 -1
- package/dist/charts/bucket.js.map +1 -1
- package/dist/charts/spline.js +2 -2
- package/dist/charts/spline.js.map +1 -1
- package/dist/charts/styles.js +18 -1
- package/dist/charts/styles.js.map +1 -1
- package/dist/core/cacheKey.js +26 -3
- package/dist/core/cacheKey.js.map +1 -1
- package/dist/core/capabilities.d.ts +5 -1
- package/dist/core/capabilities.js +11 -2
- package/dist/core/capabilities.js.map +1 -1
- package/dist/core/capture.d.ts +49 -0
- package/dist/core/contract.d.ts +74 -5
- package/dist/core/contract.js +30 -1
- package/dist/core/contract.js.map +1 -1
- package/dist/core/granularity.js +1 -1
- package/dist/core/options.d.ts +164 -6
- package/dist/core/options.js +126 -3
- package/dist/core/options.js.map +1 -1
- package/dist/core/registry.d.ts +1 -0
- package/dist/core/scopeList.js +32 -0
- package/dist/core/scopeList.js.map +1 -0
- package/dist/core/scopedRead.js +101 -30
- package/dist/core/scopedRead.js.map +1 -1
- package/dist/core/serverEvent.d.ts +60 -0
- package/dist/core/serverEvent.js +12 -0
- package/dist/core/serverEvent.js.map +1 -0
- package/dist/exports/adapters/ga4.d.ts +2 -1
- package/dist/exports/adapters/ga4.js +2 -1
- package/dist/exports/adapters/native.d.ts +3 -1
- package/dist/exports/adapters/native.js +2 -1
- package/dist/exports/client.d.ts +13 -3
- package/dist/exports/client.js +10 -1
- package/dist/exports/geo.d.ts +2 -2
- package/dist/exports/next.d.ts +2 -1
- package/dist/exports/next.js +2 -1
- package/dist/exports/react.d.ts +4 -0
- package/dist/exports/react.js +5 -0
- package/dist/exports/rsc.d.ts +11 -3
- package/dist/exports/rsc.js +7 -2
- package/dist/exports/tracker.d.ts +21 -0
- package/dist/exports/tracker.js +15 -0
- package/dist/exports/types.d.ts +16 -3
- package/dist/exports/types.js +4 -2
- package/dist/fields/AnalyticsPanelClient.js +2 -2
- package/dist/fields/AnalyticsPanelField.js +1 -1
- package/dist/fields/AnalyticsStatField.js +2 -2
- package/dist/fields/config/FilterDimensionSelectField.d.ts +14 -0
- package/dist/fields/config/FilterDimensionSelectField.js +77 -0
- package/dist/fields/config/FilterDimensionSelectField.js.map +1 -0
- package/dist/fields/config/FilterOperatorSelectField.d.ts +14 -0
- package/dist/fields/config/FilterOperatorSelectField.js +75 -0
- package/dist/fields/config/FilterOperatorSelectField.js.map +1 -0
- package/dist/fields/config/MetricSelectField.js +3 -3
- package/dist/fields/config/MetricSelectField.js.map +1 -1
- package/dist/fields/config/SourceSelectField.js +3 -3
- package/dist/fields/config/SourceSelectField.js.map +1 -1
- package/dist/fields/config/fetchSources.d.ts +5 -1
- package/dist/fields/config/fetchSources.js +7 -3
- package/dist/fields/config/fetchSources.js.map +1 -1
- package/dist/fields/config/narrow.js +2 -0
- package/dist/fields/config/narrow.js.map +1 -1
- package/dist/fields/config/sourcesState.js +19 -3
- package/dist/fields/config/sourcesState.js.map +1 -1
- package/dist/fields/config/useAnalyticsSources.d.ts +8 -3
- package/dist/fields/config/useAnalyticsSources.js +9 -6
- package/dist/fields/config/useAnalyticsSources.js.map +1 -1
- package/dist/fields/config/useFilterCapabilities.d.ts +28 -0
- package/dist/fields/config/useFilterCapabilities.js +52 -0
- package/dist/fields/config/useFilterCapabilities.js.map +1 -0
- package/dist/fields/readForDocument.d.ts +5 -0
- package/dist/fields/readForDocument.js +22 -10
- package/dist/fields/readForDocument.js.map +1 -1
- package/dist/goals/GoalSelectField.d.ts +7 -0
- package/dist/goals/GoalSelectField.js +77 -0
- package/dist/goals/GoalSelectField.js.map +1 -0
- package/dist/goals/collection.js +254 -0
- package/dist/goals/collection.js.map +1 -0
- package/dist/goals/currency.js +14 -0
- package/dist/goals/currency.js.map +1 -0
- package/dist/goals/fetchGoals.d.ts +18 -0
- package/dist/goals/fetchGoals.js +33 -0
- package/dist/goals/fetchGoals.js.map +1 -0
- package/dist/goals/goalField.d.ts +31 -0
- package/dist/goals/goalField.js +56 -0
- package/dist/goals/goalField.js.map +1 -0
- package/dist/goals/goalsEndpoint.d.ts +1 -0
- package/dist/goals/goalsEndpoint.js +58 -0
- package/dist/goals/goalsEndpoint.js.map +1 -0
- package/dist/goals/match.js +64 -0
- package/dist/goals/match.js.map +1 -0
- package/dist/goals/resolver.d.ts +8 -0
- package/dist/goals/resolver.js +147 -0
- package/dist/goals/resolver.js.map +1 -0
- package/dist/goals/trackGoalAction.d.ts +76 -0
- package/dist/goals/trackGoalAction.js +158 -0
- package/dist/goals/trackGoalAction.js.map +1 -0
- package/dist/goals/types.d.ts +33 -0
- package/dist/goals/types.js +7 -0
- package/dist/goals/types.js.map +1 -0
- package/dist/goals/useAnalyticsGoals.d.ts +20 -0
- package/dist/goals/useAnalyticsGoals.js +67 -0
- package/dist/goals/useAnalyticsGoals.js.map +1 -0
- package/dist/index.d.ts +14 -3
- package/dist/index.js +174 -19
- package/dist/index.js.map +1 -1
- package/dist/native/collections/events.js +65 -1
- package/dist/native/collections/events.js.map +1 -1
- package/dist/native/collections/rollups.js +39 -3
- package/dist/native/collections/rollups.js.map +1 -1
- package/dist/native/eventScan.js +25 -0
- package/dist/native/eventScan.js.map +1 -0
- package/dist/native/geo/composeGeoResolvers.js +2 -2
- package/dist/native/geo/composeGeoResolvers.js.map +1 -1
- package/dist/native/geo/geoResolver.d.ts +9 -2
- package/dist/native/geo/geoResolver.js.map +1 -1
- package/dist/native/geo/maxmindResolver.js +3 -5
- package/dist/native/geo/maxmindResolver.js.map +1 -1
- package/dist/native/ingest/bots.d.ts +11 -0
- package/dist/native/ingest/bots.js +71 -0
- package/dist/native/ingest/bots.js.map +1 -0
- package/dist/native/ingest/browser.js +47 -0
- package/dist/native/ingest/browser.js.map +1 -0
- package/dist/native/ingest/clientIp.js +20 -0
- package/dist/native/ingest/clientIp.js.map +1 -0
- package/dist/native/ingest/device.js +11 -3
- package/dist/native/ingest/device.js.map +1 -1
- package/dist/native/ingest/endpoint.d.ts +1 -0
- package/dist/native/ingest/endpoint.js +107 -21
- package/dist/native/ingest/endpoint.js.map +1 -1
- package/dist/native/ingest/flushBatch.js +29 -38
- package/dist/native/ingest/flushBatch.js.map +1 -1
- package/dist/native/ingest/language.js +14 -0
- package/dist/native/ingest/language.js.map +1 -0
- package/dist/native/ingest/normalizeEvent.d.ts +30 -0
- package/dist/native/ingest/normalizeEvent.js +115 -16
- package/dist/native/ingest/normalizeEvent.js.map +1 -1
- package/dist/native/ingest/referrer.js +48 -0
- package/dist/native/ingest/referrer.js.map +1 -0
- package/dist/native/ingest/requestHost.js +57 -0
- package/dist/native/ingest/requestHost.js.map +1 -0
- package/dist/native/ingest/resolveHostname.d.ts +29 -0
- package/dist/native/ingest/resolveHostname.js +52 -0
- package/dist/native/ingest/resolveHostname.js.map +1 -0
- package/dist/native/ingest/salt.js +27 -2
- package/dist/native/ingest/salt.js.map +1 -1
- package/dist/native/ingest/serverTrack.d.ts +20 -0
- package/dist/native/ingest/serverTrack.js +109 -0
- package/dist/native/ingest/serverTrack.js.map +1 -0
- package/dist/native/ingest/source.d.ts +11 -0
- package/dist/native/ingest/source.js +264 -16
- package/dist/native/ingest/source.js.map +1 -1
- package/dist/native/ingest/utm.js +33 -0
- package/dist/native/ingest/utm.js.map +1 -0
- package/dist/native/ingest/validate.js +26 -0
- package/dist/native/ingest/validate.js.map +1 -0
- package/dist/native/nativeAdapter.d.ts +37 -1
- package/dist/native/nativeAdapter.js +175 -22
- package/dist/native/nativeAdapter.js.map +1 -1
- package/dist/native/query/eventAgg.js +175 -0
- package/dist/native/query/eventAgg.js.map +1 -0
- package/dist/native/retention/pruneTask.js +53 -13
- package/dist/native/retention/pruneTask.js.map +1 -1
- package/dist/native/rollupAcc.js +12 -1
- package/dist/native/rollupAcc.js.map +1 -1
- package/dist/native/rollups/bucketKey.js +15 -0
- package/dist/native/rollups/bucketKey.js.map +1 -0
- package/dist/native/rollups/bumpRollups.js +116 -0
- package/dist/native/rollups/bumpRollups.js.map +1 -0
- package/dist/native/rollups/deltas.js +86 -11
- package/dist/native/rollups/deltas.js.map +1 -1
- package/dist/native/rollups/insertManyIfNew.js +93 -0
- package/dist/native/rollups/insertManyIfNew.js.map +1 -0
- package/dist/next/captureRewrites.d.ts +42 -0
- package/dist/next/captureRewrites.js +57 -0
- package/dist/next/captureRewrites.js.map +1 -0
- package/dist/next/posthogProxyRewrites.d.ts +5 -0
- package/dist/next/posthogProxyRewrites.js +16 -21
- package/dist/next/posthogProxyRewrites.js.map +1 -1
- package/dist/plugin/documentEndpoint.js +71 -24
- package/dist/plugin/documentEndpoint.js.map +1 -1
- package/dist/plugin/errors.d.ts +31 -0
- package/dist/plugin/errors.js +79 -0
- package/dist/plugin/errors.js.map +1 -0
- package/dist/plugin/goalHint.d.ts +1 -0
- package/dist/plugin/goalHint.js +24 -0
- package/dist/plugin/goalHint.js.map +1 -0
- package/dist/plugin/paths.js +17 -1
- package/dist/plugin/paths.js.map +1 -1
- package/dist/plugin/queryEndpoint.js +124 -0
- package/dist/plugin/queryEndpoint.js.map +1 -0
- package/dist/plugin/readContextForRequest.js +73 -0
- package/dist/plugin/readContextForRequest.js.map +1 -0
- package/dist/plugin/realtimeEndpoint.js +37 -16
- package/dist/plugin/realtimeEndpoint.js.map +1 -1
- package/dist/plugin/refreshEndpoint.js +113 -0
- package/dist/plugin/refreshEndpoint.js.map +1 -0
- package/dist/plugin/runtime.d.ts +1 -0
- package/dist/plugin/runtime.js +33 -1
- package/dist/plugin/runtime.js.map +1 -1
- package/dist/plugin/scopeChange.js +22 -0
- package/dist/plugin/scopeChange.js.map +1 -0
- package/dist/plugin/scopeFieldBoot.js +22 -0
- package/dist/plugin/scopeFieldBoot.js.map +1 -0
- package/dist/plugin/sourcesEndpoint.js +16 -41
- package/dist/plugin/sourcesEndpoint.js.map +1 -1
- package/dist/plugin/warmTask.js +0 -0
- package/dist/plugin/warmTask.js.map +1 -1
- package/dist/providers/collection.js +89 -29
- package/dist/providers/collection.js.map +1 -1
- package/dist/providers/factory.js +11 -3
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/resolver.js.map +1 -1
- package/dist/query/dates.js +64 -0
- package/dist/query/dates.js.map +1 -0
- package/dist/query/errors.d.ts +14 -0
- package/dist/query/fetchQuery.d.ts +79 -0
- package/dist/query/fetchQuery.js +117 -0
- package/dist/query/fetchQuery.js.map +1 -0
- package/dist/query/parse.d.ts +22 -0
- package/dist/query/parse.js +168 -0
- package/dist/query/parse.js.map +1 -0
- package/dist/query/response.d.ts +39 -0
- package/dist/query/response.js +11 -0
- package/dist/query/response.js.map +1 -0
- package/dist/react/AnalyticsProvider.d.ts +50 -0
- package/dist/react/AnalyticsProvider.js +67 -0
- package/dist/react/AnalyticsProvider.js.map +1 -0
- package/dist/react/TrackerBoot.d.ts +22 -0
- package/dist/react/TrackerBoot.js +30 -0
- package/dist/react/TrackerBoot.js.map +1 -0
- package/dist/react/useAnalytics.d.ts +20 -0
- package/dist/react/useAnalytics.js +52 -0
- package/dist/react/useAnalytics.js.map +1 -0
- package/dist/rsc/AnalyticsScripts.d.ts +30 -0
- package/dist/rsc/AnalyticsScripts.js +41 -0
- package/dist/rsc/AnalyticsScripts.js.map +1 -0
- package/dist/surfacing/cacheStore.d.ts +1 -0
- package/dist/surfacing/cacheStore.js +18 -2
- package/dist/surfacing/cacheStore.js.map +1 -1
- package/dist/surfacing/engine.d.ts +1 -0
- package/dist/surfacing/engine.js +47 -6
- package/dist/surfacing/engine.js.map +1 -1
- package/dist/surfacing/epoch.d.ts +1 -0
- package/dist/surfacing/epoch.js +72 -0
- package/dist/surfacing/epoch.js.map +1 -0
- package/dist/surfacing/queue.js +22 -6
- package/dist/surfacing/queue.js.map +1 -1
- package/dist/surfacing/rateLimiter.js +130 -0
- package/dist/surfacing/rateLimiter.js.map +1 -0
- package/dist/surfacing/retryPolicy.js +15 -0
- package/dist/surfacing/retryPolicy.js.map +1 -0
- package/dist/sync/collection.js +23 -7
- package/dist/sync/collection.js.map +1 -1
- package/dist/sync/syncTask.js +68 -33
- package/dist/sync/syncTask.js.map +1 -1
- package/dist/testing/memoryAdapter.d.ts +2 -0
- package/dist/testing/memoryAdapter.js +17 -1
- package/dist/testing/memoryAdapter.js.map +1 -1
- package/dist/timeframe/tz.js +17 -6
- package/dist/timeframe/tz.js.map +1 -1
- package/dist/tracker/autoCapture.d.ts +48 -0
- package/dist/tracker/autoCapture.js +129 -0
- package/dist/tracker/autoCapture.js.map +1 -0
- package/dist/tracker/consent.d.ts +24 -0
- package/dist/tracker/consent.js +48 -0
- package/dist/tracker/consent.js.map +1 -0
- package/dist/tracker/createTracker.d.ts +18 -0
- package/dist/tracker/createTracker.js +215 -0
- package/dist/tracker/createTracker.js.map +1 -0
- package/dist/tracker/exclusion.d.ts +28 -0
- package/dist/tracker/exclusion.js +50 -0
- package/dist/tracker/exclusion.js.map +1 -0
- package/dist/tracker/initTracker.d.ts +22 -0
- package/dist/tracker/initTracker.js +33 -0
- package/dist/tracker/initTracker.js.map +1 -0
- package/dist/tracker/loadScript.d.ts +14 -0
- package/dist/tracker/loadScript.js +41 -0
- package/dist/tracker/loadScript.js.map +1 -0
- package/dist/tracker/pageTracking.d.ts +17 -0
- package/dist/tracker/pageTracking.js +38 -0
- package/dist/tracker/pageTracking.js.map +1 -0
- package/dist/tracker/registry.d.ts +27 -0
- package/dist/tracker/registry.js +73 -0
- package/dist/tracker/registry.js.map +1 -0
- package/dist/tracker/sinks/ga4.d.ts +29 -0
- package/dist/tracker/sinks/ga4.js +30 -0
- package/dist/tracker/sinks/ga4.js.map +1 -0
- package/dist/tracker/sinks/native.d.ts +22 -0
- package/dist/tracker/sinks/native.js +56 -0
- package/dist/tracker/sinks/native.js.map +1 -0
- package/dist/tracker/sinks/plausible.d.ts +20 -0
- package/dist/tracker/sinks/plausible.js +32 -0
- package/dist/tracker/sinks/plausible.js.map +1 -0
- package/dist/tracker/sinks/posthog.d.ts +18 -0
- package/dist/tracker/sinks/posthog.js +30 -0
- package/dist/tracker/sinks/posthog.js.map +1 -0
- package/dist/tracker/sinks/umami.d.ts +18 -0
- package/dist/tracker/sinks/umami.js +23 -0
- package/dist/tracker/sinks/umami.js.map +1 -0
- package/dist/tracker/sinks/vendor.d.ts +14 -0
- package/dist/tracker/sinks/vendor.js +81 -0
- package/dist/tracker/sinks/vendor.js.map +1 -0
- package/dist/tracker/transport.js +28 -0
- package/dist/tracker/transport.js.map +1 -0
- package/dist/tracker/types.d.ts +91 -0
- package/dist/translations/ar.js +221 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +145 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +145 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +221 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +221 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +221 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +144 -0
- package/dist/translations/keys.js +145 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +221 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/metricKeys.js +8 -2
- package/dist/translations/metricKeys.js.map +1 -1
- package/dist/translations/pt.js +221 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +221 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/server.js.map +1 -1
- package/dist/translations/uk.js +221 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +221 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/view/AnalyticsNavLink.d.ts +19 -0
- package/dist/view/AnalyticsNavLink.js +40 -0
- package/dist/view/AnalyticsNavLink.js.map +1 -0
- package/dist/view/AnalyticsView.d.ts +23 -0
- package/dist/view/AnalyticsView.js +45 -0
- package/dist/view/AnalyticsView.js.map +1 -0
- package/dist/view/AnalyticsViewClient.d.ts +15 -0
- package/dist/view/AnalyticsViewClient.js +244 -0
- package/dist/view/AnalyticsViewClient.js.map +1 -0
- package/dist/view/authRedirect.js +32 -0
- package/dist/view/authRedirect.js.map +1 -0
- package/dist/view/conversionRate.js +18 -0
- package/dist/view/conversionRate.js.map +1 -0
- package/dist/view/dayRange.js +68 -0
- package/dist/view/dayRange.js.map +1 -0
- package/dist/view/gating.d.ts +1 -0
- package/dist/view/gating.js +142 -0
- package/dist/view/gating.js.map +1 -0
- package/dist/view/labels.js +76 -0
- package/dist/view/labels.js.map +1 -0
- package/dist/view/registerView.js +48 -0
- package/dist/view/registerView.js.map +1 -0
- package/dist/view/sections/Breakdowns.js +198 -0
- package/dist/view/sections/Breakdowns.js.map +1 -0
- package/dist/view/sections/EmptyStates.js +92 -0
- package/dist/view/sections/EmptyStates.js.map +1 -0
- package/dist/view/sections/FilterChips.js +46 -0
- package/dist/view/sections/FilterChips.js.map +1 -0
- package/dist/view/sections/GoalsPanel.js +82 -0
- package/dist/view/sections/GoalsPanel.js.map +1 -0
- package/dist/view/sections/OverviewCards.js +65 -0
- package/dist/view/sections/OverviewCards.js.map +1 -0
- package/dist/view/sections/RealtimeStrip.js +80 -0
- package/dist/view/sections/RealtimeStrip.js.map +1 -0
- package/dist/view/sections/Toolbar.js +207 -0
- package/dist/view/sections/Toolbar.js.map +1 -0
- package/dist/view/sections/Trend.js +125 -0
- package/dist/view/sections/Trend.js.map +1 -0
- package/dist/view/sections/styles.js +76 -0
- package/dist/view/sections/styles.js.map +1 -0
- package/dist/view/state.js +211 -0
- package/dist/view/state.js.map +1 -0
- package/dist/view/useViewQueries.js +153 -0
- package/dist/view/useViewQueries.js.map +1 -0
- package/dist/view/viewProps.d.ts +40 -0
- package/dist/view/viewProps.js +90 -0
- package/dist/view/viewProps.js.map +1 -0
- package/dist/widgets/AnalyticsBreakdownWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsBreakdownWidget.js +78 -11
- package/dist/widgets/AnalyticsBreakdownWidget.js.map +1 -1
- package/dist/widgets/AnalyticsGoalsWidget.d.ts +14 -0
- package/dist/widgets/AnalyticsGoalsWidget.js +196 -0
- package/dist/widgets/AnalyticsGoalsWidget.js.map +1 -0
- package/dist/widgets/AnalyticsMetricWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsMetricWidget.js +63 -13
- package/dist/widgets/AnalyticsMetricWidget.js.map +1 -1
- package/dist/widgets/AnalyticsRealtimeWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsRealtimeWidget.js +44 -22
- package/dist/widgets/AnalyticsRealtimeWidget.js.map +1 -1
- package/dist/widgets/AnalyticsTrendWidget.d.ts +2 -1
- package/dist/widgets/AnalyticsTrendWidget.js +79 -16
- package/dist/widgets/AnalyticsTrendWidget.js.map +1 -1
- package/dist/widgets/RealtimeCounter.d.ts +4 -0
- package/dist/widgets/RealtimeCounter.js +18 -4
- package/dist/widgets/RealtimeCounter.js.map +1 -1
- package/dist/widgets/WidgetViewLink.js +17 -0
- package/dist/widgets/WidgetViewLink.js.map +1 -0
- package/dist/widgets/breakdownTypes.js +38 -0
- package/dist/widgets/breakdownTypes.js.map +1 -1
- package/dist/widgets/cardChrome.js +31 -7
- package/dist/widgets/cardChrome.js.map +1 -1
- package/dist/widgets/comparison.js +15 -1
- package/dist/widgets/comparison.js.map +1 -1
- package/dist/widgets/defaults.d.ts +6 -2
- package/dist/widgets/defaults.js +78 -23
- package/dist/widgets/defaults.js.map +1 -1
- package/dist/widgets/filterCaption.js +27 -0
- package/dist/widgets/filterCaption.js.map +1 -0
- package/dist/widgets/filterField.d.ts +19 -0
- package/dist/widgets/filterField.js +75 -0
- package/dist/widgets/filterField.js.map +1 -0
- package/dist/widgets/prepareWidgetRead.d.ts +7 -0
- package/dist/widgets/prepareWidgetRead.js +74 -0
- package/dist/widgets/prepareWidgetRead.js.map +1 -0
- package/dist/widgets/range.js +43 -12
- package/dist/widgets/range.js.map +1 -1
- package/dist/widgets/readForWidget.d.ts +26 -3
- package/dist/widgets/readForWidget.js +48 -44
- package/dist/widgets/readForWidget.js.map +1 -1
- package/dist/widgets/readForWidgetBreakdown.d.ts +34 -2
- package/dist/widgets/readForWidgetBreakdown.js +53 -49
- package/dist/widgets/readForWidgetBreakdown.js.map +1 -1
- package/dist/widgets/readForWidgetGoals.d.ts +67 -0
- package/dist/widgets/readForWidgetGoals.js +140 -0
- package/dist/widgets/readForWidgetGoals.js.map +1 -0
- package/dist/widgets/readForWidgetRealtime.d.ts +8 -0
- package/dist/widgets/readForWidgetRealtime.js +23 -21
- package/dist/widgets/readForWidgetRealtime.js.map +1 -1
- package/dist/widgets/readForWidgetSeries.d.ts +26 -2
- package/dist/widgets/readForWidgetSeries.js +78 -53
- package/dist/widgets/readForWidgetSeries.js.map +1 -1
- package/dist/widgets/readMeta.js +18 -0
- package/dist/widgets/readMeta.js.map +1 -0
- package/dist/widgets/realtimePoll.js +13 -1
- package/dist/widgets/realtimePoll.js.map +1 -1
- package/dist/widgets/registerWidgets.js +62 -10
- package/dist/widgets/registerWidgets.js.map +1 -1
- package/dist/widgets/types.d.ts +15 -0
- package/dist/widgets/types.js +16 -2
- package/dist/widgets/types.js.map +1 -1
- package/dist/widgets/viewLink.d.ts +22 -0
- package/dist/widgets/viewLink.js +86 -0
- package/dist/widgets/viewLink.js.map +1 -0
- package/package.json +27 -7
- package/dist/native/rollups/applyDistinctDeltas.js +0 -9
- package/dist/native/rollups/applyDistinctDeltas.js.map +0 -1
- package/dist/native/rollups/bumpRollup.js +0 -68
- package/dist/native/rollups/bumpRollup.js.map +0 -1
- package/dist/native/rollups/insertIfNew.js +0 -19
- package/dist/native/rollups/insertIfNew.js.map +0 -1
package/dist/adapters/ga4/ga4.js
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
|
+
import { zonedCalendarDay } from "../../timeframe/tz.js";
|
|
2
|
+
import { MEASUREMENT_ID_PATTERN } from "./measurementId.js";
|
|
3
|
+
import { emptyGoalBreakdown, goalHint, hintSlugs, mergeGoalRows, mergeGoalTotals, providerMetricKeys, readGoalPair, splitGoalMetrics } from "../goalRead.js";
|
|
1
4
|
import { dayIso } from "../series.js";
|
|
5
|
+
import { ga4ExcludeGuard } from "./disableKey.js";
|
|
6
|
+
import { ga4EventName } from "./eventName.js";
|
|
2
7
|
//#region src/adapters/ga4/ga4.ts
|
|
8
|
+
/**
|
|
9
|
+
* Google's documented install snippet (https://developers.google.com/tag-platform/gtagjs/install):
|
|
10
|
+
* the inline publishes `dataLayer` and `gtag` and configures the measurement id, then the tag
|
|
11
|
+
* loads from googletagmanager.com. Inline first is Google's own ordering for consent mode, and
|
|
12
|
+
* it leaves the queue defined even when the tag itself is blocked. The tag is served from
|
|
13
|
+
* Google's CDN with the id in the query string, so there is nothing to proxy and `routes`
|
|
14
|
+
* stays empty; the snippet is rendered from an absolute `src` and the slot's proxy mount
|
|
15
|
+
* answers 404.
|
|
16
|
+
*
|
|
17
|
+
* The exclusion guard leads, ahead of the first `gtag()` call, because that is the only place
|
|
18
|
+
* GA4's disable switch counts and the tracker boots too late to set it for a snippet the
|
|
19
|
+
* server rendered.
|
|
20
|
+
*/
|
|
21
|
+
function buildCapture(measurementId) {
|
|
22
|
+
const id = JSON.stringify(measurementId);
|
|
23
|
+
return {
|
|
24
|
+
proxy: { routes: [] },
|
|
25
|
+
snippet: () => ({ scripts: [{ inline: `${ga4ExcludeGuard(measurementId)}window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag("js",new Date());gtag("config",${id})` }, {
|
|
26
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(measurementId)}`,
|
|
27
|
+
async: true
|
|
28
|
+
}] }),
|
|
29
|
+
client: {
|
|
30
|
+
kind: "ga4",
|
|
31
|
+
measurementId
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
3
35
|
const METRIC_MAP = {
|
|
4
36
|
pageviews: "screenPageViews",
|
|
5
37
|
visitors: "totalUsers",
|
|
@@ -15,6 +47,7 @@ const DIMENSION_MAP = {
|
|
|
15
47
|
page: "pagePath",
|
|
16
48
|
referrer: "pageReferrer",
|
|
17
49
|
source: "sessionSource",
|
|
50
|
+
channel: "sessionDefaultChannelGroup",
|
|
18
51
|
medium: "sessionMedium",
|
|
19
52
|
campaign: "sessionCampaignName",
|
|
20
53
|
utmSource: "sessionSource",
|
|
@@ -27,10 +60,54 @@ const DIMENSION_MAP = {
|
|
|
27
60
|
region: "region",
|
|
28
61
|
city: "city",
|
|
29
62
|
language: "language",
|
|
30
|
-
event: "eventName"
|
|
63
|
+
event: "eventName",
|
|
64
|
+
goal: "eventName"
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Metrics GA4 answers only for a goal-restricted read. A goal matches the GA4 event named by
|
|
68
|
+
* its normalized slug, since GA4 refuses the kebab-case slug itself. `keyEvents` counts
|
|
69
|
+
* events the property itself marks as key events, so an event that is a goal here but not
|
|
70
|
+
* marked there reports 0.
|
|
71
|
+
*/
|
|
72
|
+
const GOAL_METRICS = new Set(["conversions"]);
|
|
73
|
+
/**
|
|
74
|
+
* The hint's slugs keyed by the GA4 event name each one normalizes to, which is both the
|
|
75
|
+
* `eventName` list the goal request sends and the way its rows map back. Two slugs can
|
|
76
|
+
* normalize to one GA4 event, which GA4 counts once: the first hint slug owns those rows.
|
|
77
|
+
*/
|
|
78
|
+
const goalSlugsByEventName = (slugs) => {
|
|
79
|
+
const byName = /* @__PURE__ */ new Map();
|
|
80
|
+
for (const slug of slugs) {
|
|
81
|
+
const name = ga4EventName(slug);
|
|
82
|
+
if (!byName.has(name)) byName.set(name, slug);
|
|
83
|
+
}
|
|
84
|
+
return byName;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* FULL_REGEXP is a full match, so a pattern has to cover the whole value (`/docs/.*`, not
|
|
88
|
+
* `^/docs`). PARTIAL_REGEXP exists but is not the contract's `matches`.
|
|
89
|
+
*/
|
|
90
|
+
const MATCH_TYPE_MAP = {
|
|
91
|
+
eq: "EXACT",
|
|
92
|
+
contains: "CONTAINS",
|
|
93
|
+
matches: "FULL_REGEXP"
|
|
31
94
|
};
|
|
95
|
+
const CASE_SENSITIVE = {
|
|
96
|
+
EXACT: true,
|
|
97
|
+
CONTAINS: false,
|
|
98
|
+
FULL_REGEXP: true
|
|
99
|
+
};
|
|
100
|
+
const stringFilter = (fieldName, matchType, value) => ({ filter: {
|
|
101
|
+
fieldName,
|
|
102
|
+
stringFilter: {
|
|
103
|
+
matchType,
|
|
104
|
+
value,
|
|
105
|
+
caseSensitive: CASE_SENSITIVE[matchType]
|
|
106
|
+
}
|
|
107
|
+
} });
|
|
32
108
|
const ga4Metrics = new Set(Object.keys(METRIC_MAP));
|
|
33
109
|
const ga4Dimensions = new Set(Object.keys(DIMENSION_MAP));
|
|
110
|
+
const ga4Filters = new Set([...ga4Dimensions].filter((dimension) => dimension !== "goal"));
|
|
34
111
|
const toContractValue = (metric, raw) => {
|
|
35
112
|
if (metric === "avgDuration") return Math.round(raw * 1e3);
|
|
36
113
|
if (metric === "bounceRate") return Math.round(raw * 100);
|
|
@@ -40,11 +117,16 @@ function ga4(config) {
|
|
|
40
117
|
const capabilities = {
|
|
41
118
|
perPageQuery: true,
|
|
42
119
|
realtime: false,
|
|
43
|
-
comparison: false,
|
|
44
120
|
minGranularity: "day",
|
|
45
121
|
maxLookbackDays: config.maxLookbackDays !== void 0 ? config.maxLookbackDays : 425,
|
|
46
122
|
metrics: ga4Metrics,
|
|
47
123
|
dimensions: ga4Dimensions,
|
|
124
|
+
filters: ga4Filters,
|
|
125
|
+
filterOperators: new Set([
|
|
126
|
+
"eq",
|
|
127
|
+
"contains",
|
|
128
|
+
"matches"
|
|
129
|
+
]),
|
|
48
130
|
batchPageReport: true,
|
|
49
131
|
rateLimit: {
|
|
50
132
|
maxConcurrent: 10,
|
|
@@ -72,111 +154,157 @@ function ga4(config) {
|
|
|
72
154
|
})();
|
|
73
155
|
return clientPromise;
|
|
74
156
|
};
|
|
157
|
+
const measurementId = config.measurementId;
|
|
75
158
|
return {
|
|
76
159
|
id: "ga4",
|
|
77
160
|
label: "Google Analytics 4",
|
|
78
161
|
capabilities,
|
|
162
|
+
...measurementId && MEASUREMENT_ID_PATTERN.test(measurementId) ? { capture: buildCapture(measurementId) } : {},
|
|
79
163
|
isConfigured: () => Boolean(config.propertyId && config.credentials?.client_email && config.credentials?.private_key),
|
|
80
164
|
async query(q, _ctx) {
|
|
81
165
|
const fetchedAt = q.dateRange.end.toISOString();
|
|
82
|
-
const wanted = q.metrics.filter((m) => METRIC_MAP[m]);
|
|
83
|
-
const providerMetrics = [...new Set(wanted.map((m) => METRIC_MAP[m]))];
|
|
84
166
|
const dims = (q.dimensions ?? []).filter((d) => DIMENSION_MAP[d]);
|
|
167
|
+
const goalBreakdown = dims.includes("goal");
|
|
168
|
+
const hint = goalHint(q);
|
|
169
|
+
const slugs = hintSlugs(hint);
|
|
170
|
+
const empty = goalBreakdown ? emptyGoalBreakdown({
|
|
171
|
+
provider: "ga4",
|
|
172
|
+
q,
|
|
173
|
+
hint
|
|
174
|
+
}) : null;
|
|
175
|
+
if (empty) return empty;
|
|
176
|
+
const { siteMetrics, goalMetrics, unresolved } = splitGoalMetrics({
|
|
177
|
+
wanted: q.metrics.filter((m) => METRIC_MAP[m]),
|
|
178
|
+
goalOnly: GOAL_METRICS,
|
|
179
|
+
goalBreakdown,
|
|
180
|
+
hint
|
|
181
|
+
});
|
|
182
|
+
const siteKeys = providerMetricKeys(siteMetrics, METRIC_MAP);
|
|
183
|
+
const goalKeys = providerMetricKeys(goalMetrics, METRIC_MAP);
|
|
85
184
|
const providerDims = [...new Set(dims.map((d) => DIMENSION_MAP[d]))];
|
|
86
|
-
|
|
185
|
+
let goalsFailed = false;
|
|
186
|
+
const meta = () => ({
|
|
187
|
+
provider: "ga4",
|
|
188
|
+
fetchedAt,
|
|
189
|
+
...unresolved || goalsFailed ? { goalsUnresolved: true } : {}
|
|
190
|
+
});
|
|
191
|
+
const readMetrics = (ms, keys, row) => {
|
|
87
192
|
const out = {};
|
|
88
|
-
for (const m of
|
|
89
|
-
const idx =
|
|
193
|
+
for (const m of ms) {
|
|
194
|
+
const idx = keys.indexOf(METRIC_MAP[m]);
|
|
90
195
|
out[m] = toContractValue(m, Number(row.metricValues?.[idx]?.value ?? 0));
|
|
91
196
|
}
|
|
92
197
|
return out;
|
|
93
198
|
};
|
|
94
199
|
const filterExprs = [];
|
|
95
|
-
if (q.path) filterExprs.push(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
200
|
+
if (q.path) filterExprs.push(stringFilter("pagePath", "EXACT", q.path));
|
|
201
|
+
if (q.hostname) filterExprs.push(stringFilter("hostName", "EXACT", q.hostname));
|
|
202
|
+
for (const filter of q.filters ?? []) {
|
|
203
|
+
const fieldName = ga4Filters.has(filter.dimension) ? DIMENSION_MAP[filter.dimension] : void 0;
|
|
204
|
+
if (!fieldName) continue;
|
|
205
|
+
filterExprs.push(stringFilter(fieldName, MATCH_TYPE_MAP[filter.operator], filter.value));
|
|
206
|
+
}
|
|
207
|
+
const goalSlugs = slugs ? goalSlugsByEventName(slugs) : null;
|
|
208
|
+
const goalExprs = goalSlugs ? [...filterExprs, { filter: {
|
|
209
|
+
fieldName: "eventName",
|
|
210
|
+
inListFilter: {
|
|
211
|
+
values: [...goalSlugs.keys()],
|
|
212
|
+
caseSensitive: true
|
|
107
213
|
}
|
|
108
|
-
} }
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
214
|
+
} }] : filterExprs;
|
|
215
|
+
const asFilter = (exprs) => exprs.length === 0 ? void 0 : exprs.length === 1 ? exprs[0] : { andGroup: { expressions: exprs } };
|
|
216
|
+
const request = (metrics, exprs, extra) => {
|
|
217
|
+
const dimensionFilter = asFilter(exprs);
|
|
218
|
+
return {
|
|
219
|
+
property: `properties/${config.propertyId}`,
|
|
220
|
+
dateRanges: [{
|
|
221
|
+
startDate: zonedCalendarDay(q.dateRange.start, q.timezone ?? "UTC"),
|
|
222
|
+
endDate: zonedCalendarDay(q.dateRange.end, q.timezone ?? "UTC")
|
|
223
|
+
}],
|
|
224
|
+
metrics: metrics.map((name) => ({ name })),
|
|
225
|
+
...dimensionFilter ? { dimensionFilter } : {},
|
|
226
|
+
...extra
|
|
227
|
+
};
|
|
118
228
|
};
|
|
119
229
|
const client = await getClient();
|
|
230
|
+
const rowKeys = (row) => (row.dimensionValues ?? []).map((value) => value.value ?? "");
|
|
231
|
+
/**
|
|
232
|
+
* One report shape run twice, plainly and goal-filtered, unioned per row. A row the
|
|
233
|
+
* goal report has no counterpart for carries no conversions: no key event fired there.
|
|
234
|
+
* `limit` is the site report's alone, since a goal ranked outside its top N would
|
|
235
|
+
* otherwise be lost from the union.
|
|
236
|
+
*/
|
|
237
|
+
const runPair = async (extra, limit) => {
|
|
238
|
+
const runReport = async (metrics, exprs, reportExtra) => {
|
|
239
|
+
const [response] = await client.runReport(request(metrics, exprs, reportExtra));
|
|
240
|
+
return response;
|
|
241
|
+
};
|
|
242
|
+
const siteExprs = goalBreakdown ? goalExprs : filterExprs;
|
|
243
|
+
const siteExtra = limit ? {
|
|
244
|
+
...extra,
|
|
245
|
+
limit
|
|
246
|
+
} : extra;
|
|
247
|
+
const pair = await readGoalPair({
|
|
248
|
+
site: siteKeys.length ? () => runReport(siteKeys, siteExprs, siteExtra) : void 0,
|
|
249
|
+
goals: goalKeys.length ? () => runReport(goalKeys, goalExprs, extra) : void 0
|
|
250
|
+
});
|
|
251
|
+
if (pair.failed) goalsFailed = true;
|
|
252
|
+
const keyed = (response, ms, keys) => response?.rows?.map((row) => ({
|
|
253
|
+
keys: rowKeys(row),
|
|
254
|
+
metrics: readMetrics(ms, keys, row)
|
|
255
|
+
})) ?? (response ? [] : void 0);
|
|
256
|
+
const siteTotals = pair.site?.totals?.[0];
|
|
257
|
+
const goalTotals = pair.goals?.totals?.[0];
|
|
258
|
+
return {
|
|
259
|
+
rows: mergeGoalRows(keyed(pair.site, siteMetrics, siteKeys), keyed(pair.goals, goalMetrics, goalKeys)),
|
|
260
|
+
totals: mergeGoalTotals(siteTotals ? readMetrics(siteMetrics, siteKeys, siteTotals) : void 0, goalTotals ? readMetrics(goalMetrics, goalKeys, goalTotals) : void 0)
|
|
261
|
+
};
|
|
262
|
+
};
|
|
120
263
|
if (q.granularity === "day" && !dims.length) {
|
|
121
|
-
const
|
|
122
|
-
...baseRequest,
|
|
264
|
+
const report = await runPair({
|
|
123
265
|
dimensions: [{ name: "date" }],
|
|
124
266
|
metricAggregations: ["TOTAL"],
|
|
125
267
|
orderBys: [{ dimension: { dimensionName: "date" } }]
|
|
126
268
|
});
|
|
127
269
|
const rows = [];
|
|
128
|
-
for (const row of
|
|
129
|
-
const ymd = row.
|
|
270
|
+
for (const row of report.rows) {
|
|
271
|
+
const ymd = row.keys[0] ?? "";
|
|
130
272
|
const ts = dayIso(`${ymd.slice(0, 4)}-${ymd.slice(4, 6)}-${ymd.slice(6, 8)}`);
|
|
131
273
|
if (ts) rows.push({
|
|
132
274
|
timestamp: ts,
|
|
133
|
-
metrics:
|
|
275
|
+
metrics: row.metrics
|
|
134
276
|
});
|
|
135
277
|
}
|
|
136
|
-
const totalsRow = response.totals?.[0];
|
|
137
278
|
return {
|
|
138
279
|
rows,
|
|
139
|
-
totals:
|
|
140
|
-
meta:
|
|
141
|
-
provider: "ga4",
|
|
142
|
-
fetchedAt
|
|
143
|
-
}
|
|
280
|
+
totals: report.totals ?? {},
|
|
281
|
+
meta: meta()
|
|
144
282
|
};
|
|
145
283
|
}
|
|
146
|
-
const
|
|
147
|
-
...baseRequest,
|
|
148
|
-
...providerDims.length ? { dimensions: providerDims.map((name) => ({ name })) } : {},
|
|
149
|
-
...q.limit ? { limit: q.limit } : {}
|
|
150
|
-
});
|
|
284
|
+
const report = await runPair(providerDims.length ? { dimensions: providerDims.map((name) => ({ name })) } : {}, q.limit);
|
|
151
285
|
if (!dims.length) {
|
|
152
|
-
const
|
|
153
|
-
const totals = row ? readRow(row) : {};
|
|
286
|
+
const totals = report.rows[0]?.metrics ?? {};
|
|
154
287
|
return {
|
|
155
288
|
rows: [{ metrics: totals }],
|
|
156
289
|
totals,
|
|
157
|
-
meta:
|
|
158
|
-
provider: "ga4",
|
|
159
|
-
fetchedAt
|
|
160
|
-
}
|
|
290
|
+
meta: meta()
|
|
161
291
|
};
|
|
162
292
|
}
|
|
163
293
|
return {
|
|
164
|
-
rows:
|
|
294
|
+
rows: report.rows.map((row) => {
|
|
165
295
|
const dimValues = {};
|
|
166
296
|
for (const d of dims) {
|
|
167
297
|
const idx = providerDims.indexOf(DIMENSION_MAP[d]);
|
|
168
|
-
|
|
298
|
+
const value = row.keys[idx] ?? "";
|
|
299
|
+
dimValues[d] = d === "goal" ? goalSlugs?.get(value) ?? value : value;
|
|
169
300
|
}
|
|
170
301
|
return {
|
|
171
302
|
dimensions: dimValues,
|
|
172
|
-
metrics:
|
|
303
|
+
metrics: row.metrics
|
|
173
304
|
};
|
|
174
305
|
}),
|
|
175
306
|
totals: void 0,
|
|
176
|
-
meta:
|
|
177
|
-
provider: "ga4",
|
|
178
|
-
fetchedAt
|
|
179
|
-
}
|
|
307
|
+
meta: meta()
|
|
180
308
|
};
|
|
181
309
|
}
|
|
182
310
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ga4.js","names":[],"sources":["../../../src/adapters/ga4/ga4.ts"],"sourcesContent":["import type { BetaAnalyticsDataClient, protos } from '@google-analytics/data'\nimport type {\n\tAdapterContext,\n\tAnalyticsAdapter,\n\tAnalyticsCapabilities,\n\tAnalyticsQuery,\n\tAnalyticsResult,\n\tAnalyticsRow,\n\tDimensionKey,\n\tMetricKey,\n} from '../../core/contract'\nimport { dayIso } from '../series'\n\nexport interface Ga4Config {\n\t/** GA4 property id (numeric), e.g. '123456789'. */\n\tpropertyId: string\n\t/** Service-account credentials. */\n\tcredentials: { client_email: string; private_key: string }\n\t/** GCP project id; inferred from the credentials when omitted. */\n\tprojectId?: string\n\t/** Maximum days of historical data. Defaults to 425 (GA4's rolling-window limit). Pass null to disable clamping. */\n\tmaxLookbackDays?: number | null\n}\n\nconst METRIC_MAP: Partial<Record<MetricKey, string>> = {\n\tpageviews: 'screenPageViews',\n\tvisitors: 'totalUsers',\n\tvisits: 'sessions',\n\tsessions: 'sessions',\n\tbounceRate: 'bounceRate',\n\tavgDuration: 'averageSessionDuration',\n\tevents: 'eventCount',\n\tconversions: 'keyEvents',\n\trevenue: 'totalRevenue',\n}\n\nconst DIMENSION_MAP: Partial<Record<DimensionKey, string>> = {\n\tpage: 'pagePath',\n\treferrer: 'pageReferrer',\n\tsource: 'sessionSource',\n\tmedium: 'sessionMedium',\n\tcampaign: 'sessionCampaignName',\n\tutmSource: 'sessionSource',\n\tutmMedium: 'sessionMedium',\n\tutmCampaign: 'sessionCampaignName',\n\tdevice: 'deviceCategory',\n\tbrowser: 'browser',\n\tos: 'operatingSystem',\n\tcountry: 'countryId',\n\tregion: 'region',\n\tcity: 'city',\n\tlanguage: 'language',\n\tevent: 'eventName',\n}\n\nconst ga4Metrics: ReadonlySet<MetricKey> = new Set(Object.keys(METRIC_MAP) as MetricKey[])\nconst ga4Dimensions: ReadonlySet<DimensionKey> = new Set(\n\tObject.keys(DIMENSION_MAP) as DimensionKey[]\n)\n\n// GA4 returns bounceRate as a 0..1 ratio and averageSessionDuration in seconds; the\n// contract uses a 0..100 percentage and milliseconds.\nconst toContractValue = (metric: MetricKey, raw: number): number => {\n\tif (metric === 'avgDuration') {\n\t\treturn Math.round(raw * 1000)\n\t}\n\tif (metric === 'bounceRate') {\n\t\treturn Math.round(raw * 100)\n\t}\n\treturn raw\n}\n\nexport function ga4(config: Ga4Config): AnalyticsAdapter {\n\tconst maxLookbackDays = config.maxLookbackDays !== undefined ? config.maxLookbackDays : 425\n\n\tconst capabilities: AnalyticsCapabilities = {\n\t\tperPageQuery: true,\n\t\trealtime: false,\n\t\tcomparison: false,\n\t\tminGranularity: 'day',\n\t\tmaxLookbackDays,\n\t\tmetrics: ga4Metrics,\n\t\tdimensions: ga4Dimensions,\n\t\tbatchPageReport: true,\n\t\trateLimit: { maxConcurrent: 10, quotaModel: 'tokens', readsCountAsUsage: true },\n\t\trecommendedTtl: { realtime: 300, aggregate: 21600 },\n\t}\n\n\tlet clientPromise: Promise<BetaAnalyticsDataClient> | undefined\n\n\tconst getClient = (): Promise<BetaAnalyticsDataClient> => {\n\t\tif (!clientPromise) {\n\t\t\tclientPromise = (async () => {\n\t\t\t\tlet mod: typeof import('@google-analytics/data')\n\t\t\t\ttry {\n\t\t\t\t\tmod = await import('@google-analytics/data')\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'@10x-media/analytics: the GA4 adapter requires the optional peer dependency \"@google-analytics/data\". Install it with: pnpm add @google-analytics/data'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn new mod.BetaAnalyticsDataClient({\n\t\t\t\t\tcredentials: config.credentials,\n\t\t\t\t\tprojectId: config.projectId,\n\t\t\t\t})\n\t\t\t})()\n\t\t}\n\t\treturn clientPromise\n\t}\n\n\treturn {\n\t\tid: 'ga4',\n\t\tlabel: 'Google Analytics 4',\n\t\tcapabilities,\n\t\tisConfigured: () =>\n\t\t\tBoolean(\n\t\t\t\tconfig.propertyId && config.credentials?.client_email && config.credentials?.private_key\n\t\t\t),\n\t\t// The gRPC SDK's gax CallOptions has no AbortSignal field, so ctx.signal cannot be\n\t\t// forwarded; gax cancellation uses the call's own handle, not our signal.\n\t\tasync query(q: AnalyticsQuery, _ctx: AdapterContext): Promise<AnalyticsResult> {\n\t\t\tconst fetchedAt = q.dateRange.end.toISOString()\n\t\t\tconst wanted = q.metrics.filter((m) => METRIC_MAP[m])\n\t\t\tconst providerMetrics = [...new Set(wanted.map((m) => METRIC_MAP[m] as string))]\n\t\t\tconst dims = (q.dimensions ?? []).filter((d) => DIMENSION_MAP[d])\n\t\t\tconst providerDims = [...new Set(dims.map((d) => DIMENSION_MAP[d] as string))]\n\n\t\t\tconst readRow = (\n\t\t\t\trow: protos.google.analytics.data.v1beta.IRow\n\t\t\t): Partial<Record<MetricKey, number>> => {\n\t\t\t\tconst out: Partial<Record<MetricKey, number>> = {}\n\t\t\t\tfor (const m of wanted) {\n\t\t\t\t\tconst idx = providerMetrics.indexOf(METRIC_MAP[m] as string)\n\t\t\t\t\tout[m] = toContractValue(m, Number(row.metricValues?.[idx]?.value ?? 0))\n\t\t\t\t}\n\t\t\t\treturn out\n\t\t\t}\n\n\t\t\tconst filterExprs: protos.google.analytics.data.v1beta.IFilterExpression[] = []\n\t\t\tif (q.path) {\n\t\t\t\tfilterExprs.push({\n\t\t\t\t\tfilter: { fieldName: 'pagePath', stringFilter: { matchType: 'EXACT', value: q.path } },\n\t\t\t\t})\n\t\t\t}\n\t\t\tif (q.hostname) {\n\t\t\t\tfilterExprs.push({\n\t\t\t\t\tfilter: {\n\t\t\t\t\t\tfieldName: 'hostName',\n\t\t\t\t\t\tstringFilter: { matchType: 'EXACT', value: q.hostname },\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t\tconst dimensionFilter =\n\t\t\t\tfilterExprs.length === 0\n\t\t\t\t\t? undefined\n\t\t\t\t\t: filterExprs.length === 1\n\t\t\t\t\t\t? filterExprs[0]\n\t\t\t\t\t\t: { andGroup: { expressions: filterExprs } }\n\n\t\t\tconst baseRequest: protos.google.analytics.data.v1beta.IRunReportRequest = {\n\t\t\t\tproperty: `properties/${config.propertyId}`,\n\t\t\t\tdateRanges: [\n\t\t\t\t\t{\n\t\t\t\t\t\tstartDate: q.dateRange.start.toISOString().slice(0, 10),\n\t\t\t\t\t\tendDate: q.dateRange.end.toISOString().slice(0, 10),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tmetrics: providerMetrics.map((name) => ({ name })),\n\t\t\t\t...(dimensionFilter ? { dimensionFilter } : {}),\n\t\t\t}\n\n\t\t\tconst client = await getClient()\n\n\t\t\tif (q.granularity === 'day' && !dims.length) {\n\t\t\t\tconst [response] = await client.runReport({\n\t\t\t\t\t...baseRequest,\n\t\t\t\t\tdimensions: [{ name: 'date' }],\n\t\t\t\t\tmetricAggregations: [\n\t\t\t\t\t\t'TOTAL',\n\t\t\t\t\t] as unknown as protos.google.analytics.data.v1beta.MetricAggregation[],\n\t\t\t\t\torderBys: [{ dimension: { dimensionName: 'date' } }],\n\t\t\t\t})\n\t\t\t\tconst rows: AnalyticsRow[] = []\n\t\t\t\tfor (const row of response.rows ?? []) {\n\t\t\t\t\tconst ymd = row.dimensionValues?.[0]?.value ?? ''\n\t\t\t\t\tconst ts = dayIso(`${ymd.slice(0, 4)}-${ymd.slice(4, 6)}-${ymd.slice(6, 8)}`)\n\t\t\t\t\tif (ts) {\n\t\t\t\t\t\trows.push({ timestamp: ts, metrics: readRow(row) })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst totalsRow = response.totals?.[0]\n\t\t\t\tconst totals = totalsRow ? readRow(totalsRow) : {}\n\t\t\t\treturn { rows, totals, meta: { provider: 'ga4', fetchedAt } }\n\t\t\t}\n\n\t\t\tconst [response] = await client.runReport({\n\t\t\t\t...baseRequest,\n\t\t\t\t...(providerDims.length ? { dimensions: providerDims.map((name) => ({ name })) } : {}),\n\t\t\t\t...(q.limit ? { limit: q.limit } : {}),\n\t\t\t})\n\n\t\t\tif (!dims.length) {\n\t\t\t\tconst row = response.rows?.[0]\n\t\t\t\tconst totals = row ? readRow(row) : {}\n\t\t\t\treturn { rows: [{ metrics: totals }], totals, meta: { provider: 'ga4', fetchedAt } }\n\t\t\t}\n\n\t\t\tconst rows: AnalyticsRow[] = (response.rows ?? []).map((row) => {\n\t\t\t\tconst dimValues: Partial<Record<DimensionKey, string>> = {}\n\t\t\t\tfor (const d of dims) {\n\t\t\t\t\tconst idx = providerDims.indexOf(DIMENSION_MAP[d] as string)\n\t\t\t\t\tdimValues[d] = row.dimensionValues?.[idx]?.value ?? ''\n\t\t\t\t}\n\t\t\t\treturn { dimensions: dimValues, metrics: readRow(row) }\n\t\t\t})\n\t\t\treturn { rows, totals: undefined, meta: { provider: 'ga4', fetchedAt } }\n\t\t},\n\t}\n}\n"],"mappings":";;AAwBA,MAAM,aAAiD;CACtD,WAAW;CACX,UAAU;CACV,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,aAAa;CACb,QAAQ;CACR,aAAa;CACb,SAAS;AACV;AAEA,MAAM,gBAAuD;CAC5D,MAAM;CACN,UAAU;CACV,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,WAAW;CACX,WAAW;CACX,aAAa;CACb,QAAQ;CACR,SAAS;CACT,IAAI;CACJ,SAAS;CACT,QAAQ;CACR,MAAM;CACN,UAAU;CACV,OAAO;AACR;AAEA,MAAM,aAAqC,IAAI,IAAI,OAAO,KAAK,UAAU,CAAgB;AACzF,MAAM,gBAA2C,IAAI,IACpD,OAAO,KAAK,aAAa,CAC1B;AAIA,MAAM,mBAAmB,QAAmB,QAAwB;CACn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ga4.ts"],"sourcesContent":["import type { BetaAnalyticsDataClient, protos } from '@google-analytics/data'\nimport type { CaptureSupport } from '../../core/capture'\nimport type {\n\tAdapterContext,\n\tAnalyticsAdapter,\n\tAnalyticsCapabilities,\n\tAnalyticsQuery,\n\tAnalyticsResult,\n\tAnalyticsRow,\n\tDimensionKey,\n\tFilterOperator,\n\tMetricKey,\n} from '../../core/contract'\nimport { DEFAULT_TIMEZONE, zonedCalendarDay } from '../../timeframe/tz'\nimport {\n\temptyGoalBreakdown,\n\ttype GoalKeyedRow,\n\tgoalHint,\n\thintSlugs,\n\tmergeGoalRows,\n\tmergeGoalTotals,\n\tproviderMetricKeys,\n\treadGoalPair,\n\tsplitGoalMetrics,\n} from '../goalRead'\nimport { dayIso } from '../series'\nimport { ga4ExcludeGuard } from './disableKey'\nimport { ga4EventName } from './eventName'\nimport { MEASUREMENT_ID_PATTERN } from './measurementId'\n\nexport interface Ga4Config {\n\t/** GA4 property id (numeric), e.g. '123456789'. */\n\tpropertyId: string\n\t/** Service-account credentials. */\n\tcredentials: { client_email: string; private_key: string }\n\t/** GCP project id; inferred from the credentials when omitted. */\n\tprojectId?: string\n\t/** Maximum days of historical data. Defaults to 425 (GA4's rolling-window limit). Pass null to disable clamping. */\n\tmaxLookbackDays?: number | null\n\t/**\n\t * Public measurement id (`G-XXXXXXX`). Setting it turns on capture: the tag is loaded\n\t * from googletagmanager.com and booted with gtag.\n\t */\n\tmeasurementId?: string\n}\n\n/**\n * Google's documented install snippet (https://developers.google.com/tag-platform/gtagjs/install):\n * the inline publishes `dataLayer` and `gtag` and configures the measurement id, then the tag\n * loads from googletagmanager.com. Inline first is Google's own ordering for consent mode, and\n * it leaves the queue defined even when the tag itself is blocked. The tag is served from\n * Google's CDN with the id in the query string, so there is nothing to proxy and `routes`\n * stays empty; the snippet is rendered from an absolute `src` and the slot's proxy mount\n * answers 404.\n *\n * The exclusion guard leads, ahead of the first `gtag()` call, because that is the only place\n * GA4's disable switch counts and the tracker boots too late to set it for a snippet the\n * server rendered.\n */\nfunction buildCapture(measurementId: string): CaptureSupport {\n\tconst id = JSON.stringify(measurementId)\n\treturn {\n\t\tproxy: { routes: [] },\n\t\tsnippet: () => ({\n\t\t\tscripts: [\n\t\t\t\t{\n\t\t\t\t\tinline: `${ga4ExcludeGuard(measurementId)}window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag(\"js\",new Date());gtag(\"config\",${id})`,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tsrc: `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(measurementId)}`,\n\t\t\t\t\tasync: true,\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t\tclient: { kind: 'ga4', measurementId },\n\t}\n}\n\nconst METRIC_MAP: Partial<Record<MetricKey, string>> = {\n\tpageviews: 'screenPageViews',\n\tvisitors: 'totalUsers',\n\tvisits: 'sessions',\n\tsessions: 'sessions',\n\tbounceRate: 'bounceRate',\n\tavgDuration: 'averageSessionDuration',\n\tevents: 'eventCount',\n\tconversions: 'keyEvents',\n\trevenue: 'totalRevenue',\n}\n\nconst DIMENSION_MAP: Partial<Record<DimensionKey, string>> = {\n\tpage: 'pagePath',\n\treferrer: 'pageReferrer',\n\tsource: 'sessionSource',\n\tchannel: 'sessionDefaultChannelGroup',\n\tmedium: 'sessionMedium',\n\tcampaign: 'sessionCampaignName',\n\tutmSource: 'sessionSource',\n\tutmMedium: 'sessionMedium',\n\tutmCampaign: 'sessionCampaignName',\n\tdevice: 'deviceCategory',\n\tbrowser: 'browser',\n\tos: 'operatingSystem',\n\tcountry: 'countryId',\n\tregion: 'region',\n\tcity: 'city',\n\tlanguage: 'language',\n\tevent: 'eventName',\n\tgoal: 'eventName',\n}\n\n/**\n * Metrics GA4 answers only for a goal-restricted read. A goal matches the GA4 event named by\n * its normalized slug, since GA4 refuses the kebab-case slug itself. `keyEvents` counts\n * events the property itself marks as key events, so an event that is a goal here but not\n * marked there reports 0.\n */\nconst GOAL_METRICS: ReadonlySet<MetricKey> = new Set(['conversions'])\n\n/**\n * The hint's slugs keyed by the GA4 event name each one normalizes to, which is both the\n * `eventName` list the goal request sends and the way its rows map back. Two slugs can\n * normalize to one GA4 event, which GA4 counts once: the first hint slug owns those rows.\n */\nconst goalSlugsByEventName = (slugs: string[]): Map<string, string> => {\n\tconst byName = new Map<string, string>()\n\tfor (const slug of slugs) {\n\t\tconst name = ga4EventName(slug)\n\t\tif (!byName.has(name)) {\n\t\t\tbyName.set(name, slug)\n\t\t}\n\t}\n\treturn byName\n}\n\ntype StringMatchType = 'EXACT' | 'CONTAINS' | 'FULL_REGEXP'\n\n/**\n * FULL_REGEXP is a full match, so a pattern has to cover the whole value (`/docs/.*`, not\n * `^/docs`). PARTIAL_REGEXP exists but is not the contract's `matches`.\n */\nconst MATCH_TYPE_MAP: Record<FilterOperator, StringMatchType> = {\n\teq: 'EXACT',\n\tcontains: 'CONTAINS',\n\tmatches: 'FULL_REGEXP',\n}\n\n// caseSensitive is explicit on every string filter because the Data API defaults it to\n// false: `contains` stays insensitive, matching the native source and Umami's ilike, while\n// `eq` and `matches` compare literally.\nconst CASE_SENSITIVE: Record<StringMatchType, boolean> = {\n\tEXACT: true,\n\tCONTAINS: false,\n\tFULL_REGEXP: true,\n}\n\nconst stringFilter = (\n\tfieldName: string,\n\tmatchType: StringMatchType,\n\tvalue: string\n): protos.google.analytics.data.v1beta.IFilterExpression => ({\n\tfilter: {\n\t\tfieldName,\n\t\tstringFilter: { matchType, value, caseSensitive: CASE_SENSITIVE[matchType] },\n\t},\n})\n\nconst ga4Metrics: ReadonlySet<MetricKey> = new Set(Object.keys(METRIC_MAP) as MetricKey[])\nconst ga4Dimensions: ReadonlySet<DimensionKey> = new Set(\n\tObject.keys(DIMENSION_MAP) as DimensionKey[]\n)\n// `goal` is a breakdown, not a filter: the read's own goal slugs own the eventName clause.\nconst ga4Filters: ReadonlySet<DimensionKey> = new Set(\n\t[...ga4Dimensions].filter((dimension) => dimension !== 'goal')\n)\n\n// GA4 returns bounceRate as a 0..1 ratio and averageSessionDuration in seconds; the\n// contract uses a 0..100 percentage and milliseconds.\nconst toContractValue = (metric: MetricKey, raw: number): number => {\n\tif (metric === 'avgDuration') {\n\t\treturn Math.round(raw * 1000)\n\t}\n\tif (metric === 'bounceRate') {\n\t\treturn Math.round(raw * 100)\n\t}\n\treturn raw\n}\n\nexport function ga4(config: Ga4Config): AnalyticsAdapter {\n\tconst maxLookbackDays = config.maxLookbackDays !== undefined ? config.maxLookbackDays : 425\n\n\tconst capabilities: AnalyticsCapabilities = {\n\t\tperPageQuery: true,\n\t\trealtime: false,\n\t\tminGranularity: 'day',\n\t\tmaxLookbackDays,\n\t\tmetrics: ga4Metrics,\n\t\tdimensions: ga4Dimensions,\n\t\tfilters: ga4Filters,\n\t\tfilterOperators: new Set(['eq', 'contains', 'matches']),\n\t\tbatchPageReport: true,\n\t\trateLimit: { maxConcurrent: 10, quotaModel: 'tokens', readsCountAsUsage: true },\n\t\trecommendedTtl: { realtime: 300, aggregate: 21600 },\n\t}\n\n\tlet clientPromise: Promise<BetaAnalyticsDataClient> | undefined\n\n\tconst getClient = (): Promise<BetaAnalyticsDataClient> => {\n\t\tif (!clientPromise) {\n\t\t\tclientPromise = (async () => {\n\t\t\t\tlet mod: typeof import('@google-analytics/data')\n\t\t\t\ttry {\n\t\t\t\t\tmod = await import('@google-analytics/data')\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'@10x-media/analytics: the GA4 adapter requires the optional peer dependency \"@google-analytics/data\". Install it with: pnpm add @google-analytics/data'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn new mod.BetaAnalyticsDataClient({\n\t\t\t\t\tcredentials: config.credentials,\n\t\t\t\t\tprojectId: config.projectId,\n\t\t\t\t})\n\t\t\t})()\n\t\t}\n\t\treturn clientPromise\n\t}\n\n\tconst measurementId = config.measurementId\n\treturn {\n\t\tid: 'ga4',\n\t\tlabel: 'Google Analytics 4',\n\t\tcapabilities,\n\t\t// An id that is not a bare token is dropped rather than escaped: it lands in an inline\n\t\t// script and in the tag URL, and no legitimate measurement id needs anything else.\n\t\t...(measurementId && MEASUREMENT_ID_PATTERN.test(measurementId)\n\t\t\t? { capture: buildCapture(measurementId) }\n\t\t\t: {}),\n\t\tisConfigured: () =>\n\t\t\tBoolean(\n\t\t\t\tconfig.propertyId && config.credentials?.client_email && config.credentials?.private_key\n\t\t\t),\n\t\t// The gRPC SDK's gax CallOptions has no AbortSignal field, so ctx.signal cannot be\n\t\t// forwarded; gax cancellation uses the call's own handle, not our signal.\n\t\tasync query(q: AnalyticsQuery, _ctx: AdapterContext): Promise<AnalyticsResult> {\n\t\t\tconst fetchedAt = q.dateRange.end.toISOString()\n\t\t\tconst dims = (q.dimensions ?? []).filter((d) => DIMENSION_MAP[d])\n\t\t\tconst goalBreakdown = dims.includes('goal')\n\t\t\tconst hint = goalHint(q)\n\t\t\tconst slugs = hintSlugs(hint)\n\t\t\tconst empty = goalBreakdown ? emptyGoalBreakdown({ provider: 'ga4', q, hint }) : null\n\t\t\tif (empty) {\n\t\t\t\treturn empty\n\t\t\t}\n\t\t\tconst wanted = q.metrics.filter((m) => METRIC_MAP[m])\n\t\t\tconst { siteMetrics, goalMetrics, unresolved } = splitGoalMetrics({\n\t\t\t\twanted,\n\t\t\t\tgoalOnly: GOAL_METRICS,\n\t\t\t\tgoalBreakdown,\n\t\t\t\thint,\n\t\t\t})\n\t\t\tconst siteKeys = providerMetricKeys(siteMetrics, METRIC_MAP)\n\t\t\tconst goalKeys = providerMetricKeys(goalMetrics, METRIC_MAP)\n\t\t\tconst providerDims = [...new Set(dims.map((d) => DIMENSION_MAP[d] as string))]\n\t\t\t// Set when GA4 rejects a goal report the site report survived, so the rows keep their\n\t\t\t// site metrics and lose only their conversions.\n\t\t\tlet goalsFailed = false\n\t\t\tconst meta = (): AnalyticsResult['meta'] => ({\n\t\t\t\tprovider: 'ga4',\n\t\t\t\tfetchedAt,\n\t\t\t\t...(unresolved || goalsFailed ? { goalsUnresolved: true as const } : {}),\n\t\t\t})\n\n\t\t\tconst readMetrics = (\n\t\t\t\tms: MetricKey[],\n\t\t\t\tkeys: string[],\n\t\t\t\trow: protos.google.analytics.data.v1beta.IRow\n\t\t\t): Partial<Record<MetricKey, number>> => {\n\t\t\t\tconst out: Partial<Record<MetricKey, number>> = {}\n\t\t\t\tfor (const m of ms) {\n\t\t\t\t\tconst idx = keys.indexOf(METRIC_MAP[m] as string)\n\t\t\t\t\tout[m] = toContractValue(m, Number(row.metricValues?.[idx]?.value ?? 0))\n\t\t\t\t}\n\t\t\t\treturn out\n\t\t\t}\n\n\t\t\tconst filterExprs: protos.google.analytics.data.v1beta.IFilterExpression[] = []\n\t\t\tif (q.path) {\n\t\t\t\tfilterExprs.push(stringFilter('pagePath', 'EXACT', q.path))\n\t\t\t}\n\t\t\tif (q.hostname) {\n\t\t\t\tfilterExprs.push(stringFilter('hostName', 'EXACT', q.hostname))\n\t\t\t}\n\t\t\t// Capability gating (filters/filterOperators) is the real contract upstream; an\n\t\t\t// unsupported dimension is dropped here as the safety net.\n\t\t\tfor (const filter of q.filters ?? []) {\n\t\t\t\tconst fieldName = ga4Filters.has(filter.dimension)\n\t\t\t\t\t? DIMENSION_MAP[filter.dimension]\n\t\t\t\t\t: undefined\n\t\t\t\tif (!fieldName) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfilterExprs.push(stringFilter(fieldName, MATCH_TYPE_MAP[filter.operator], filter.value))\n\t\t\t}\n\t\t\tconst goalSlugs = slugs ? goalSlugsByEventName(slugs) : null\n\t\t\tconst goalExprs = goalSlugs\n\t\t\t\t? [\n\t\t\t\t\t\t...filterExprs,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfilter: {\n\t\t\t\t\t\t\t\tfieldName: 'eventName',\n\t\t\t\t\t\t\t\tinListFilter: { values: [...goalSlugs.keys()], caseSensitive: true },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: filterExprs\n\t\t\tconst asFilter = (\n\t\t\t\texprs: protos.google.analytics.data.v1beta.IFilterExpression[]\n\t\t\t): protos.google.analytics.data.v1beta.IFilterExpression | undefined =>\n\t\t\t\texprs.length === 0\n\t\t\t\t\t? undefined\n\t\t\t\t\t: exprs.length === 1\n\t\t\t\t\t\t? exprs[0]\n\t\t\t\t\t\t: { andGroup: { expressions: exprs } }\n\n\t\t\tconst request = (\n\t\t\t\tmetrics: string[],\n\t\t\t\texprs: protos.google.analytics.data.v1beta.IFilterExpression[],\n\t\t\t\textra: protos.google.analytics.data.v1beta.IRunReportRequest\n\t\t\t): protos.google.analytics.data.v1beta.IRunReportRequest => {\n\t\t\t\tconst dimensionFilter = asFilter(exprs)\n\t\t\t\treturn {\n\t\t\t\t\tproperty: `properties/${config.propertyId}`,\n\t\t\t\t\tdateRanges: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstartDate: zonedCalendarDay(q.dateRange.start, q.timezone ?? DEFAULT_TIMEZONE),\n\t\t\t\t\t\t\tendDate: zonedCalendarDay(q.dateRange.end, q.timezone ?? DEFAULT_TIMEZONE),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tmetrics: metrics.map((name) => ({ name })),\n\t\t\t\t\t...(dimensionFilter ? { dimensionFilter } : {}),\n\t\t\t\t\t...extra,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst client = await getClient()\n\n\t\t\tinterface PairedReport {\n\t\t\t\trows: GoalKeyedRow[]\n\t\t\t\ttotals: Partial<Record<MetricKey, number>> | undefined\n\t\t\t}\n\n\t\t\tconst rowKeys = (row: protos.google.analytics.data.v1beta.IRow): string[] =>\n\t\t\t\t(row.dimensionValues ?? []).map((value) => value.value ?? '')\n\n\t\t\t/**\n\t\t\t * One report shape run twice, plainly and goal-filtered, unioned per row. A row the\n\t\t\t * goal report has no counterpart for carries no conversions: no key event fired there.\n\t\t\t * `limit` is the site report's alone, since a goal ranked outside its top N would\n\t\t\t * otherwise be lost from the union.\n\t\t\t */\n\t\t\tconst runPair = async (\n\t\t\t\textra: protos.google.analytics.data.v1beta.IRunReportRequest,\n\t\t\t\tlimit?: number\n\t\t\t): Promise<PairedReport> => {\n\t\t\t\tconst runReport = async (\n\t\t\t\t\tmetrics: string[],\n\t\t\t\t\texprs: protos.google.analytics.data.v1beta.IFilterExpression[],\n\t\t\t\t\treportExtra: protos.google.analytics.data.v1beta.IRunReportRequest\n\t\t\t\t) => {\n\t\t\t\t\tconst [response] = await client.runReport(request(metrics, exprs, reportExtra))\n\t\t\t\t\treturn response\n\t\t\t\t}\n\t\t\t\t// A goal breakdown restricts its own rows, so its one report carries the hint too.\n\t\t\t\tconst siteExprs = goalBreakdown ? goalExprs : filterExprs\n\t\t\t\tconst siteExtra = limit ? { ...extra, limit } : extra\n\t\t\t\tconst pair = await readGoalPair({\n\t\t\t\t\tsite: siteKeys.length ? () => runReport(siteKeys, siteExprs, siteExtra) : undefined,\n\t\t\t\t\tgoals: goalKeys.length ? () => runReport(goalKeys, goalExprs, extra) : undefined,\n\t\t\t\t})\n\t\t\t\tif (pair.failed) {\n\t\t\t\t\tgoalsFailed = true\n\t\t\t\t}\n\t\t\t\tconst keyed = (\n\t\t\t\t\tresponse: protos.google.analytics.data.v1beta.IRunReportResponse | undefined,\n\t\t\t\t\tms: MetricKey[],\n\t\t\t\t\tkeys: string[]\n\t\t\t\t): GoalKeyedRow[] | undefined =>\n\t\t\t\t\tresponse?.rows?.map((row) => ({\n\t\t\t\t\t\tkeys: rowKeys(row),\n\t\t\t\t\t\tmetrics: readMetrics(ms, keys, row),\n\t\t\t\t\t})) ?? (response ? [] : undefined)\n\t\t\t\tconst siteTotals = pair.site?.totals?.[0]\n\t\t\t\tconst goalTotals = pair.goals?.totals?.[0]\n\t\t\t\treturn {\n\t\t\t\t\trows: mergeGoalRows(\n\t\t\t\t\t\tkeyed(pair.site, siteMetrics, siteKeys),\n\t\t\t\t\t\tkeyed(pair.goals, goalMetrics, goalKeys)\n\t\t\t\t\t),\n\t\t\t\t\ttotals: mergeGoalTotals(\n\t\t\t\t\t\tsiteTotals ? readMetrics(siteMetrics, siteKeys, siteTotals) : undefined,\n\t\t\t\t\t\tgoalTotals ? readMetrics(goalMetrics, goalKeys, goalTotals) : undefined\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (q.granularity === 'day' && !dims.length) {\n\t\t\t\tconst report = await runPair({\n\t\t\t\t\tdimensions: [{ name: 'date' }],\n\t\t\t\t\tmetricAggregations: [\n\t\t\t\t\t\t'TOTAL',\n\t\t\t\t\t] as unknown as protos.google.analytics.data.v1beta.MetricAggregation[],\n\t\t\t\t\torderBys: [{ dimension: { dimensionName: 'date' } }],\n\t\t\t\t})\n\t\t\t\tconst rows: AnalyticsRow[] = []\n\t\t\t\tfor (const row of report.rows) {\n\t\t\t\t\tconst ymd = row.keys[0] ?? ''\n\t\t\t\t\tconst ts = dayIso(`${ymd.slice(0, 4)}-${ymd.slice(4, 6)}-${ymd.slice(6, 8)}`)\n\t\t\t\t\tif (ts) {\n\t\t\t\t\t\trows.push({ timestamp: ts, metrics: row.metrics })\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { rows, totals: report.totals ?? {}, meta: meta() }\n\t\t\t}\n\n\t\t\tconst report = await runPair(\n\t\t\t\tproviderDims.length ? { dimensions: providerDims.map((name) => ({ name })) } : {},\n\t\t\t\tq.limit\n\t\t\t)\n\n\t\t\tif (!dims.length) {\n\t\t\t\tconst totals = report.rows[0]?.metrics ?? {}\n\t\t\t\treturn { rows: [{ metrics: totals }], totals, meta: meta() }\n\t\t\t}\n\n\t\t\tconst rows: AnalyticsRow[] = report.rows.map((row) => {\n\t\t\t\tconst dimValues: Partial<Record<DimensionKey, string>> = {}\n\t\t\t\tfor (const d of dims) {\n\t\t\t\t\tconst idx = providerDims.indexOf(DIMENSION_MAP[d] as string)\n\t\t\t\t\tconst value = row.keys[idx] ?? ''\n\t\t\t\t\t// A `goal` row reports the slug it was asked for; an `event` row reports GA4's own\n\t\t\t\t\t// event name, even though both read the same dimension.\n\t\t\t\t\tdimValues[d] = d === 'goal' ? (goalSlugs?.get(value) ?? value) : value\n\t\t\t\t}\n\t\t\t\treturn { dimensions: dimValues, metrics: row.metrics }\n\t\t\t})\n\t\t\treturn { rows, totals: undefined, meta: meta() }\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2DA,SAAS,aAAa,eAAuC;CAC5D,MAAM,KAAK,KAAK,UAAU,aAAa;CACvC,OAAO;EACN,OAAO,EAAE,QAAQ,CAAC,EAAE;EACpB,gBAAgB,EACf,SAAS,CACR,EACC,QAAQ,GAAG,gBAAgB,aAAa,EAAE,sHAAsH,GAAG,GACpK,GACA;GACC,KAAK,+CAA+C,mBAAmB,aAAa;GACpF,OAAO;EACR,CACD,EACD;EACA,QAAQ;GAAE,MAAM;GAAO;EAAc;CACtC;AACD;AAEA,MAAM,aAAiD;CACtD,WAAW;CACX,UAAU;CACV,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,aAAa;CACb,QAAQ;CACR,aAAa;CACb,SAAS;AACV;AAEA,MAAM,gBAAuD;CAC5D,MAAM;CACN,UAAU;CACV,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,UAAU;CACV,WAAW;CACX,WAAW;CACX,aAAa;CACb,QAAQ;CACR,SAAS;CACT,IAAI;CACJ,SAAS;CACT,QAAQ;CACR,MAAM;CACN,UAAU;CACV,OAAO;CACP,MAAM;AACP;;;;;;;AAQA,MAAM,eAAuC,IAAI,IAAI,CAAC,aAAa,CAAC;;;;;;AAOpE,MAAM,wBAAwB,UAAyC;CACtE,MAAM,yBAAS,IAAI,IAAoB;CACvC,KAAK,MAAM,QAAQ,OAAO;EACzB,MAAM,OAAO,aAAa,IAAI;EAC9B,IAAI,CAAC,OAAO,IAAI,IAAI,GACnB,OAAO,IAAI,MAAM,IAAI;C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G,CAAC,EAAE,GAAG,IAAI,MAAM,GAAG,CAAC,EAAE,GAAG,IAAI,MAAM,GAAG,CAAC,GAAG;KAC5E,IAAI,IACH,KAAK,KAAK;MAAE,WAAW;MAAI,SAAS,IAAI;KAAQ,CAAC;IAEnD;IACA,OAAO;KAAE;KAAM,QAAQ,OAAO,UAAU,CAAC;KAAG,MAAM,KAAK;IAAE;GAC1D;GAEA,MAAM,SAAS,MAAM,QACpB,aAAa,SAAS,EAAE,YAAY,aAAa,KAAK,UAAU,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,GAChF,EAAE,KACH;GAEA,IAAI,CAAC,KAAK,QAAQ;IACjB,MAAM,SAAS,OAAO,KAAK,IAAI,WAAW,CAAC;IAC3C,OAAO;KAAE,MAAM,CAAC,EAAE,SAAS,OAAO,CAAC;KAAG;KAAQ,MAAM,KAAK;IAAE;GAC5D;GAaA,OAAO;IAAE,MAXoB,OAAO,KAAK,KAAK,QAAQ;KACrD,MAAM,YAAmD,CAAC;KAC1D,KAAK,MAAM,KAAK,MAAM;MACrB,MAAM,MAAM,aAAa,QAAQ,cAAc,EAAY;MAC3D,MAAM,QAAQ,IAAI,KAAK,QAAQ;MAG/B,UAAU,KAAK,MAAM,SAAU,WAAW,IAAI,KAAK,KAAK,QAAS;KAClE;KACA,OAAO;MAAE,YAAY;MAAW,SAAS,IAAI;KAAQ;IACtD,CACY;IAAG,QAAQ,KAAA;IAAW,MAAM,KAAK;GAAE;EAChD;CACD;AACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { keys } from "../../translations/keys.js";
|
|
2
|
+
import { asTranslate } from "../../translations/server.js";
|
|
3
|
+
//#region src/adapters/ga4/measurementId.ts
|
|
4
|
+
/** What Google's own ids look like, and all the inline snippet and the tag URL may carry. */
|
|
5
|
+
const MEASUREMENT_ID_PATTERN = /^[A-Za-z0-9-]+$/;
|
|
6
|
+
/**
|
|
7
|
+
* Its own module so the providers collection can validate the id on the same terms the
|
|
8
|
+
* adapter admits it, without importing the adapter and its `@google-analytics/data` peer.
|
|
9
|
+
* Empty is allowed: the id is optional and only turns capture on.
|
|
10
|
+
*/
|
|
11
|
+
const validateMeasurementId = (value, { req }) => !value || MEASUREMENT_ID_PATTERN.test(value) ? true : asTranslate(req.t)(keys.providerErrorMeasurementId);
|
|
12
|
+
//#endregion
|
|
13
|
+
export { MEASUREMENT_ID_PATTERN, validateMeasurementId };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=measurementId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measurementId.js","names":[],"sources":["../../../src/adapters/ga4/measurementId.ts"],"sourcesContent":["import type { TextFieldSingleValidation } from 'payload'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\n\n/** What Google's own ids look like, and all the inline snippet and the tag URL may carry. */\nexport const MEASUREMENT_ID_PATTERN = /^[A-Za-z0-9-]+$/\n\n/**\n * Its own module so the providers collection can validate the id on the same terms the\n * adapter admits it, without importing the adapter and its `@google-analytics/data` peer.\n * Empty is allowed: the id is optional and only turns capture on.\n */\nexport const validateMeasurementId: TextFieldSingleValidation = (value, { req }) =>\n\t!value || MEASUREMENT_ID_PATTERN.test(value)\n\t\t? true\n\t\t: asTranslate(req.t)(keys.providerErrorMeasurementId)\n"],"mappings":";;;;AAKA,MAAa,yBAAyB;;;;;;AAOtC,MAAa,yBAAoD,OAAO,EAAE,UACzE,CAAC,SAAS,uBAAuB,KAAK,KAAK,IACxC,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,0BAA0B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//#region src/adapters/goalRead.ts
|
|
2
|
+
const goalHint = (q) => {
|
|
3
|
+
if (q.goalSlugs === void 0) return null;
|
|
4
|
+
if (q.goalSlugs === "unresolved") return "unresolved";
|
|
5
|
+
return { slugs: [...new Set(q.goalSlugs.filter((slug) => slug.length > 0))] };
|
|
6
|
+
};
|
|
7
|
+
/** The slugs a provider request filters by, or null when the hint names none to filter by. */
|
|
8
|
+
const hintSlugs = (hint) => hint === null || hint === "unresolved" || hint.slugs.length === 0 ? null : hint.slugs;
|
|
9
|
+
/**
|
|
10
|
+
* Whether goal numbers are missing because the hint failed or was never set, rather than
|
|
11
|
+
* because the install configured no goals, which is an empty result and not a failure.
|
|
12
|
+
*/
|
|
13
|
+
const hintFailed = (hint) => hint === null || hint === "unresolved";
|
|
14
|
+
/** A `goal` breakdown a provider was asked for without the hint that defines its rows. */
|
|
15
|
+
const goalsUnresolvedResult = (provider, q, meta) => ({
|
|
16
|
+
rows: [],
|
|
17
|
+
meta: {
|
|
18
|
+
provider,
|
|
19
|
+
fetchedAt: q.dateRange.end.toISOString(),
|
|
20
|
+
...meta,
|
|
21
|
+
goalsUnresolved: true
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* The answer a `goal` breakdown owes before it reads, or null when its hint names rows to
|
|
26
|
+
* read. A failed or absent hint is reported with `goalsUnresolved`; an install that
|
|
27
|
+
* configured no goals gets the same empty rows without the flag.
|
|
28
|
+
*/
|
|
29
|
+
const emptyGoalBreakdown = ({ provider, q, hint, meta }) => {
|
|
30
|
+
if (hintSlugs(hint) !== null) return null;
|
|
31
|
+
return hintFailed(hint) ? goalsUnresolvedResult(provider, q, meta) : {
|
|
32
|
+
rows: [],
|
|
33
|
+
meta: {
|
|
34
|
+
provider,
|
|
35
|
+
fetchedAt: q.dateRange.end.toISOString(),
|
|
36
|
+
...meta
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* How a provider that serves goal metrics only under a goal filter splits one read in two.
|
|
42
|
+
* A goal breakdown restricts every row it returns, so its single request carries everything;
|
|
43
|
+
* anywhere else the goal metrics need a request of their own, because filtering the whole
|
|
44
|
+
* read would scope the site metrics to goal hits as well.
|
|
45
|
+
*/
|
|
46
|
+
const splitGoalMetrics = ({ wanted, goalOnly, goalBreakdown, hint }) => {
|
|
47
|
+
if (goalBreakdown) return {
|
|
48
|
+
siteMetrics: wanted,
|
|
49
|
+
goalMetrics: [],
|
|
50
|
+
unresolved: false
|
|
51
|
+
};
|
|
52
|
+
const goalMetrics = wanted.filter((m) => goalOnly.has(m));
|
|
53
|
+
return {
|
|
54
|
+
siteMetrics: wanted.filter((m) => !goalOnly.has(m)),
|
|
55
|
+
goalMetrics: hintSlugs(hint) === null ? [] : goalMetrics,
|
|
56
|
+
unresolved: goalMetrics.length > 0 && hintFailed(hint)
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Provider metric names for a contract metric list, deduped: several contract metrics can
|
|
61
|
+
* alias one provider metric (sessions and visits both map to Plausible's `visits`), so each
|
|
62
|
+
* is read back from its provider key's position rather than from the request index.
|
|
63
|
+
*/
|
|
64
|
+
const providerMetricKeys = (metrics, map) => [...new Set(metrics.map((m) => map[m]))];
|
|
65
|
+
/**
|
|
66
|
+
* The two halves of a pair read unioned by dimension key. A row only the site request
|
|
67
|
+
* returned keeps its conversions absent (no goal fired there); a row only the goal request
|
|
68
|
+
* returned is appended carrying its goal metrics alone, since the site request answers a
|
|
69
|
+
* different ranking and its own limit may have cut the row off.
|
|
70
|
+
*/
|
|
71
|
+
const mergeGoalRows = (site, goals) => {
|
|
72
|
+
if (!site) return goals ?? [];
|
|
73
|
+
if (!goals) return site;
|
|
74
|
+
const byKey = new Map(goals.map((row) => [JSON.stringify(row.keys), row]));
|
|
75
|
+
return [...site.map((row) => {
|
|
76
|
+
const key = JSON.stringify(row.keys);
|
|
77
|
+
const goalRow = byKey.get(key);
|
|
78
|
+
if (!goalRow) return row;
|
|
79
|
+
byKey.delete(key);
|
|
80
|
+
return {
|
|
81
|
+
keys: row.keys,
|
|
82
|
+
metrics: {
|
|
83
|
+
...row.metrics,
|
|
84
|
+
...goalRow.metrics
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}), ...byKey.values()];
|
|
88
|
+
};
|
|
89
|
+
/** The same union over a pair's totals rows, which carry no dimensions to key on. */
|
|
90
|
+
const mergeGoalTotals = (site, goals) => site || goals ? {
|
|
91
|
+
...site,
|
|
92
|
+
...goals
|
|
93
|
+
} : void 0;
|
|
94
|
+
/**
|
|
95
|
+
* One request shape issued twice, plainly and goal-filtered. Sequential rather than
|
|
96
|
+
* concurrent: the engine takes a single limiter permit per `adapter.query`, so a parallel
|
|
97
|
+
* pair would exceed the provider's declared concurrency. A goal request the provider rejects
|
|
98
|
+
* (a property with no key events, a site with no revenue goals) costs the read its
|
|
99
|
+
* conversions rather than all of it, unless there is no site half left to serve.
|
|
100
|
+
*/
|
|
101
|
+
const readGoalPair = async ({ site, goals }) => {
|
|
102
|
+
const siteResponse = site ? await site() : void 0;
|
|
103
|
+
if (!goals) return {
|
|
104
|
+
site: siteResponse,
|
|
105
|
+
goals: void 0,
|
|
106
|
+
failed: false
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
return {
|
|
110
|
+
site: siteResponse,
|
|
111
|
+
goals: await goals(),
|
|
112
|
+
failed: false
|
|
113
|
+
};
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!site) throw error;
|
|
116
|
+
return {
|
|
117
|
+
site: siteResponse,
|
|
118
|
+
goals: void 0,
|
|
119
|
+
failed: true
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
124
|
+
export { emptyGoalBreakdown, goalHint, hintFailed, hintSlugs, mergeGoalRows, mergeGoalTotals, providerMetricKeys, readGoalPair, splitGoalMetrics };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=goalRead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goalRead.js","names":[],"sources":["../../src/adapters/goalRead.ts"],"sourcesContent":["import type { AnalyticsQuery, AnalyticsResult, MetricKey } from '../core/contract'\n\n/**\n * What a read tells a provider about this install's goals: the slugs its goal rows are\n * restricted to (possibly none, for an install that configured none), `'unresolved'` when\n * the resolver failed, or null when the caller set no hint at all. Nothing in a provider\n * marks which of its events are this install's goals, so a provider adapter counts\n * conversions for the hinted names and for no others.\n */\nexport type GoalHint = { slugs: string[] } | 'unresolved' | null\n\nexport const goalHint = (q: AnalyticsQuery): GoalHint => {\n\tif (q.goalSlugs === undefined) {\n\t\treturn null\n\t}\n\tif (q.goalSlugs === 'unresolved') {\n\t\treturn 'unresolved'\n\t}\n\treturn { slugs: [...new Set(q.goalSlugs.filter((slug) => slug.length > 0))] }\n}\n\n/** The slugs a provider request filters by, or null when the hint names none to filter by. */\nexport const hintSlugs = (hint: GoalHint): string[] | null =>\n\thint === null || hint === 'unresolved' || hint.slugs.length === 0 ? null : hint.slugs\n\n/**\n * Whether goal numbers are missing because the hint failed or was never set, rather than\n * because the install configured no goals, which is an empty result and not a failure.\n */\nexport const hintFailed = (hint: GoalHint): boolean => hint === null || hint === 'unresolved'\n\n/** Meta a goal read still has to report beside its empty rows (unapplied filters, sampling). */\ntype GoalsUnresolvedMeta = Omit<\n\tAnalyticsResult['meta'],\n\t'provider' | 'fetchedAt' | 'goalsUnresolved'\n>\n\n/** A `goal` breakdown a provider was asked for without the hint that defines its rows. */\nexport const goalsUnresolvedResult = (\n\tprovider: string,\n\tq: AnalyticsQuery,\n\tmeta?: GoalsUnresolvedMeta\n): AnalyticsResult => ({\n\trows: [],\n\tmeta: {\n\t\tprovider,\n\t\tfetchedAt: q.dateRange.end.toISOString(),\n\t\t...meta,\n\t\tgoalsUnresolved: true,\n\t},\n})\n\n/**\n * The answer a `goal` breakdown owes before it reads, or null when its hint names rows to\n * read. A failed or absent hint is reported with `goalsUnresolved`; an install that\n * configured no goals gets the same empty rows without the flag.\n */\nexport const emptyGoalBreakdown = ({\n\tprovider,\n\tq,\n\thint,\n\tmeta,\n}: {\n\tprovider: string\n\tq: AnalyticsQuery\n\thint: GoalHint\n\tmeta?: GoalsUnresolvedMeta\n}): AnalyticsResult | null => {\n\tif (hintSlugs(hint) !== null) {\n\t\treturn null\n\t}\n\treturn hintFailed(hint)\n\t\t? goalsUnresolvedResult(provider, q, meta)\n\t\t: { rows: [], meta: { provider, fetchedAt: q.dateRange.end.toISOString(), ...meta } }\n}\n\nexport interface GoalMetricSplit {\n\t/** Metrics the plain request asks for. */\n\tsiteMetrics: MetricKey[]\n\t/** Metrics only the goal-filtered request can answer; empty when the hint names no goal. */\n\tgoalMetrics: MetricKey[]\n\t/** The read wanted goal numbers it had no hint to ask for. */\n\tunresolved: boolean\n}\n\n/**\n * How a provider that serves goal metrics only under a goal filter splits one read in two.\n * A goal breakdown restricts every row it returns, so its single request carries everything;\n * anywhere else the goal metrics need a request of their own, because filtering the whole\n * read would scope the site metrics to goal hits as well.\n */\nexport const splitGoalMetrics = ({\n\twanted,\n\tgoalOnly,\n\tgoalBreakdown,\n\thint,\n}: {\n\twanted: MetricKey[]\n\tgoalOnly: ReadonlySet<MetricKey>\n\tgoalBreakdown: boolean\n\thint: GoalHint\n}): GoalMetricSplit => {\n\tif (goalBreakdown) {\n\t\treturn { siteMetrics: wanted, goalMetrics: [], unresolved: false }\n\t}\n\tconst goalMetrics = wanted.filter((m) => goalOnly.has(m))\n\treturn {\n\t\tsiteMetrics: wanted.filter((m) => !goalOnly.has(m)),\n\t\tgoalMetrics: hintSlugs(hint) === null ? [] : goalMetrics,\n\t\tunresolved: goalMetrics.length > 0 && hintFailed(hint),\n\t}\n}\n\n/**\n * Provider metric names for a contract metric list, deduped: several contract metrics can\n * alias one provider metric (sessions and visits both map to Plausible's `visits`), so each\n * is read back from its provider key's position rather than from the request index.\n */\nexport const providerMetricKeys = (\n\tmetrics: MetricKey[],\n\tmap: Partial<Record<MetricKey, string>>\n): string[] => [...new Set(metrics.map((m) => map[m] as string))]\n\nexport interface GoalKeyedRow {\n\t/** The row's dimension values in the request's dimension order; empty for a totals row. */\n\tkeys: string[]\n\tmetrics: Partial<Record<MetricKey, number>>\n}\n\n/**\n * The two halves of a pair read unioned by dimension key. A row only the site request\n * returned keeps its conversions absent (no goal fired there); a row only the goal request\n * returned is appended carrying its goal metrics alone, since the site request answers a\n * different ranking and its own limit may have cut the row off.\n */\nexport const mergeGoalRows = (\n\tsite: GoalKeyedRow[] | undefined,\n\tgoals: GoalKeyedRow[] | undefined\n): GoalKeyedRow[] => {\n\tif (!site) {\n\t\treturn goals ?? []\n\t}\n\tif (!goals) {\n\t\treturn site\n\t}\n\tconst byKey = new Map(goals.map((row) => [JSON.stringify(row.keys), row]))\n\tconst merged = site.map((row) => {\n\t\tconst key = JSON.stringify(row.keys)\n\t\tconst goalRow = byKey.get(key)\n\t\tif (!goalRow) {\n\t\t\treturn row\n\t\t}\n\t\tbyKey.delete(key)\n\t\treturn { keys: row.keys, metrics: { ...row.metrics, ...goalRow.metrics } }\n\t})\n\treturn [...merged, ...byKey.values()]\n}\n\n/** The same union over a pair's totals rows, which carry no dimensions to key on. */\nexport const mergeGoalTotals = (\n\tsite: Partial<Record<MetricKey, number>> | undefined,\n\tgoals: Partial<Record<MetricKey, number>> | undefined\n): Partial<Record<MetricKey, number>> | undefined =>\n\tsite || goals ? { ...site, ...goals } : undefined\n\nexport interface GoalPair<Response> {\n\tsite: Response | undefined\n\tgoals: Response | undefined\n\t/** The goal request failed, so the read is served without its goal numbers. */\n\tfailed: boolean\n}\n\n/**\n * One request shape issued twice, plainly and goal-filtered. Sequential rather than\n * concurrent: the engine takes a single limiter permit per `adapter.query`, so a parallel\n * pair would exceed the provider's declared concurrency. A goal request the provider rejects\n * (a property with no key events, a site with no revenue goals) costs the read its\n * conversions rather than all of it, unless there is no site half left to serve.\n */\nexport const readGoalPair = async <Response>({\n\tsite,\n\tgoals,\n}: {\n\tsite: (() => Promise<Response>) | undefined\n\tgoals: (() => Promise<Response>) | undefined\n}): Promise<GoalPair<Response>> => {\n\tconst siteResponse = site ? await site() : undefined\n\tif (!goals) {\n\t\treturn { site: siteResponse, goals: undefined, failed: false }\n\t}\n\ttry {\n\t\treturn { site: siteResponse, goals: await goals(), failed: false }\n\t} catch (error) {\n\t\tif (!site) {\n\t\t\tthrow error\n\t\t}\n\t\treturn { site: siteResponse, goals: undefined, failed: true }\n\t}\n}\n"],"mappings":";AAWA,MAAa,YAAY,MAAgC;CACxD,IAAI,EAAE,cAAc,KAAA,GACnB,OAAO;CAER,IAAI,EAAE,cAAc,cACnB,OAAO;CAER,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE,UAAU,QAAQ,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE;AAC7E;;AAGA,MAAa,aAAa,SACzB,SAAS,QAAQ,SAAS,gBAAgB,KAAK,MAAM,WAAW,IAAI,OAAO,KAAK;;;;;AAMjF,MAAa,cAAc,SAA4B,SAAS,QAAQ,SAAS;;AASjF,MAAa,yBACZ,UACA,GACA,UACsB;CACtB,MAAM,CAAC;CACP,MAAM;EACL;EACA,WAAW,EAAE,UAAU,IAAI,YAAY;EACvC,GAAG;EACH,iBAAiB;CAClB;AACD;;;;;;AAOA,MAAa,sBAAsB,EAClC,UACA,GACA,MACA,WAM6B;CAC7B,IAAI,UAAU,IAAI,MAAM,MACvB,OAAO;CAER,OAAO,WAAW,IAAI,IACnB,sBAAsB,UAAU,GAAG,IAAI,IACvC;EAAE,MAAM,CAAC;EAAG,MAAM;GAAE;GAAU,WAAW,EAAE,UAAU,IAAI,YAAY;GAAG,GAAG;EAAK;CAAE;AACtF;;;;;;;AAiBA,MAAa,oBAAoB,EAChC,QACA,UACA,eACA,WAMsB;CACtB,IAAI,eACH,OAAO;EAAE,aAAa;EAAQ,aAAa,CAAC;EAAG,YAAY;CAAM;CAElE,MAAM,cAAc,OAAO,QAAQ,MAAM,SAAS,IAAI,CAAC,CAAC;CACxD,OAAO;EACN,aAAa,OAAO,QAAQ,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;EAClD,aAAa,UAAU,IAAI,MAAM,OAAO,CAAC,IAAI;EAC7C,YAAY,YAAY,SAAS,KAAK,WAAW,IAAI;CACtD;AACD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maxLookbackDays?: number | null;
|
|
11
|
+
/**
|
|
12
|
+
* Site domain for the legacy script tag (`data-domain`). Takes priority over `scriptId`.
|
|
13
|
+
* The adapter declares `capture` only when one of the two is set.
|
|
14
|
+
*/
|
|
15
|
+
domain?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Per-site tracker id (`pa-<id>.js`) for the newer per-site script model. The adapter
|
|
18
|
+
* declares `capture` only when one of it and `domain` is set.
|
|
19
|
+
*/
|
|
20
|
+
scriptId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The ISO currency of the site's revenue goals. Declaring it turns on the `revenue`
|
|
23
|
+
* metric: Plausible serves `total_revenue` only where a revenue goal exists, and errors
|
|
24
|
+
* the whole request on a site that has none.
|
|
25
|
+
*/
|
|
26
|
+
revenueCurrency?: string;
|
|
11
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Plausible identifies a goal by its display name in the site's own goal list ("Signup",
|
|
30
|
+
* "Visit /thank-you"), so a plugin goal's slug must equal that name for its conversions to
|
|
31
|
+
* read. Conversions are the `events` metric on goal rows, which is the dashboard's Total
|
|
32
|
+
* Conversions; revenue is `total_revenue`, which Plausible serves only for a revenue goal
|
|
33
|
+
* and reports as an object whose `value` is null when the rows mix currencies. Revenue is
|
|
34
|
+
* offered only when `revenueCurrency` says the site has such a goal: asking for it on a site
|
|
35
|
+
* without one errors the request.
|
|
36
|
+
*/
|
|
12
37
|
declare function plausible(config: PlausibleConfig): AnalyticsAdapter;
|
|
13
38
|
//#endregion
|
|
14
39
|
export { PlausibleConfig, plausible };
|