Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it universal #37

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"inline-package-json",
"transform-class-properties",
"transform-object-rest-spread"
],
],
"env": {
"test": {
"plugins": [
Expand Down
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ engines:
- javascript
eslint:
enabled: true
channel: "eslint-2"
channel: "eslint-3"

ratings:
paths:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[![Build Status](https://travis-ci.org/neiker/analytics-react-native.svg)](https://travis-ci.org/neiker/analytics-react-native) [![Code Climate](https://codeclimate.com/github/neiker/analytics-react-native/badges/gpa.svg)](https://codeclimate.com/github/neiker/analytics-react-native)
[![codecov.io](http://codecov.io/github/neiker/analytics-react-native/coverage.svg?branch=master)](http://codecov.io/github/neiker/analytics-react-native?branch=master)
[![Build Status](https://travis-ci.org/neiker/analytics-universal.svg)](https://travis-ci.org/neiker/analytics-universal) [![Code Climate](https://codeclimate.com/github/neiker/analytics-universal/badges/gpa.svg)](https://codeclimate.com/github/neiker/analytics-universal)
[![codecov.io](http://codecov.io/github/neiker/analytics-universal/coverage.svg?branch=master)](http://codecov.io/github/neiker/analytics-universal?branch=master)

![dependencies](https://david-dm.org/neiker/analytics-react-native.svg)
![dependencies](https://david-dm.org/neiker/analytics-universal.svg)

A React Native client for [Segment](https://segment.com). The hassle-free way to integrate analytics into any application.
A universal javascript client for [Segment](https://segment.com).

This library is based on its node counterpart, [analytics-node](https://github.com/segmentio/analytics-node). Despite being designed to run on react-native, it will also work in browsers (via webpack or browserify) and even in nodejs. You only need to include [fetch](https://github.com/github/fetch) for browsers or [node-fetch](https://github.com/bitinn/node-fetch) for nodejs or io.js.
This library is based on [analytics-node](https://github.com/segmentio/analytics-node) and have the same API, but is re writed to also work in browsers (via webpack or browserify) server side, React Native and NativeScript. You only need to include [fetch](https://github.com/github/fetch) for browsers (check [here](http://caniuse.com/#feat=fetch) if you really need it) or [node-fetch](https://github.com/bitinn/node-fetch) for nodejs or io.js.

## Installation

```bash
npm install analytics-react-native
npm install analytics-universal
```

## Usage

```javascript
import Analytics from 'analytics-react-native';
import Analytics from 'analytics-universal';

const analytics = new Analytics(YOUR_WRITE_KEY);

Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "analytics-react-native",
"version": "1.0.1",
"description": "A React Native client for [Segment](https://segment.com) — The hassle-free way to integrate analytics into any application.",
"name": "analytics-universal",
"version": "1.1.0",
"description": "An universal client for [Segment](https://segment.com). Works in browsers, React Native, NativeScript or nodejs",
"keywords": [
"analytics",
"segment.io",
"segmentio",
"client",
"driver",
"react-native"
"react-native",
"node"
],
"main": "lib/index.js",
"scripts": {
Expand All @@ -23,13 +24,13 @@
},
"repository": {
"type": "git",
"url": "https://github.com/neiker/analytics-react-native.git"
"url": "https://github.com/neiker/analytics-universal.git"
},
"author": "Javier Alvarez <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/neiker/analytics-react-native",
"homepage": "https://github.com/neiker/analytics-universal",
"bugs": {
"url": "https://github.com/neiker/analytics-react-native/issues"
"url": "https://github.com/neiker/analytics-universal/issues"
},
"dependencies": {
"base-64": "0.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export default class Analytics {
message.type = messageType;
message.context = message.context ? { ...message.context } : {};
message.context.library = {
name: 'analytics-react-native',
name: 'analytics-universal',
version: VERSION,
};

Expand All @@ -262,7 +262,7 @@ export default class Analytics {
}

if (!message.messageId) {
message.messageId = `react-native-${uid(32)}`;
message.messageId = `universal-${uid(32)}`;
}

this.queue.push({
Expand Down
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const noop = function noop() {};
const id = 'id';
const context = {
library: {
name: 'analytics-react-native',
name: 'analytics-universal',
version,
},
};
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('Analytics', () => {
analytics.enqueue('type', { event: 'test', context: { name: 'travis' } }, noop);
assert.deepEqual(analytics.queue[0].message.context, {
library: {
name: 'analytics-react-native',
name: 'analytics-universal',
version,
},
name: 'travis',
Expand All @@ -154,7 +154,7 @@ describe('Analytics', () => {

const msg = analytics.queue[0].message;
assert(msg.messageId);
assert(/react-native-[a-zA-Z0-9]{32}/.test(msg.messageId));
assert(/universal-[a-zA-Z0-9]{32}/.test(msg.messageId));
});

it('shouldn\'t change the message id', () => {
Expand Down