Compare commits

..

No commits in common. "master" and "v1.0.3" have entirely different histories.

24 changed files with 411 additions and 1285 deletions

View File

@ -1,147 +1,63 @@
# gitzone standard # gitzone standard
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-node:npmts
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages: stages:
- security
- test - test
- release - release
- metadata - trigger
- pages
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLEGACY: testLEGACY:
stage: test stage: test
script: script:
- npmci npm prepare - npmci test legacy
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
allow_failure: true allow_failure: true
testLTS: testLTS:
stage: test stage: test
script: script:
- npmci npm prepare - npmci test lts
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testSTABLE: testSTABLE:
stage: test stage: test
script: script:
- npmci npm prepare - npmci test stable
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci publish
- npmci npm publish
only: only:
- tags - tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags: tags:
- docker - docker
- notpriv
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: pages
script:
- npmci command npmpage --publish gitlab
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@ -1,16 +1,13 @@
# smartanalytics # smartanalytics
Google Analytics everywhere Google Analytics everywhere
## Availabililty ## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartanalytics) [![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartanalytics)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartanalytics) [![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartanalytics)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartanalytics) [![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartanalytics)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartanalytics/) [![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartanalytics/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/smartanalytics/badges/master/build.svg)](https://GitLab.com/pushrocks/smartanalytics/commits/master) [![build status](https://GitLab.com/pushrocks/smartanalytics/badges/master/build.svg)](https://GitLab.com/pushrocks/smartanalytics/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartanalytics/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartanalytics/commits/master) [![coverage report](https://GitLab.com/pushrocks/smartanalytics/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartanalytics/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartanalytics.svg)](https://www.npmjs.com/package/smartanalytics) [![npm downloads per month](https://img.shields.io/npm/dm/smartanalytics.svg)](https://www.npmjs.com/package/smartanalytics)
@ -22,39 +19,24 @@ Google Analytics everywhere
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
### Why does this package exist? ### Why does this package exist?
Tracking users in webapps is common. We use Google Analytics to gain insight in who is using what
Tracking users in webapps is common, often to gain insight in who is using what and where to spend dev resources for best efficiency. and where to spend resources for best efficiency.
Doing the same stuff in apps can be a bit of a hassle. Doing the same stuff in apps can be a bit of a hassle.
Unnecessary dependencies used by many existing analytics tools make the whole app slow Unnecessary dependencies used by many existing analytics tools make the whole app slow
just to gain a little usage info. just to gain a little usage info.
Say hello to smartanalytics.
**Say hello to smartanalytics. :)** It features a very slim dependency tree using the native node request module to send posts to Google Analytics.
It features a very slim dependency tree using the native node request module to send posts to a tracking API of your choice.
### How do I use this package? ### How do I use this package?
```javascript ```javascript
import { Analytics } from 'smartanalytics'; import {AnalyticsAccount} from 'smartanalytics'
let myAnalytics = new plugins.smartanalytics.Analytics({ let myAnalyticsAccount = new AnalyticsAccount('My App Name', 'UA-XXXXXX-Y')
apiEndPoint: 'https://somepubapi.endpoint.com', myAnalyticsAccount.sendEvent('npmtool', 'install', 'somelabel')
projectId: 'gitzone',
appName: 'npmts'
});
myAnalytics
.recordEvent('someEvent', {
myKey1: 'myValue1',
myKey2: 'myValue2',
myDataKey3: 3
})
.catch(err => {
console.log(err);
});
``` ```
For further information read the linked docs at the top of this README. For further information read the linked docs at the top of this README.

1
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export { AnalyticsAccount } from './smartanalytics.classes.analyticsaccount';

4
dist/index.js vendored Normal file
View File

@ -0,0 +1,4 @@
"use strict";
var smartanalytics_classes_analyticsaccount_1 = require("./smartanalytics.classes.analyticsaccount");
exports.AnalyticsAccount = smartanalytics_classes_analyticsaccount_1.AnalyticsAccount;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEscUdBQTRFO0FBQW5FLHFFQUFBLGdCQUFnQixDQUFBIn0=

View File

@ -0,0 +1,6 @@
export declare class AnalyticsAccount {
appName: string;
trackingId: string;
constructor(appNameArg: string, trackingIdArg: string);
sendEvent(eventCategoryArg: any, eventActionArg: any, eventLabelArg: string): void;
}

View File

