moveo-one-segment-destination-web 1.0.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pavle Rogan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # Moveo One — Segment Destination Plugin (Web / TypeScript)
2
+
3
+ A Segment destination plugin that forwards every Segment event to Moveo One, so both platforms receive identical event data from a single instrumentation.
4
+
5
+ Built for Segment's [`@segment/analytics-next`](https://github.com/segmentio/analytics-next) browser SDK.
6
+
7
+ Two ways to use it:
8
+
9
+ - **npm package** — `npm install moveo-one-segment-destination-web` (see below).
10
+ - **Copy-paste single file** — drop [`standalone/MoveoOneDestination.ts`](standalone/MoveoOneDestination.ts) into your project, no dependency to install. See [standalone/README.md](standalone/README.md).
11
+
12
+ ---
13
+
14
+ ## Requirements
15
+
16
+ - [`@segment/analytics-next`](https://github.com/segmentio/analytics-next) `1.x+`
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install moveo-one-segment-destination-web
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Usage
29
+
30
+ Initialise Segment as you normally would, then register the plugin. That's it — every `track`, `page`, `screen`, `identify`, `group`, and `alias` call is forwarded to Moveo One automatically.
31
+
32
+ ```ts
33
+ import { AnalyticsBrowser } from "@segment/analytics-next";
34
+ import { moveoOneDestination } from "moveo-one-segment-destination-web";
35
+
36
+ export const analytics = AnalyticsBrowser.load({ writeKey: "YOUR_SEGMENT_WRITE_KEY" });
37
+
38
+ analytics.register(moveoOneDestination({ apiKey: "YOUR_MOVEO_API_KEY" }));
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Configuration
44
+
45
+ | Option | Type | Default | Description |
46
+ |--------|------|---------|-------------|
47
+ | `apiKey` | `string` | — | **Required.** Your Moveo One API key (sent as the `Authorization` header). |
48
+ | `endpoint` | `string` | Production URL | Override the ingestion endpoint. |
49
+ | `debug` | `boolean` | `false` | Log request and response details to the console. |
50
+ | `gzip` | `boolean` | `true` | Gzip-compress upload bodies (`Content-Encoding: gzip`) via `CompressionStream`. Falls back to plain JSON when unsupported. |
51
+ | `batchSize` | `number` | `20` | Number of events that trigger an immediate flush. |
52
+ | `flushIntervalMs` | `number` | `30000` | How often the batch is flushed automatically (ms). |
53
+ | `maxQueueBytes` | `number` | `5000000` | Max bytes of queued events held in storage. When exceeded, the oldest batches are evicted. |
54
+ | `maxQueueAgeMs` | `number` | `604800000` | Max age (ms) of a queued batch before it is evicted (default 7 days). |
55
+ | `maxRetries` | `number` | `10` | Max upload attempts for a batch before it is dropped. |
56
+ | `filter` | `Record<string, string[]>` | `undefined` | Property filter — see [Filtering events](#filtering-events) below. |
57
+
58
+ > Most apps never set any of these. The one knob you may want is `flushIntervalMs` or `batchSize`. Everything else has production defaults.
59
+
60
+ ```ts
61
+ analytics.register(
62
+ moveoOneDestination({
63
+ apiKey: "YOUR_MOVEO_API_KEY",
64
+ debug: true, // enable console output during development
65
+ }),
66
+ );
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Reliability & delivery
72
+
73
+ - **Durable queue** — events are written to `localStorage` *before* any network call, so they survive page reloads and crashes. They are deleted only after the server confirms receipt (HTTP `2xx`). If `localStorage` is unavailable (e.g. SSR, private mode, or a hardened CSP), the plugin transparently falls back to an in-memory queue.
74
+ - **Batching & flushing** — events are sent when `batchSize` is reached, a request-size limit is hit, the `flushIntervalMs` timer fires, or the page is hidden/unloaded (`visibilitychange` / `pagehide`, using `fetch` `keepalive`).
75
+ - **Smart retries** — failed uploads retry with exponential backoff + jitter. HTTP `429` and the `Retry-After` header are honoured; `5xx`/network errors retry; non-`429` `4xx` responses are treated as permanent and dropped. A batch is dropped after `maxRetries` attempts so one bad batch can't block the queue.
76
+ - **Bounded** — the queue is capped by `maxQueueBytes` and `maxQueueAgeMs`; when over budget the **oldest** batches are evicted (logged when `debug = true`).
77
+ - **Compression** — uploads are gzip-compressed by default (`Content-Encoding: gzip`). The backend handles both gzip and plain JSON; set `gzip = false` to disable.
78
+
79
+ > **Delivery is at-least-once.** After a crash a batch may be sent twice. Each event carries a stable `messageId`; the Moveo One backend de-duplicates on it.
80
+
81
+ ---
82
+
83
+ ## Filtering events
84
+
85
+ By default every event is forwarded. Pass a `filter` object to forward only events whose properties or traits match your criteria.
86
+
87
+ Each entry is a condition: `propertyName: [allowedValue1, allowedValue2, ...]`.
88
+ When multiple entries are provided **all conditions must match** (AND logic).
89
+ Events that do not match are dropped immediately and never queued.
90
+
91
+ **Forward only events with a specific property value**
92
+
93
+ ```ts
94
+ moveoOneDestination({
95
+ apiKey: "YOUR_MOVEO_API_KEY",
96
+ filter: { category: ["purchase"] },
97
+ });
98
+ ```
99
+
100
+ **Combine multiple conditions — all must match**
101
+
102
+ ```ts
103
+ moveoOneDestination({
104
+ apiKey: "YOUR_MOVEO_API_KEY",
105
+ filter: {
106
+ category: ["purchase", "subscription"],
107
+ currency: ["USD", "EUR"],
108
+ },
109
+ });
110
+ ```
111
+
112
+ > **Note:** The filter checks `properties` for `track`, `page`, and `screen` events, and `traits` for `identify` and `group` events. Events where a required property is missing or is not a primitive value (string / number / boolean) are dropped.
113
+
114
+ ---
115
+
116
+ ## Event types
117
+
118
+ | Segment call | Forwarded |
119
+ |---|---|
120
+ | `analytics.track(...)` | ✅ |
121
+ | `analytics.page(...)` | ✅ |
122
+ | `analytics.screen(...)` | ✅ |
123
+ | `analytics.identify(...)` | ✅ |
124
+ | `analytics.group(...)` | ✅ |
125
+ | `analytics.alias(...)` | ✅ common fields only |
126
+
127
+ > `alias` is an advanced call used to merge two user identities. Only the common Segment fields are forwarded.
128
+
129
+ ---
130
+
131
+ ## Development
132
+
133
+ ```bash
134
+ npm install
135
+ npm run build # bundles ESM + CJS + type declarations into dist/
136
+ npm run typecheck # type-checks without emitting
137
+ ```