我需要从分析报告中过滤内部质量检查人员。有条件地加载谷歌分析
目前,我们在我们的网站代码,显示/隐藏信息的div如果游客是“学生”的角色:
$(document).ready(function(){
if($.inArray('student',ENV['current_user_roles']) === 1 && $.inArray('student',ENV['current_user_roles']) === 1){
if ($.inArray('teacher',ENV['current_user_roles']) == -1){
paramArray = window.location.href.split('/');
if (paramArray.indexOf('assignments') == -1 && paramArray.indexOf('settings') == -1 && paramArray.indexOf('grades') == -1 && paramArray.indexOf('quizzes') == -1 && paramArray.indexOf('users') == -1){
var l = $('#right-side-wrapper a.edit_link.button.button-sidebar-wide');
if(l===null || l.length===0){
$('body').removeClass('with-right-side');
}
}
}
}
});
我不是很精通JavaScript的,但它好像有应该是一个简单的方式重新使用此代码,但包裹谷歌分析里面的跟踪代码,只加载它,如果用户是角色的“学生:”
$(document).ready(function(){
if($.inArray('student',ENV['current_user_roles']) === 1 && $.inArray('student',ENV['current_user_roles']) === 1){
if ($.inArray('teacher',ENV['current_user_roles']) == -1){
var _gaq=[["_setAccount","UA-xxxxxxxx-1"],["_trackPageview"]];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));
}
}
});
我尝试了上面的基础上,我在互联网上看到的[https://gist.github.com/benbalter/902140],但是这个实现并没有有意识地滤除非学生。
有什么建议吗?