I need to filter internal QA people out of our analytics reporting.
We currently have code in our site that shows/hides an information div if the visitor is of the 'student' role:
$(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');
}
}
}
}
});
I am not well-versed in JavaScript, but it seems like there should be a simple way to re-use this code, but wrap the google analytics tracking code inside, and only load it if the user is of the role 'student:'
$(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"));
}
}
});
I tried the above, based on what I saw around the internet [ https://gist.github.com/benbalter/902140 ], but this implementation did not successfully filter out non-students.
Any advice?