关于收集统计的通知
您可以通知您的网站用户将收集统计,并推迟在网站页面上加载 Yandex Metrica 计数器的代码片段。
如果用户同意传输信息,则计数器代码将正常加载。 未经用户同意,将不会加载该代码片段。 用户的一次性选择可以应用于网站或域上的所有其他页面。
要启用警报并实现计数器代码的延迟加载,请联系您的网站管理员。
警报示例
您可以使用任何文本向用户通知统计收集的情况。 以下提供的同意文本仅具有建议性质;Yandex 对其是否符合法律要求不承担责任。 在发布同意文本之前,我们建议您咨询您的律师。
本网站使用 Yandex Metrica 网络分析服务。
[贵网站《使用条款》或《隐私政策》的链接]
实现有关收集统计的警报的示例
代码实现的示例:
...
<head>
<meta charset="UTF-8">
<title>Page title</title>
<!--This example uses the reset.css style. You can use your own approach.-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<!--The example uses the js-cookie library for working with cookies. You can use your own approach-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.2/js.cookie.js"></script>
<style>
* {
box-sizing: border-box;
}
body {
width: 100%;
height: 100%;
}
.cookie-notification {
position: fixed;
background-color: rgba(0, 0, 0, .8);
bottom: 0;
width: 100%;
color: white;
padding: 15px;
}
.cookie-notification_hidden_yes {
display: none;
}
.cookie-notification__header {
margin-bottom: 10px;
font-size: 23px;
}
.cookie-notification__body {
margin-bottom: 10px;
}
</style>
</head>
<body>
Website content
<div class="cookie-notification cookie-notification_hidden_yes">
<div class="cookie-notification__header">We use the Yandex Metrica</div>
<div class="cookie-notification__body">
<p>This website uses the Yandex Metrica web analytics service provided by the Yandex LLC (hereinafter referred to as «Yandex»).</p>
<p>Yandex Metrica uses «cookies», small text files placed on users’ computers to analyze user activity.</p>
<p>Information collected by cookies does not reveal your identity, but it can help us to improve our website performance. Information about your use of this website collected by cookies will be transferred to Yandex and can be stored on Yandex’s servers in the EEA and/or Russia. Yandex will process this information on behalf of the website owner, inter alia, to assess how you use the website, compile reports on your usage of website. Yandex processes this information as specified in the Terms of Use of Yandex Metrica Service.</p>
<p>You can opt out of using cookie files by choosing the corresponding settings in your browser. You can also use the tool https://yandex.com/support/metrica/general/opt-out.html. However, it can affect some website functions. By using this website, you agree that your data can be processed in the above manner and for the above purposes.</p>
</div>
<div class="cookie-notification__buttons">
<button class="cookie-notification__button" id="yes">I agree</button>
</div>
</div>
<script type="text/javascript">
var messageElement = document.querySelector('.cookie-notification');
// If there aren't any cookies, show a placeholder
if (!Cookies.get('agreement')) {
showMessage();
} else {
initCounter();
}
// Load the code snippet immediately
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document,'script','//mc.yandex.ru/metrika/tag.js', 'ym')
// This function adds the class to the DOM element. You can use the jQuery library or another framework
function addClass (o, c) {
var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g");
if (!o || re.test(o.className)) {
return;
}
o.className = (o.className + " " + c).replace(/\s+/g, " ").replace(/(^ | $)/g, "");
}
// This function removes the class from the DOM element. You can use the jQuery library or another framework.
function removeClass (o, c) {
var re = new RegExp('(^|\\s)' + c + '(\\s|$)', 'g');
if (!o) {
return;
}
o.className = o.className.replace(re, '$1').replace(/\s+/g, ' ').replace(/(^ | $)/g, '');
}
// Function that hides the alert.
function hideMessage () {
addClass(messageElement, 'cookie-notification_hidden_yes');
}
// Function that shows the alert.
function showMessage () {
removeClass(messageElement, 'cookie-notification_hidden_yes');
}
function saveAnswer () {
// Hide the alert.
hideMessage();
// Set cookies.
Cookies.set('agreement', '1');
}
function initCounter () {
ym(XXXX, 'init', {});
saveAnswer();
}
// Clicked the "I agree" button.
document.querySelector('#yes').addEventListener('click', function () {
initCounter();
});
</script>
</body>
...
其中
XXXXXX
是您的计数器编号。
实用链接 |
线上培训 |
已复制