|
3 | 3 | [](https://circleci.com/gh/segmentio/analytics.js-core)
|
4 | 4 | [](https://codecov.io/gh/segmentio/analytics.js-core)
|
5 | 5 |
|
6 |
| -This is the core of [Analytics.js][], the open-source library that powers data collection at [Segment](https://segment.com). |
| 6 | +This is the core of [Analytics.js](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/), the open-source library that powers data collection at [Segment](https://segment.com). |
7 | 7 |
|
8 | 8 | To build this into a full, usable library, see the [Analytics.js](https://github.com/segmentio/analytics.js) repository.
|
9 | 9 |
|
10 |
| -## Using Types |
| 10 | +## Using Types (v.4.0.0-beta.0 and later) |
11 | 11 |
|
12 |
| -We've recently introduced Typescript support and types to Analytics.js Core. While the exposed types still need some work |
13 |
| -(pull requests are welcome!), they're ready to be used. |
| 12 | +We recently introduced Typescript support and types to Analytics.js Core. While the exposed types still need some work (pull requests are welcome!), they're ready to be used. |
14 | 13 |
|
15 | 14 | ### Importing as an npm module
|
16 | 15 |
|
17 |
| -If you use analytics.js-core as an npm module, you can leverage its types out of the box: |
18 |
| -<img src="" alt="Example of using analytics js types" width="500px"> |
| 16 | +If you use analytics.js-core as an npm module, you can use its types out of the box: |
| 17 | +<img src="https://user-images.githubusercontent.com/484013/89060070-2e235f00-d317-11ea-9fd9-e1c77aaca9f9.gif" alt="Example of Types usage in Analytics JS" width="500px"> |
| 18 | + |
| 19 | +### Using types with the AJS Snippet |
| 20 | + |
| 21 | +If you create a source at https://app.segment.com, Segement automatically generates a JS snippet that you can add to your website. (for more information visit our [documentation](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/)). |
| 22 | + |
| 23 | +To use types with the snippet, add `analytics` as part of the global module. |
| 24 | +Something like this: |
| 25 | + |
| 26 | +```typescript |
| 27 | +import { SegmentAnalytics } from '@segment/analytics.js-core'; |
| 28 | + |
| 29 | +declare global { |
| 30 | + interface Window { |
| 31 | + analytics: SegmentAnalytics.AnalyticsJS; |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
19 | 35 |
|
20 | 36 | ## License
|
21 | 37 |
|
|
0 commit comments