在wordpress上跟踪内部用户 [英] Tracking internal users on wordpress

查看:114
本文介绍了在wordpress上跟踪内部用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个内部WordPress网站,大约有25个用户。我们目前的Google分析设置会告诉我们一次访问过多少次网页,但是因为每个人都来自同一个IP地址,所以它认为它基本上是一个非常勤奋的人点击了很多。



有没有人有跟踪个人用户的策略?



(它们都是根据我们的单点登录登录WordPress的。)

解决方案

您可以使用 _setCustomVar 方法从 JavaScript API 中提供当前用户的用户名。据我所知,没有用于Wordpress的GA插件支持这一点,所以您需要将跟踪代码直接放入主题中或为其编写自定义插件。自定义变量将在Google Analytics中显示为细分受众群。要获取当前用户,您可以使用 wp_get_current_user API调用



您的跟踪代码将如下所示:

 <?php 
if (is_user_logged_in()){
$ user = wp_get_current_user();
$ userName = $ user-> user_login;
}
?>
< script type =text / javascript>

var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-XXXXX-Y']);
<?php if(isset($ userName)):?>
_gaq.push(['_ setCustomVar',1,'Username',<?php echo(json_encode($ userName));?> ;, 1]);
<?php endif; ?>
_gaq.push(['_ trackPageview']);

(function(){
var ga = document.createElement('script'); ga.type ='text / javascript'; ga.async = true;
ga .src =('https:'== document.location.protocol?'https:// ssl':'http:// www')+'.google-analytics.com / ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga,s);
})();
< / script>

对于Universal Analytics版本

 <?php 
if(is_user_logged_in()){
$ user = wp_get_current_user();
$ userName = $ user-> user_login;
}
?>
< script>
(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','UA-XXXX-1','auto');
<?php if(isset($ userName)):?>
ga('set','userId',<?php echo(json_encode($ userName));?>); //使用已登录的user_id设置用户ID。
<?php endif; ?>
ga('send','pageview');
< / script>


We have an internal WordPress site, and about 25 users. Our current Google analytics set-up will show us how many times a page has been visited, but because everyone comes from the same IP address it thinks that it is basically one very industrious person clicking a lot.

Does anyone have a strategy for tracking individual users?

(They are all logged into WordPress as a function of our single sign on.)

解决方案

You can use the _setCustomVar method from the JavaScript API to provide the user name of the current user. To my knowledge no GA plugins for Wordpress support this, so you will need to put your tracking code directly into the theme or write a custom plugin for it. The custom variable will then show up as a segment in Google Analytics. To get the current user you can use the wp_get_current_user API call.

Your tracking code would then look something like this:

<?php
    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        $userName = $user->user_login;
    }
?>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-Y']);
<?php if (isset($userName)) : ?>
  _gaq.push(['_setCustomVar', 1, 'Username', <?php echo(json_encode($userName)); ?>, 1]);
<?php endif; ?>
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

For the Universal Analytics version:

<?php
    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        $userName = $user->user_login;
    }
?>
<script>
    (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', 'UA-XXXX-1', 'auto');
    <?php if (isset($userName)) : ?>
        ga('set', 'userId', <?php echo(json_encode($userName)); ?>); // Set the user ID using signed-in user_id.
    <?php endif; ?>
    ga('send', 'pageview');
</script>

这篇关于在wordpress上跟踪内部用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