Skip to content

Commit

Permalink
Merge pull request #2 from jpreynat/master
Browse files Browse the repository at this point in the history
Adapt plugin to GitBook 3
  • Loading branch information
Dima Kalduzov authored Jun 15, 2016
2 parents b60a8fd + f118476 commit b86f6b5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 38 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a best tracker from Russia! Enjoy it!

### Install

```
```
$ npm install gitbook-plugin-yametrika
```

Expand Down Expand Up @@ -53,6 +53,25 @@ You can customize the tracker object by passing additional configuration options
}
}
```

When using GitBook 3, the whole configuration settings should be set directly in the `"yametrika"` property, using the default configuration for the API:
``` json
{
"plugins": ["yametrika"],
"pluginsConfig": {
"yametrika": {
"id": 11111111,
"webvisor": true,
"clickmap": true,
"trackLinks": true,
"accurateTrackBounce": true,
"trackHash": true,
"ut": "noindex"
}
}
}
```

Available for customize options:
- Webvisor (Вебвизор)
- Clickmap (Карта кликов)
Expand All @@ -69,7 +88,7 @@ default track options status:

- Webvisor (Вебвизор) - **false** (!new)
- Clickmap (Карта кликов) - **false** (!new)
- TrackLinks (Внешние ссылки, загрузки файлов и отчёт по кнопке «Поделиться») - **false** (!new)
- TrackLinks (Внешние ссылки, загрузки файлов и отчёт по кнопке «Поделиться») - **false** (!new)
- AccurateTrackBounce (Точный показатель отказов) - **false** (!new)
- Informer (Информер) - **false**
- Ut (Запрет на индексацию страниц) - **false**
Expand Down
33 changes: 33 additions & 0 deletions _layouts/website/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends template.self %}

{% block javascript %}
{{ super() }}
<script type='text/javascript'>
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
try {
w.yaCounter{{ config.pluginsConfig.yametrika.id }} = new Ya.Metrika({{ config.pluginsConfig.yametrika|dump|safe }});
} catch(e) { }
});
var n = d.getElementsByTagName('script')[0],
s = d.createElement('script'),
f = function () {
n.parentNode.insertBefore(s, n);
};

s.type = 'text/javascript';
s.async = true;
s.src = (d.location.protocol == 'https:' ? 'https:' : 'http:') + '//mc.yandex.ru/metrika/watch.js';
if (w.opera == '[object Opera]') {
d.addEventListener('DOMContentLoaded', f, false);
} else {
f();
}
})(document, window, 'yandex_metrika_callbacks');
</script>
<noscript>
<div>
<img src="//mc.yandex.ru/watch/{{ config.pluginsConfig.yametrika.id }}" style="position:absolute; left:-9999px;" alt=""/>
</div>
</noscript>
{% endblock %}
36 changes: 1 addition & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,6 @@ module.exports = {
assets: "./book",
js: [
"plugin.js"
],
html: {
"body:end": function() {
var config = this.options.pluginsConfig.yametrika || {},
settings = "";

if (!config.number) {
throw "Need to option 'number' for Yandex Metrika plugin";
}

if(typeof config.settings === 'object' && config.settings !== null) {

for (option in config.settings) {

if (typeof config.settings[option] !== 'string') {

settings += ", " + option + ":" + config.settings[option];

} else {

settings += ", " + option + ":'" + config.settings[option] + "'";
}
}
}

return "<script type='text/javascript'>(function (d, w, c) { (w[c] = w[c] || []).push(function() { try { "
+ "w.yaCounter" + config.number + " = new Ya.Metrika({id:" + config.number + settings + "});"
+ " } catch(e) { } }); var n = d.getElementsByTagName('script')"
+ "[0], s = d.createElement('script'), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "
+ "'text/javascript'; s.async = true; s.src = (d.location.protocol == 'https:' ? 'https:' : 'http:') + "
+ "'//mc.yandex.ru/metrika/watch.js'; if (w.opera == '[object Opera]') { d.addEventListener('DOMContentLoaded'"
+ ", f, false); } else { f(); } })(document, window, 'yandex_metrika_callbacks');</script><noscript><div><img "
+ "src='//mc.yandex.ru/watch/" + config.number + "' style='position:absolute; left:-9999px;' alt=''/></div></noscript>";
}
}
]
}
};
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
"metrika"
],
"author": "mikaspell",
"license": "MIT"
"license": "MIT",
"gitbook": {
"properties": {
"id": {
"type": "number",
"description": "Yandex Metrika tracking ID",
"required": true
}
}
}
}

0 comments on commit b86f6b5

Please sign in to comment.