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

readme: adding instructions to use the npm module #180

Merged
merged 3 commits into from
Aug 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,50 @@ declare global {
}
```

## Using as a standalone `npm` package
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:

1- Install the dependencies
```
yarn add @segment/analytics.js-core
yarn add @segment/analytics.js-integration-segmentio
// you may need this depending on the bundler
yarn add uuid@^3.4
```

2- Import the dependencies
```javascript
import Analytics from "@segment/analytics.js-core/build/analytics";
import SegmentIntegration from "@segment/analytics.js-integration-segmentio";
```

3- Initialize Segment and add Segment's own integration
```javascript
// instantiate the library
const analytics = new Analytics();

// add Segment's own integration ( or any other device mode integration )
analytics.use(SegmentIntegration);

// define the integration settings object.
// Since we are using only Segment integration in this example, we only have
// "Segment.io" in the integrationSettings object
const integrationSettings = {
"Segment.io": {
apiKey: "<YOUR SEGMENT WRITE KEY>",
retryQueue: true,
addBundledMetadata: true
}
};


// Initialize the library
analytics.initialize(integrationSettings);

// Happy tracking!
analytics.track('🚀');
```

## License

Released under the [MIT license](LICENSE).
Expand Down