Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update signals readme -- snippet users #1165

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions packages/signals/signals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@
See: [settings.ts](src/types/settings.ts)

## Quick start

## Snippet Users
```html
<head>
<title>My Website</title>

<!-- Load SignalsPlugin -->
<script src="https://cdn.jsdelivr.net/npm/@segment/analytics-signals@latest/dist/umd/analytics-signals.umd.js"></script>

<!-- Load Segment (copy snippet from app.segment.com) -->
<script>
!function(){var i="analytics",analytics=window[i]... // etc
analytics.load("<YOUR_WRITE_KEY>");
analytics.page();
}()
</script>

<!-- Register SignalsPlugin -->
<script>
const signalsPlugin = new SignalsPlugin()
analytics.register(signalsPlugin)
</script>
</head>
```

## `npm` Users
### Installation
```bash
# npm
Expand All @@ -21,16 +47,25 @@ pnpm install @segment/analytics-signals
import { AnalyticsBrowser } from '@segment/analytics-next'
import { SignalsPlugin } from '@segment/analytics-signals'

const analytics = new AnalyticsBrowser()
const signalsPlugin = new SignalsPlugin()
export const analytics = new AnalyticsBrowser()
export const signalsPlugin = new SignalsPlugin()

analytics.register(signalsPlugin)

analytics.load({
writeKey: '<YOUR_WRITE_KEY>'
})

```
### Extending / Emitting Custom Signals
```ts
import { signalsPlugin } from './analytics' // assuming you exported your plugin instance.

signalsPlugin.addSignal({
type: 'userDefined',
data: { foo: 'bar' }
})
```

### Debugging
#### Enable debug mode
Expand All @@ -49,17 +84,10 @@ https://my-website.com?segment_signals_debug=false
#### Listening to signals
```ts
const signalsPlugin = new SignalsPlugin()

signalsPlugin.onSignal((signal) => console.log(signal))
```

### Emitting Signals
```ts
const signalsPlugin = new SignalsPlugin()
signalsPlugin.addSignal({
type: 'userDefined',
data: { foo: 'bar' }
})
```

### Playground / Development / Testing
See the [signals example repo](../signals-example).
Expand Down
Loading