1.1.0 • Published 9 days ago

@scaleway/use-segment v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

@scaleway/use-segment

A tiny hooks to handle segment events

use @segment/analytics-next

Install

$ pnpm add @scaleway/use-segment

Usage

Event directory

Create an events directory with all you specific events.

events
 ┣ pageTypes
 ┃ ┗ index.ts
 ┣ 📂loginEvent
 ┃ ┗ index.ts
 ┃ index.ts ( export all you functions )

Each event will have a format like this:

const pageVisited =
  (analytics?: Analytics) =>
  async (args: Args): Promise<void> => {
    // here do what you have to do with analytics
    await analytics?.page(args)
  }

export default pageVisited
import pageTypes from './pageTypes'
import testEvents from './testEvents'

export default {
  pageTypes,
  testEvents,
}

Context Load

Inside you global app you have to use our Segment Provider to allow loading of segment from your settting app. This will trigger a load and return analitycs function inside you provider.

import SegmentProvider from '@scaleway/use-segment'
import { captureMessage } from '@sentry/browser'
import events from './events'

const App = () => (
  <SegmentProvider
    settings={{ cdn: 'https://cdn.url', writeKey: 'WRITE_KEY' }} // check your gtm writeKey
    events={events}
    onError={e => captureMessage(`Error on Segment: ${e.message}`)}
  >
    <App />
  </SegmentProvider>
)

Hook utility

Now you maybe want to use your events inside your app . If you are using typescript, you may

import { useSegment } from '@scaleway/use-segment'
import type { Events } from 'types/events'
import { Form, Submit } from '@scaleway/form'

const Login = () => {
  const { events } = useSegment<Events>()

  const onSubmit = async args => {
    // make you api calls
    await events.login()
  }

  return (
    <Form onSubmit={onSubmit}>
      // others fields
      <Submit />
    </Form>
  )
}
1.1.0

9 days ago

1.0.3

15 days ago

1.0.2

18 days ago

1.0.1

2 months ago

1.0.0

2 months ago

0.10.2

4 months ago

0.10.1

4 months ago

0.10.0

5 months ago

0.9.25

5 months ago

0.9.13

10 months ago

0.9.14

10 months ago

0.9.15

9 months ago

0.9.16

8 months ago

0.9.17

8 months ago

0.9.18

8 months ago

0.9.19

7 months ago

0.9.23

6 months ago

0.9.24

6 months ago

0.9.20

7 months ago

0.9.21

7 months ago

0.9.22

6 months ago

0.9.12

11 months ago

0.9.10

1 year ago

0.9.11

11 months ago

0.9.8

1 year ago

0.9.7

1 year ago

0.9.9

1 year ago

0.9.6

1 year ago

0.9.4

1 year ago

0.9.5

1 year ago

0.8.5

1 year ago

0.9.3

1 year ago

0.8.4

1 year ago

0.8.7

1 year ago

0.8.6

1 year ago

0.9.0

1 year ago

0.9.2

1 year ago

0.8.3

1 year ago

0.9.1

1 year ago

0.7.5

1 year ago

0.8.1

1 year ago

0.7.2

2 years ago

0.8.0

1 year ago

0.7.4

1 year ago

0.8.2

1 year ago

0.7.3

2 years ago

0.7.1

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.10

2 years ago

0.6.12

2 years ago

0.6.11

2 years ago

0.6.13

2 years ago

0.7.0

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.4

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.3.3

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago