Skip to content

Commit

Permalink
Yandex Metrika
Browse files Browse the repository at this point in the history
  • Loading branch information
vslinko committed Dec 24, 2016
1 parent da04ef4 commit 5220842
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
7 changes: 4 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ app.use(express.static(path.join(__dirname, 'assets')));
app.get('/', (req, res) => {
const csp = {
'default-src': `'self'`,
'script-src': `'self' https://www.googletagmanager.com https://www.google-analytics.com`,
'script-src': `'self' https://www.google-analytics.com https://mc.yandex.ru`,
'style-src': `'self'`,
'img-src': `'self' https://www.google-analytics.com`,
'img-src': `'self' https://www.google-analytics.com https://mc.yandex.ru`,
'connect-src': `'self' https://mc.yandex.ru`
};

const nonce = (type) => {
Expand All @@ -27,7 +28,7 @@ app.get('/', (req, res) => {

res.set(
'Content-Security-Policy',
`default-src ${csp['default-src']}; script-src ${csp['script-src']}; style-src ${csp['style-src']}; img-src ${csp['img-src']}`
`default-src ${csp['default-src']}; script-src ${csp['script-src']}; style-src ${csp['style-src']}; img-src ${csp['img-src']}; connect-src ${csp['connect-src']}`
);

res.send(html)
Expand Down
29 changes: 28 additions & 1 deletion templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,33 @@ function ga(context) {
script.src = 'https://www.google-analytics.com/analytics.js';
document.getElementsByTagName('script')[0].parentNode.appendChild(script);
})();
</script>`
</script>`
);
}

function ym(context) {
return (
`<script nonce="${context.nonce('script-src')}">
(function() {
window.yandex_metrika_callbacks = [
function() {
try {
window.yaCounter41805634 = new Ya.Metrika({
id: 41805634,
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: true,
});
} catch(e) {}
},
];
var script = document.createElement('script');
script.async = true;
script.src = 'https://mc.yandex.ru/metrika/watch.js';
document.getElementsByTagName('script')[0].parentNode.appendChild(script);
})();
</script>`
);
}

Expand Down Expand Up @@ -68,6 +94,7 @@ module.exports.index = function index(context) {
padding: 32px;
}
</style>
${ym(context)}
${ga(context)}
<meta property="og:title" content="BeerJS Moscow">
<meta property="og:type" content="website">
Expand Down

0 comments on commit 5220842

Please sign in to comment.