{"id":21361254,"url":"https://github.com/bem-contrib/stat-counters","last_synced_at":"2025-07-13T02:32:12.905Z","repository":{"id":30169648,"uuid":"33719999","full_name":"bem-contrib/stat-counters","owner":"bem-contrib","description":"The library, which provides statistics counters, e.g. Google analytics, Yandex metrica, etc","archived":false,"fork":false,"pushed_at":"2018-08-08T12:20:20.000Z","size":59,"stargazers_count":18,"open_issues_count":7,"forks_count":8,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-11T14:50:01.961Z","etag":null,"topics":["bem","counter","google-analytics","google-tag-manager","statcounter","yandex-metrika"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bem-contrib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-10T09:21:50.000Z","updated_at":"2024-01-18T14:15:27.000Z","dependencies_parsed_at":"2022-08-28T05:50:07.846Z","dependency_job_id":null,"html_url":"https://github.com/bem-contrib/stat-counters","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem-contrib%2Fstat-counters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem-contrib%2Fstat-counters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem-contrib%2Fstat-counters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem-contrib%2Fstat-counters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bem-contrib","download_url":"https://codeload.github.com/bem-contrib/stat-counters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225850243,"owners_count":17534067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bem","counter","google-analytics","google-tag-manager","statcounter","yandex-metrika"],"created_at":"2024-11-22T06:09:08.961Z","updated_at":"2024-11-22T06:09:09.452Z","avatar_url":"https://github.com/bem-contrib.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Statistics counters BEM library\n[![Build Status](https://travis-ci.org/bem-contrib/stat-counters.svg)](https://travis-ci.org/bem-contrib/stat-counters)\n[![Coverage Status](https://coveralls.io/repos/bem-contrib/stat-counters/badge.svg)](https://coveralls.io/r/bem-contrib/stat-counters)\n\nA library for web analytics that provides site statistics counters to any BEM-based project.\n\n## Blocks inside\n  - [yandex-metrica](#yandex-metrica) — uses [Yandex.Metrica](https://metrica.yandex.com) service.\n  - [google-tag-manager](#google-tag-manager) — uses [Google Tag Manager](https://www.google.com/tagmanager/) service.\n  - [google-analytics](#google-analytics) — uses [Google Analytics](https://www.google.com/analytics) service.\n  - [statcounter](#statcounter) — uses [StatCounter](http://statcounter.com/) service.\n\n## Get the library:\n\nvia bower:\n\n```sh\n$ bower install bem-stat-counters --save\n```\n\nvia npm:\n\n```sh\n$ npm install https://github.com/bem-contrib/stat-counters.git --save\n```\n\n## How to use\n\nInclude the library to the levels declaration in your compiler tool configuration (e.g. [ENB](https://github.com/enb-make/enb) or [bem-tools](https://ru.bem.info/tools/bem/bem-tools/)):\n\n*ENB example*\n```js\nfunction getLevels(config) {\n    return [\n        // vendors levels\n        {\n            path: 'vendors/bem-stat-counters/common.blocks',\n            check: false\n        },\n        // your own levels\n    ].map(function(levelPath) { return config.resolvePath(levelPath); });\n}\n```\n\n*bem-tools example*\n```js\nexports.getConfig = function() {\n\n    return extend({}, this.__base() || {}, {\n\n        bundleBuildLevels: this.resolvePaths([\n            // vendors levels\n            'vendors/stat-counters/common.blocks'\n            // your own levels\n        ])\n\n    });\n\n};\n```\n\n*bem-tools example if you use [bem-project-stub](https://github.com/bem/project-stub)*\n```js\ngetLevelsMap: function() {\n   return {\n       desktop: [\n            // vendors levels\n            'vendors/stat-counters/common.blocks'\n            // your own levels\n       ]\n   };\n}\n```\n\nDeclare a counter in your project BEMJSON:\n\n```js\n{\n    block: 'footer',\n    content: [\n        // smth content,\n        {\n            block: 'yandex-metrica',\n            params: {\n                id: '0000000',\n                webvisor: true,\n                clickmap: true,\n                trackLinks: true,\n                accurateTrackBounce: true,\n                v2: true\n            }\n        }\n    ]\n}\n```\n\n## How to declare blocks\n### yandex-metrica\n\nSet the following parameters of the block:\n\n* `id` — required\n* `webvisor` — optional\n* `clickmap` — optional\n* `trackLinks` — optional\n* `accurateTrackBounce` — optional\n* `v2` — optional\n\n*Example*\n```js\n{\n    block: 'yandex-metrica',\n    params: {\n        id: '0000000', // required param\n        webvisor: true,\n        clickmap: true,\n        trackLinks: true,\n        accurateTrackBounce: true,\n        v2: true\n    }\n}\n```\n\n### google-tag-manager\n\nSet the following parameters of the block:\n\n* `id` — required\n\n*Example*\n```js\n{\n    block: 'google-tag-manager',\n    params: {\n        id: 'GTM-XXXX'\n    }\n}\n```\n\n### google-analytics\n\nSet the following parameters of the block:\n\n* `id` — required\n\n*Example*\n```js\n{\n    block: 'google-analytics',\n    params: {\n        id: 'UA-XXXXXXXX-X'\n    }\n}\n```\n\nAlso the block has a simple API to track custom user events on page. Click [here](https://github.com/bem-contrib/stat-counters/blob/master/common.blocks/google-analytics/google-analytics.en.md) to learn more.\n\n### statcounter\n\nSet the following parameters of the block:\n\n* `id` — required\n* `security` — required\n\nSupport only invisible mode.\n\n*Example*\n```js\n{\n    block: 'statcounter',\n    params: {\n        project: XXXXXXXX,\n        security: 'YYYYYYYY'\n    }\n}\n```\n\n## Content Security Policy (CSP) support\n\nYou can use counters even if your web server has CSP settings which forbid inline scripts using. In this case you should provide the same value of the `nonce`-parameter in the CSP http header and the html attribute for inline script.\n\n*Example*\n\n1) CSP header\n```\nContent-Security-Policy:\n ...\n script-src 'nonce-FOO'\n ...\n```\n\n2) counter block declaration\n```js\n{\n    block: 'google-analytics', // or any another block of the library\n    params: {\n        id: 'UA-XXXXXXXX-X'\n    },\n    nonce: 'FOO'\n}\n```\n\n## License\n\nMIT [License](https://github.com/bem-contrib/stat-counters/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbem-contrib%2Fstat-counters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbem-contrib%2Fstat-counters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbem-contrib%2Fstat-counters/lists"}