text 在WP中添加GA和Yandex.Metrika
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 在WP中添加GA和Yandex.Metrika相关的知识,希望对你有一定的参考价值。
<?php
// Counters
add_action('wp_footer', function () {
$yandexCode = '?????';
$googleCode = '??-ddddddd-d';
$prodMode = !(defined('WP_DEBUG') && WP_DEBUG);
?>
<!-- Yandex.Metrika counter -->
<script type="text/javascript">
function yaInitAfterPageLoad() {
var d = document, w = window, c = "yandex_metrika_callbacks";
yaCounter = w[c] = undefined;
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
try {
w.yaCounter<?= $yandexCode ?> = new Ya.Metrika({
id:<?= $yandexCode ?>,
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
trackHash:true,
webvisor:false
});
} 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 = "https://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="https://mc.yandex.ru/watch/<?= $yandexCode ?>" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
<!-- Google analytics -->
<script type="text/javascript">
function gaInitAfterPageLoad() {
ga = undefined;
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '<?= $googleCode ?>', 'auto');
ga('send', 'pageview');
}
</script>
<!-- Google analytics -->
<?php if ($prodMode): ?>
<script type="text/javascript">
function skyninLoadCounters() {
setTimeout(function() {
if (document.getElementById('wpadminbar') ||
(document.getElementsByClassName &&
document.getElementsByClassName('logged-in').length)) return;
gaInitAfterPageLoad();
yaInitAfterPageLoad();
}, 100);
if(window.addEventListener) window.removeEventListener('load',skyninLoadCounters,false); //W3C
else window.detachEvent('onload',skyninLoadCounters); //IE
}
if(window.addEventListener) window.addEventListener('load',skyninLoadCounters,false); //W3C
else window.attachEvent('onload',skyninLoadCounters); //IE
</script>
<?php
endif;
});
以上是关于text 在WP中添加GA和Yandex.Metrika的主要内容,如果未能解决你的问题,请参考以下文章
text 在WP管理栏中隐藏Yoast SEO。添加到功能。
text 添加wp支持svg
text WP =添加新的自定义程序部分(字段)
text js-将placeholdertext添加到wp用户字段
text 如果本地不存在,则从实时域上传 - 必须添加到wp-content / uploads / .htaccess
text 如果用户未登录,则仅显示维护模式。将maintenance.php文件添加到wp-content文件夹以自定义维护页面。