# @segment/analytics.js-core

> The hassle-free way to integrate analytics into any web application.

Latest version **4.1.11** (published 2021-04-26) · SEE LICENSE IN LICENSE license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @segment/analytics.js-core
pnpm add @segment/analytics.js-core
yarn add @segment/analytics.js-core
bun add @segment/analytics.js-core
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.1.11 |
| Published | 2021-04-26 |
| First published | 2016-05-26 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 30 |
| Unpacked size | 184.9 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 133 |
| Author | Segment |
| Maintainers | eric.rogner, yannieyip, marcelopv, kiara.daswani, gilomer, anna.choi, alistairbarrell, odoren, arta.razavi, kelcook, gnijor, lauramunozjimenez, parsa-segment, ynguyen, mshwery, flaque, gpsamson, amillet89, av-segment, scruwys1, rowno, chenpengcheng, segmentaimee, eesegment, segmentio, segment-admin, dominicbarnes, ladanazita, anoonan, peripheral, achille-roussel, nettofarah, albert.segment, segment-danielstjules, jlee9595, n2parko, segment-andy-yeo, sahilp, vdemedes, emilio-gomez-lavin, f2prateek, andreiko_ru, xagos, emily.luckette, leifdreizler, alan-segment, tyson_segment, bgamwell, jfabre-segment, uditmehta, hellooimkat, brienne.mcnally, sanscontext, eculver, aultimus, erikdw, fauzyy, jaimal, davidbirdsong, ktrinh, calthomson, yunqiaohuang, dk1027, nickatsegment, nielssegment, knoonan, cdrycroft, yabrira, shse, julee05, kamebkj, ryan_segment, laurenmreeder, tidothegreat, mericsson, prayansh-segmentt, stargaesser, andyguwc, jeremylarkin, bsneed, danieljackins, tomeliaz, segment-seth, xav_segment, bihl, shamil.ataev, james9446, priscilla.giatti, kellylu, smokeybears, jmbuckner, benhorowitz, yolken-segment, nlsun, thomas-pelletier-segment, brian-segment, segment-michael, cohara87, osamakhn, drew-thompson, andy-li, segment-jsingh, vanesng, cvillela, pauljaeinyoo, stevenmiller888, mniehe, iajiboye, stephment, sharadbhadouria, emilyc, maggieyu, anoonan16, durgani, colinlohner, julio.farah, hblanks-segment, rsata, shyaan, juhaelee, akleiner2, kathryn-taylor, andrius-segment, pooyaj, llbsgmt, lab176, valerieernst, emilyluckette, ucarion, solon.aguiar, rjenkinsseg, segment-ulysse, khinkalilover, maloneya, zackurey |
| Keywords | analytics, analytics.js, segment, segment.io |

## Links

- npm: https://www.npmjs.com/package/@segment/analytics.js-core
- Repository: https://github.com/segmentio/analytics.js-core
- Homepage: https://github.com/segmentio/analytics.js-core#readme
- Issues: https://github.com/segmentio/analytics.js-core/issues
- npm.io page: https://npm.io/package/@segment/analytics.js-core

## Dependencies (30)

- [is](https://npm.io/package/is.md) ^3.1.0
- [uuid](https://npm.io/package/uuid.md) ^3.4.0
- [debug](https://npm.io/package/debug.md) ^2.6.9
- [extend](https://npm.io/package/extend.md) 3.0.2
- [install](https://npm.io/package/install.md) ^0.7.3
- [bind-all](https://npm.io/package/bind-all.md) ^1.0.0
- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [new-date](https://npm.io/package/new-date.md) ^1.0.0
- [next-tick](https://npm.io/package/next-tick.md) ^0.2.2
- [spark-md5](https://npm.io/package/spark-md5.md) ^2.0.2
- [@ndhoule/keys](https://npm.io/package/@ndhoule/keys.md) ^2.0.0
- [@ndhoule/pick](https://npm.io/package/@ndhoule/pick.md) ^2.0.0
- [component-url](https://npm.io/package/component-url.md) ^0.2.1
- [@segment/store](https://npm.io/package/@segment/store.md) ^1.3.20
- [component-type](https://npm.io/package/component-type.md) ^1.2.1
- [@ndhoule/extend](https://npm.io/package/@ndhoule/extend.md) ^2.0.0
- [@segment/cookie](https://npm.io/package/@segment/cookie.md) ^1.1.5
- [component-event](https://npm.io/package/component-event.md) ^0.1.4
- [@segment/is-meta](https://npm.io/package/@segment/is-meta.md) ^1.0.0
- [@segment/isodate](https://npm.io/package/@segment/isodate.md) ^1.0.2
- [segmentio-facade](https://npm.io/package/segmentio-facade.md) ^3.2.7
- [@ndhoule/defaults](https://npm.io/package/@ndhoule/defaults.md) ^2.0.1
- [@ndhoule/includes](https://npm.io/package/@ndhoule/includes.md) ^2.0.1
- [component-emitter](https://npm.io/package/component-emitter.md) ^1.2.1
- [@segment/canonical](https://npm.io/package/@segment/canonical.md) ^1.0.0
- [@segment/send-json](https://npm.io/package/@segment/send-json.md) ^3.0.0
- [@segment/top-domain](https://npm.io/package/@segment/top-domain.md) ^3.0.1
- [package-json-versionify](https://npm.io/package/package-json-versionify.md) ^1.0.4
- [@segment/prevent-default](https://npm.io/package/@segment/prevent-default.md) ^1.0.0
- [@segment/isodate-traverse](https://npm.io/package/@segment/isodate-traverse.md) ^1.0.1

## Recent versions

- 4.1.11 (latest) — 2021-04-26
- 4.1.9-beta.0 (beta) — 2021-03-26
- 4.1.10 — 2021-04-14
- 4.1.10-beta.0 — 2021-04-14
- 4.1.9 — 2021-03-26
- 4.1.8 — 2021-03-23
- 4.0.8 — 2021-03-18
- 4.0.7 — 2021-03-18
- 4.0.6 — 2021-03-18
- 4.0.5 — 2021-03-18
- 4.1.7 — 2021-03-17
- 4.1.5 — 2020-09-17
- 4.1.4 — 2020-09-16
- 4.1.3 — 2020-09-16
- 4.1.2 — 2020-09-16
- … 54 more at https://npm.io/package/@segment/analytics.js-core/versions

## README

# analytics.js-core

[![CircleCI](https://circleci.com/gh/segmentio/analytics.js-core.svg?style=shield)](https://circleci.com/gh/segmentio/analytics.js-core)
[![Codecov](https://img.shields.io/codecov/c/github/segmentio/analytics.js-core/master.svg)](https://codecov.io/gh/segmentio/analytics.js-core)

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

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

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

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.

### Importing as an npm module

If you use analytics.js-core as an npm module, you can use its types out of the box:
<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">

### Using types with the AJS Snippet

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

To use types with the snippet, add `analytics` as part of the global module.
Something like this:

```typescript
import { SegmentAnalytics } from '@segment/analytics.js-core';

declare global {
  interface Window {
    analytics: SegmentAnalytics.AnalyticsJS;
  }
}
```

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

[analytics.js]: https://segment.com/docs/libraries/analytics.js/

---
_Source: https://npm.io/package/@segment/analytics.js-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
