简体   繁体   English

WordPress登录跟踪Google Analytics(分析)

[英]Wordpress Login Tracking Google Analytics

I have o track this code whit a custom variable in Google Analytics, the code is of wordpress site and check if user is logged in or not. 我已经在Google Analytics(分析)中使用自定义变量跟踪了此代码,该代码是wordpress网站的代码,并检查用户是否登录。 The specific code is inside this: http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/pluggable.php#L716 具体代码在其中: http : //core.trac.wordpress.org/browser/tags/3.6/wp-includes/pluggable.php#L716

The portion of code to track is: 要跟踪的代码部分是:

function is_user_logged_in() {
    $user = wp_get_current_user();

    if ( ! $user->exists() )
        return false;

    return true;
}

When the condition logged_in is satisfied i have to push to Analytics a custom variable: 满足条件login_in时,我必须将一个自定义变量推送至Google Analytics(分析):

_gaq.push(['_setCustomVar',
      1,             
     'User Type', 
     'Member',      
      2
   ]);

where do I insert the analytics code (this is based on session) to make it shoot only when the condition "logged in" is satisfied? 我应该在哪里插入分析代码(基于会话),使其仅在满足“登录”条件时才拍摄?

There might be a way to do this in your plugin (depends on the plugin), but assuming the Analytics code is added in the header, you could add the following just before </head> in header.php : 在您的插件中可能有一种方法(取决于插件),但是假设在标头中添加了Analytics代码,则可以在header.php </head>之前添加以下内容:

<?php if (is_user_logged_in()) { ?>
    <script type="text/javascript">
        _gaq.push(['_setCustomVar',
            1,             
            'User Type', 
            'Member',      
            2
        ]);
    </script>
<?php } ?>

It's untested, but it should do the trick. 它未经测试,但可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM