@customerio/cdp-analytics-browser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.MD +22 -0
- package/README.md +21 -0
- package/dist/cjs/browser/browser-umd.js +20 -0
- package/dist/cjs/browser/browser-umd.js.map +1 -0
- package/dist/cjs/browser/index.js +310 -0
- package/dist/cjs/browser/index.js.map +1 -0
- package/dist/cjs/browser/standalone-analytics.js +60 -0
- package/dist/cjs/browser/standalone-analytics.js.map +1 -0
- package/dist/cjs/browser/standalone.js +83 -0
- package/dist/cjs/browser/standalone.js.map +1 -0
- package/dist/cjs/core/analytics/index.js +544 -0
- package/dist/cjs/core/analytics/index.js.map +1 -0
- package/dist/cjs/core/analytics/interfaces.js +3 -0
- package/dist/cjs/core/analytics/interfaces.js.map +1 -0
- package/dist/cjs/core/arguments-resolver/index.js +106 -0
- package/dist/cjs/core/arguments-resolver/index.js.map +1 -0
- package/dist/cjs/core/auto-track.js +108 -0
- package/dist/cjs/core/auto-track.js.map +1 -0
- package/dist/cjs/core/buffer/index.js +237 -0
- package/dist/cjs/core/buffer/index.js.map +1 -0
- package/dist/cjs/core/buffer/snippet.js +30 -0
- package/dist/cjs/core/buffer/snippet.js.map +1 -0
- package/dist/cjs/core/callback/index.js +7 -0
- package/dist/cjs/core/callback/index.js.map +1 -0
- package/dist/cjs/core/connection/index.js +16 -0
- package/dist/cjs/core/connection/index.js.map +1 -0
- package/dist/cjs/core/context/index.js +19 -0
- package/dist/cjs/core/context/index.js.map +1 -0
- package/dist/cjs/core/environment/index.js +12 -0
- package/dist/cjs/core/environment/index.js.map +1 -0
- package/dist/cjs/core/events/index.js +134 -0
- package/dist/cjs/core/events/index.js.map +1 -0
- package/dist/cjs/core/events/interfaces.js +3 -0
- package/dist/cjs/core/events/interfaces.js.map +1 -0
- package/dist/cjs/core/inspector/index.js +14 -0
- package/dist/cjs/core/inspector/index.js.map +1 -0
- package/dist/cjs/core/plugin/index.js +3 -0
- package/dist/cjs/core/plugin/index.js.map +1 -0
- package/dist/cjs/core/query-string/gracefulDecodeURIComponent.js +20 -0
- package/dist/cjs/core/query-string/gracefulDecodeURIComponent.js.map +1 -0
- package/dist/cjs/core/query-string/index.js +48 -0
- package/dist/cjs/core/query-string/index.js.map +1 -0
- package/dist/cjs/core/query-string/pickPrefix.js +20 -0
- package/dist/cjs/core/query-string/pickPrefix.js.map +1 -0
- package/dist/cjs/core/queue/event-queue.js +15 -0
- package/dist/cjs/core/queue/event-queue.js.map +1 -0
- package/dist/cjs/core/stats/index.js +23 -0
- package/dist/cjs/core/stats/index.js.map +1 -0
- package/dist/cjs/core/stats/remote-metrics.js +107 -0
- package/dist/cjs/core/stats/remote-metrics.js.map +1 -0
- package/dist/cjs/core/user/index.js +422 -0
- package/dist/cjs/core/user/index.js.map +1 -0
- package/dist/cjs/core/user/tld.js +64 -0
- package/dist/cjs/core/user/tld.js.map +1 -0
- package/dist/cjs/generated/version.js +6 -0
- package/dist/cjs/generated/version.js.map +1 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/bind-all.js +17 -0
- package/dist/cjs/lib/bind-all.js.map +1 -0
- package/dist/cjs/lib/browser-polyfill.js +22 -0
- package/dist/cjs/lib/browser-polyfill.js.map +1 -0
- package/dist/cjs/lib/create-deferred.js +21 -0
- package/dist/cjs/lib/create-deferred.js.map +1 -0
- package/dist/cjs/lib/csp-detection.js +33 -0
- package/dist/cjs/lib/csp-detection.js.map +1 -0
- package/dist/cjs/lib/embedded-write-key.js +22 -0
- package/dist/cjs/lib/embedded-write-key.js.map +1 -0
- package/dist/cjs/lib/fetch.js +19 -0
- package/dist/cjs/lib/fetch.js.map +1 -0
- package/dist/cjs/lib/get-global.js +21 -0
- package/dist/cjs/lib/get-global.js.map +1 -0
- package/dist/cjs/lib/get-process-env.js +15 -0
- package/dist/cjs/lib/get-process-env.js.map +1 -0
- package/dist/cjs/lib/group-by.js +28 -0
- package/dist/cjs/lib/group-by.js.map +1 -0
- package/dist/cjs/lib/is-plan-event-enabled.js +20 -0
- package/dist/cjs/lib/is-plan-event-enabled.js.map +1 -0
- package/dist/cjs/lib/is-thenable.js +15 -0
- package/dist/cjs/lib/is-thenable.js.map +1 -0
- package/dist/cjs/lib/load-script.js +56 -0
- package/dist/cjs/lib/load-script.js.map +1 -0
- package/dist/cjs/lib/merged-options.js +31 -0
- package/dist/cjs/lib/merged-options.js.map +1 -0
- package/dist/cjs/lib/on-page-leave.js +35 -0
- package/dist/cjs/lib/on-page-leave.js.map +1 -0
- package/dist/cjs/lib/p-while.js +25 -0
- package/dist/cjs/lib/p-while.js.map +1 -0
- package/dist/cjs/lib/parse-cdn.js +79 -0
- package/dist/cjs/lib/parse-cdn.js.map +1 -0
- package/dist/cjs/lib/priority-queue/backoff.js +10 -0
- package/dist/cjs/lib/priority-queue/backoff.js.map +1 -0
- package/dist/cjs/lib/priority-queue/index.js +7 -0
- package/dist/cjs/lib/priority-queue/index.js.map +1 -0
- package/dist/cjs/lib/priority-queue/persisted.js +108 -0
- package/dist/cjs/lib/priority-queue/persisted.js.map +1 -0
- package/dist/cjs/lib/sleep.js +10 -0
- package/dist/cjs/lib/sleep.js.map +1 -0
- package/dist/cjs/lib/to-facade.js +32 -0
- package/dist/cjs/lib/to-facade.js.map +1 -0
- package/dist/cjs/node/index.js +43 -0
- package/dist/cjs/node/index.js.map +1 -0
- package/dist/cjs/node/node.browser.js +13 -0
- package/dist/cjs/node/node.browser.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/index.js +345 -0
- package/dist/cjs/plugins/ajs-destination/index.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/loader.js +110 -0
- package/dist/cjs/plugins/ajs-destination/loader.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/types.js +3 -0
- package/dist/cjs/plugins/ajs-destination/types.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/utils.js +23 -0
- package/dist/cjs/plugins/ajs-destination/utils.js.map +1 -0
- package/dist/cjs/plugins/analytics-node/index.js +65 -0
- package/dist/cjs/plugins/analytics-node/index.js.map +1 -0
- package/dist/cjs/plugins/customerio/batched-dispatcher.js +102 -0
- package/dist/cjs/plugins/customerio/batched-dispatcher.js.map +1 -0
- package/dist/cjs/plugins/customerio/fetch-dispatcher.js +18 -0
- package/dist/cjs/plugins/customerio/fetch-dispatcher.js.map +1 -0
- package/dist/cjs/plugins/customerio/index.js +97 -0
- package/dist/cjs/plugins/customerio/index.js.map +1 -0
- package/dist/cjs/plugins/customerio/normalize.js +176 -0
- package/dist/cjs/plugins/customerio/normalize.js.map +1 -0
- package/dist/cjs/plugins/customerio/schedule-flush.js +76 -0
- package/dist/cjs/plugins/customerio/schedule-flush.js.map +1 -0
- package/dist/cjs/plugins/legacy-video-plugins/index.js +25 -0
- package/dist/cjs/plugins/legacy-video-plugins/index.js.map +1 -0
- package/dist/cjs/plugins/middleware/index.js +124 -0
- package/dist/cjs/plugins/middleware/index.js.map +1 -0
- package/dist/cjs/plugins/page-enrichment/index.js +98 -0
- package/dist/cjs/plugins/page-enrichment/index.js.map +1 -0
- package/dist/cjs/plugins/remote-loader/index.js +211 -0
- package/dist/cjs/plugins/remote-loader/index.js.map +1 -0
- package/dist/cjs/plugins/remote-middleware/index.js +70 -0
- package/dist/cjs/plugins/remote-middleware/index.js.map +1 -0
- package/dist/cjs/plugins/routing-middleware/index.js +26 -0
- package/dist/cjs/plugins/routing-middleware/index.js.map +1 -0
- package/dist/cjs/plugins/schema-filter/index.js +67 -0
- package/dist/cjs/plugins/schema-filter/index.js.map +1 -0
- package/dist/cjs/plugins/validation/index.js +70 -0
- package/dist/cjs/plugins/validation/index.js.map +1 -0
- package/dist/pkg/browser/browser-umd.js +17 -0
- package/dist/pkg/browser/browser-umd.js.map +1 -0
- package/dist/pkg/browser/index.js +306 -0
- package/dist/pkg/browser/index.js.map +1 -0
- package/dist/pkg/browser/standalone-analytics.js +56 -0
- package/dist/pkg/browser/standalone-analytics.js.map +1 -0
- package/dist/pkg/browser/standalone.js +81 -0
- package/dist/pkg/browser/standalone.js.map +1 -0
- package/dist/pkg/core/analytics/index.js +541 -0
- package/dist/pkg/core/analytics/index.js.map +1 -0
- package/dist/pkg/core/analytics/interfaces.js +2 -0
- package/dist/pkg/core/analytics/interfaces.js.map +1 -0
- package/dist/pkg/core/arguments-resolver/index.js +99 -0
- package/dist/pkg/core/arguments-resolver/index.js.map +1 -0
- package/dist/pkg/core/auto-track.js +103 -0
- package/dist/pkg/core/auto-track.js.map +1 -0
- package/dist/pkg/core/buffer/index.js +231 -0
- package/dist/pkg/core/buffer/index.js.map +1 -0
- package/dist/pkg/core/buffer/snippet.js +25 -0
- package/dist/pkg/core/buffer/snippet.js.map +1 -0
- package/dist/pkg/core/callback/index.js +2 -0
- package/dist/pkg/core/callback/index.js.map +1 -0
- package/dist/pkg/core/connection/index.js +11 -0
- package/dist/pkg/core/connection/index.js.map +1 -0
- package/dist/pkg/core/context/index.js +16 -0
- package/dist/pkg/core/context/index.js.map +1 -0
- package/dist/pkg/core/environment/index.js +7 -0
- package/dist/pkg/core/environment/index.js.map +1 -0
- package/dist/pkg/core/events/index.js +131 -0
- package/dist/pkg/core/events/index.js.map +1 -0
- package/dist/pkg/core/events/interfaces.js +2 -0
- package/dist/pkg/core/events/interfaces.js.map +1 -0
- package/dist/pkg/core/inspector/index.js +10 -0
- package/dist/pkg/core/inspector/index.js.map +1 -0
- package/dist/pkg/core/plugin/index.js +2 -0
- package/dist/pkg/core/plugin/index.js.map +1 -0
- package/dist/pkg/core/query-string/gracefulDecodeURIComponent.js +16 -0
- package/dist/pkg/core/query-string/gracefulDecodeURIComponent.js.map +1 -0
- package/dist/pkg/core/query-string/index.js +44 -0
- package/dist/pkg/core/query-string/index.js.map +1 -0
- package/dist/pkg/core/query-string/pickPrefix.js +16 -0
- package/dist/pkg/core/query-string/pickPrefix.js.map +1 -0
- package/dist/pkg/core/queue/event-queue.js +12 -0
- package/dist/pkg/core/queue/event-queue.js.map +1 -0
- package/dist/pkg/core/stats/index.js +20 -0
- package/dist/pkg/core/stats/index.js.map +1 -0
- package/dist/pkg/core/stats/remote-metrics.js +104 -0
- package/dist/pkg/core/stats/remote-metrics.js.map +1 -0
- package/dist/pkg/core/user/index.js +418 -0
- package/dist/pkg/core/user/index.js.map +1 -0
- package/dist/pkg/core/user/tld.js +59 -0
- package/dist/pkg/core/user/tld.js.map +1 -0
- package/dist/pkg/generated/version.js +3 -0
- package/dist/pkg/generated/version.js.map +1 -0
- package/dist/pkg/index.js +8 -0
- package/dist/pkg/index.js.map +1 -0
- package/dist/pkg/lib/bind-all.js +14 -0
- package/dist/pkg/lib/bind-all.js.map +1 -0
- package/dist/pkg/lib/browser-polyfill.js +18 -0
- package/dist/pkg/lib/browser-polyfill.js.map +1 -0
- package/dist/pkg/lib/create-deferred.js +17 -0
- package/dist/pkg/lib/create-deferred.js.map +1 -0
- package/dist/pkg/lib/csp-detection.js +29 -0
- package/dist/pkg/lib/csp-detection.js.map +1 -0
- package/dist/pkg/lib/embedded-write-key.js +18 -0
- package/dist/pkg/lib/embedded-write-key.js.map +1 -0
- package/dist/pkg/lib/fetch.js +14 -0
- package/dist/pkg/lib/fetch.js.map +1 -0
- package/dist/pkg/lib/get-global.js +17 -0
- package/dist/pkg/lib/get-global.js.map +1 -0
- package/dist/pkg/lib/get-process-env.js +11 -0
- package/dist/pkg/lib/get-process-env.js.map +1 -0
- package/dist/pkg/lib/group-by.js +24 -0
- package/dist/pkg/lib/group-by.js.map +1 -0
- package/dist/pkg/lib/is-plan-event-enabled.js +16 -0
- package/dist/pkg/lib/is-plan-event-enabled.js.map +1 -0
- package/dist/pkg/lib/is-thenable.js +11 -0
- package/dist/pkg/lib/is-thenable.js.map +1 -0
- package/dist/pkg/lib/load-script.js +51 -0
- package/dist/pkg/lib/load-script.js.map +1 -0
- package/dist/pkg/lib/merged-options.js +27 -0
- package/dist/pkg/lib/merged-options.js.map +1 -0
- package/dist/pkg/lib/on-page-leave.js +31 -0
- package/dist/pkg/lib/on-page-leave.js.map +1 -0
- package/dist/pkg/lib/p-while.js +21 -0
- package/dist/pkg/lib/p-while.js.map +1 -0
- package/dist/pkg/lib/parse-cdn.js +72 -0
- package/dist/pkg/lib/parse-cdn.js.map +1 -0
- package/dist/pkg/lib/priority-queue/backoff.js +6 -0
- package/dist/pkg/lib/priority-queue/backoff.js.map +1 -0
- package/dist/pkg/lib/priority-queue/index.js +3 -0
- package/dist/pkg/lib/priority-queue/index.js.map +1 -0
- package/dist/pkg/lib/priority-queue/persisted.js +105 -0
- package/dist/pkg/lib/priority-queue/persisted.js.map +1 -0
- package/dist/pkg/lib/sleep.js +6 -0
- package/dist/pkg/lib/sleep.js.map +1 -0
- package/dist/pkg/lib/to-facade.js +28 -0
- package/dist/pkg/lib/to-facade.js.map +1 -0
- package/dist/pkg/node/index.js +40 -0
- package/dist/pkg/node/index.js.map +1 -0
- package/dist/pkg/node/node.browser.js +10 -0
- package/dist/pkg/node/node.browser.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/index.js +341 -0
- package/dist/pkg/plugins/ajs-destination/index.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/loader.js +102 -0
- package/dist/pkg/plugins/ajs-destination/loader.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/types.js +2 -0
- package/dist/pkg/plugins/ajs-destination/types.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/utils.js +18 -0
- package/dist/pkg/plugins/ajs-destination/utils.js.map +1 -0
- package/dist/pkg/plugins/analytics-node/index.js +60 -0
- package/dist/pkg/plugins/analytics-node/index.js.map +1 -0
- package/dist/pkg/plugins/customerio/batched-dispatcher.js +99 -0
- package/dist/pkg/plugins/customerio/batched-dispatcher.js.map +1 -0
- package/dist/pkg/plugins/customerio/fetch-dispatcher.js +15 -0
- package/dist/pkg/plugins/customerio/fetch-dispatcher.js.map +1 -0
- package/dist/pkg/plugins/customerio/index.js +93 -0
- package/dist/pkg/plugins/customerio/index.js.map +1 -0
- package/dist/pkg/plugins/customerio/normalize.js +168 -0
- package/dist/pkg/plugins/customerio/normalize.js.map +1 -0
- package/dist/pkg/plugins/customerio/schedule-flush.js +72 -0
- package/dist/pkg/plugins/customerio/schedule-flush.js.map +1 -0
- package/dist/pkg/plugins/legacy-video-plugins/index.js +25 -0
- package/dist/pkg/plugins/legacy-video-plugins/index.js.map +1 -0
- package/dist/pkg/plugins/middleware/index.js +119 -0
- package/dist/pkg/plugins/middleware/index.js.map +1 -0
- package/dist/pkg/plugins/page-enrichment/index.js +93 -0
- package/dist/pkg/plugins/page-enrichment/index.js.map +1 -0
- package/dist/pkg/plugins/remote-loader/index.js +207 -0
- package/dist/pkg/plugins/remote-loader/index.js.map +1 -0
- package/dist/pkg/plugins/remote-middleware/index.js +66 -0
- package/dist/pkg/plugins/remote-middleware/index.js.map +1 -0
- package/dist/pkg/plugins/routing-middleware/index.js +21 -0
- package/dist/pkg/plugins/routing-middleware/index.js.map +1 -0
- package/dist/pkg/plugins/schema-filter/index.js +63 -0
- package/dist/pkg/plugins/schema-filter/index.js.map +1 -0
- package/dist/pkg/plugins/validation/index.js +63 -0
- package/dist/pkg/plugins/validation/index.js.map +1 -0
- package/dist/types/browser/browser-umd.d.ts +2 -0
- package/dist/types/browser/browser-umd.d.ts.map +1 -0
- package/dist/types/browser/index.d.ts +86 -0
- package/dist/types/browser/index.d.ts.map +1 -0
- package/dist/types/browser/standalone-analytics.d.ts +16 -0
- package/dist/types/browser/standalone-analytics.d.ts.map +1 -0
- package/dist/types/browser/standalone.d.ts +2 -0
- package/dist/types/browser/standalone.d.ts.map +1 -0
- package/dist/types/core/analytics/index.d.ts +116 -0
- package/dist/types/core/analytics/index.d.ts.map +1 -0
- package/dist/types/core/analytics/interfaces.d.ts +77 -0
- package/dist/types/core/analytics/interfaces.d.ts.map +1 -0
- package/dist/types/core/arguments-resolver/index.d.ts +34 -0
- package/dist/types/core/arguments-resolver/index.d.ts.map +1 -0
- package/dist/types/core/auto-track.d.ts +10 -0
- package/dist/types/core/auto-track.d.ts.map +1 -0
- package/dist/types/core/buffer/index.d.ts +86 -0
- package/dist/types/core/buffer/index.d.ts.map +1 -0
- package/dist/types/core/buffer/snippet.d.ts +10 -0
- package/dist/types/core/buffer/snippet.d.ts.map +1 -0
- package/dist/types/core/callback/index.d.ts +2 -0
- package/dist/types/core/callback/index.d.ts.map +1 -0
- package/dist/types/core/connection/index.d.ts +3 -0
- package/dist/types/core/connection/index.d.ts.map +1 -0
- package/dist/types/core/context/index.d.ts +9 -0
- package/dist/types/core/context/index.d.ts.map +1 -0
- package/dist/types/core/environment/index.d.ts +3 -0
- package/dist/types/core/environment/index.d.ts.map +1 -0
- package/dist/types/core/events/index.d.ts +21 -0
- package/dist/types/core/events/index.d.ts.map +1 -0
- package/dist/types/core/events/interfaces.d.ts +9 -0
- package/dist/types/core/events/interfaces.d.ts.map +1 -0
- package/dist/types/core/inspector/index.d.ts +3 -0
- package/dist/types/core/inspector/index.d.ts.map +1 -0
- package/dist/types/core/plugin/index.d.ts +11 -0
- package/dist/types/core/plugin/index.d.ts.map +1 -0
- package/dist/types/core/query-string/gracefulDecodeURIComponent.d.ts +9 -0
- package/dist/types/core/query-string/gracefulDecodeURIComponent.d.ts.map +1 -0
- package/dist/types/core/query-string/index.d.ts +7 -0
- package/dist/types/core/query-string/index.d.ts.map +1 -0
- package/dist/types/core/query-string/pickPrefix.d.ts +9 -0
- package/dist/types/core/query-string/pickPrefix.d.ts.map +1 -0
- package/dist/types/core/queue/event-queue.d.ts +8 -0
- package/dist/types/core/queue/event-queue.d.ts.map +1 -0
- package/dist/types/core/stats/index.d.ts +7 -0
- package/dist/types/core/stats/index.d.ts.map +1 -0
- package/dist/types/core/stats/remote-metrics.d.ts +29 -0
- package/dist/types/core/stats/remote-metrics.d.ts.map +1 -0
- package/dist/types/core/user/index.d.ts +128 -0
- package/dist/types/core/user/index.d.ts.map +1 -0
- package/dist/types/core/user/tld.d.ts +2 -0
- package/dist/types/core/user/tld.d.ts.map +1 -0
- package/dist/types/generated/version.d.ts +2 -0
- package/dist/types/generated/version.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/bind-all.d.ts +4 -0
- package/dist/types/lib/bind-all.d.ts.map +1 -0
- package/dist/types/lib/browser-polyfill.d.ts +2 -0
- package/dist/types/lib/browser-polyfill.d.ts.map +1 -0
- package/dist/types/lib/create-deferred.d.ts +9 -0
- package/dist/types/lib/create-deferred.d.ts.map +1 -0
- package/dist/types/lib/csp-detection.d.ts +4 -0
- package/dist/types/lib/csp-detection.d.ts.map +1 -0
- package/dist/types/lib/embedded-write-key.d.ts +7 -0
- package/dist/types/lib/embedded-write-key.d.ts.map +1 -0
- package/dist/types/lib/fetch.d.ts +5 -0
- package/dist/types/lib/fetch.d.ts.map +1 -0
- package/dist/types/lib/get-global.d.ts +2 -0
- package/dist/types/lib/get-global.d.ts.map +1 -0
- package/dist/types/lib/get-process-env.d.ts +8 -0
- package/dist/types/lib/get-process-env.d.ts.map +1 -0
- package/dist/types/lib/group-by.d.ts +4 -0
- package/dist/types/lib/group-by.d.ts.map +1 -0
- package/dist/types/lib/is-plan-event-enabled.d.ts +9 -0
- package/dist/types/lib/is-plan-event-enabled.d.ts.map +1 -0
- package/dist/types/lib/is-thenable.d.ts +6 -0
- package/dist/types/lib/is-thenable.d.ts.map +1 -0
- package/dist/types/lib/load-script.d.ts +3 -0
- package/dist/types/lib/load-script.d.ts.map +1 -0
- package/dist/types/lib/merged-options.d.ts +13 -0
- package/dist/types/lib/merged-options.d.ts.map +1 -0
- package/dist/types/lib/on-page-leave.d.ts +11 -0
- package/dist/types/lib/on-page-leave.d.ts.map +1 -0
- package/dist/types/lib/p-while.d.ts +2 -0
- package/dist/types/lib/p-while.d.ts.map +1 -0
- package/dist/types/lib/parse-cdn.d.ts +10 -0
- package/dist/types/lib/parse-cdn.d.ts.map +1 -0
- package/dist/types/lib/priority-queue/backoff.d.ts +13 -0
- package/dist/types/lib/priority-queue/backoff.d.ts.map +1 -0
- package/dist/types/lib/priority-queue/index.d.ts +3 -0
- package/dist/types/lib/priority-queue/index.d.ts.map +1 -0
- package/dist/types/lib/priority-queue/persisted.d.ts +6 -0
- package/dist/types/lib/priority-queue/persisted.d.ts.map +1 -0
- package/dist/types/lib/sleep.d.ts +2 -0
- package/dist/types/lib/sleep.d.ts.map +1 -0
- package/dist/types/lib/to-facade.d.ts +7 -0
- package/dist/types/lib/to-facade.d.ts.map +1 -0
- package/dist/types/node/index.d.ts +8 -0
- package/dist/types/node/index.d.ts.map +1 -0
- package/dist/types/node/node.browser.d.ts +4 -0
- package/dist/types/node/node.browser.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/index.d.ts +42 -0
- package/dist/types/plugins/ajs-destination/index.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/loader.d.ts +12 -0
- package/dist/types/plugins/ajs-destination/loader.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/types.d.ts +36 -0
- package/dist/types/plugins/ajs-destination/types.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/utils.d.ts +5 -0
- package/dist/types/plugins/ajs-destination/utils.d.ts.map +1 -0
- package/dist/types/plugins/analytics-node/index.d.ts +12 -0
- package/dist/types/plugins/analytics-node/index.d.ts.map +1 -0
- package/dist/types/plugins/customerio/batched-dispatcher.d.ts +8 -0
- package/dist/types/plugins/customerio/batched-dispatcher.d.ts.map +1 -0
- package/dist/types/plugins/customerio/fetch-dispatcher.d.ts +8 -0
- package/dist/types/plugins/customerio/fetch-dispatcher.d.ts.map +1 -0
- package/dist/types/plugins/customerio/index.d.ts +26 -0
- package/dist/types/plugins/customerio/index.d.ts.map +1 -0
- package/dist/types/plugins/customerio/normalize.d.ts +12 -0
- package/dist/types/plugins/customerio/normalize.d.ts.map +1 -0
- package/dist/types/plugins/customerio/schedule-flush.d.ts +5 -0
- package/dist/types/plugins/customerio/schedule-flush.d.ts.map +1 -0
- package/dist/types/plugins/legacy-video-plugins/index.d.ts +3 -0
- package/dist/types/plugins/legacy-video-plugins/index.d.ts.map +1 -0
- package/dist/types/plugins/middleware/index.d.ts +18 -0
- package/dist/types/plugins/middleware/index.d.ts.map +1 -0
- package/dist/types/plugins/page-enrichment/index.d.ts +21 -0
- package/dist/types/plugins/page-enrichment/index.d.ts.map +1 -0
- package/dist/types/plugins/remote-loader/index.d.ts +43 -0
- package/dist/types/plugins/remote-loader/index.d.ts.map +1 -0
- package/dist/types/plugins/remote-middleware/index.d.ts +5 -0
- package/dist/types/plugins/remote-middleware/index.d.ts.map +1 -0
- package/dist/types/plugins/routing-middleware/index.d.ts +13 -0
- package/dist/types/plugins/routing-middleware/index.d.ts.map +1 -0
- package/dist/types/plugins/schema-filter/index.d.ts +5 -0
- package/dist/types/plugins/schema-filter/index.d.ts.map +1 -0
- package/dist/types/plugins/validation/index.d.ts +7 -0
- package/dist/types/plugins/validation/index.d.ts.map +1 -0
- package/dist/umd/799.bundle.f804d7b881cf284fbd56.js +1 -0
- package/dist/umd/799.bundle.f804d7b881cf284fbd56.js.gz +0 -0
- package/dist/umd/870.bundle.e0b7bfa4797bb87217c9.js +1 -0
- package/dist/umd/870.bundle.e0b7bfa4797bb87217c9.js.gz +0 -0
- package/dist/umd/ajs-destination.bundle.847bf422720e5616c9d5.js +1 -0
- package/dist/umd/ajs-destination.bundle.847bf422720e5616c9d5.js.gz +0 -0
- package/dist/umd/auto-track.bundle.758629f7a47544af2d44.js +1 -0
- package/dist/umd/auto-track.bundle.758629f7a47544af2d44.js.gz +0 -0
- package/dist/umd/index.js +1 -0
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/legacyVideos.bundle.d7ac356ab28fab36e111.js +1 -0
- package/dist/umd/legacyVideos.bundle.d7ac356ab28fab36e111.js.gz +0 -0
- package/dist/umd/queryString.bundle.913501e40ce64ef92884.js +1 -0
- package/dist/umd/queryString.bundle.913501e40ce64ef92884.js.gz +0 -0
- package/dist/umd/remoteMiddleware.bundle.3bc569811c4c2c93d90c.js +1 -0
- package/dist/umd/remoteMiddleware.bundle.3bc569811c4c2c93d90c.js.gz +0 -0
- package/dist/umd/schemaFilter.bundle.bb8180ae95843c8f138e.js +1 -0
- package/dist/umd/schemaFilter.bundle.bb8180ae95843c8f138e.js.gz +0 -0
- package/dist/umd/standalone.js +1 -0
- package/dist/umd/standalone.js.gz +0 -0
- package/dist/umd/tsub-middleware.bundle.af0f402084ddd2b605cc.js +1 -0
- package/dist/umd/tsub-middleware.bundle.af0f402084ddd2b605cc.js.gz +0 -0
- package/package.json +103 -0
- package/src/browser/browser-umd.ts +19 -0
- package/src/browser/index.ts +397 -0
- package/src/browser/standalone-analytics.ts +74 -0
- package/src/browser/standalone.ts +78 -0
- package/src/core/analytics/index.ts +567 -0
- package/src/core/analytics/interfaces.ts +100 -0
- package/src/core/arguments-resolver/index.ts +166 -0
- package/src/core/auto-track.ts +152 -0
- package/src/core/buffer/index.ts +289 -0
- package/src/core/buffer/snippet.ts +43 -0
- package/src/core/callback/index.ts +1 -0
- package/src/core/connection/index.ts +13 -0
- package/src/core/context/index.ts +21 -0
- package/src/core/environment/index.ts +7 -0
- package/src/core/events/index.ts +254 -0
- package/src/core/events/interfaces.ts +36 -0
- package/src/core/inspector/index.ts +14 -0
- package/src/core/plugin/index.ts +12 -0
- package/src/core/query-string/gracefulDecodeURIComponent.ts +16 -0
- package/src/core/query-string/index.ts +64 -0
- package/src/core/query-string/pickPrefix.ts +20 -0
- package/src/core/queue/event-queue.ts +11 -0
- package/src/core/stats/index.ts +15 -0
- package/src/core/stats/remote-metrics.ts +137 -0
- package/src/core/user/index.ts +534 -0
- package/src/core/user/tld.ts +65 -0
- package/src/generated/version.ts +2 -0
- package/src/index.ts +10 -0
- package/src/lib/bind-all.ts +19 -0
- package/src/lib/browser-polyfill.ts +23 -0
- package/src/lib/create-deferred.ts +16 -0
- package/src/lib/csp-detection.ts +26 -0
- package/src/lib/embedded-write-key.ts +24 -0
- package/src/lib/fetch.ts +10 -0
- package/src/lib/get-global.ts +16 -0
- package/src/lib/get-process-env.ts +11 -0
- package/src/lib/group-by.ts +30 -0
- package/src/lib/is-plan-event-enabled.ts +20 -0
- package/src/lib/is-thenable.ts +9 -0
- package/src/lib/load-script.ts +66 -0
- package/src/lib/merged-options.ts +46 -0
- package/src/lib/on-page-leave.ts +29 -0
- package/src/lib/p-while.ts +12 -0
- package/src/lib/parse-cdn.ts +85 -0
- package/src/lib/priority-queue/backoff.ts +24 -0
- package/src/lib/priority-queue/index.ts +6 -0
- package/src/lib/priority-queue/persisted.ts +127 -0
- package/src/lib/sleep.ts +4 -0
- package/src/lib/to-facade.ts +53 -0
- package/src/node/index.ts +36 -0
- package/src/node/node.browser.ts +7 -0
- package/src/plugins/ajs-destination/index.ts +388 -0
- package/src/plugins/ajs-destination/loader.ts +127 -0
- package/src/plugins/ajs-destination/types.ts +44 -0
- package/src/plugins/ajs-destination/utils.ts +34 -0
- package/src/plugins/analytics-node/index.ts +64 -0
- package/src/plugins/customerio/batched-dispatcher.ts +115 -0
- package/src/plugins/customerio/fetch-dispatcher.ts +24 -0
- package/src/plugins/customerio/index.ts +142 -0
- package/src/plugins/customerio/normalize.ts +223 -0
- package/src/plugins/customerio/schedule-flush.ts +58 -0
- package/src/plugins/legacy-video-plugins/index.ts +16 -0
- package/src/plugins/middleware/index.ts +131 -0
- package/src/plugins/page-enrichment/index.ts +127 -0
- package/src/plugins/remote-loader/index.ts +240 -0
- package/src/plugins/remote-middleware/index.ts +44 -0
- package/src/plugins/routing-middleware/index.ts +37 -0
- package/src/plugins/schema-filter/index.ts +90 -0
- package/src/plugins/validation/index.ts +80 -0
- package/src/test-helpers/browser-storage.ts +72 -0
- package/src/test-helpers/factories.ts +18 -0
- package/src/test-helpers/fetch-parse.ts +8 -0
- package/src/test-helpers/fixtures/cdn-settings.ts +299 -0
- package/src/test-helpers/fixtures/classic-destination.ts +25 -0
- package/src/test-helpers/fixtures/create-fetch-method.ts +24 -0
- package/src/test-helpers/test-writekeys.ts +5 -0
- package/src/test-helpers/type-assertions.ts +11 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { CustomerioEvent } from '../../core/events'
|
|
2
|
+
import { fetch } from '../../lib/fetch'
|
|
3
|
+
import { onPageLeave } from '../../lib/on-page-leave'
|
|
4
|
+
|
|
5
|
+
export type BatchingDispatchConfig = {
|
|
6
|
+
size?: number
|
|
7
|
+
timeout?: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const MAX_PAYLOAD_SIZE = 500
|
|
11
|
+
|
|
12
|
+
function kilobytes(buffer: unknown): number {
|
|
13
|
+
const size = encodeURI(JSON.stringify(buffer)).split(/%..|./).length - 1
|
|
14
|
+
return size / 1024
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the payload is over or close to
|
|
19
|
+
* the maximum payload size allowed by tracking
|
|
20
|
+
* API.
|
|
21
|
+
*/
|
|
22
|
+
function approachingTrackingAPILimit(buffer: unknown): boolean {
|
|
23
|
+
return kilobytes(buffer) >= MAX_PAYLOAD_SIZE - 50
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function chunks(batch: object[]): Array<object[]> {
|
|
27
|
+
const result: object[][] = []
|
|
28
|
+
let index = 0
|
|
29
|
+
|
|
30
|
+
batch.forEach((item) => {
|
|
31
|
+
const size = kilobytes(result[index])
|
|
32
|
+
if (size >= 64) {
|
|
33
|
+
index++
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (result[index]) {
|
|
37
|
+
result[index].push(item)
|
|
38
|
+
} else {
|
|
39
|
+
result[index] = [item]
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function batch(
|
|
47
|
+
apiHost: string,
|
|
48
|
+
config?: BatchingDispatchConfig
|
|
49
|
+
) {
|
|
50
|
+
let buffer: object[] = []
|
|
51
|
+
let pageUnloaded = false
|
|
52
|
+
|
|
53
|
+
const limit = config?.size ?? 10
|
|
54
|
+
const timeout = config?.timeout ?? 5000
|
|
55
|
+
|
|
56
|
+
function sendBatch(batch: object[]) {
|
|
57
|
+
if (batch.length === 0) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const writeKey = (batch[0] as CustomerioEvent)?.writeKey
|
|
62
|
+
|
|
63
|
+
return fetch(`https://${apiHost}/b`, {
|
|
64
|
+
keepalive: pageUnloaded,
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': 'text/plain',
|
|
67
|
+
},
|
|
68
|
+
method: 'post',
|
|
69
|
+
body: JSON.stringify({ batch, writeKey }),
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function flush(): Promise<unknown> {
|
|
74
|
+
if (buffer.length) {
|
|
75
|
+
const batch = buffer
|
|
76
|
+
buffer = []
|
|
77
|
+
return sendBatch(batch)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let schedule: NodeJS.Timeout | undefined
|
|
82
|
+
|
|
83
|
+
function scheduleFlush(): void {
|
|
84
|
+
if (schedule) {
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
schedule = setTimeout(() => {
|
|
89
|
+
schedule = undefined
|
|
90
|
+
flush().catch(console.error)
|
|
91
|
+
}, timeout)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onPageLeave(() => {
|
|
95
|
+
pageUnloaded = true
|
|
96
|
+
|
|
97
|
+
if (buffer.length) {
|
|
98
|
+
const reqs = chunks(buffer).map(sendBatch)
|
|
99
|
+
Promise.all(reqs).catch(console.error)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
async function dispatch(_url: string, body: object): Promise<unknown> {
|
|
104
|
+
buffer.push(body)
|
|
105
|
+
|
|
106
|
+
const bufferOverflow =
|
|
107
|
+
buffer.length >= limit || approachingTrackingAPILimit(buffer)
|
|
108
|
+
|
|
109
|
+
return bufferOverflow || pageUnloaded ? flush() : scheduleFlush()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
dispatch,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { fetch } from '../../lib/fetch'
|
|
2
|
+
|
|
3
|
+
export type Dispatcher = (url: string, body: object) => Promise<unknown>
|
|
4
|
+
|
|
5
|
+
export type StandardDispatcherConfig = {
|
|
6
|
+
keepalive?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function (config?: StandardDispatcherConfig): {
|
|
10
|
+
dispatch: Dispatcher
|
|
11
|
+
} {
|
|
12
|
+
function dispatch(url: string, body: object): Promise<unknown> {
|
|
13
|
+
return fetch(url, {
|
|
14
|
+
keepalive: config?.keepalive,
|
|
15
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
16
|
+
method: 'post',
|
|
17
|
+
body: JSON.stringify(body),
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
dispatch,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Facade } from '@segment/facade'
|
|
2
|
+
import { Analytics } from '../../core/analytics'
|
|
3
|
+
import { LegacySettings } from '../../browser'
|
|
4
|
+
import { isOffline } from '../../core/connection'
|
|
5
|
+
import { Context } from '../../core/context'
|
|
6
|
+
import { Plugin } from '../../core/plugin'
|
|
7
|
+
import { PriorityQueue } from '../../lib/priority-queue'
|
|
8
|
+
import { PersistedPriorityQueue } from '../../lib/priority-queue/persisted'
|
|
9
|
+
import { toFacade } from '../../lib/to-facade'
|
|
10
|
+
import batch, { BatchingDispatchConfig } from './batched-dispatcher'
|
|
11
|
+
import standard, { StandardDispatcherConfig } from './fetch-dispatcher'
|
|
12
|
+
import { normalize } from './normalize'
|
|
13
|
+
import { scheduleFlush } from './schedule-flush'
|
|
14
|
+
|
|
15
|
+
type DeliveryStrategy =
|
|
16
|
+
| {
|
|
17
|
+
strategy?: 'standard'
|
|
18
|
+
config?: StandardDispatcherConfig
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
strategy?: 'batching'
|
|
22
|
+
config?: BatchingDispatchConfig
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type CustomerioSettings = {
|
|
26
|
+
apiKey: string
|
|
27
|
+
apiHost?: string
|
|
28
|
+
protocol?: 'http' | 'https'
|
|
29
|
+
|
|
30
|
+
addBundledMetadata?: boolean
|
|
31
|
+
unbundledIntegrations?: string[]
|
|
32
|
+
bundledConfigIds?: string[]
|
|
33
|
+
unbundledConfigIds?: string[]
|
|
34
|
+
|
|
35
|
+
maybeBundledConfigIds?: Record<string, string[]>
|
|
36
|
+
|
|
37
|
+
deliveryStrategy?: DeliveryStrategy
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type JSON = ReturnType<Facade['json']>
|
|
41
|
+
|
|
42
|
+
function onAlias(analytics: Analytics, json: JSON): JSON {
|
|
43
|
+
const user = analytics.user()
|
|
44
|
+
json.previousId =
|
|
45
|
+
json.previousId ?? json.from ?? user.id() ?? user.anonymousId()
|
|
46
|
+
json.userId = json.userId ?? json.to
|
|
47
|
+
delete json.from
|
|
48
|
+
delete json.to
|
|
49
|
+
return json
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function customerio(
|
|
53
|
+
analytics: Analytics,
|
|
54
|
+
settings?: CustomerioSettings,
|
|
55
|
+
integrations?: LegacySettings['integrations']
|
|
56
|
+
): Plugin {
|
|
57
|
+
// Attach `pagehide` before buffer is created so that inflight events are added
|
|
58
|
+
// to the buffer before the buffer persists events in its own `pagehide` handler.
|
|
59
|
+
window.addEventListener('pagehide', () => {
|
|
60
|
+
buffer.push(...Array.from(inflightEvents))
|
|
61
|
+
inflightEvents.clear()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const buffer = analytics.options.disableClientPersistence
|
|
65
|
+
? new PriorityQueue<Context>(analytics.queue.queue.maxAttempts, [])
|
|
66
|
+
: new PersistedPriorityQueue(
|
|
67
|
+
analytics.queue.queue.maxAttempts,
|
|
68
|
+
`dest-Customer.io-Data-Pipelines`
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const inflightEvents = new Set<Context>()
|
|
72
|
+
const flushing = false
|
|
73
|
+
|
|
74
|
+
const apiHost = settings?.apiHost ?? 'cdp.customer.io/v1'
|
|
75
|
+
const protocol = settings?.protocol ?? 'https'
|
|
76
|
+
const remote = `${protocol}://${apiHost}`
|
|
77
|
+
|
|
78
|
+
const deliveryStrategy = settings?.deliveryStrategy
|
|
79
|
+
const client =
|
|
80
|
+
deliveryStrategy?.strategy === 'batching'
|
|
81
|
+
? batch(apiHost, deliveryStrategy.config)
|
|
82
|
+
: standard(deliveryStrategy?.config as StandardDispatcherConfig)
|
|
83
|
+
|
|
84
|
+
async function send(ctx: Context): Promise<Context> {
|
|
85
|
+
if (isOffline()) {
|
|
86
|
+
buffer.push(ctx)
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
88
|
+
scheduleFlush(flushing, buffer, customerio, scheduleFlush)
|
|
89
|
+
return ctx
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
inflightEvents.add(ctx)
|
|
93
|
+
|
|
94
|
+
const path = ctx.event.type.charAt(0)
|
|
95
|
+
let json = toFacade(ctx.event).json()
|
|
96
|
+
|
|
97
|
+
if (ctx.event.type === 'track') {
|
|
98
|
+
delete json.traits
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (ctx.event.type === 'alias') {
|
|
102
|
+
json = onAlias(analytics, json)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return client
|
|
106
|
+
.dispatch(
|
|
107
|
+
`${remote}/${path}`,
|
|
108
|
+
normalize(analytics, json, settings, integrations)
|
|
109
|
+
)
|
|
110
|
+
.then(() => ctx)
|
|
111
|
+
.catch(() => {
|
|
112
|
+
buffer.pushWithBackoff(ctx)
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
114
|
+
scheduleFlush(flushing, buffer, customerio, scheduleFlush)
|
|
115
|
+
return ctx
|
|
116
|
+
})
|
|
117
|
+
.finally(() => {
|
|
118
|
+
inflightEvents.delete(ctx)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const customerio: Plugin = {
|
|
123
|
+
name: 'Customer.io Data Pipelines',
|
|
124
|
+
type: 'after',
|
|
125
|
+
version: '0.1.0',
|
|
126
|
+
isLoaded: (): boolean => true,
|
|
127
|
+
load: (): Promise<void> => Promise.resolve(),
|
|
128
|
+
track: send,
|
|
129
|
+
identify: send,
|
|
130
|
+
page: send,
|
|
131
|
+
alias: send,
|
|
132
|
+
group: send,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Buffer may already have items if they were previously stored in localStorage.
|
|
136
|
+
// Start flushing them immediately.
|
|
137
|
+
if (buffer.todo) {
|
|
138
|
+
scheduleFlush(flushing, buffer, customerio, scheduleFlush)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return customerio
|
|
142
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import jar from 'js-cookie'
|
|
2
|
+
import { Analytics } from '../../core/analytics'
|
|
3
|
+
import { LegacySettings } from '../../browser'
|
|
4
|
+
import { CustomerioEvent } from '../../core/events'
|
|
5
|
+
import { gracefulDecodeURIComponent } from '../../core/query-string/gracefulDecodeURIComponent'
|
|
6
|
+
import { tld } from '../../core/user/tld'
|
|
7
|
+
import { CustomerioFacade } from '../../lib/to-facade'
|
|
8
|
+
import { CustomerioSettings } from './index'
|
|
9
|
+
import { version } from '../../generated/version'
|
|
10
|
+
import { getAvailableStorageOptions, UniversalStorage } from '../../core/user'
|
|
11
|
+
|
|
12
|
+
let cookieOptions: jar.CookieAttributes | undefined
|
|
13
|
+
function getCookieOptions(): jar.CookieAttributes {
|
|
14
|
+
if (cookieOptions) {
|
|
15
|
+
return cookieOptions
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const domain = tld(window.location.href)
|
|
19
|
+
cookieOptions = {
|
|
20
|
+
expires: 31536000000, // 1 year
|
|
21
|
+
secure: false,
|
|
22
|
+
path: '/',
|
|
23
|
+
}
|
|
24
|
+
if (domain) {
|
|
25
|
+
cookieOptions.domain = domain
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return cookieOptions
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Default value will be updated to 'web' in `bundle-umd.ts` for web build.
|
|
32
|
+
let _version: 'web' | 'npm' = 'npm'
|
|
33
|
+
|
|
34
|
+
export function setVersionType(version: typeof _version) {
|
|
35
|
+
_version = version
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getVersionType(): typeof _version {
|
|
39
|
+
return _version
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type Ad = { id: string; type: string }
|
|
43
|
+
|
|
44
|
+
export function ampId(): string | undefined {
|
|
45
|
+
const ampId = jar.get('_ga')
|
|
46
|
+
if (ampId && ampId.startsWith('amp')) {
|
|
47
|
+
return ampId
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function utm(query: string): Record<string, string> {
|
|
52
|
+
if (query.startsWith('?')) {
|
|
53
|
+
query = query.substring(1)
|
|
54
|
+
}
|
|
55
|
+
query = query.replace(/\?/g, '&')
|
|
56
|
+
|
|
57
|
+
return query.split('&').reduce((acc, str) => {
|
|
58
|
+
const [k, v = ''] = str.split('=')
|
|
59
|
+
if (k.includes('utm_') && k.length > 4) {
|
|
60
|
+
let utmParam = k.substr(4)
|
|
61
|
+
if (utmParam === 'campaign') {
|
|
62
|
+
utmParam = 'name'
|
|
63
|
+
}
|
|
64
|
+
acc[utmParam] = gracefulDecodeURIComponent(v)
|
|
65
|
+
}
|
|
66
|
+
return acc
|
|
67
|
+
}, {} as Record<string, string>)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function ads(query: string): Ad | undefined {
|
|
71
|
+
const queryIds: Record<string, string> = {
|
|
72
|
+
btid: 'dataxu',
|
|
73
|
+
urid: 'millennial-media',
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (query.startsWith('?')) {
|
|
77
|
+
query = query.substring(1)
|
|
78
|
+
}
|
|
79
|
+
query = query.replace(/\?/g, '&')
|
|
80
|
+
const parts = query.split('&')
|
|
81
|
+
|
|
82
|
+
for (const part of parts) {
|
|
83
|
+
const [k, v] = part.split('=')
|
|
84
|
+
if (queryIds[k]) {
|
|
85
|
+
return {
|
|
86
|
+
id: v,
|
|
87
|
+
type: queryIds[k],
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function referrerId(
|
|
94
|
+
query: string,
|
|
95
|
+
ctx: CustomerioEvent['context'],
|
|
96
|
+
disablePersistance: boolean
|
|
97
|
+
): void {
|
|
98
|
+
const storage = new UniversalStorage<{
|
|
99
|
+
's:context.referrer': Ad
|
|
100
|
+
}>(
|
|
101
|
+
disablePersistance ? [] : ['cookie'],
|
|
102
|
+
getAvailableStorageOptions(getCookieOptions())
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const stored = storage.get('s:context.referrer')
|
|
106
|
+
let ad: Ad | undefined | null = ads(query)
|
|
107
|
+
|
|
108
|
+
ad = ad ?? stored
|
|
109
|
+
|
|
110
|
+
if (!ad) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (ctx) {
|
|
115
|
+
ctx.referrer = { ...ctx.referrer, ...ad }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
storage.set('s:context.referrer', ad)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function normalize(
|
|
122
|
+
analytics: Analytics,
|
|
123
|
+
json: ReturnType<CustomerioFacade['json']>,
|
|
124
|
+
settings?: CustomerioSettings,
|
|
125
|
+
integrations?: LegacySettings['integrations']
|
|
126
|
+
): object {
|
|
127
|
+
const user = analytics.user()
|
|
128
|
+
const query = window.location.search
|
|
129
|
+
|
|
130
|
+
json.context = json.context ?? json.options ?? {}
|
|
131
|
+
const ctx = json.context
|
|
132
|
+
|
|
133
|
+
delete json.options
|
|
134
|
+
json.writeKey = settings?.apiKey
|
|
135
|
+
ctx.userAgent = window.navigator.userAgent
|
|
136
|
+
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
const locale = navigator.userLanguage || navigator.language
|
|
139
|
+
|
|
140
|
+
if (typeof ctx.locale === 'undefined' && typeof locale !== 'undefined') {
|
|
141
|
+
ctx.locale = locale
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!ctx.library) {
|
|
145
|
+
const type = getVersionType()
|
|
146
|
+
if (type === 'web') {
|
|
147
|
+
ctx.library = {
|
|
148
|
+
name: 'analytics.js',
|
|
149
|
+
version: `next-${version}`,
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
ctx.library = {
|
|
153
|
+
name: 'analytics.js',
|
|
154
|
+
version: `npm:next-${version}`,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (query && !ctx.campaign) {
|
|
160
|
+
ctx.campaign = utm(query)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
referrerId(query, ctx, analytics.options.disableClientPersistence ?? false)
|
|
164
|
+
|
|
165
|
+
json.userId = json.userId || user.id()
|
|
166
|
+
json.anonymousId = json.anonymousId || user.anonymousId()
|
|
167
|
+
|
|
168
|
+
json.sentAt = new Date()
|
|
169
|
+
|
|
170
|
+
const failed = analytics.queue.failedInitializations || []
|
|
171
|
+
if (failed.length > 0) {
|
|
172
|
+
json._metadata = { failedInitializations: failed }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const bundled: string[] = []
|
|
176
|
+
const unbundled: string[] = []
|
|
177
|
+
|
|
178
|
+
for (const key in integrations) {
|
|
179
|
+
const integration = integrations[key]
|
|
180
|
+
if (key === 'Customer.io Data Pipelines') {
|
|
181
|
+
bundled.push(key)
|
|
182
|
+
}
|
|
183
|
+
if (integration.bundlingStatus === 'bundled') {
|
|
184
|
+
bundled.push(key)
|
|
185
|
+
}
|
|
186
|
+
if (integration.bundlingStatus === 'unbundled') {
|
|
187
|
+
unbundled.push(key)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// This will make sure that the disabled cloud mode destinations will be
|
|
192
|
+
// included in the unbundled list.
|
|
193
|
+
for (const settingsUnbundled of settings?.unbundledIntegrations || []) {
|
|
194
|
+
if (!unbundled.includes(settingsUnbundled)) {
|
|
195
|
+
unbundled.push(settingsUnbundled)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const configIds = settings?.maybeBundledConfigIds ?? {}
|
|
200
|
+
const bundledConfigIds: string[] = []
|
|
201
|
+
|
|
202
|
+
bundled.sort().forEach((name) => {
|
|
203
|
+
; (configIds[name] ?? []).forEach((id) => {
|
|
204
|
+
bundledConfigIds.push(id)
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
if (settings?.addBundledMetadata !== false) {
|
|
209
|
+
json._metadata = {
|
|
210
|
+
...json._metadata,
|
|
211
|
+
bundled: bundled.sort(),
|
|
212
|
+
unbundled: unbundled.sort(),
|
|
213
|
+
bundledIds: bundledConfigIds,
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const amp = ampId()
|
|
218
|
+
if (amp) {
|
|
219
|
+
ctx.amp = { id: amp }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return json
|
|
223
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isOffline } from '../../core/connection'
|
|
2
|
+
import { Context } from '../../core/context'
|
|
3
|
+
import { Plugin } from '../../core/plugin'
|
|
4
|
+
import { attempt } from '@customerio/cdp-analytics-core'
|
|
5
|
+
import { pWhile } from '../../lib/p-while'
|
|
6
|
+
import { PriorityQueue } from '../../lib/priority-queue'
|
|
7
|
+
|
|
8
|
+
async function flushQueue(
|
|
9
|
+
xt: Plugin,
|
|
10
|
+
queue: PriorityQueue<Context>
|
|
11
|
+
): Promise<PriorityQueue<Context>> {
|
|
12
|
+
const failedQueue: Context[] = []
|
|
13
|
+
if (isOffline()) {
|
|
14
|
+
return queue
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await pWhile(
|
|
18
|
+
() => queue.length > 0 && !isOffline(),
|
|
19
|
+
async () => {
|
|
20
|
+
const ctx = queue.pop()
|
|
21
|
+
if (!ctx) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const result = await attempt(ctx, xt)
|
|
26
|
+
const success = result instanceof Context
|
|
27
|
+
if (!success) {
|
|
28
|
+
failedQueue.push(ctx)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
// re-add failed tasks
|
|
33
|
+
failedQueue.map((failed) => queue.pushWithBackoff(failed))
|
|
34
|
+
return queue
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function scheduleFlush(
|
|
38
|
+
flushing: boolean,
|
|
39
|
+
buffer: PriorityQueue<Context>,
|
|
40
|
+
xt: Plugin,
|
|
41
|
+
scheduleFlush: Function
|
|
42
|
+
): void {
|
|
43
|
+
if (flushing) {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
48
|
+
setTimeout(async () => {
|
|
49
|
+
let isFlushing = true
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
51
|
+
const newBuffer = await flushQueue(xt, buffer)
|
|
52
|
+
isFlushing = false
|
|
53
|
+
|
|
54
|
+
if (buffer.todo > 0) {
|
|
55
|
+
scheduleFlush(isFlushing, newBuffer, xt, scheduleFlush)
|
|
56
|
+
}
|
|
57
|
+
}, Math.random() * 5000)
|
|
58
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Analytics } from '../../core/analytics'
|
|
2
|
+
|
|
3
|
+
export async function loadLegacyVideoPlugins(
|
|
4
|
+
analytics: Analytics
|
|
5
|
+
): Promise<void> {
|
|
6
|
+
const plugins = await import(
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
'@segment/analytics.js-video-plugins/dist/index.umd.js'
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// This is super gross, but we need to support the `window.analytics.plugins` namespace
|
|
12
|
+
// that is linked in the docs in order to be backwards compatible with ajs-classic
|
|
13
|
+
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
analytics._plugins = plugins
|
|
16
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Context, ContextCancelation } from '../../core/context'
|
|
2
|
+
import { CustomerioEvent } from '../../core/events'
|
|
3
|
+
import { Plugin } from '../../core/plugin'
|
|
4
|
+
import { CustomerioFacade, toFacade } from '../../lib/to-facade'
|
|
5
|
+
|
|
6
|
+
export interface MiddlewareParams {
|
|
7
|
+
payload: CustomerioFacade
|
|
8
|
+
|
|
9
|
+
integrations?: CustomerioEvent['integrations']
|
|
10
|
+
next: (payload: MiddlewareParams['payload'] | null) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DestinationMiddlewareParams {
|
|
14
|
+
payload: CustomerioFacade
|
|
15
|
+
integration: string
|
|
16
|
+
next: (payload: MiddlewareParams['payload'] | null) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type MiddlewareFunction = (
|
|
20
|
+
middleware: MiddlewareParams
|
|
21
|
+
) => void | Promise<void>
|
|
22
|
+
|
|
23
|
+
export type DestinationMiddlewareFunction = (
|
|
24
|
+
middleware: DestinationMiddlewareParams
|
|
25
|
+
) => void | Promise<void>
|
|
26
|
+
|
|
27
|
+
export async function applyDestinationMiddleware(
|
|
28
|
+
destination: string,
|
|
29
|
+
evt: CustomerioEvent,
|
|
30
|
+
middleware: DestinationMiddlewareFunction[]
|
|
31
|
+
): Promise<CustomerioEvent | null> {
|
|
32
|
+
// Clone the event so mutations are localized to a single destination.
|
|
33
|
+
let modifiedEvent = toFacade(evt, {
|
|
34
|
+
clone: true,
|
|
35
|
+
traverse: false,
|
|
36
|
+
}).rawEvent() as CustomerioEvent
|
|
37
|
+
async function applyMiddleware(
|
|
38
|
+
event: CustomerioEvent,
|
|
39
|
+
fn: DestinationMiddlewareFunction
|
|
40
|
+
): Promise<CustomerioEvent | null> {
|
|
41
|
+
let nextCalled = false
|
|
42
|
+
let returnedEvent: CustomerioEvent | null = null
|
|
43
|
+
|
|
44
|
+
await fn({
|
|
45
|
+
payload: toFacade(event, {
|
|
46
|
+
clone: true,
|
|
47
|
+
traverse: false,
|
|
48
|
+
}),
|
|
49
|
+
integration: destination,
|
|
50
|
+
next(evt) {
|
|
51
|
+
nextCalled = true
|
|
52
|
+
|
|
53
|
+
if (evt === null) {
|
|
54
|
+
returnedEvent = null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (evt) {
|
|
58
|
+
returnedEvent = evt.obj
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if (!nextCalled && returnedEvent !== null) {
|
|
64
|
+
returnedEvent = returnedEvent as CustomerioEvent
|
|
65
|
+
returnedEvent.integrations = {
|
|
66
|
+
...event.integrations,
|
|
67
|
+
[destination]: false,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return returnedEvent
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const md of middleware) {
|
|
75
|
+
const result = await applyMiddleware(modifiedEvent, md)
|
|
76
|
+
if (result === null) {
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
modifiedEvent = result
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return modifiedEvent
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function sourceMiddlewarePlugin(
|
|
86
|
+
fn: MiddlewareFunction,
|
|
87
|
+
integrations: CustomerioEvent['integrations']
|
|
88
|
+
): Plugin {
|
|
89
|
+
async function apply(ctx: Context): Promise<Context> {
|
|
90
|
+
let nextCalled = false
|
|
91
|
+
|
|
92
|
+
await fn({
|
|
93
|
+
payload: toFacade(ctx.event, {
|
|
94
|
+
clone: true,
|
|
95
|
+
traverse: false,
|
|
96
|
+
}),
|
|
97
|
+
integrations: integrations ?? {},
|
|
98
|
+
next(evt) {
|
|
99
|
+
nextCalled = true
|
|
100
|
+
if (evt) {
|
|
101
|
+
ctx.event = evt.obj
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
if (!nextCalled) {
|
|
107
|
+
throw new ContextCancelation({
|
|
108
|
+
retry: false,
|
|
109
|
+
type: 'middleware_cancellation',
|
|
110
|
+
reason: 'Middleware `next` function skipped',
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return ctx
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
name: `Source Middleware ${fn.name}`,
|
|
119
|
+
type: 'before',
|
|
120
|
+
version: '0.1.0',
|
|
121
|
+
|
|
122
|
+
isLoaded: (): boolean => true,
|
|
123
|
+
load: (ctx): Promise<Context> => Promise.resolve(ctx),
|
|
124
|
+
|
|
125
|
+
track: apply,
|
|
126
|
+
page: apply,
|
|
127
|
+
identify: apply,
|
|
128
|
+
alias: apply,
|
|
129
|
+
group: apply,
|
|
130
|
+
}
|
|
131
|
+
}
|