Skip to content

Commit d3b68e6

Browse files
authored
Update signals runtime readme (#1249)
1 parent 7c24459 commit d3b68e6

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed
Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,69 @@
11
# @segment/analytics-signals-runtime
22
Encapsulates Signals runtime functionality, in order to share logic between the signals plugins for browser and mobile.
33

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+
### Importing the signals runtime as a module (e.g. `signals.find()`)
17+
18+
```ts
19+
import { WebSignalsRuntime, Signal } from '@segment/analytics-signals-runtime'
20+
// MobileSignalsRuntime
21+
// WebRuntimeConstants,
22+
// MobileRuntimeConstants,
23+
24+
const mockSignalBuffer: Signal[] = [{
25+
type: "network",
26+
data: {
27+
action: "response",
28+
url: "https://segment-integrations.github.io/segment-shop-auto/cart",
29+
data: { foo: "bar" },
30+
ok: true,
31+
status: 201,
32+
contentType: "application/json",
33+
page: {
34+
path: "/segment-shop-auto/",
35+
referrer: "",
36+
title: "Segment Shop - Home Collection - Timecraft",
37+
search: "",
38+
url: "https://segment-integrations.github.io/segment-shop-auto/#/home-collection/Timecraft",
39+
hostname: "segment-integrations.github.io",
40+
hash: "#/home-collection/Timecraft"
41+
}
42+
}
43+
}]
44+
45+
const signals = new WebSignalsRuntime(mockSignalBuffer)
46+
47+
const networkSignal = signals.find(null, 'network')
48+
49+
```
50+
### Importing the signals runtime a JS string
51+
```ts
52+
import { getRuntimeCode, getMobileRuntimeCode } from '@segment/analytics-signals-runtime'
53+
54+
eval(`
55+
${getMobileRuntimeCode()}
56+
signals.signalBuffer = [....]
57+
`)
58+
```
59+
60+
### API documentation
61+
For all exports, explore [the index.ts](src/index.ts).
62+
463
### Development
564
`yarn build` generate the following artifacts:
665
| Generated File(s) | Description |
766
|--------|-------------|
867
| `/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 |
968
| `/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. |
69+
| `/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

Comments
 (0)