@ -0,0 +1,13 @@
"use strict";
const send = require("./smartanalytics.send");
class AnalyticsAccount {
constructor(appNameArg, trackingIdArg) {
this.appName = appNameArg;
this.trackingId = trackingIdArg;
}
sendEvent(eventCategoryArg, eventActionArg, eventLabelArg) {
send.event(this.trackingId, this.appName, eventCategoryArg, eventActionArg, eventLabelArg);
}
}
exports.AnalyticsAccount = AnalyticsAccount;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhbmFseXRpY3MuY2xhc3Nlcy5hbmFseXRpY3NhY2NvdW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhbmFseXRpY3MuY2xhc3Nlcy5hbmFseXRpY3NhY2NvdW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFDQSw4Q0FBNkM7QUFFN0M7SUFHRSxZQUFZLFVBQWtCLEVBQUUsYUFBcUI7UUFDbkQsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUE7UUFDekIsSUFBSSxDQUFDLFVBQVUsR0FBRyxhQUFhLENBQUE7SUFDakMsQ0FBQztJQUVELFNBQVMsQ0FBRSxnQkFBZ0IsRUFBRSxjQUFjLEVBQUUsYUFBcUI7UUFDaEUsSUFBSSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsVUFBVSxFQUFFLElBQUksQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsY0FBYyxFQUFFLGFBQWEsQ0FBQyxDQUFBO0lBQzVGLENBQUM7Q0FDRjtBQVhELDRDQVdDIn0=

4
dist/smartanalytics.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
import 'typings-global';
import * as smartrequest from 'smartrequest';
import * as smartq from 'smartq';
export { smartrequest, smartq };

7
dist/smartanalytics.plugins.js vendored Normal file
View File

@ -0,0 +1,7 @@
"use strict";
require("typings-global");
const smartrequest = require("smartrequest");
exports.smartrequest = smartrequest;
const smartq = require("smartq");
exports.smartq = smartq;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhbmFseXRpY3MucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0YW5hbHl0aWNzLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qiw2Q0FBNEM7QUFJeEMsb0NBQVk7QUFIaEIsaUNBQWdDO0FBSTVCLHdCQUFNIn0=

1
dist/smartanalytics.send.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare let event: (trackingIdArg: string, appNameArg: string, eventCategoryArg: string, eventActionArg: any, eventLabelArg?: string) => void;

29
dist/smartanalytics.send.js vendored Normal file
View File

@ -0,0 +1,29 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const plugins = require("./smartanalytics.plugins");
exports.event = (trackingIdArg, appNameArg, eventCategoryArg, eventActionArg, eventLabelArg = 'null') => {
let payload = 'v=1' +
`&tid=${trackingIdArg}` +
'&cid=555' +
'&aip=1' +
'&t=event' +
`&ec=${eventCategoryArg}` +
`&ea=${eventActionArg}` +
`&el=${eventLabelArg}` +
'&ev=300' +
`&an=${eventLabelArg}`;
send(payload);
};
let send = (requestBodyArg) => __awaiter(this, void 0, void 0, function* () {
yield plugins.smartrequest.post('https://www.google-analytics.com/collect', {
requestBody: requestBodyArg
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhbmFseXRpY3Muc2VuZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0YW5hbHl0aWNzLnNlbmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsb0RBQW1EO0FBRXhDLFFBQUEsS0FBSyxHQUFHLENBQUMsYUFBcUIsRUFBRSxVQUFrQixFQUFFLGdCQUF3QixFQUFFLGNBQWMsRUFBRSxnQkFBd0IsTUFBTTtJQUNuSSxJQUFJLE9BQU8sR0FBVyxLQUFLO1FBQ3ZCLFFBQVEsYUFBYSxFQUFFO1FBQ3ZCLFVBQVU7UUFDVixRQUFRO1FBQ1IsVUFBVTtRQUNWLE9BQU8sZ0JBQWdCLEVBQUU7UUFDekIsT0FBTyxjQUFjLEVBQUU7UUFDdkIsT0FBTyxhQUFhLEVBQUU7UUFDdEIsU0FBUztRQUNULE9BQU8sYUFBYSxFQUFFLENBQUE7SUFDMUIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFBO0FBQ2pCLENBQUMsQ0FBQTtBQUdELElBQUksSUFBSSxHQUFHLENBQU8sY0FBc0I7SUFDcEMsTUFBTSxPQUFPLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQywwQ0FBMEMsRUFBRTtRQUN4RSxXQUFXLEVBQUUsY0FBYztLQUM5QixDQUFDLENBQUE7QUFDTixDQUFDLENBQUEsQ0FBQSJ9

19
license
View File

@ -1,19 +0,0 @@
Copyright (c) 2018 Lossless GmbH (hello@lossless.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,7 +1,7 @@
{ {
"npmts": {},
"npmci": { "npmci": {
"npmGlobalTools": [], "globalNpmTools": [
"npmAccessLevel": "public" "npmts"
]
} }
} }

1046
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,21 @@
{ {
"name": "@push.rocks/smartanalytics", "name": "smartanalytics",
"version": "2.0.15", "version": "1.0.3",
"private": false,
"description": "Google Analytics everywhere", "description": "Google Analytics everywhere",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(npmts)"
"build": "(tsbuild)"
}, },
"author": "Lossless GmbH", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^2.0.5", "smartq": "^1.1.1",
"@pushrocks/smartrequest": "^1.1.14" "smartrequest": "^1.0.4",
"typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "smartchai": "^1.0.3",
"@gitzone/tstest": "^1.0.15", "typings-test": "^1.0.3"
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
} }
} }

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

31
test/test.js Executable file
View File

@ -0,0 +1,31 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
require("typings-test");
const smartanalytics = require("../dist/index");
let testAccount;
describe('smartanalytics', function () {
it('should create a valid AnalyticsAccount', function () {
testAccount = new smartanalytics.AnalyticsAccount('smartanalytics', 'UA-92592300-1');
});
it('should send a request to Google Analytics', function () {
let doit = () => __awaiter(this, void 0, void 0, function* () {
yield testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq');
yield testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics');
yield testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq');
yield testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics');
yield testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq');
yield testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics');
yield testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq');
yield testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics');
});
doit();
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsd0JBQXFCO0FBSXJCLGdEQUErQztBQUUvQyxJQUFJLFdBQTRDLENBQUE7QUFFaEQsUUFBUSxDQUFDLGdCQUFnQixFQUFFO0lBQ3pCLEVBQUUsQ0FBQyx3Q0FBd0MsRUFBRTtRQUMzQyxXQUFXLEdBQUcsSUFBSSxjQUFjLENBQUMsZ0JBQWdCLENBQUMsZ0JBQWdCLEVBQUUsZUFBZSxDQUFDLENBQUE7SUFDdEYsQ0FBQyxDQUFDLENBQUE7SUFFRixFQUFFLENBQUMsMkNBQTJDLEVBQUU7UUFDOUMsSUFBSSxJQUFJLEdBQUc7WUFDVCxNQUFNLFdBQVcsQ0FBQyxTQUFTLENBQUMsU0FBUyxFQUFFLFNBQVMsRUFBRSxrQkFBa0IsQ0FBQyxDQUFBO1lBQ3JFLE1BQU0sV0FBVyxDQUFDLFNBQVMsQ0FBQyxTQUFTLEVBQUUsU0FBUyxFQUFFLDBCQUEwQixDQUFDLENBQUE7WUFDN0UsTUFBTSxXQUFXLENBQUMsU0FBUyxDQUFDLFNBQVMsRUFBRSxTQUFTLEVBQUUsa0JBQWtCLENBQUMsQ0FBQTtZQUNyRSxNQUFNLFdBQVcsQ0FBQyxTQUFTLENBQUMsU0FBUyxFQUFFLFNBQVMsRUFBRSwwQkFBMEIsQ0FBQyxDQUFBO1lBQzdFLE1BQU0sV0FBVyxDQUFDLFNBQVMsQ0FBQyxTQUFTLEVBQUUsU0FBUyxFQUFFLGtCQUFrQixDQUFDLENBQUE7WUFDckUsTUFBTSxXQUFXLENBQUMsU0FBUyxDQUFDLFNBQVMsRUFBRSxTQUFTLEVBQUUsMEJBQTBCLENBQUMsQ0FBQTtZQUM3RSxNQUFNLFdBQVcsQ0FBQyxTQUFTLENBQUMsU0FBUyxFQUFFLFNBQVMsRUFBRSxrQkFBa0IsQ0FBQyxDQUFBO1lBQ3JFLE1BQU0sV0FBVyxDQUFDLFNBQVMsQ0FBQyxTQUFTLEVBQUUsU0FBUyxFQUFFLDBCQUEwQixDQUFDLENBQUE7UUFDL0UsQ0FBQyxDQUFBLENBQUE7UUFDRCxJQUFJLEVBQUUsQ0FBQTtJQUNSLENBQUMsQ0FBQyxDQUFBO0FBQ0osQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -1,27 +1,27 @@
import { expect, tap } from '@pushrocks/tapbundle'; import 'typings-test'
import * as smartanalytics from '../ts/index'; import { expect } from 'smartchai'
let testAnalytics: smartanalytics.Analytics; import * as smartanalytics from '../dist/index'
tap.test('should create a valid AnalyticsAccount', async () => { let testAccount: smartanalytics.AnalyticsAccount
testAnalytics = new smartanalytics.Analytics({
projectId: 'sandbox',
appName: 'smartanalytics',
apiEndPoint: 'https://pubapi.lossless.one/analytics'
});
});
tap.test('should send a request to Lossless API endpoint', async () => { describe('smartanalytics', function () {
let doit = async () => { it('should create a valid AnalyticsAccount', function () {
await testAnalytics.recordEvent('sandbox', { testAccount = new smartanalytics.AnalyticsAccount('smartanalytics', 'UA-92592300-1')
trackingPurpose: 'test' })
});
await testAnalytics.recordEvent('sandbox', {
someValue: 'someData'
});
};
doit();
});
tap.start(); it('should send a request to Google Analytics', function () {
let doit = async () => {
await testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq')
await testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics')
await testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq')
await testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics')
await testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq')
await testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics')
await testAccount.sendEvent('npmtool', 'install', 'pushrocks/smartq')
await testAccount.sendEvent('npmtool', 'started', 'pushrocks/smartanalytics')
}
doit()
})
})

View File

@ -1 +1 @@
export { Analytics } from './smartanalytics.classes.analytics'; export { AnalyticsAccount } from './smartanalytics.classes.analyticsaccount'

View File

@ -1,41 +0,0 @@
import * as plugins from './smartanalytics.plugins';
export class Analytics {
public projectId: string;
public appName: string;
public apiEndPoint: string;
public secretKey: string = '';
constructor(optionsArg: {
projectId: string;
appName: string;
apiEndPoint: string;
secretKey?: string;
}) {
this.projectId = optionsArg.projectId;
this.appName = optionsArg.appName;
this.apiEndPoint = optionsArg.apiEndPoint;
if (optionsArg.secretKey) {
this.secretKey = optionsArg.secretKey;
}
}
async recordEvent(eventIdArg: string, analyticsDataArg: any) {
let dataToSend = {
projectId: this.projectId,
appName: this.appName,
eventId: eventIdArg,
analyticsData: analyticsDataArg
};
await plugins.smartrequest
.postJson(this.apiEndPoint, {
headers: {
authenticate: this.secretKey,
'Content-Type': 'application/json'
},
requestBody: dataToSend
})
.catch(err => {
console.log(err);
});
}
}

View File

@ -0,0 +1,15 @@
import * as plugins from './smartanalytics.plugins'
import * as send from './smartanalytics.send'
export class AnalyticsAccount {
appName: string
trackingId: string
constructor(appNameArg: string, trackingIdArg: string) {
this.appName = appNameArg
this.trackingId = trackingIdArg
}
sendEvent (eventCategoryArg, eventActionArg, eventLabelArg: string) {
send.event(this.trackingId, this.appName, eventCategoryArg, eventActionArg, eventLabelArg)
}
}

View File

@ -1,4 +1,8 @@
import * as smartrequest from '@pushrocks/smartrequest'; import 'typings-global'
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartrequest from 'smartrequest'
import * as smartq from 'smartq'
export { smartrequest, smartpromise }; export {
smartrequest,
smartq
}

22
ts/smartanalytics.send.ts Executable file
View File

@ -0,0 +1,22 @@
import * as plugins from './smartanalytics.plugins'
export let event = (trackingIdArg: string, appNameArg: string, eventCategoryArg: string, eventActionArg, eventLabelArg: string = 'null') => {
let payload: string = 'v=1' +
`&tid=${trackingIdArg}` + // the tracking ID
'&cid=555' +
'&aip=1' + // anonymize the IP
'&t=event' +
`&ec=${eventCategoryArg}` +
`&ea=${eventActionArg}` +
`&el=${eventLabelArg}` +
'&ev=300' +
`&an=${eventLabelArg}`
send(payload)
}
let send = async (requestBodyArg: string) => {
await plugins.smartrequest.post('https://www.google-analytics.com/collect', {
requestBody: requestBodyArg
})
}

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}

198
yarn.lock Executable file
View File

@ -0,0 +1,198 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/chai-as-promised@0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-0.0.29.tgz#43d52892aa998e185a3de3e2477edb8573be1d77"
dependencies:
"@types/chai" "*"
"@types/promises-a-plus" "*"
"@types/chai-string@^1.1.30":
version "1.1.30"
resolved "https://registry.yarnpkg.com/@types/chai-string/-/chai-string-1.1.30.tgz#4d8744b31a5a2295fc01c981ed1e2d4c8a070f0a"
dependencies:
"@types/chai" "*"
"@types/chai@*", "@types/chai@^3.4.35":
version "3.4.35"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-3.4.35.tgz#e8d65f83492d2944f816fc620741821c28a8c900"
"@types/mocha@^2.2.31":
version "2.2.39"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.39.tgz#f68d63db8b69c38e9558b4073525cf96c4f7a829"
"@types/promises-a-plus@*":
version "0.0.27"
resolved "https://registry.yarnpkg.com/@types/promises-a-plus/-/promises-a-plus-0.0.27.tgz#c64651134614c84b8f5d7114ce8901d36a609780"
assertion-error@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"
balanced-match@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
brace-expansion@^1.0.0:
version "1.1.6"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.6.tgz#7197d7eaa9b87e648390ea61fc66c84427420df9"
dependencies:
balanced-match "^0.4.1"
concat-map "0.0.1"
chai-as-promised@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-6.0.0.tgz#1a02a433a6f24dafac63b9c96fa1684db1aa8da6"
dependencies:
check-error "^1.0.2"
chai-string@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/chai-string/-/chai-string-1.3.0.tgz#df6139f294391b1035be5606f60a843b3a5041e7"
chai@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"
dependencies:
assertion-error "^1.0.1"
deep-eql "^0.1.3"
type-detect "^1.0.0"
check-error@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
deep-eql@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2"
dependencies:
type-detect "0.1.1"
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
glob@^7.0.0:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.2"
once "^1.3.0"
path-is-absolute "^1.0.0"
inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
dependencies:
once "^1.3.0"
wrappy "1"
inherits@2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
interpret@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.1.tgz#d579fb7f693b858004947af39fa0db49f795602c"
minimatch@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
dependencies:
brace-expansion "^1.0.0"
once@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
dependencies:
wrappy "1"
path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
dependencies:
resolve "^1.1.6"
resolve@^1.1.6:
version "1.2.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.2.0.tgz#9589c3f2f6149d1417a40becc1663db6ec6bc26c"
semver@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
shelljs@^0.7.4:
version "0.7.6"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.6.tgz#379cccfb56b91c8601e4793356eb5382924de9ad"
dependencies:
glob "^7.0.0"
interpret "^1.0.0"
rechoir "^0.6.2"
smartchai@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/smartchai/-/smartchai-1.0.3.tgz#de6d010bb8b5aef24cb70b31a5f5334e8c41b72f"
dependencies:
"@types/chai" "^3.4.35"
"@types/chai-as-promised" "0.0.29"
"@types/chai-string" "^1.1.30"
chai "^3.5.0"
chai-as-promised "^6.0.0"
chai-string "^1.3.0"
smartq@^1.1.0, smartq@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.1.tgz#efb358705260d41ae18aef7ffd815f7b6fe17dd3"
dependencies:
typed-promisify "^0.3.0"
typings-global "^1.0.14"
smartrequest@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/smartrequest/-/smartrequest-1.0.4.tgz#86af2163ae28f1031b01c2d8ad8c429733920611"
dependencies:
smartq "^1.1.0"
typings-global "^1.0.14"
type-detect@0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822"
type-detect@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"
typed-promisify@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/typed-promisify/-/typed-promisify-0.3.0.tgz#1ba0af5e444c87d8047406f18ce49092a1191853"
typings-global@*, typings-global@^1.0.14:
version "1.0.14"
resolved "https://registry.yarnpkg.com/typings-global/-/typings-global-1.0.14.tgz#ab682720a03d6b9278869fb5c30c30d7dc61d12c"
dependencies:
semver "^5.3.0"
shelljs "^0.7.4"
typings-test@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/typings-test/-/typings-test-1.0.3.tgz#fbab895eb3f0c44842e73db059f65946b971e369"
dependencies:
"@types/mocha" "^2.2.31"
typings-global "*"
wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"