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

Commit 174fc20

Browse files
authored
readme: adding instructions to use the npm module (#180)
* readme: adding instructions to use the npm module * Adding a note on uuid dependency * Fix typos
1 parent 9a33279 commit 174fc20

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,50 @@ declare global {
3333
}
3434
```
3535

36+
## Using as a standalone `npm` package
37+
We recommend using the CDN version of `analytics.js` as it offers all the project and workspace specific settings, enabled integrations, and middleware. But if you prefer to use `analytics.js-core` as a standalone npm package using your own tooling & workflow, you can do the following:
38+
39+
1- Install the dependencies
40+
```
41+
yarn add @segment/analytics.js-core
42+
yarn add @segment/analytics.js-integration-segmentio
43+
// you may need this depending on the bundler
44+
yarn add uuid@^3.4
45+
```
46+
47+
2- Import the dependencies
48+
```javascript
49+
import Analytics from "@segment/analytics.js-core/build/analytics";
50+
import SegmentIntegration from "@segment/analytics.js-integration-segmentio";
51+
```
52+
53+
3- Initialize Segment and add Segment's own integration
54+
```javascript
55+
// instantiate the library
56+
const analytics = new Analytics();
57+
58+
// add Segment's own integration ( or any other device mode integration )
59+
analytics.use(SegmentIntegration);
60+
61+
// define the integration settings object.
62+
// Since we are using only Segment integration in this example, we only have
63+
// "Segment.io" in the integrationSettings object
64+
const integrationSettings = {
65+
"Segment.io": {
66+
apiKey: "<YOUR SEGMENT WRITE KEY>",
67+
retryQueue: true,
68+
addBundledMetadata: true
69+
}
70+
};
71+
72+
73+
// Initialize the library
74+
analytics.initialize(integrationSettings);
75+
76+
// Happy tracking!
77+
analytics.track('🚀');
78+
```
79+
3680
## License
3781

3882
Released under the [MIT license](LICENSE).

0 commit comments

Comments
 (0)