|
1 | 1 | # @segment/analytics-signals-runtime |
2 | 2 | Encapsulates Signals runtime functionality, in order to share logic between the signals plugins for browser and mobile. |
3 | 3 |
|
| 4 | +### Installation |
| 5 | +```bash |
| 6 | +# npm |
| 7 | +npm install @segment/analytics-signals-runtime |
| 8 | +# yarn |
| 9 | +yarn add @segment/analytics-signals-runtime |
| 10 | +# pnpm |
| 11 | +pnpm install @segment/analytics-signals-runtime |
| 12 | +``` |
| 13 | + |
| 14 | +### Usage |
| 15 | + |
| 16 | +### As a regular library |
| 17 | + |
| 18 | +```ts |
| 19 | +import { |
| 20 | + WebSignalsRuntime, |
| 21 | + // WebRuntimeConstants, |
| 22 | + // MobileSignalsRuntime |
| 23 | + // MobileRuntimeConstants |
| 24 | +} from '@segment/analytics-signals-runtime' |
| 25 | + |
| 26 | +const signals = new WebSignalsRuntime([....]) |
| 27 | + |
| 28 | +// get the more recent network signal in the buffer |
| 29 | +const networkSignal = signals.find(null, 'network') |
| 30 | + |
| 31 | +// all signals |
| 32 | +const allInstrumentationSignals = signals.find(null, 'network') |
| 33 | + |
| 34 | + |
| 35 | +``` |
| 36 | +### As a string |
| 37 | +Exposes the SignalsObject |
| 38 | + |
| 39 | +```ts |
| 40 | +import { getRuntimeCode } from '@segment/analytics-signals-runtime`` |
| 41 | + |
| 42 | +eval(` |
| 43 | + ${getRuntimeCode()} |
| 44 | + signals.signalBuffer = [....] |
| 45 | + `) |
| 46 | + |
| 47 | +``` |
4 | 48 | ### Development |
5 | 49 | `yarn build` generate the following artifacts: |
6 | 50 | | Generated File(s) | Description | |
7 | 51 | |--------|-------------| |
8 | 52 | | `/dist/runtime/index.[platform].js`, `/[platform]/get-runtime-code.generated.js` | Exposes `globalThis.Signals` and constants (e.g. `SignalType`), either through the script tag or in the mobile JS engine | |
9 | 53 | | `/dist/editor/[platform]-editor.d.ts.txt` | Type definitions for monaco editor on app.segment.com |
10 | | -| `/dist/esm/index.js` | Entry point for `@segment/analytics-signals` and the segment app, for consumers that want to consume the types / runtime code as an npm package. | |
| 54 | +| `/dist/esm/index.js` | Entry point for `@segment/analytics-signals` and the segment app, for consumers that want to consume the types / runtime code as an npm package. | |
0 commit comments