Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Sep 30, 2022
1 parent 307cc96 commit 64fab5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/core/src/plugins/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface MiddlewareParams {
next: (payload: MiddlewareParams['payload'] | null) => void
}

analytics.identify('Test User', { loggedIn: true }, { userId: '123456' })
export interface DestinationMiddlewareParams {
payload: SegmentFacade
integration: string
Expand Down
34 changes: 30 additions & 4 deletions packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,31 @@ import { AnalyticsNode } from '@segment/analytics-node'
export const analytics = new AnalyticsNode({ writeKey: '<MY_WRITE_KEY>' })


// app.ts
// routes.ts
...
import { analytics } from './analytics'
...

const app = express()

...

app.post('/login', (req, res) => {
analytics.identify({
userId: req.body.userId,
previousId: req.body.previousId
})
})

app.post('/cart', (req, res) => {
analytics.track({
userId: req.body.userId,
event: 'Add to cart',
properties: { productId: '123456' }
})
});


analytics.identify('Test User', { loggedIn: true }, { userId: "123456" })
analytics.track('hello world', {}, { userId: "123456" })

```
## Graceful Shutdown
Expand All @@ -37,7 +57,13 @@ import express from 'express'
const analytics = new AnalyticsNode({ writeKey: '<MY_WRITE_KEY>' })

const app = express()
app.get('/', (req, res) => res.send('Hello World!'));
app.post('/cart', (req, res) => {
analytics.track({
userId: req.body.id,
event: 'Add to cart',
properties: { productId: '123456' }
})
});

const server = app.listen(3000)

Expand Down

0 comments on commit 64fab5d

Please sign in to comment.