4.1.11 • Published 3 years ago

@segment/analytics.js-core v4.1.11

Weekly downloads
19,651
License
SEE LICENSE IN LI...
Repository
github
Last release
3 years ago

analytics.js-core

CircleCI Codecov

This is the core of Analytics.js, the open-source library that powers data collection at Segment.

To build this into a full, usable library, see the 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:

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

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

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

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

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

4.1.11

3 years ago

4.1.10

3 years ago

4.1.10-beta.0

3 years ago

4.1.9-beta.0

3 years ago

4.1.9

3 years ago

4.1.8

3 years ago

4.0.5

3 years ago

4.0.7

3 years ago

4.0.6

3 years ago

4.0.8

3 years ago

4.1.7

3 years ago

4.1.5

4 years ago

4.1.4

4 years ago

4.1.3

4 years ago

4.1.2

4 years ago

4.1.1-beta

4 years ago

4.1.0

4 years ago

4.1.1

4 years ago

4.1.1-beta1

4 years ago

4.0.4

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

4.0.0-beta.1

4 years ago

3.13.9

4 years ago

3.13.8

4 years ago

3.13.7

4 years ago

3.13.6

4 years ago

3.13.4

4 years ago

3.13.5

4 years ago

3.13.4-beta.1

4 years ago

3.13.4-beta.0

4 years ago

3.13.2

4 years ago

3.13.3

4 years ago

3.13.1

4 years ago

3.13.0

4 years ago

3.12.4

4 years ago

3.11.4

4 years ago

3.11.2

4 years ago

3.11.1-dev.0

4 years ago

3.11.0

4 years ago

3.10.1

4 years ago

3.10.0

4 years ago

3.9.1

4 years ago

3.9.0

5 years ago

3.8.2

5 years ago

3.8.1

5 years ago

3.8.0

5 years ago

3.7.2

6 years ago

3.6.0

6 years ago

3.6.0-alpha.2

6 years ago

3.6.0-alpha

6 years ago

3.5.2

6 years ago

3.5.1

6 years ago

3.5.0

6 years ago

3.4.1

6 years ago

3.4.0

6 years ago

3.3.0

6 years ago

3.2.7

6 years ago

3.2.6

6 years ago

3.2.5

6 years ago

3.2.3

6 years ago

3.2.2

6 years ago

3.1.3

6 years ago

3.1.2

6 years ago

3.1.1

6 years ago

3.0.0

8 years ago