修改Google Analytics自定义维度以跟踪作者的_modified_author?

时间:2015-05-27 22:23:03

标签: google-analytics

此代码用于跟踪Google Analytics上的作者综合浏览量。但是,我想通过the_modified_author跟踪帖子的综合浏览量。

任何人都可以为此调整代码吗?感谢您的任何努力。

如果有人能够做到这一点,我只需要跟踪WordPress博客的Author,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');

1 个答案:

答案 0 :(得分:0)

如果您在google_load_file函数中使用get_the_modified_author()函数,它将返回上次修改帖子的作者的显示名称。至少是函数的描述:

  

检索上次编辑当前帖子的作者。

     

返回值:作者的显示名称。

function google_load_file() {
$this_post = get_queried_object();        
$name = get_the_modified_author();

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 ) );
}

我认为这只会出现在单个帖子的模板中。