|
1 | | -# streamsql-js |
2 | | -The javascript ingestion API for streamsql. |
| 1 | +# StreamSQL Javascript Ingestion API |
| 2 | + |
| 3 | +> Upload data on your StreamSQL event streams. |
| 4 | +
|
| 5 | +## Install |
| 6 | + |
| 7 | +### npm |
| 8 | + |
| 9 | +```sh |
| 10 | +npm install @streamsql/streamsql-js |
| 11 | +``` |
| 12 | + |
| 13 | +### CDN |
| 14 | + |
| 15 | +If not using a bundler, the package is available via CDN. Include the script tag in all pages where `streamsql` is used. |
| 16 | + |
| 17 | +```html |
| 18 | +<script crossorigin src="https://unpkg.com/@streamsql/streamsql-js"></script> |
| 19 | +``` |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +```javascript |
| 24 | +import streamsql from '@streamsql/streamsql-js' |
| 25 | + |
| 26 | +// Initialize the client |
| 27 | +streamsql.init(process.env.APIKEY) |
| 28 | + |
| 29 | +// Set custom user properties |
| 30 | +streamsql.identify('USER_ID') |
| 31 | + |
| 32 | +// Send data on your streams |
| 33 | +streamsql.sendEvent( |
| 34 | + 'my-event-stream', |
| 35 | + { eventName: 'My Event' }, |
| 36 | +) |
| 37 | +``` |
| 38 | + |
| 39 | +## API |
| 40 | + |
| 41 | +### streamsql |
| 42 | + |
| 43 | +#### `streamsql.init(APIKEY <string>)` |
| 44 | + |
| 45 | +Initialize the streamsql client with your API key. If you are using the CDN script, this must be called first on every page streamsql is used. |
| 46 | + |
| 47 | +#### `streamsql.identify(userId <string>)` |
| 48 | + |
| 49 | +Set a user id to be tied with events. The user id is persisted throughout multiple sessions.Use `streamsql.unidentify()` to clear set user ids. |
| 50 | + |
| 51 | +#### `streamsql.unidentify()` |
| 52 | + |
| 53 | +Clears any stored user ids that were set by `streamsql.identify('userId')`. |
| 54 | + |
| 55 | +#### `streamsql.sendEvent(streamName <string> [,data <object>, onSent? <function>])` |
| 56 | + |
| 57 | +Send data to `streamName`. The stream name must be valid and registered prior to sending. If data is not provided, default options will be sent including page context, any set user ids, timestamps, and so on. `onSent` is a an optional callback that is called with the response status code and response text when sending is complete. |
| 58 | + |
| 59 | +## Related |
| 60 | + |
| 61 | +> streamsql-pixel: Simple starter script to gather some general visitor data. |
0 commit comments