summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdamGerthel2016-05-20 10:36:32 -0400
committerMaciej Zgadzaj2016-05-20 10:36:32 -0400
commit748c0fcb52fae883b9ca742838d4550de3a8cd03 (patch)
tree8bf52399c96ba45f90306d5b0b886701128e1ded
parentd2ed2682cdc8b84699b6aca088a882baabe63724 (diff)
Issue #2632522 by AdamGerthel: Ability to control Pixel visibility based on user role
-rwxr-xr-xfacebook_pixel.admin.inc14
-rwxr-xr-xfacebook_pixel.module32
2 files changed, 45 insertions, 1 deletions
diff --git a/facebook_pixel.admin.inc b/facebook_pixel.admin.inc
index 5c9935b..37b8612 100755
--- a/facebook_pixel.admin.inc
+++ b/facebook_pixel.admin.inc
@@ -25,5 +25,19 @@ function facebook_pixel_admin_settings_form($form_state) {
'#default_value' => variable_get('facebook_pixel_exclude_admin_paths', 1),
);
+ // Role specific visibility configurations.
+ $roles = user_roles();
+ $role_options = array();
+ foreach ($roles as $rid => $name) {
+ $role_options[$rid] = $name;
+ }
+ $form['facebook_pixel_roles'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Remove Facebook Pixel for specific roles'),
+ '#default_value' => variable_get('facebook_pixel_roles', array()),
+ '#options' => $role_options,
+ '#description' => t('Remove script only for the selected role(s). If none of the roles are selected, all roles will have the Facebook Pixel. Otherwise, any roles selected here will NOT have the script.'),
+ );
+
return system_settings_form($form);
}
diff --git a/facebook_pixel.module b/facebook_pixel.module
index f55dff1..6efbe28 100755
--- a/facebook_pixel.module
+++ b/facebook_pixel.module
@@ -125,7 +125,12 @@ function facebook_pixel_add_event($event) {
* @see facebook_pixel_add_event()
*/
function facebook_pixel_preprocess_page(&$variables) {
- if (variable_get('facebook_pixel_exclude_admin_paths', 1) && path_is_admin(current_path())) {
+ global $user;
+
+ if (
+ variable_get('facebook_pixel_exclude_admin_paths', 1) && path_is_admin(current_path())
+ || !facebook_pixel_user_visibility($user)
+ ) {
return;
}
@@ -216,3 +221,28 @@ function facebook_pixel_data_ViewContent($nid) {
);
return drupal_json_encode($data);
}
+
+/**
+ * Utility function to perform tracking visibility check for a user.
+ *
+ * @param object $user
+ * a user object containing an array of roles to check.
+ * @return boolean
+ * whether or not the current user should be served the pixel.
+ */
+function facebook_pixel_user_visibility($user) {
+ $visible = TRUE;
+ $roles = variable_get('facebook_pixel_roles', array());
+ if (array_sum($roles) > 0) {
+ // One or more roles are selected for tracking.
+ foreach (array_keys($user->roles) as $rid) {
+ // Is the current user a member of a role selected in settings?
+ if (isset($roles[$rid]) && $rid == $roles[$rid]) {
+ // Current user is a member of a role that is selected in settings.
+ $visible = FALSE;
+ break;
+ }
+ }
+ }
+ return $visible;
+}