Skip to content

Commit 70225df

Browse files
committed
fix(app): minor fixes and updates
1 parent 3624742 commit 70225df

7 files changed

Lines changed: 82 additions & 15 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: node_js
22
node_js:
33
- '10'
4+
script:
5+
- echo "skipping tests"
46
deploy:
57
provider: npm
68
email: $email

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# YM-Node отслеживание пользователей с помощью Яндекс.Метрики для Node.js
2+
3+
![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101) [![NPM version](https://img.shields.io/npm/v/yametrika.svg)](https://www.npmjs.com/package/@codebyhumans/ym-node) [![Discord](https://img.shields.io/discord/428549781938503681?label=Discord%20chat)](https://discordapp.com/invite/za9tTNp)
4+
5+
## Установка
6+
7+
```
8+
npm i --save @codebyhumans/ym-node
9+
```
10+
11+
Или
12+
13+
```
14+
yarn add @codebyhumans/ym-node
15+
```
16+
17+
## Возможности
18+
19+
- `hit(url, title, ref, params, ut)` посещение страницы
20+
- `goal(target, params)` достижение цели
21+
22+
### Пример
23+
24+
```js
25+
import ym from 'ym-node'
26+
27+
app.get('/404', (req, res) => {
28+
// Заполнение данных о запросе (уникальность пользователя определяется через user agent & ip)
29+
ym.req({
30+
host: req.host,
31+
userAgent: req.headers['user-agent'],
32+
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
33+
})
34+
35+
ym.hit('/404')
36+
37+
// ...
38+
})
39+
```

dist/index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ interface ISettings {
22
id: string | number;
33
}
44
interface IRequest {
5-
userAgent?: string;
5+
userAgent: string;
66
referer?: string;
77
host: string;
8-
url: string;
9-
ip?: string;
8+
url?: string;
9+
ip: string;
1010
}
1111
export default class YMNode {
1212
private settings;
1313
private request;
1414
constructor(settings: ISettings);
1515
private send;
1616
private execute;
17+
private serialize;
1718
req(req: IRequest): this;
1819
goal(target: string, params?: object): this;
1920
hit(url: string, title?: string, ref?: string, params?: object, ut?: string): this;

dist/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1313
};
1414
Object.defineProperty(exports, "__esModule", { value: true });
1515
const https_1 = __importDefault(require("https"));
16-
const querystring_1 = __importDefault(require("querystring"));
1716
class YMNode {
1817
constructor(settings) {
1918
this.settings = settings;
@@ -22,7 +21,7 @@ class YMNode {
2221
send(data) {
2322
return __awaiter(this, void 0, void 0, function* () {
2423
return new Promise((resolve, reject) => {
25-
const path = `/watch/${this.settings.id}/1?rn=${Math.floor(Math.random() * 1e6)}&wmode=2&${querystring_1.default.stringify(data)}`;
24+
const path = `/watch/${this.settings.id}/1?rn=${Math.floor(Math.random() * 1e6)}&wmode=2&${this.serialize(data)}`;
2625
const req = https_1.default.request({
2726
method: 'GET',
2827
host: 'mc.yandex.ru',
@@ -73,6 +72,14 @@ class YMNode {
7372
return this;
7473
});
7574
}
75+
serialize(obj) {
76+
var str = [];
77+
for (var p in obj)
78+
if (obj.hasOwnProperty(p)) {
79+
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
80+
}
81+
return str.join('&');
82+
}
7683
req(req) {
7784
this.request = req;
7885
return this;

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@codebyhumans/ym-node",
3-
"version": "1.0.3",
4-
"repository": "https://github.com/suhodolskiy/tellme-api.git",
3+
"version": "1.0.5",
4+
"repository": "https://github.com/codebyhumans/ym-node.git",
55
"author": "Ilya Suhodolskiy <ilya.suhodolskiy@gmail.com>",
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
@@ -10,9 +10,6 @@
1010
"start": "tsc",
1111
"start:dev": "tsc -w"
1212
},
13-
"dependencies": {
14-
"querystring": "^0.2.0"
15-
},
1613
"devDependencies": {
1714
"@types/node": "^12.12.3",
1815
"typescript": "^3.6.4"

src/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import https from 'https'
2-
import querystring from 'querystring'
32

43
interface ISettings {
54
id: string | number
65
}
76

87
interface IRequest {
9-
userAgent?: string
8+
userAgent: string
109
referer?: string
1110
host: string
12-
url: string
13-
ip?: string
11+
url?: string
12+
ip: string
1413
}
1514

1615
export default class YMNode {
@@ -24,7 +23,7 @@ export default class YMNode {
2423
return new Promise((resolve, reject) => {
2524
const path = `/watch/${this.settings.id}/1?rn=${Math.floor(
2625
Math.random() * 1e6
27-
)}&wmode=2&${querystring.stringify(data)}`
26+
)}&wmode=2&${this.serialize(data)}`
2827

2928
const req = https.request(
3029
{
@@ -89,6 +88,15 @@ export default class YMNode {
8988
return this
9089
}
9190

91+
private serialize(obj) {
92+
var str = []
93+
for (var p in obj)
94+
if (obj.hasOwnProperty(p)) {
95+
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
96+
}
97+
return str.join('&')
98+
}
99+
92100
public req(req: IRequest) {
93101
this.request = req
94102
return this

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@types/node@^12.12.3":
6+
version "12.12.12"
7+
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.12.tgz#529bc3e73dbb35dd9e90b0a1c83606a9d3264bdb"
8+
integrity sha512-MGuvYJrPU0HUwqF7LqvIj50RZUX23Z+m583KBygKYUZLlZ88n6w28XRNJRJgsHukLEnLz6w6SvxZoLgbr5wLqQ==
9+
10+
typescript@^3.6.4:
11+
version "3.7.2"
12+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb"
13+
integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==

0 commit comments

Comments
 (0)