0
此代码正在跟踪Google Analytics上的作者综合浏览量。但是,我想通过the_modified_author来跟踪帖子的浏览量。修改Google Analytics自定义维度以跟踪作者的修改作者?
任何人都可以请适应这个代码吗?感谢您的努力。
如果有人能够做到这一点,我只需要跟踪WordPress博客的作者,the_modified_author和类别。如果来自社区的人可以编辑此代码(或提供不同的代码),除了我真正的感谢和赞赏之外,我会从他们的愿望清单中提供高达20美元左右的东西。
加入的functions.php
function google_load_file() {
$this_post = get_queried_object();
$author_id = $this_post->post_author;
$name = get_the_author_meta('display_name', $author_id);
wp_enqueue_script('author-tracking', get_stylesheet_directory_uri() . '/js/google.js', array(), '1.0.0', true);
wp_localize_script('author-tracking', 'author', array('name' => $name));
}
add_action('wp_print_scripts', 'google_load_file');
一个JS为了这个目的
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-12345678-3', 'domain.com');
ga('require', 'displayfeatures');
ga('set', 'dimension1', author.name);
ga('send', 'pageview');
非常感谢Eike Pierstorff。你知道我是否可以将你的代码行添加到我的现有代码中(以跟踪两者),还是应该复制我使用的代码,根据你的代码修改代码,并且在文件中依次编写代码? –
更改两行:$ author_id = $ this_post-> post_author; $ name = get_the_author_meta('display_name',$ author_id);为一行$ name = get_the_modified_author();.根据WordPress的文档,这应该给你你想要的结果。 –
为了跟踪这两个变量(作者和the_modified_author,虽然? –