@10x-media/analytics 0.1.0-beta.4 → 1.0.0-beta.10
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 +280 -0
- package/LICENSE +21 -21
- 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 +17 -2
- package/dist/core/capabilities.js +20 -1
- 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 +168 -8
- package/dist/core/options.js +132 -4
- 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 -29
- 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 +16 -2
- package/dist/exports/client.js +13 -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 +12 -4
- 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 +17 -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.d.ts +23 -0
- package/dist/fields/config/MetricSelectField.js +51 -0
- package/dist/fields/config/MetricSelectField.js.map +1 -0
- package/dist/fields/config/SourceSelectField.d.ts +14 -0
- package/dist/fields/config/SourceSelectField.js +46 -0
- package/dist/fields/config/SourceSelectField.js.map +1 -0
- package/dist/fields/config/fetchSources.d.ts +16 -0
- package/dist/fields/config/fetchSources.js +33 -0
- package/dist/fields/config/fetchSources.js.map +1 -0
- package/dist/fields/config/narrow.js +32 -0
- package/dist/fields/config/narrow.js.map +1 -0
- package/dist/fields/config/sourcesState.js +27 -0
- package/dist/fields/config/sourcesState.js.map +1 -0
- package/dist/fields/config/toSelectOption.js +27 -0
- package/dist/fields/config/toSelectOption.js.map +1 -0
- package/dist/fields/config/useAnalyticsSources.d.ts +24 -0
- package/dist/fields/config/useAnalyticsSources.js +62 -0
- package/dist/fields/config/useAnalyticsSources.js.map +1 -0
- 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 +185 -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 +19 -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 +39 -18
- 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 +28 -0
- package/dist/plugin/sourcesEndpoint.js.map +1 -0
- package/dist/plugin/warmTask.js +0 -0
- package/dist/plugin/warmTask.js.map +1 -1
- package/dist/providers/access.js +2 -1
- package/dist/providers/access.js.map +1 -1
- package/dist/providers/collection.js +90 -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 +45 -23
- 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 +16 -1
- package/dist/widgets/realtimePoll.js.map +1 -1
- package/dist/widgets/registerWidgets.js +76 -14
- 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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/tracker/exclusion.ts
|
|
2
|
+
/** Where the exclusion flag lives. Stable across releases: hosts read it too. */
|
|
3
|
+
const EXCLUSION_STORAGE_KEY = "analytics:exclude";
|
|
4
|
+
/** The query parameter that flips the flag, unless the host renamed or disabled it. */
|
|
5
|
+
const DEFAULT_EXCLUSION_PARAM = "analytics_exclude";
|
|
6
|
+
const EXCLUDED = "1";
|
|
7
|
+
const INCLUDED = "0";
|
|
8
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
9
|
+
/**
|
|
10
|
+
* Notified after every write, so a React tree can render the flag without polling storage.
|
|
11
|
+
* Returns the unsubscribe.
|
|
12
|
+
*/
|
|
13
|
+
const subscribeExclusion = (listener) => {
|
|
14
|
+
listeners.add(listener);
|
|
15
|
+
return () => {
|
|
16
|
+
listeners.delete(listener);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** The persisted flag. False when absent or unreadable. */
|
|
20
|
+
const readExclusion = (win) => {
|
|
21
|
+
try {
|
|
22
|
+
return win.localStorage?.getItem(EXCLUSION_STORAGE_KEY) === EXCLUDED;
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Persists the flag and tells the subscribers. Blocked storage is not a failure: the caller
|
|
29
|
+
* keeps the value in memory, so the exclusion holds for this page and is gone on the next.
|
|
30
|
+
*/
|
|
31
|
+
const writeExclusion = (win, excluded) => {
|
|
32
|
+
try {
|
|
33
|
+
win.localStorage?.setItem(EXCLUSION_STORAGE_KEY, excluded ? EXCLUDED : INCLUDED);
|
|
34
|
+
} catch {}
|
|
35
|
+
for (const listener of listeners) listener(excluded);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* What a query string asks for: `1` or `true` excludes, `0` or `false` includes, and an
|
|
39
|
+
* absent parameter or any other value leaves the stored flag as it is.
|
|
40
|
+
*/
|
|
41
|
+
const readExclusionParam = (search, param) => {
|
|
42
|
+
const value = new URLSearchParams(search).get(param);
|
|
43
|
+
if (value === "1" || value === "true") return true;
|
|
44
|
+
if (value === "0" || value === "false") return false;
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { DEFAULT_EXCLUSION_PARAM, EXCLUSION_STORAGE_KEY, readExclusion, readExclusionParam, subscribeExclusion, writeExclusion };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=exclusion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exclusion.js","names":[],"sources":["../../src/tracker/exclusion.ts"],"sourcesContent":["import type { TrackerWindow } from './types'\n\n/** Where the exclusion flag lives. Stable across releases: hosts read it too. */\nexport const EXCLUSION_STORAGE_KEY = 'analytics:exclude'\n\n/** The query parameter that flips the flag, unless the host renamed or disabled it. */\nexport const DEFAULT_EXCLUSION_PARAM = 'analytics_exclude'\n\nconst EXCLUDED = '1'\nconst INCLUDED = '0'\n\ntype ExclusionListener = (excluded: boolean) => void\n\nconst listeners = new Set<ExclusionListener>()\n\n/**\n * Notified after every write, so a React tree can render the flag without polling storage.\n * Returns the unsubscribe.\n */\nexport const subscribeExclusion = (listener: ExclusionListener): (() => void) => {\n\tlisteners.add(listener)\n\treturn () => {\n\t\tlisteners.delete(listener)\n\t}\n}\n\n/** The persisted flag. False when absent or unreadable. */\nexport const readExclusion = (win: TrackerWindow): boolean => {\n\ttry {\n\t\treturn win.localStorage?.getItem(EXCLUSION_STORAGE_KEY) === EXCLUDED\n\t} catch {\n\t\t// Storage disabled (Safari private mode, a strict partitioning policy).\n\t\treturn false\n\t}\n}\n\n/**\n * Persists the flag and tells the subscribers. Blocked storage is not a failure: the caller\n * keeps the value in memory, so the exclusion holds for this page and is gone on the next.\n */\nexport const writeExclusion = (win: TrackerWindow, excluded: boolean): void => {\n\ttry {\n\t\twin.localStorage?.setItem(EXCLUSION_STORAGE_KEY, excluded ? EXCLUDED : INCLUDED)\n\t} catch {\n\t\t// Storage disabled; the flag holds for this page only.\n\t}\n\tfor (const listener of listeners) {\n\t\tlistener(excluded)\n\t}\n}\n\n/**\n * What a query string asks for: `1` or `true` excludes, `0` or `false` includes, and an\n * absent parameter or any other value leaves the stored flag as it is.\n */\nexport const readExclusionParam = (search: string, param: string): boolean | null => {\n\tconst value = new URLSearchParams(search).get(param)\n\tif (value === '1' || value === 'true') {\n\t\treturn true\n\t}\n\tif (value === '0' || value === 'false') {\n\t\treturn false\n\t}\n\treturn null\n}\n"],"mappings":";;AAGA,MAAa,wBAAwB;;AAGrC,MAAa,0BAA0B;AAEvC,MAAM,WAAW;AACjB,MAAM,WAAW;AAIjB,MAAM,4BAAY,IAAI,IAAuB;;;;;AAM7C,MAAa,sBAAsB,aAA8C;CAChF,UAAU,IAAI,QAAQ;CACtB,aAAa;EACZ,UAAU,OAAO,QAAQ;CAC1B;AACD;;AAGA,MAAa,iBAAiB,QAAgC;CAC7D,IAAI;EACH,OAAO,IAAI,cAAc,QAAQ,qBAAqB,MAAM;CAC7D,QAAQ;EAEP,OAAO;CACR;AACD;;;;;AAMA,MAAa,kBAAkB,KAAoB,aAA4B;CAC9E,IAAI;EACH,IAAI,cAAc,QAAQ,uBAAuB,WAAW,WAAW,QAAQ;CAChF,QAAQ,CAER;CACA,KAAK,MAAM,YAAY,WACtB,SAAS,QAAQ;AAEnB;;;;;AAMA,MAAa,sBAAsB,QAAgB,UAAkC;CACpF,MAAM,QAAQ,IAAI,gBAAgB,MAAM,EAAE,IAAI,KAAK;CACnD,IAAI,UAAU,OAAO,UAAU,QAC9B,OAAO;CAER,IAAI,UAAU,OAAO,UAAU,SAC9B,OAAO;CAER,OAAO;AACR"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Tracker, TrackerOptions } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/tracker/initTracker.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Where the plugin mounts the public tracker config on a default install. The only place
|
|
6
|
+
* the path is written down on the client: the RSC path hands the config over directly, and
|
|
7
|
+
* an app that moved `routes.api` passes its own `endpoint`.
|
|
8
|
+
*/
|
|
9
|
+
declare const DEFAULT_TRACKER_ENDPOINT = "/api/analytics/tracker";
|
|
10
|
+
interface InitTrackerArgs extends TrackerOptions {
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Boots the tracker from the public tracker endpoint, for hosts that render no RSC. The
|
|
15
|
+
* request is same-origin so a scoped install resolves the visitor's tenant from the request
|
|
16
|
+
* itself. A config that cannot be fetched yields a tracker that does nothing rather than a
|
|
17
|
+
* rejected promise: a missing analytics config must never break the page that awaited it.
|
|
18
|
+
*/
|
|
19
|
+
declare const initTracker: (args?: InitTrackerArgs) => Promise<Tracker>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { DEFAULT_TRACKER_ENDPOINT, InitTrackerArgs, initTracker };
|
|
22
|
+
//# sourceMappingURL=initTracker.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createNoopTracker, createTracker } from "./createTracker.js";
|
|
2
|
+
//#region src/tracker/initTracker.ts
|
|
3
|
+
/**
|
|
4
|
+
* Where the plugin mounts the public tracker config on a default install. The only place
|
|
5
|
+
* the path is written down on the client: the RSC path hands the config over directly, and
|
|
6
|
+
* an app that moved `routes.api` passes its own `endpoint`.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_TRACKER_ENDPOINT = "/api/analytics/tracker";
|
|
9
|
+
/**
|
|
10
|
+
* Boots the tracker from the public tracker endpoint, for hosts that render no RSC. The
|
|
11
|
+
* request is same-origin so a scoped install resolves the visitor's tenant from the request
|
|
12
|
+
* itself. A config that cannot be fetched yields a tracker that does nothing rather than a
|
|
13
|
+
* rejected promise: a missing analytics config must never break the page that awaited it.
|
|
14
|
+
*/
|
|
15
|
+
const initTracker = async (args = {}) => {
|
|
16
|
+
const { endpoint = DEFAULT_TRACKER_ENDPOINT, ...options } = args;
|
|
17
|
+
const win = options.window ?? globalThis.window;
|
|
18
|
+
if (!win) return createNoopTracker();
|
|
19
|
+
try {
|
|
20
|
+
const response = await win.fetch(endpoint, { credentials: "same-origin" });
|
|
21
|
+
if (!response.ok) return createNoopTracker();
|
|
22
|
+
return createTracker(await response.json(), {
|
|
23
|
+
...options,
|
|
24
|
+
window: win
|
|
25
|
+
});
|
|
26
|
+
} catch {
|
|
27
|
+
return createNoopTracker();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { DEFAULT_TRACKER_ENDPOINT, initTracker };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=initTracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initTracker.js","names":[],"sources":["../../src/tracker/initTracker.ts"],"sourcesContent":["import type { TrackerConfig } from '../capture/trackerConfig'\nimport { createNoopTracker, createTracker } from './createTracker'\nimport type { Tracker, TrackerOptions, TrackerWindow } from './types'\n\n/**\n * Where the plugin mounts the public tracker config on a default install. The only place\n * the path is written down on the client: the RSC path hands the config over directly, and\n * an app that moved `routes.api` passes its own `endpoint`.\n */\nexport const DEFAULT_TRACKER_ENDPOINT = '/api/analytics/tracker'\n\nexport interface InitTrackerArgs extends TrackerOptions {\n\tendpoint?: string\n}\n\n/**\n * Boots the tracker from the public tracker endpoint, for hosts that render no RSC. The\n * request is same-origin so a scoped install resolves the visitor's tenant from the request\n * itself. A config that cannot be fetched yields a tracker that does nothing rather than a\n * rejected promise: a missing analytics config must never break the page that awaited it.\n */\nexport const initTracker = async (args: InitTrackerArgs = {}): Promise<Tracker> => {\n\tconst { endpoint = DEFAULT_TRACKER_ENDPOINT, ...options } = args\n\tconst win = options.window ?? (globalThis as { window?: TrackerWindow }).window\n\tif (!win) {\n\t\treturn createNoopTracker()\n\t}\n\ttry {\n\t\tconst response = await win.fetch(endpoint, { credentials: 'same-origin' })\n\t\tif (!response.ok) {\n\t\t\treturn createNoopTracker()\n\t\t}\n\t\treturn createTracker((await response.json()) as TrackerConfig, { ...options, window: win })\n\t} catch {\n\t\treturn createNoopTracker()\n\t}\n}\n"],"mappings":";;;;;;;AASA,MAAa,2BAA2B;;;;;;;AAYxC,MAAa,cAAc,OAAO,OAAwB,CAAC,MAAwB;CAClF,MAAM,EAAE,WAAW,0BAA0B,GAAG,YAAY;CAC5D,MAAM,MAAM,QAAQ,UAAW,WAA0C;CACzE,IAAI,CAAC,KACJ,OAAO,kBAAkB;CAE1B,IAAI;EACH,MAAM,WAAW,MAAM,IAAI,MAAM,UAAU,EAAE,aAAa,cAAc,CAAC;EACzE,IAAI,CAAC,SAAS,IACb,OAAO,kBAAkB;EAE1B,OAAO,cAAe,MAAM,SAAS,KAAK,GAAqB;GAAE,GAAG;GAAS,QAAQ;EAAI,CAAC;CAC3F,QAAQ;EACP,OAAO,kBAAkB;CAC1B;AACD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LoadScript, TrackerWindow } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/tracker/loadScript.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The default `loadScript` seam: injects a snippet script into `<head>`, resolving once it
|
|
6
|
+
* has run. A script the page already carries is a no-op, which is what makes the RSC path
|
|
7
|
+
* safe: `AnalyticsScripts` renders the same snippets server-side, and the sink booting over
|
|
8
|
+
* them must not load a second copy. Inline scripts resolve as soon as they are appended,
|
|
9
|
+
* since appending runs them.
|
|
10
|
+
*/
|
|
11
|
+
declare const createScriptLoader: (win: TrackerWindow, nonce?: string) => LoadScript;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createScriptLoader };
|
|
14
|
+
//# sourceMappingURL=loadScript.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/tracker/loadScript.ts
|
|
2
|
+
const alreadyPresent = (win, script) => {
|
|
3
|
+
for (const el of win.document.querySelectorAll("script")) {
|
|
4
|
+
if (script.src && el.getAttribute("src") === script.src) return true;
|
|
5
|
+
if (script.inline && el.textContent === script.inline) return true;
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The default `loadScript` seam: injects a snippet script into `<head>`, resolving once it
|
|
11
|
+
* has run. A script the page already carries is a no-op, which is what makes the RSC path
|
|
12
|
+
* safe: `AnalyticsScripts` renders the same snippets server-side, and the sink booting over
|
|
13
|
+
* them must not load a second copy. Inline scripts resolve as soon as they are appended,
|
|
14
|
+
* since appending runs them.
|
|
15
|
+
*/
|
|
16
|
+
const createScriptLoader = (win, nonce) => (script) => new Promise((resolve, reject) => {
|
|
17
|
+
if (!script.src && !script.inline || alreadyPresent(win, script)) {
|
|
18
|
+
resolve();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const el = win.document.createElement("script");
|
|
22
|
+
for (const [name, value] of Object.entries(script.attrs ?? {})) el.setAttribute(name, value);
|
|
23
|
+
if (script.type) el.type = script.type;
|
|
24
|
+
if (nonce) el.setAttribute("nonce", nonce);
|
|
25
|
+
if (script.inline) {
|
|
26
|
+
el.text = script.inline;
|
|
27
|
+
win.document.head.appendChild(el);
|
|
28
|
+
resolve();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
el.async = script.async ?? false;
|
|
32
|
+
el.defer = script.defer ?? false;
|
|
33
|
+
el.addEventListener("load", () => resolve());
|
|
34
|
+
el.addEventListener("error", () => reject(/* @__PURE__ */ new Error(`analytics: failed to load ${script.src}`)));
|
|
35
|
+
el.src = script.src;
|
|
36
|
+
win.document.head.appendChild(el);
|
|
37
|
+
});
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createScriptLoader };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=loadScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadScript.js","names":[],"sources":["../../src/tracker/loadScript.ts"],"sourcesContent":["import type { SnippetScript } from '../core/capture'\nimport type { LoadScript, TrackerWindow } from './types'\n\nconst alreadyPresent = (win: TrackerWindow, script: SnippetScript): boolean => {\n\tfor (const el of win.document.querySelectorAll('script')) {\n\t\tif (script.src && el.getAttribute('src') === script.src) {\n\t\t\treturn true\n\t\t}\n\t\tif (script.inline && el.textContent === script.inline) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n/**\n * The default `loadScript` seam: injects a snippet script into `<head>`, resolving once it\n * has run. A script the page already carries is a no-op, which is what makes the RSC path\n * safe: `AnalyticsScripts` renders the same snippets server-side, and the sink booting over\n * them must not load a second copy. Inline scripts resolve as soon as they are appended,\n * since appending runs them.\n */\nexport const createScriptLoader =\n\t(win: TrackerWindow, nonce?: string): LoadScript =>\n\t(script) =>\n\t\tnew Promise((resolve, reject) => {\n\t\t\tif ((!script.src && !script.inline) || alreadyPresent(win, script)) {\n\t\t\t\tresolve()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst el = win.document.createElement('script')\n\t\t\tfor (const [name, value] of Object.entries(script.attrs ?? {})) {\n\t\t\t\tel.setAttribute(name, value)\n\t\t\t}\n\t\t\tif (script.type) {\n\t\t\t\tel.type = script.type\n\t\t\t}\n\t\t\tif (nonce) {\n\t\t\t\tel.setAttribute('nonce', nonce)\n\t\t\t}\n\t\t\tif (script.inline) {\n\t\t\t\tel.text = script.inline\n\t\t\t\twin.document.head.appendChild(el)\n\t\t\t\tresolve()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tel.async = script.async ?? false\n\t\t\tel.defer = script.defer ?? false\n\t\t\tel.addEventListener('load', () => resolve())\n\t\t\tel.addEventListener('error', () =>\n\t\t\t\treject(new Error(`analytics: failed to load ${script.src}`))\n\t\t\t)\n\t\t\tel.src = script.src as string\n\t\t\twin.document.head.appendChild(el)\n\t\t})\n"],"mappings":";AAGA,MAAM,kBAAkB,KAAoB,WAAmC;CAC9E,KAAK,MAAM,MAAM,IAAI,SAAS,iBAAiB,QAAQ,GAAG;EACzD,IAAI,OAAO,OAAO,GAAG,aAAa,KAAK,MAAM,OAAO,KACnD,OAAO;EAER,IAAI,OAAO,UAAU,GAAG,gBAAgB,OAAO,QAC9C,OAAO;CAET;CACA,OAAO;AACR;;;;;;;;AASA,MAAa,sBACX,KAAoB,WACpB,WACA,IAAI,SAAS,SAAS,WAAW;CAChC,IAAK,CAAC,OAAO,OAAO,CAAC,OAAO,UAAW,eAAe,KAAK,MAAM,GAAG;EACnE,QAAQ;EACR;CACD;CACA,MAAM,KAAK,IAAI,SAAS,cAAc,QAAQ;CAC9C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,SAAS,CAAC,CAAC,GAC5D,GAAG,aAAa,MAAM,KAAK;CAE5B,IAAI,OAAO,MACV,GAAG,OAAO,OAAO;CAElB,IAAI,OACH,GAAG,aAAa,SAAS,KAAK;CAE/B,IAAI,OAAO,QAAQ;EAClB,GAAG,OAAO,OAAO;EACjB,IAAI,SAAS,KAAK,YAAY,EAAE;EAChC,QAAQ;EACR;CACD;CACA,GAAG,QAAQ,OAAO,SAAS;CAC3B,GAAG,QAAQ,OAAO,SAAS;CAC3B,GAAG,iBAAiB,cAAc,QAAQ,CAAC;CAC3C,GAAG,iBAAiB,eACnB,uBAAO,IAAI,MAAM,6BAA6B,OAAO,KAAK,CAAC,CAC5D;CACA,GAAG,MAAM,OAAO;CAChB,IAAI,SAAS,KAAK,YAAY,EAAE;AACjC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TrackerWindow } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/tracker/pageTracking.d.ts
|
|
4
|
+
interface PageTracking {
|
|
5
|
+
destroy(): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Turns SPA navigations into page changes. `history.pushState`/`replaceState` fire no event
|
|
9
|
+
* of their own, so both are wrapped; `popstate` covers back and forward. Only a changed
|
|
10
|
+
* `location.pathname` counts, so a query or hash rewrite (a filter panel, an anchor link)
|
|
11
|
+
* does not report a second pageview. The originals are restored on destroy, which keeps a
|
|
12
|
+
* hot-reloaded or unmounted app from stacking wrappers.
|
|
13
|
+
*/
|
|
14
|
+
declare const createPageTracking: (win: TrackerWindow, onChange: () => void) => PageTracking;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { PageTracking, createPageTracking };
|
|
17
|
+
//# sourceMappingURL=pageTracking.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/tracker/pageTracking.ts
|
|
2
|
+
/**
|
|
3
|
+
* Turns SPA navigations into page changes. `history.pushState`/`replaceState` fire no event
|
|
4
|
+
* of their own, so both are wrapped; `popstate` covers back and forward. Only a changed
|
|
5
|
+
* `location.pathname` counts, so a query or hash rewrite (a filter panel, an anchor link)
|
|
6
|
+
* does not report a second pageview. The originals are restored on destroy, which keeps a
|
|
7
|
+
* hot-reloaded or unmounted app from stacking wrappers.
|
|
8
|
+
*/
|
|
9
|
+
const createPageTracking = (win, onChange) => {
|
|
10
|
+
const history = win.history;
|
|
11
|
+
const pushState = history.pushState;
|
|
12
|
+
const replaceState = history.replaceState;
|
|
13
|
+
let lastPath = win.location.pathname;
|
|
14
|
+
const check = () => {
|
|
15
|
+
const path = win.location.pathname;
|
|
16
|
+
if (path === lastPath) return;
|
|
17
|
+
lastPath = path;
|
|
18
|
+
onChange();
|
|
19
|
+
};
|
|
20
|
+
const wrap = (original) => (...args) => {
|
|
21
|
+
original.apply(history, args);
|
|
22
|
+
check();
|
|
23
|
+
};
|
|
24
|
+
const patchedPush = wrap(pushState);
|
|
25
|
+
const patchedReplace = wrap(replaceState);
|
|
26
|
+
history.pushState = patchedPush;
|
|
27
|
+
history.replaceState = patchedReplace;
|
|
28
|
+
win.addEventListener("popstate", check);
|
|
29
|
+
return { destroy() {
|
|
30
|
+
if (history.pushState === patchedPush) history.pushState = pushState;
|
|
31
|
+
if (history.replaceState === patchedReplace) history.replaceState = replaceState;
|
|
32
|
+
win.removeEventListener("popstate", check);
|
|
33
|
+
} };
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createPageTracking };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=pageTracking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageTracking.js","names":[],"sources":["../../src/tracker/pageTracking.ts"],"sourcesContent":["import type { TrackerWindow } from './types'\n\nexport interface PageTracking {\n\tdestroy(): void\n}\n\n/**\n * Turns SPA navigations into page changes. `history.pushState`/`replaceState` fire no event\n * of their own, so both are wrapped; `popstate` covers back and forward. Only a changed\n * `location.pathname` counts, so a query or hash rewrite (a filter panel, an anchor link)\n * does not report a second pageview. The originals are restored on destroy, which keeps a\n * hot-reloaded or unmounted app from stacking wrappers.\n */\nexport const createPageTracking = (win: TrackerWindow, onChange: () => void): PageTracking => {\n\tconst history = win.history\n\tconst pushState = history.pushState\n\tconst replaceState = history.replaceState\n\tlet lastPath = win.location.pathname\n\n\tconst check = () => {\n\t\tconst path = win.location.pathname\n\t\tif (path === lastPath) {\n\t\t\treturn\n\t\t}\n\t\tlastPath = path\n\t\tonChange()\n\t}\n\n\tconst wrap =\n\t\t(original: typeof history.pushState) =>\n\t\t(...args: Parameters<typeof history.pushState>) => {\n\t\t\toriginal.apply(history, args)\n\t\t\tcheck()\n\t\t}\n\n\tconst patchedPush = wrap(pushState)\n\tconst patchedReplace = wrap(replaceState)\n\thistory.pushState = patchedPush\n\thistory.replaceState = patchedReplace\n\twin.addEventListener('popstate', check)\n\n\treturn {\n\t\tdestroy() {\n\t\t\t// Only unwind our own wrapper: another library may have patched on top of it,\n\t\t\t// and restoring the original underneath it would silently unhook that library.\n\t\t\tif (history.pushState === patchedPush) {\n\t\t\t\thistory.pushState = pushState\n\t\t\t}\n\t\t\tif (history.replaceState === patchedReplace) {\n\t\t\t\thistory.replaceState = replaceState\n\t\t\t}\n\t\t\twin.removeEventListener('popstate', check)\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,sBAAsB,KAAoB,aAAuC;CAC7F,MAAM,UAAU,IAAI;CACpB,MAAM,YAAY,QAAQ;CAC1B,MAAM,eAAe,QAAQ;CAC7B,IAAI,WAAW,IAAI,SAAS;CAE5B,MAAM,cAAc;EACnB,MAAM,OAAO,IAAI,SAAS;EAC1B,IAAI,SAAS,UACZ;EAED,WAAW;EACX,SAAS;CACV;CAEA,MAAM,QACJ,cACA,GAAG,SAA+C;EAClD,SAAS,MAAM,SAAS,IAAI;EAC5B,MAAM;CACP;CAED,MAAM,cAAc,KAAK,SAAS;CAClC,MAAM,iBAAiB,KAAK,YAAY;CACxC,QAAQ,YAAY;CACpB,QAAQ,eAAe;CACvB,IAAI,iBAAiB,YAAY,KAAK;CAEtC,OAAO,EACN,UAAU;EAGT,IAAI,QAAQ,cAAc,aACzB,QAAQ,YAAY;EAErB,IAAI,QAAQ,iBAAiB,gBAC5B,QAAQ,eAAe;EAExB,IAAI,oBAAoB,YAAY,KAAK;CAC1C,EACD;AACD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TrackerConfig } from "../capture/trackerConfig.js";
|
|
2
|
+
import { Tracker, TrackerOptions } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/tracker/registry.d.ts
|
|
5
|
+
interface TrackerLease {
|
|
6
|
+
tracker: Tracker;
|
|
7
|
+
/** Gives up this holder's claim. Safe to call more than once. */
|
|
8
|
+
release(): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Hands out the one tracker a window is allowed to have, reference counted.
|
|
12
|
+
*
|
|
13
|
+
* React mounts an effect, tears it down, and mounts it again on the same commit under
|
|
14
|
+
* StrictMode, so a component that created a tracker in its effect booted two of them and
|
|
15
|
+
* sent two boot pageviews. Here the second mount finds the live instance instead. The
|
|
16
|
+
* teardown is deferred to a macrotask and skipped if a new holder arrived in the meantime,
|
|
17
|
+
* which is what makes that synchronous remount free; a real unmount still destroys the
|
|
18
|
+
* tracker on the next tick.
|
|
19
|
+
*
|
|
20
|
+
* One tracker per window also means `<AnalyticsScripts />` and `<AnalyticsProvider>` can
|
|
21
|
+
* both be rendered without double-counting. The first holder's config wins for as long as
|
|
22
|
+
* the tracker lives.
|
|
23
|
+
*/
|
|
24
|
+
declare const acquireTracker: (config: TrackerConfig, options?: TrackerOptions) => TrackerLease;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { TrackerLease, acquireTracker };
|
|
27
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createNoopTracker, createTracker } from "./createTracker.js";
|
|
2
|
+
//#region src/tracker/registry.ts
|
|
3
|
+
const entries = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* The tracker a window already holds, or null. A peek, never a boot: a caller that has no
|
|
6
|
+
* config of its own (`useAnalytics` outside a provider) can reach the instance
|
|
7
|
+
* `<TrackerBoot />` or `<AnalyticsProvider>` acquired without taking a lease or creating a
|
|
8
|
+
* second one. An instance released this tick is still reachable until its teardown runs,
|
|
9
|
+
* and a destroyed tracker is inert rather than broken.
|
|
10
|
+
*/
|
|
11
|
+
const liveTracker = (window) => {
|
|
12
|
+
const win = window ?? globalThis.window;
|
|
13
|
+
return win ? entries.get(win)?.tracker ?? null : null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Hands out the one tracker a window is allowed to have, reference counted.
|
|
17
|
+
*
|
|
18
|
+
* React mounts an effect, tears it down, and mounts it again on the same commit under
|
|
19
|
+
* StrictMode, so a component that created a tracker in its effect booted two of them and
|
|
20
|
+
* sent two boot pageviews. Here the second mount finds the live instance instead. The
|
|
21
|
+
* teardown is deferred to a macrotask and skipped if a new holder arrived in the meantime,
|
|
22
|
+
* which is what makes that synchronous remount free; a real unmount still destroys the
|
|
23
|
+
* tracker on the next tick.
|
|
24
|
+
*
|
|
25
|
+
* One tracker per window also means `<AnalyticsScripts />` and `<AnalyticsProvider>` can
|
|
26
|
+
* both be rendered without double-counting. The first holder's config wins for as long as
|
|
27
|
+
* the tracker lives.
|
|
28
|
+
*/
|
|
29
|
+
const acquireTracker = (config, options = {}) => {
|
|
30
|
+
const win = options.window ?? globalThis.window;
|
|
31
|
+
if (!win) return {
|
|
32
|
+
tracker: createNoopTracker(),
|
|
33
|
+
release: () => void 0
|
|
34
|
+
};
|
|
35
|
+
let entry = entries.get(win);
|
|
36
|
+
if (!entry) {
|
|
37
|
+
entry = {
|
|
38
|
+
tracker: createTracker(config, {
|
|
39
|
+
...options,
|
|
40
|
+
window: win
|
|
41
|
+
}),
|
|
42
|
+
refs: 0,
|
|
43
|
+
teardown: null
|
|
44
|
+
};
|
|
45
|
+
entries.set(win, entry);
|
|
46
|
+
}
|
|
47
|
+
if (entry.teardown !== null) {
|
|
48
|
+
win.clearTimeout(entry.teardown);
|
|
49
|
+
entry.teardown = null;
|
|
50
|
+
}
|
|
51
|
+
entry.refs += 1;
|
|
52
|
+
const held = entry;
|
|
53
|
+
let released = false;
|
|
54
|
+
return {
|
|
55
|
+
tracker: entry.tracker,
|
|
56
|
+
release() {
|
|
57
|
+
if (released) return;
|
|
58
|
+
released = true;
|
|
59
|
+
held.refs -= 1;
|
|
60
|
+
if (held.refs > 0 || held.teardown !== null) return;
|
|
61
|
+
held.teardown = win.setTimeout(() => {
|
|
62
|
+
held.teardown = null;
|
|
63
|
+
if (held.refs > 0) return;
|
|
64
|
+
held.tracker.destroy();
|
|
65
|
+
if (entries.get(win) === held) entries.delete(win);
|
|
66
|
+
}, 0);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
export { acquireTracker, liveTracker };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../src/tracker/registry.ts"],"sourcesContent":["import type { TrackerConfig } from '../capture/trackerConfig'\nimport { createNoopTracker, createTracker } from './createTracker'\nimport type { Tracker, TrackerOptions, TrackerWindow } from './types'\n\nexport interface TrackerLease {\n\ttracker: Tracker\n\t/** Gives up this holder's claim. Safe to call more than once. */\n\trelease(): void\n}\n\ninterface Entry {\n\ttracker: Tracker\n\trefs: number\n\tteardown: ReturnType<Window['setTimeout']> | null\n}\n\nconst entries = new WeakMap<TrackerWindow, Entry>()\n\n/**\n * The tracker a window already holds, or null. A peek, never a boot: a caller that has no\n * config of its own (`useAnalytics` outside a provider) can reach the instance\n * `<TrackerBoot />` or `<AnalyticsProvider>` acquired without taking a lease or creating a\n * second one. An instance released this tick is still reachable until its teardown runs,\n * and a destroyed tracker is inert rather than broken.\n */\nexport const liveTracker = (window?: TrackerWindow): Tracker | null => {\n\tconst win = window ?? (globalThis as { window?: TrackerWindow }).window\n\treturn win ? (entries.get(win)?.tracker ?? null) : null\n}\n\n/**\n * Hands out the one tracker a window is allowed to have, reference counted.\n *\n * React mounts an effect, tears it down, and mounts it again on the same commit under\n * StrictMode, so a component that created a tracker in its effect booted two of them and\n * sent two boot pageviews. Here the second mount finds the live instance instead. The\n * teardown is deferred to a macrotask and skipped if a new holder arrived in the meantime,\n * which is what makes that synchronous remount free; a real unmount still destroys the\n * tracker on the next tick.\n *\n * One tracker per window also means `<AnalyticsScripts />` and `<AnalyticsProvider>` can\n * both be rendered without double-counting. The first holder's config wins for as long as\n * the tracker lives.\n */\nexport const acquireTracker = (\n\tconfig: TrackerConfig,\n\toptions: TrackerOptions = {}\n): TrackerLease => {\n\tconst win = options.window ?? (globalThis as { window?: TrackerWindow }).window\n\tif (!win) {\n\t\treturn { tracker: createNoopTracker(), release: () => undefined }\n\t}\n\tlet entry = entries.get(win)\n\tif (!entry) {\n\t\tentry = {\n\t\t\ttracker: createTracker(config, { ...options, window: win }),\n\t\t\trefs: 0,\n\t\t\tteardown: null,\n\t\t}\n\t\tentries.set(win, entry)\n\t}\n\tif (entry.teardown !== null) {\n\t\twin.clearTimeout(entry.teardown)\n\t\tentry.teardown = null\n\t}\n\tentry.refs += 1\n\tconst held = entry\n\tlet released = false\n\n\treturn {\n\t\ttracker: entry.tracker,\n\t\trelease() {\n\t\t\tif (released) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\treleased = true\n\t\t\theld.refs -= 1\n\t\t\tif (held.refs > 0 || held.teardown !== null) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\theld.teardown = win.setTimeout(() => {\n\t\t\t\theld.teardown = null\n\t\t\t\tif (held.refs > 0) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\theld.tracker.destroy()\n\t\t\t\tif (entries.get(win) === held) {\n\t\t\t\t\tentries.delete(win)\n\t\t\t\t}\n\t\t\t}, 0)\n\t\t},\n\t}\n}\n"],"mappings":";;AAgBA,MAAM,0BAAU,IAAI,QAA8B;;;;;;;;AASlD,MAAa,eAAe,WAA2C;CACtE,MAAM,MAAM,UAAW,WAA0C;CACjE,OAAO,MAAO,QAAQ,IAAI,GAAG,GAAG,WAAW,OAAQ;AACpD;;;;;;;;;;;;;;;AAgBA,MAAa,kBACZ,QACA,UAA0B,CAAC,MACT;CAClB,MAAM,MAAM,QAAQ,UAAW,WAA0C;CACzE,IAAI,CAAC,KACJ,OAAO;EAAE,SAAS,kBAAkB;EAAG,eAAe,KAAA;CAAU;CAEjE,IAAI,QAAQ,QAAQ,IAAI,GAAG;CAC3B,IAAI,CAAC,OAAO;EACX,QAAQ;GACP,SAAS,cAAc,QAAQ;IAAE,GAAG;IAAS,QAAQ;GAAI,CAAC;GAC1D,MAAM;GACN,UAAU;EACX;EACA,QAAQ,IAAI,KAAK,KAAK;CACvB;CACA,IAAI,MAAM,aAAa,MAAM;EAC5B,IAAI,aAAa,MAAM,QAAQ;EAC/B,MAAM,WAAW;CAClB;CACA,MAAM,QAAQ;CACd,MAAM,OAAO;CACb,IAAI,WAAW;CAEf,OAAO;EACN,SAAS,MAAM;EACf,UAAU;GACT,IAAI,UACH;GAED,WAAW;GACX,KAAK,QAAQ;GACb,IAAI,KAAK,OAAO,KAAK,KAAK,aAAa,MACtC;GAED,KAAK,WAAW,IAAI,iBAAiB;IACpC,KAAK,WAAW;IAChB,IAAI,KAAK,OAAO,GACf;IAED,KAAK,QAAQ,QAAQ;IACrB,IAAI,QAAQ,IAAI,GAAG,MAAM,MACxB,QAAQ,OAAO,GAAG;GAEpB,GAAG,CAAC;EACL;CACD;AACD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Sink } from "../types.js";
|
|
2
|
+
import { VendorSinkArgs } from "./vendor.js";
|
|
3
|
+
import { GA4_DISABLE_PREFIX } from "../../adapters/ga4/disableKey.js";
|
|
4
|
+
|
|
5
|
+
//#region src/tracker/sinks/ga4.d.ts
|
|
6
|
+
interface Ga4SinkArgs extends VendorSinkArgs {
|
|
7
|
+
/** From the slot's client descriptor: the switch is per measurement id. */
|
|
8
|
+
measurementId?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Forwards events and goals to `gtag('event', name, params)`, under the name GA4 accepts for
|
|
12
|
+
* them rather than the kebab-case slug: the other vendors take hyphens, GA4 does not. Revenue
|
|
13
|
+
* rides along as the `value` and `currency` params, which is what GA4's own ecommerce reports
|
|
14
|
+
* read. The inline half of the snippet defines `gtag` and its `dataLayer` queue the moment it
|
|
15
|
+
* runs, so calls made before gtag.js lands are replayed by it.
|
|
16
|
+
*
|
|
17
|
+
* Pageviews are dropped by `createVendorSink`, as for every other vendor: `gtag('config', id)`
|
|
18
|
+
* sends the first page view itself, and page views on history changes come from the web data
|
|
19
|
+
* stream's enhanced measurement (https://support.google.com/analytics/answer/9216061), on by
|
|
20
|
+
* default and switchable per stream. An install that turned that option off should turn it
|
|
21
|
+
* back on: this sink forwards no pageview, because on a default stream it would double-count.
|
|
22
|
+
*/
|
|
23
|
+
declare const createGa4Sink: ({
|
|
24
|
+
measurementId,
|
|
25
|
+
...args
|
|
26
|
+
}: Ga4SinkArgs) => Sink;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { Ga4SinkArgs, createGa4Sink };
|
|
29
|
+
//# sourceMappingURL=ga4.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ga4DisableKey } from "../../adapters/ga4/disableKey.js";
|
|
2
|
+
import { ga4EventName } from "../../adapters/ga4/eventName.js";
|
|
3
|
+
import { createVendorSink, flatProps, vendorEventName } from "./vendor.js";
|
|
4
|
+
//#region src/tracker/sinks/ga4.ts
|
|
5
|
+
/**
|
|
6
|
+
* Forwards events and goals to `gtag('event', name, params)`, under the name GA4 accepts for
|
|
7
|
+
* them rather than the kebab-case slug: the other vendors take hyphens, GA4 does not. Revenue
|
|
8
|
+
* rides along as the `value` and `currency` params, which is what GA4's own ecommerce reports
|
|
9
|
+
* read. The inline half of the snippet defines `gtag` and its `dataLayer` queue the moment it
|
|
10
|
+
* runs, so calls made before gtag.js lands are replayed by it.
|
|
11
|
+
*
|
|
12
|
+
* Pageviews are dropped by `createVendorSink`, as for every other vendor: `gtag('config', id)`
|
|
13
|
+
* sends the first page view itself, and page views on history changes come from the web data
|
|
14
|
+
* stream's enhanced measurement (https://support.google.com/analytics/answer/9216061), on by
|
|
15
|
+
* default and switchable per stream. An install that turned that option off should turn it
|
|
16
|
+
* back on: this sink forwards no pageview, because on a default stream it would double-count.
|
|
17
|
+
*/
|
|
18
|
+
const createGa4Sink = ({ measurementId, ...args }) => createVendorSink(args, {
|
|
19
|
+
...measurementId ? { exclude: (excluded) => {
|
|
20
|
+
Reflect.set(args.win, ga4DisableKey(measurementId), excluded);
|
|
21
|
+
} } : {},
|
|
22
|
+
has: () => typeof args.win.gtag === "function",
|
|
23
|
+
dispatch: (event) => {
|
|
24
|
+
args.win.gtag?.("event", ga4EventName(vendorEventName(event)), flatProps(event));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createGa4Sink };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=ga4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ga4.js","names":[],"sources":["../../../src/tracker/sinks/ga4.ts"],"sourcesContent":["import { ga4DisableKey } from '../../adapters/ga4/disableKey'\nimport { ga4EventName } from '../../adapters/ga4/eventName'\nimport type { Sink, TrackerWindow } from '../types'\nimport { createVendorSink, flatProps, type VendorSinkArgs, vendorEventName } from './vendor'\n\nexport { GA4_DISABLE_PREFIX } from '../../adapters/ga4/disableKey'\n\ntype GtagWindow = TrackerWindow & {\n\tgtag?: (command: 'event', name: string, params?: Record<string, unknown>) => void\n}\n\nexport interface Ga4SinkArgs extends VendorSinkArgs {\n\t/** From the slot's client descriptor: the switch is per measurement id. */\n\tmeasurementId?: string\n}\n\n/**\n * Forwards events and goals to `gtag('event', name, params)`, under the name GA4 accepts for\n * them rather than the kebab-case slug: the other vendors take hyphens, GA4 does not. Revenue\n * rides along as the `value` and `currency` params, which is what GA4's own ecommerce reports\n * read. The inline half of the snippet defines `gtag` and its `dataLayer` queue the moment it\n * runs, so calls made before gtag.js lands are replayed by it.\n *\n * Pageviews are dropped by `createVendorSink`, as for every other vendor: `gtag('config', id)`\n * sends the first page view itself, and page views on history changes come from the web data\n * stream's enhanced measurement (https://support.google.com/analytics/answer/9216061), on by\n * default and switchable per stream. An install that turned that option off should turn it\n * back on: this sink forwards no pageview, because on a default stream it would double-count.\n */\nexport const createGa4Sink = ({ measurementId, ...args }: Ga4SinkArgs): Sink =>\n\tcreateVendorSink(args, {\n\t\t...(measurementId\n\t\t\t? {\n\t\t\t\t\t// The rendered snippet sets this for itself; re-asserting it covers a gated slot,\n\t\t\t\t\t// whose snippet this sink injects, and a runtime flip either way.\n\t\t\t\t\texclude: (excluded: boolean) => {\n\t\t\t\t\t\tReflect.set(args.win, ga4DisableKey(measurementId), excluded)\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t\thas: () => typeof (args.win as GtagWindow).gtag === 'function',\n\t\tdispatch: (event) => {\n\t\t\t;(args.win as GtagWindow).gtag?.(\n\t\t\t\t'event',\n\t\t\t\tga4EventName(vendorEventName(event)),\n\t\t\t\tflatProps(event)\n\t\t\t)\n\t\t},\n\t})\n"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAa,iBAAiB,EAAE,eAAe,GAAG,WACjD,iBAAiB,MAAM;CACtB,GAAI,gBACD,EAGA,UAAU,aAAsB;EAC/B,QAAQ,IAAI,KAAK,KAAK,cAAc,aAAa,GAAG,QAAQ;CAC7D,EACD,IACC,CAAC;CACJ,WAAW,OAAQ,KAAK,IAAmB,SAAS;CACpD,WAAW,UAAU;EACnB,KAAM,IAAmB,OACzB,SACA,aAAa,gBAAgB,KAAK,CAAC,GACnC,UAAU,KAAK,CAChB;CACD;AACD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Sink, TrackerWindow } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/tracker/sinks/native.d.ts
|
|
4
|
+
/** How long a pageview waits for its duration before it is sent anyway. */
|
|
5
|
+
declare const PAGEVIEW_BUFFER_MS = 10000;
|
|
6
|
+
/**
|
|
7
|
+
* Posts events to the plugin's own ingest endpoint. Events and goals go out immediately;
|
|
8
|
+
* a pageview is held so it can carry `durationMs` and the page's deepest scroll, and is
|
|
9
|
+
* sent on the first of: the next navigation, `flush()` (which the tracker calls on
|
|
10
|
+
* `pagehide`), or `PAGEVIEW_BUFFER_MS`. The tradeoff is bounded: a tab that dies inside
|
|
11
|
+
* the window is caught by `pagehide`, and one killed without firing it loses that single
|
|
12
|
+
* pageview rather than its duration.
|
|
13
|
+
*/
|
|
14
|
+
declare const createNativeSink: (args: {
|
|
15
|
+
slot: Sink["slot"];
|
|
16
|
+
win: TrackerWindow;
|
|
17
|
+
url: string; /** Deepest scroll on the current page, read at flush time. */
|
|
18
|
+
scrollDepth?: () => number | undefined;
|
|
19
|
+
}) => Sink;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { PAGEVIEW_BUFFER_MS, createNativeSink };
|
|
22
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { sendPayload } from "../transport.js";
|
|
2
|
+
//#region src/tracker/sinks/native.ts
|
|
3
|
+
/** How long a pageview waits for its duration before it is sent anyway. */
|
|
4
|
+
const PAGEVIEW_BUFFER_MS = 1e4;
|
|
5
|
+
/**
|
|
6
|
+
* Posts events to the plugin's own ingest endpoint. Events and goals go out immediately;
|
|
7
|
+
* a pageview is held so it can carry `durationMs` and the page's deepest scroll, and is
|
|
8
|
+
* sent on the first of: the next navigation, `flush()` (which the tracker calls on
|
|
9
|
+
* `pagehide`), or `PAGEVIEW_BUFFER_MS`. The tradeoff is bounded: a tab that dies inside
|
|
10
|
+
* the window is caught by `pagehide`, and one killed without firing it loses that single
|
|
11
|
+
* pageview rather than its duration.
|
|
12
|
+
*/
|
|
13
|
+
const createNativeSink = (args) => {
|
|
14
|
+
const { slot, win, url, scrollDepth } = args;
|
|
15
|
+
let buffered = null;
|
|
16
|
+
let timer = null;
|
|
17
|
+
const clear = () => {
|
|
18
|
+
if (timer !== null) {
|
|
19
|
+
win.clearTimeout(timer);
|
|
20
|
+
timer = null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const flush = () => {
|
|
24
|
+
const pending = buffered;
|
|
25
|
+
buffered = null;
|
|
26
|
+
clear();
|
|
27
|
+
if (!pending) return;
|
|
28
|
+
const depth = scrollDepth?.();
|
|
29
|
+
sendPayload(win, url, {
|
|
30
|
+
...pending.event,
|
|
31
|
+
durationMs: Math.max(0, Date.now() - pending.startedAt),
|
|
32
|
+
...depth === void 0 ? {} : { scrollDepth: depth }
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
slot,
|
|
37
|
+
ready: () => Promise.resolve(),
|
|
38
|
+
send(event) {
|
|
39
|
+
if (event.type !== "pageview") {
|
|
40
|
+
sendPayload(win, url, event);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
flush();
|
|
44
|
+
buffered = {
|
|
45
|
+
event,
|
|
46
|
+
startedAt: Date.now()
|
|
47
|
+
};
|
|
48
|
+
timer = win.setTimeout(flush, PAGEVIEW_BUFFER_MS);
|
|
49
|
+
},
|
|
50
|
+
flush
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { PAGEVIEW_BUFFER_MS, createNativeSink };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.js","names":[],"sources":["../../../src/tracker/sinks/native.ts"],"sourcesContent":["import { sendPayload } from '../transport'\nimport type { Sink, TrackerEvent, TrackerWindow } from '../types'\n\n/** How long a pageview waits for its duration before it is sent anyway. */\nexport const PAGEVIEW_BUFFER_MS = 10_000\n\n/**\n * Posts events to the plugin's own ingest endpoint. Events and goals go out immediately;\n * a pageview is held so it can carry `durationMs` and the page's deepest scroll, and is\n * sent on the first of: the next navigation, `flush()` (which the tracker calls on\n * `pagehide`), or `PAGEVIEW_BUFFER_MS`. The tradeoff is bounded: a tab that dies inside\n * the window is caught by `pagehide`, and one killed without firing it loses that single\n * pageview rather than its duration.\n */\nexport const createNativeSink = (args: {\n\tslot: Sink['slot']\n\twin: TrackerWindow\n\turl: string\n\t/** Deepest scroll on the current page, read at flush time. */\n\tscrollDepth?: () => number | undefined\n}): Sink => {\n\tconst { slot, win, url, scrollDepth } = args\n\tlet buffered: { event: TrackerEvent; startedAt: number } | null = null\n\tlet timer: ReturnType<Window['setTimeout']> | null = null\n\n\tconst clear = () => {\n\t\tif (timer !== null) {\n\t\t\twin.clearTimeout(timer)\n\t\t\ttimer = null\n\t\t}\n\t}\n\n\tconst flush = () => {\n\t\tconst pending = buffered\n\t\tbuffered = null\n\t\tclear()\n\t\tif (!pending) {\n\t\t\treturn\n\t\t}\n\t\tconst depth = scrollDepth?.()\n\t\tsendPayload(win, url, {\n\t\t\t...pending.event,\n\t\t\tdurationMs: Math.max(0, Date.now() - pending.startedAt),\n\t\t\t...(depth === undefined ? {} : { scrollDepth: depth }),\n\t\t})\n\t}\n\n\treturn {\n\t\tslot,\n\t\tready: () => Promise.resolve(),\n\t\tsend(event) {\n\t\t\tif (event.type !== 'pageview') {\n\t\t\t\tsendPayload(win, url, event)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tflush()\n\t\t\tbuffered = { event, startedAt: Date.now() }\n\t\t\ttimer = win.setTimeout(flush, PAGEVIEW_BUFFER_MS)\n\t\t},\n\t\tflush,\n\t}\n}\n"],"mappings":";;;AAIA,MAAa,qBAAqB;;;;;;;;;AAUlC,MAAa,oBAAoB,SAMrB;CACX,MAAM,EAAE,MAAM,KAAK,KAAK,gBAAgB;CACxC,IAAI,WAA8D;CAClE,IAAI,QAAiD;CAErD,MAAM,cAAc;EACnB,IAAI,UAAU,MAAM;GACnB,IAAI,aAAa,KAAK;GACtB,QAAQ;EACT;CACD;CAEA,MAAM,cAAc;EACnB,MAAM,UAAU;EAChB,WAAW;EACX,MAAM;EACN,IAAI,CAAC,SACJ;EAED,MAAM,QAAQ,cAAc;EAC5B,YAAY,KAAK,KAAK;GACrB,GAAG,QAAQ;GACX,YAAY,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,QAAQ,SAAS;GACtD,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,MAAM;EACrD,CAAC;CACF;CAEA,OAAO;EACN;EACA,aAAa,QAAQ,QAAQ;EAC7B,KAAK,OAAO;GACX,IAAI,MAAM,SAAS,YAAY;IAC9B,YAAY,KAAK,KAAK,KAAK;IAC3B;GACD;GACA,MAAM;GACN,WAAW;IAAE;IAAO,WAAW,KAAK,IAAI;GAAE;GAC1C,QAAQ,IAAI,WAAW,OAAO,kBAAkB;EACjD;EACA;CACD;AACD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Sink } from "../types.js";
|
|
2
|
+
import { VendorSinkArgs } from "./vendor.js";
|
|
3
|
+
|
|
4
|
+
//#region src/tracker/sinks/plausible.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Plausible's own opt-out flag, which its script checks before every event
|
|
7
|
+
* (https://plausible.io/docs/excluding-localstorage). Set it and the script logs
|
|
8
|
+
* "Ignoring Event: localStorage flag" instead of counting the visit.
|
|
9
|
+
*/
|
|
10
|
+
declare const PLAUSIBLE_IGNORE_KEY = "plausible_ignore";
|
|
11
|
+
/**
|
|
12
|
+
* Forwards events and goals to the `plausible` queue function. Revenue uses Plausible's
|
|
13
|
+
* documented ecommerce shape, `{ revenue: { amount, currency } }`
|
|
14
|
+
* (https://plausible.io/docs/ecommerce-revenue-tracking). The per-site snippet publishes the
|
|
15
|
+
* `plausible.q` stub, so calls made before the tracker loads are replayed by it.
|
|
16
|
+
*/
|
|
17
|
+
declare const createPlausibleSink: (args: VendorSinkArgs) => Sink;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { PLAUSIBLE_IGNORE_KEY, createPlausibleSink };
|
|
20
|
+
//# sourceMappingURL=plausible.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createVendorSink, vendorEventName, vendorStorageExclusion } from "./vendor.js";
|
|
2
|
+
//#region src/tracker/sinks/plausible.ts
|
|
3
|
+
/**
|
|
4
|
+
* Plausible's own opt-out flag, which its script checks before every event
|
|
5
|
+
* (https://plausible.io/docs/excluding-localstorage). Set it and the script logs
|
|
6
|
+
* "Ignoring Event: localStorage flag" instead of counting the visit.
|
|
7
|
+
*/
|
|
8
|
+
const PLAUSIBLE_IGNORE_KEY = "plausible_ignore";
|
|
9
|
+
/**
|
|
10
|
+
* Forwards events and goals to the `plausible` queue function. Revenue uses Plausible's
|
|
11
|
+
* documented ecommerce shape, `{ revenue: { amount, currency } }`
|
|
12
|
+
* (https://plausible.io/docs/ecommerce-revenue-tracking). The per-site snippet publishes the
|
|
13
|
+
* `plausible.q` stub, so calls made before the tracker loads are replayed by it.
|
|
14
|
+
*/
|
|
15
|
+
const createPlausibleSink = (args) => createVendorSink(args, {
|
|
16
|
+
exclude: vendorStorageExclusion(args.win, PLAUSIBLE_IGNORE_KEY, "true"),
|
|
17
|
+
has: () => typeof args.win.plausible === "function",
|
|
18
|
+
dispatch: (event) => {
|
|
19
|
+
const options = {
|
|
20
|
+
...event.props ? { props: event.props } : {},
|
|
21
|
+
...event.value === void 0 ? {} : { revenue: {
|
|
22
|
+
amount: event.value,
|
|
23
|
+
...event.currency === void 0 ? {} : { currency: event.currency }
|
|
24
|
+
} }
|
|
25
|
+
};
|
|
26
|
+
args.win.plausible?.(vendorEventName(event), options);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { PLAUSIBLE_IGNORE_KEY, createPlausibleSink };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=plausible.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plausible.js","names":[],"sources":["../../../src/tracker/sinks/plausible.ts"],"sourcesContent":["import type { Sink, TrackerWindow } from '../types'\nimport {\n\tcreateVendorSink,\n\ttype VendorSinkArgs,\n\tvendorEventName,\n\tvendorStorageExclusion,\n} from './vendor'\n\n/**\n * Plausible's own opt-out flag, which its script checks before every event\n * (https://plausible.io/docs/excluding-localstorage). Set it and the script logs\n * \"Ignoring Event: localStorage flag\" instead of counting the visit.\n */\nexport const PLAUSIBLE_IGNORE_KEY = 'plausible_ignore'\n\ninterface PlausibleOptions {\n\tprops?: Record<string, unknown>\n\trevenue?: { amount: number; currency?: string }\n}\n\ntype PlausibleWindow = TrackerWindow & {\n\tplausible?: (name: string, options?: PlausibleOptions) => void\n}\n\n/**\n * Forwards events and goals to the `plausible` queue function. Revenue uses Plausible's\n * documented ecommerce shape, `{ revenue: { amount, currency } }`\n * (https://plausible.io/docs/ecommerce-revenue-tracking). The per-site snippet publishes the\n * `plausible.q` stub, so calls made before the tracker loads are replayed by it.\n */\nexport const createPlausibleSink = (args: VendorSinkArgs): Sink =>\n\tcreateVendorSink(args, {\n\t\texclude: vendorStorageExclusion(args.win, PLAUSIBLE_IGNORE_KEY, 'true'),\n\t\thas: () => typeof (args.win as PlausibleWindow).plausible === 'function',\n\t\tdispatch: (event) => {\n\t\t\tconst options: PlausibleOptions = {\n\t\t\t\t...(event.props ? { props: event.props } : {}),\n\t\t\t\t...(event.value === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\trevenue: {\n\t\t\t\t\t\t\t\tamount: event.value,\n\t\t\t\t\t\t\t\t...(event.currency === undefined ? {} : { currency: event.currency }),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t}\n\t\t\t;(args.win as PlausibleWindow).plausible?.(vendorEventName(event), options)\n\t\t},\n\t})\n"],"mappings":";;;;;;;AAaA,MAAa,uBAAuB;;;;;;;AAiBpC,MAAa,uBAAuB,SACnC,iBAAiB,MAAM;CACtB,SAAS,uBAAuB,KAAK,KAAK,sBAAsB,MAAM;CACtE,WAAW,OAAQ,KAAK,IAAwB,cAAc;CAC9D,WAAW,UAAU;EACpB,MAAM,UAA4B;GACjC,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAC5C,GAAI,MAAM,UAAU,KAAA,IACjB,CAAC,IACD,EACA,SAAS;IACR,QAAQ,MAAM;IACd,GAAI,MAAM,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,MAAM,SAAS;GACpE,EACD;EACH;EACC,KAAM,IAAwB,YAAY,gBAAgB,KAAK,GAAG,OAAO;CAC3E;AACD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Sink } from "../types.js";
|
|
2
|
+
import { VendorSinkArgs } from "./vendor.js";
|
|
3
|
+
|
|
4
|
+
//#region src/tracker/sinks/posthog.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Forwards events and goals to `posthog.capture`. Revenue rides along as the `value` and
|
|
7
|
+
* `currency` properties, which is what PostHog's own revenue analytics reads. The adapter's
|
|
8
|
+
* snippet publishes PostHog's queueing stub, so `capture` is callable (and replayed) from
|
|
9
|
+
* the moment the snippet runs, well before `array.js` lands.
|
|
10
|
+
*
|
|
11
|
+
* Exclusion goes through PostHog's own opt-out, which the stub queues like any other call.
|
|
12
|
+
* A slot whose snippet has not run has no global to opt out of, and none is loaded while
|
|
13
|
+
* the tracker is excluded.
|
|
14
|
+
*/
|
|
15
|
+
declare const createPosthogSink: (args: VendorSinkArgs) => Sink;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createPosthogSink };
|
|
18
|
+
//# sourceMappingURL=posthog.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createVendorSink, flatProps, vendorEventName } from "./vendor.js";
|
|
2
|
+
//#region src/tracker/sinks/posthog.ts
|
|
3
|
+
/**
|
|
4
|
+
* Forwards events and goals to `posthog.capture`. Revenue rides along as the `value` and
|
|
5
|
+
* `currency` properties, which is what PostHog's own revenue analytics reads. The adapter's
|
|
6
|
+
* snippet publishes PostHog's queueing stub, so `capture` is callable (and replayed) from
|
|
7
|
+
* the moment the snippet runs, well before `array.js` lands.
|
|
8
|
+
*
|
|
9
|
+
* Exclusion goes through PostHog's own opt-out, which the stub queues like any other call.
|
|
10
|
+
* A slot whose snippet has not run has no global to opt out of, and none is loaded while
|
|
11
|
+
* the tracker is excluded.
|
|
12
|
+
*/
|
|
13
|
+
const createPosthogSink = (args) => createVendorSink(args, {
|
|
14
|
+
exclude: (excluded) => {
|
|
15
|
+
const { posthog } = args.win;
|
|
16
|
+
if (excluded) {
|
|
17
|
+
posthog?.opt_out_capturing?.();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
posthog?.opt_in_capturing?.();
|
|
21
|
+
},
|
|
22
|
+
has: () => typeof args.win.posthog?.capture === "function",
|
|
23
|
+
dispatch: (event) => {
|
|
24
|
+
args.win.posthog?.capture(vendorEventName(event), flatProps(event));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createPosthogSink };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=posthog.js.map
|