|
24 | 24 |
|
25 | 25 | const FATHOM_URL_OPTION_NAME = 'fathom_url'; |
26 | 26 | const FATHOM_SITE_ID_OPTION_NAME = 'fathom_site_id'; |
| 27 | +const FATHOM_ADMIN_TRACKING_OPTION_NAME = 'fathom_track_admin'; |
27 | 28 |
|
28 | 29 | /** |
29 | 30 | * @since 1.0.0 |
@@ -52,17 +53,29 @@ function fathom_get_site_id() { |
52 | 53 | return get_option( FATHOM_SITE_ID_OPTION_NAME, '' ); |
53 | 54 | } |
54 | 55 |
|
| 56 | +/** |
| 57 | + * @since 1.0.1 |
| 58 | + */ |
| 59 | +function fathom_get_admin_tracking() { |
| 60 | + return get_option( FATHOM_ADMIN_TRACKING_OPTION_NAME, ''); |
| 61 | +} |
| 62 | + |
55 | 63 | /** |
56 | 64 | * @since 1.0.0 |
57 | 65 | */ |
58 | 66 | function fathom_print_js_snippet() { |
59 | 67 | $url = fathom_get_url(); |
| 68 | + $exclude_admin = fathom_get_admin_tracking(); |
60 | 69 |
|
61 | 70 | // don't print snippet if fathom URL is empty |
62 | 71 | if( empty( $url ) ) { |
63 | 72 | return; |
64 | 73 | } |
65 | 74 |
|
| 75 | + if( empty( $exclude_admin ) && current_user_can('manage_options') ) { |
| 76 | + return; |
| 77 | + } |
| 78 | + |
66 | 79 | $site_id = fathom_get_site_id(); |
67 | 80 |
|
68 | 81 | ?> |
@@ -98,11 +111,14 @@ function fathom_register_settings() { |
98 | 111 | // register options |
99 | 112 | register_setting( 'fathom', FATHOM_URL_OPTION_NAME, array( 'type' => 'string' ) ); |
100 | 113 | register_setting( 'fathom', FATHOM_SITE_ID_OPTION_NAME, array( 'type' => 'string' ) ); |
| 114 | + register_setting( 'fathom', FATHOM_ADMIN_TRACKING_OPTION_NAME, array( 'type' => 'string') ); |
101 | 115 |
|
102 | 116 | // register settings fields |
103 | 117 | add_settings_field( FATHOM_URL_OPTION_NAME, __( 'Dashboard URL', 'fathom-analytics' ), 'fathom_print_url_setting_field', 'fathom-analytics', 'default' ); |
104 | 118 |
|
105 | 119 | 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'); |
106 | 122 | } |
107 | 123 |
|
108 | 124 | /** |
@@ -138,6 +154,15 @@ function fathom_print_site_id_setting_field( $args = array() ) { |
138 | 154 | echo '<p class="description">' . __( 'Find your site ID by by clicking the gearwheel in your Fathom dashboard.', 'fathom-analytics' ) . '</p>'; |
139 | 155 | } |
140 | 156 |
|
| 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 | + |
141 | 166 | add_action( 'wp_head', 'fathom_print_js_snippet', 50 ); |
142 | 167 |
|
143 | 168 | if( is_admin() && ! wp_doing_ajax() ) { |
|
0 commit comments