Socket
Socket
Sign inDemoInstall

@segment/analytics.js-core

Package Overview
Dependencies
49
Maintainers
154
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0-beta.1 to 4.0.0

.idea/analytics.js-core.iml

12

build/analytics.js

@@ -39,3 +39,3 @@ 'use strict';

var prevent = require('@segment/prevent-default');
var querystring = require('component-querystring');
var qs = require('query-string');
var store = require('./store');

@@ -727,3 +727,3 @@ var user = require('./user');

// Parse querystring to an object
var q = querystring.parse(query);
var q = qs.parse(query);
// Create traits and properties objects, populate from querysting params

@@ -747,12 +747,12 @@ var traits = pickPrefix('ajs_trait_', q);

*/
function pickPrefix(prefix, object) {
function pickPrefix(prefix, queryString) {
var length = prefix.length;
var sub;
return foldl(function (acc, val, key) {
return Object.keys(queryString).reduce(function (acc, key) {
if (key.substr(0, length) === prefix) {
sub = key.substr(length);
acc[sub] = val;
acc[sub] = queryString[key];
}
return acc;
}, {}, object);
}, {});
}

@@ -759,0 +759,0 @@ };

@@ -0,13 +1,16 @@

# 4.0.0 / 2020-08-20
4.0.0-beta.1 / 2020-07-30
=========================
- Drop beta release
- TypeScript 4
* export interfaces
* fix importing types issues
# 4.0.0-beta.1 / 2020-07-30
3.13.8 / 2020-07-29
===================
- export interfaces
- fix importing types issues
* Add --declaration back to build scripts
* Publish v3.13.7 (#176)
# 3.13.8 / 2020-07-29
- Add --declaration back to build scripts
- Publish v3.13.7 (#176)
# 3.13.7 / 2020-07-29

@@ -14,0 +17,0 @@

{
"name": "@segment/analytics.js-core",
"author": "Segment <friends@segment.com>",
"version": "4.0.0-beta.1",
"version": "4.0.0",
"description": "The hassle-free way to integrate analytics into any web application.",

@@ -92,7 +92,6 @@ "types": "lib/index.d.ts",

"karma-browserify": "^5.0.4",
"karma-chrome-launcher": "^1.0.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^1.0.0",
"karma-junit-reporter": "^1.0.0",
"karma-mocha": "1.0.1",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.0.0",

@@ -106,3 +105,2 @@ "karma-spec-reporter": "0.0.26",

"np": "^3.0.4",
"phantomjs-prebuilt": "^2.1.7",
"prettier-eslint-cli": "^4.7.1",

@@ -114,3 +112,3 @@ "proclaim": "^3.4.1",

"ts-node": "^8.10.2",
"typescript": "^3.9.7",
"typescript": "^4.0.2",
"wait-on": "^5.0.1",

@@ -117,0 +115,0 @@ "watchify": "^3.7.0"

@@ -6,16 +6,76 @@ # analytics.js-core

This is the core of [Analytics.js][], the open-source library that powers data collection at [Segment](https://segment.com).
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
## Using Types (v.4.0.0-beta.0 and later)
We've 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.
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 leverage its types out of the box:
<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">
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

@@ -22,0 +82,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc