Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
IPRIT committed Feb 16, 2019
0 parents commit bc4ce89
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
node_modules/
.vscode/
npm-debug.log
.idea/
coverage/
report.html
.vs/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Change Log
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @rabota/analytics-layer
[![npm](https://img.shields.io/npm/dt/@rabota/analytics-layer.svg?style=flat-square)](https://www.npmjs.com/package/@rabota/analytics-layer)
[![npm (scoped with tag)](https://img.shields.io/npm/v/@rabota/analytics-layer/latest.svg?style=flat-square)](https://www.npmjs.com/package/@rabota/analytics-layer)
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src';
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@rabota/analytics-layer",
"version": "0.0.1",
"license": "MIT",
"repository": "https://github.com/RabotaRu/analytics-layer",
"homepage": "https://github.com/RabotaRu/analytics-layer/tree/master",
"publishConfig": {
"access": "public"
},
"main": "index.js"
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './yandex-layer';
105 changes: 105 additions & 0 deletions src/layer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
export class Layer {

/**
* @type {string}
* @private
*/
_provider = '';

/**
* @type {string}
* @private
*/
_layerName = '';

/**
* @type {Array<string|number>}
* @private
*/
_counters = [];

/**
* @param {Array<string|number>} counters
*/
constructor (counters = []) {
this._counters = counters;
}

/**
* @param {string} provider
*/
setProvider (provider) {
this._provider = provider;
}

/**
* @param {string} layerName
*/
setLayer (layerName) {
this._layerName = layerName;
}

/**
* @param {Array<string|number>} counters
*/
setCounters (counters = []) {
this._counters = counters;
}

/**
* @param {*} args
*/
pushAll (...args) {
for (let i = 0; i < this._counters.length; ++i) {
this.pushTo( this._counters[ i ], ...args );
}
}

/**
* @param {string|number} counterId
* @param {*} args
* @abstract
*/
pushTo (counterId, ...args) {
}

/**
* @param {*} args
*/
push (...args) {
if (typeof window === 'undefined') {
return;
}

this._log( ...args );

window[ this._layerName ]( ...args );
}

/**
* @return {string}
*/
get provider () {
return this._provider;
}

/**
* @param args
* @private
*/
_log (...args) {
console.log(
`[Analytic service: ${this._capitalize(this._provider)}]`,
...args
);
}

/**
* @param {string} text
* @return {string}
* @private
*/
_capitalize (text) {
return text[ 0 ].toUpperCase() + text.substr( 1 );
}
}
24 changes: 24 additions & 0 deletions src/yandex-layer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Layer } from "./layer";

export class YandexLayer extends Layer {

static YANDEX_LAYER_KEY = 'ym';

/**
* @param {Array<number>} counters
*/
constructor (counters) {
super( counters );

this.setLayer( YandexLayer.YANDEX_LAYER_KEY );
this.setProvider( 'yandex' );
}

/**
* @param {number} counterId
* @param {*} args
*/
pushTo (counterId, ...args) {
this.push( counterId, ...args );
}
}

0 comments on commit bc4ce89

Please sign in to comment.