Skip to content

Commit 0c2d58f

Browse files
committed
Adding option to exclude administrators from tracking
1 parent ae18a0c commit 0c2d58f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

fathom-analytics.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
const FATHOM_URL_OPTION_NAME = 'fathom_url';
2626
const FATHOM_SITE_ID_OPTION_NAME = 'fathom_site_id';
27+
const FATHOM_ADMIN_TRACKING_OPTION_NAME = 'fathom_track_admin';
2728

2829
/**
2930
* @since 1.0.0
@@ -52,17 +53,29 @@ function fathom_get_site_id() {
5253
return get_option( FATHOM_SITE_ID_OPTION_NAME, '' );
5354
}
5455

56+
/**
57+
* @since 1.0.1
58+
*/
59+
function fathom_get_admin_tracking() {
60+
return get_option( FATHOM_ADMIN_TRACKING_OPTION_NAME, '');
61+
}
62+
5563
/**
5664
* @since 1.0.0
5765
*/
5866
function fathom_print_js_snippet() {
5967
$url = fathom_get_url();
68+
$exclude_admin = fathom_get_admin_tracking();
6069

6170
// don't print snippet if fathom URL is empty
6271
if( empty( $url ) ) {
6372
return;
6473
}
6574

75+
if( empty( $exclude_admin ) && current_user_can('manage_options') ) {
76+
return;
77+
}
78+
6679
$site_id = fathom_get_site_id();
6780

6881
?>
@@ -98,11 +111,14 @@ function fathom_register_settings() {
98111
// register options
99112
register_setting( 'fathom', FATHOM_URL_OPTION_NAME, array( 'type' => 'string' ) );
100113
register_setting( 'fathom', FATHOM_SITE_ID_OPTION_NAME, array( 'type' => 'string' ) );
114+
register_setting( 'fathom', FATHOM_ADMIN_TRACKING_OPTION_NAME, array( 'type' => 'string') );
101115

102116
// register settings fields
103117
add_settings_field( FATHOM_URL_OPTION_NAME, __( 'Dashboard URL', 'fathom-analytics' ), 'fathom_print_url_setting_field', 'fathom-analytics', 'default' );
104118

105119
add_settings_field( FATHOM_SITE_ID_OPTION_NAME, __( 'Site ID', 'fathom-analytics' ), 'fathom_print_site_id_setting_field', 'fathom-analytics', 'default' );
120+
121+
add_settings_field( FATHOM_ADMIN_TRACKING_OPTION_NAME, __('Track Administrators', 'fathom-analytics'), 'fathom_print_admin_tracking_setting_field', 'fathom-analytics', 'default');
106122
}
107123

108124
/**
@@ -138,6 +154,15 @@ function fathom_print_site_id_setting_field( $args = array() ) {
138154
echo '<p class="description">' . __( 'Find your site ID by by clicking the gearwheel in your Fathom dashboard.', 'fathom-analytics' ) . '</p>';
139155
}
140156

157+
/**
158+
* @since 1.0.1
159+
*/
160+
function fathom_print_admin_tracking_setting_field( $args = array() ) {
161+
$value = get_option( FATHOM_ADMIN_TRACKING_OPTION_NAME );
162+
echo sprintf( '<input type="checkbox" name="%s" id="%s" value="1" %s />', FATHOM_ADMIN_TRACKING_OPTION_NAME, FATHOM_ADMIN_TRACKING_OPTION_NAME, checked( 1, $value, false ) );
163+
echo '<p class="description">' . __( 'Check if you want to track visits by administrators', 'fathom-analytics' ) . '</p>';
164+
}
165+
141166
add_action( 'wp_head', 'fathom_print_js_snippet', 50 );
142167

143168
if( is_admin() && ! wp_doing_ajax() ) {

0 commit comments

Comments
 (0)