Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 9a33279

Browse files
Julio Farahsanscontext
Julio Farah
and
sanscontext
authored
Document how to use types with the AJS snippet (#179)
* Document how to use types with the snippet * fix broken gif * quick copy edit * fix link ;) Co-authored-by: sanscontext <[email protected]>
1 parent 45256be commit 9a33279

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,35 @@
33
[![CircleCI](https://circleci.com/gh/segmentio/analytics.js-core.svg?style=shield)](https://circleci.com/gh/segmentio/analytics.js-core)
44
[![Codecov](https://img.shields.io/codecov/c/github/segmentio/analytics.js-core/master.svg)](https://codecov.io/gh/segmentio/analytics.js-core)
55

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).
77

88
To build this into a full, usable library, see the [Analytics.js](https://github.com/segmentio/analytics.js) repository.
99

10-
## Using Types
10+
## Using Types (v.4.0.0-beta.0 and later)
1111

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.
1413

1514
### Importing as an npm module
1615

17-
If you use analytics.js-core as an npm module, you can leverage its types out of the box:
18-
<img src="![types](https://user-images.githubusercontent.com/484013/88733944-bbcf3680-d0ec-11ea-904c-a63b68f4975e.gif)" 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+
```
1935

2036
## License
2137

0 commit comments

Comments
 (0)