templates
3 years ago
ga-accounts-selector.php
4 years ago
ga-auth-button.php
3 years ago
ga-code.php
4 years ago
ga-dashboard-widget.php
4 years ago
ga-debug-modal.php
4 years ago
ga-ga4-settings.php
3 years ago
ga-googleanalytics-loader.php
4 years ago
ga-notice.php
3 years ago
ga-oauth-notice.php
4 years ago
ga-wp-notice.php
4 years ago
old-page.php
3 years ago
page.php
3 years ago
statistics.php
3 years ago
stats.php
3 years ago
trending.php
4 years ago
ga-ga4-settings.php
291 lines
| 1 | <?php |
| 2 | $ga4_exclude_roles = true === is_array( $ga4_exclude_roles ) ? $ga4_exclude_roles : array(); |
| 3 | $ga_admin = new Ga_Admin(); |
| 4 | $auth_info = $ga_admin->getGa4AuthInfo(); |
| 5 | ?> |
| 6 | <script type="text/javascript"> |
| 7 | const GA_NONCE = '<?php echo esc_js( $ga_nonce ); ?>'; |
| 8 | const GA_NONCE_FIELD = 'ga4-setup'; |
| 9 | </script> |
| 10 | <div class="settings-wrap setup-wrap<?php echo true === $setup_done ? ' hide' : ''; ?>"> |
| 11 | <div class="ga-step ga-step-1<?php echo false === $has_code && false === $has_property ? ' engage' : ''; ?>"> |
| 12 | <div class="ga-steps"> |
| 13 | 1 of 3 |
| 14 | <div class="ga-dots"><span class="dark-green">•</span> • •</div> |
| 15 | </div> |
| 16 | <h2>Setup Google Authentication</h2> |
| 17 | <p>Use our configuration wizard to properly setup Google Analytics with WordPress (with just a few clicks).</p> |
| 18 | <a id="google-auth-link" href="<?php echo esc_url( $auth_info['auth_url'] ); ?>"> |
| 19 | <img src="<?php echo esc_url( plugins_url() ) . '/googleanalytics/assets/images/Google-logo.svg'; ?>" alt="Google Logo">Sign in with Google |
| 20 | </a> |
| 21 | </div> |
| 22 | <div class="ga-step ga-step-2<?php echo false !== $has_code && false === $has_property ? ' engage' : ''; ?>"> |
| 23 | <div class="ga-steps"> |
| 24 | 2 of 3 |
| 25 | <div class="ga-dots">• <span class="dark-green">•</span> •</div> |
| 26 | </div> |
| 27 | <h2>Select Account Property</h2> |
| 28 | <p>Choose the view you want to use for your reports.</p> |
| 29 | <label for="ga4-property"> |
| 30 | <select id="ga4-property"> |
| 31 | <option>Choose Property</option> |
| 32 | <?php |
| 33 | foreach ( $auth_info['properties'] as $account => $properties ) : |
| 34 | if ( false === empty( $properties ) ) : |
| 35 | ?> |
| 36 | <option disabled><?php echo esc_html( $account ); ?>:</option> |
| 37 | <?php |
| 38 | foreach ( $properties as $property ) : |
| 39 | // Only add UA properties with default profile IDs. |
| 40 | if ( true === isset( $property['id'] ) && |
| 41 | false !== strpos( $property['id'], 'UA-' ) && |
| 42 | false === isset( $property['defaultProfileId'] ) |
| 43 | ) { |
| 44 | continue; |
| 45 | } |
| 46 | ?> |
| 47 | <option data-view-id="<?php echo isset( $property['defaultProfileId'] ) ? esc_attr( $property['defaultProfileId'] ) : ''; ?>" value="<?php echo isset( $property['defaultProfileId'] ) ? 'properties/' . esc_attr( $property['internalWebPropertyId'] ) : esc_attr( $property['name'] ); ?>"> |
| 48 | <?php echo isset( $property['displayName'] ) ? esc_html( $property['displayName'] ) : esc_html( $property['name'] ); ?> |
| 49 | </option> |
| 50 | <?php |
| 51 | endforeach; |
| 52 | endif; |
| 53 | endforeach; |
| 54 | ?> |
| 55 | </select> |
| 56 | </label> |
| 57 | <a id="to-step-3">Next</a> |
| 58 | </div> |
| 59 | <div class="ga-step ga-step-3<?php echo false === $setup_done && false !== $has_code && false !== $has_property ? ' engage' : ''; ?>"> |
| 60 | <div class="ga-steps"> |
| 61 | 3 of 3 |
| 62 | <div class="ga-dots">• • <span class="dark-green">•</span></div> |
| 63 | </div> |
| 64 | <div class="extra-settings"> |
| 65 | <h2>Settings</h2> |
| 66 | <div class="ga-row"> |
| 67 | <div class="ua-dual-settings"> |
| 68 | <div class="ga-ua-col"> |
| 69 | <h2>If using Google Optimize, enter optimize code here</h2> |
| 70 | <label> |
| 71 | <input id="ga4-google-optimize" type="text" placeholder="GMT-XXXXXX" value=""> |
| 72 | </label> |
| 73 | |
| 74 | <h2>Exclude Tracking for Roles</h2> |
| 75 | <div class="ga-exclude-roles"> |
| 76 | <div class="switch"> |
| 77 | <label class="item"> |
| 78 | <input type="checkbox" value="administrator"> |
| 79 | <span class="lever"></span> |
| 80 | Administrator |
| 81 | </label> |
| 82 | </div> |
| 83 | <div class="switch"> |
| 84 | <label class="item"> |
| 85 | <input type="checkbox" value="contributor"> |
| 86 | <span class="lever"></span> |
| 87 | Contributor |
| 88 | </label> |
| 89 | </div> |
| 90 | <div class="switch"> |
| 91 | <label class="item"> |
| 92 | <input type="checkbox" value="editor"> |
| 93 | <span class="lever"></span> |
| 94 | Editor |
| 95 | </label> |
| 96 | </div> |
| 97 | <div class="switch"> |
| 98 | <label class="item"> |
| 99 | <input type="checkbox" value="subscriber"> |
| 100 | <span class="lever"></span> |
| 101 | Subscriber |
| 102 | </label> |
| 103 | </div> |
| 104 | <div class="switch"> |
| 105 | <label class="item"> |
| 106 | <input type="checkbox" value="author"> |
| 107 | <span class="lever"></span> |
| 108 | Author |
| 109 | </label> |
| 110 | </div> |
| 111 | </div> |
| 112 | </div> |
| 113 | <div class="ga-ua-col"> |
| 114 | <div class="switch"> |
| 115 | <label class="item"> |
| 116 | Enable Demographics |
| 117 | <input id="ga4-enable-demo" type="checkbox"> |
| 118 | <span class="lever"></span> |
| 119 | </label> |
| 120 | </div> |
| 121 | <div class="switch"> |
| 122 | <label class="item"> |
| 123 | Enable IP Anonymization |
| 124 | <input type="checkbox" id="ga4-enable-ip-anon"> |
| 125 | <span class="lever"></span> |
| 126 | </label> |
| 127 | </div> |
| 128 | <div class="switch"> |
| 129 | <label class="item"> |
| 130 | Enable GDPR Consent Management Tool |
| 131 | <input type="checkbox" id="ga4-enable-gdpr"> |
| 132 | <span class="lever"></span> |
| 133 | </label> |
| 134 | </div> |
| 135 | </div> |
| 136 | </div> |
| 137 | </div> |
| 138 | <a id="complete-ga4-setup" class="green-button" href="<?php echo esc_url( get_admin_url() ); ?>admin.php?page=googleanalytics">Complete and go to dashboard</a> |
| 139 | </div> |
| 140 | </div> |
| 141 | </div> |
| 142 | |
| 143 | <?php if (true === $setup_done) : ?> |
| 144 | <div style="margin-top: 0;<?php echo true === $setup_done ? '' : ' display: none;'; ?>" class="ga4_container ga_container"> |
| 145 | <?php if ( false === empty( $data['error_message'] ) ) : ?> |
| 146 | <?php echo wp_kses_post( $data['error_message'] ); ?> |
| 147 | <?php endif; ?> |
| 148 | <h1>Settings</h1> |
| 149 | <form id="ga4_form" method="post" action="options.php"> |
| 150 | <?php settings_fields( 'googleanalyticsga4' ); ?> |
| 151 | <table class="form-table"> |
| 152 | <tr> |
| 153 | <?php if ( false === empty( $data['popup_url'] ) ) : ?> |
| 154 | <th scope="row"> |
| 155 | <label class="<?php echo esc_attr( false === Ga_Helper::are_features_enabled() ? 'label-grey ga-tooltip"' : '' ); ?>"> |
| 156 | <?php esc_html_e( 'Google Profile' ); ?>: |
| 157 | <span class="ga-tooltiptext ga-tt-abs"><?php echo esc_html( $tooltip ); ?></span> |
| 158 | </label> |
| 159 | </th> |
| 160 | <?php endif; ?> |
| 161 | </tr> |
| 162 | <?php if ( false === empty( $auth_info['properties'] ) ) : ?> |
| 163 | <tr> |
| 164 | <td> |
| 165 | <select id="ga_account_selector" name="googleanalytics-ga4-property"> |
| 166 | <option>Please select your Google Analytics account:</option> |
| 167 | <?php |
| 168 | foreach ( $auth_info['properties'] as $account => $properties ) : |
| 169 | if ( false === empty( $properties ) ) : |
| 170 | ?> |
| 171 | <option disabled><?php echo esc_html( $account ); ?>:</option> |
| 172 | <?php |
| 173 | foreach ( $properties as $property ) : |
| 174 | // Only add UA properties with default profile IDs. |
| 175 | if ( true === isset( $property['id'] ) && |
| 176 | false !== strpos( $property['id'], 'UA-' ) && |
| 177 | false === isset( $property['defaultProfileId'] ) |
| 178 | ) { |
| 179 | continue; |
| 180 | } |
| 181 | |
| 182 | $property_name = isset( $property['defaultProfileId'] ) ? 'properties/' . esc_attr( $property['internalWebPropertyId'] ) : esc_attr( $property['name'] ); |
| 183 | ?> |
| 184 | <option data-view-id="<?php echo isset( $property['defaultProfileId'] ) ? esc_attr( $property['defaultProfileId'] ) : ''; ?>" value="<?php echo esc_attr( $property_name ); ?>" <?php echo $property_name === $has_property ? 'selected' : ''; ?>> |
| 185 | <?php echo isset( $property['displayName'] ) ? esc_html( $property['displayName'] ) : esc_html( $property['name'] ); ?> |
| 186 | </option> |
| 187 | <?php |
| 188 | endforeach; |
| 189 | endif; |
| 190 | endforeach; |
| 191 | ?> |
| 192 | </select> |
| 193 | </td> |
| 194 | <td> |
| 195 | <button id="ga4_sign_out" class="button-secondary" type="button"> |
| 196 | <?php esc_html_e( 'Sign out', 'googleanalytics' ); ?> |
| 197 | </button> |
| 198 | </td> |
| 199 | </tr> |
| 200 | <?php endif; ?> |
| 201 | <tr id="ga_roles_wrapper"> |
| 202 | <th scope="row"> |
| 203 | <label class="<?php echo esc_attr( false === Ga_Helper::are_features_enabled() ? 'label-grey ga-tooltip' : '' ); ?>"> |
| 204 | <?php esc_html_e( 'Exclude Tracking for Roles' ); ?> |
| 205 | : |
| 206 | <span class="ga-tooltiptext ga-tt-abs"><?php echo esc_html( $tooltip ); ?></span> |
| 207 | </label> |
| 208 | </th> |
| 209 | </tr> |
| 210 | <tr> |
| 211 | <td> |
| 212 | <?php |
| 213 | if ( false === empty( $data['roles'] ) && true === is_array( $ga4_exclude_roles ) ) { |
| 214 | $roles = $data['roles']; |
| 215 | foreach ( $roles as $role_item ) { |
| 216 | $role_id = true === isset( $role_item['id'] ) ? $role_item['id'] : ''; |
| 217 | $role_name = true === isset( $role_item['name'] ) ? $role_item['name'] : ''; |
| 218 | ?> |
| 219 | <div class="checkbox"> |
| 220 | <label class="ga_checkbox_label <?php echo esc_attr( false === Ga_Helper::are_features_enabled() ? 'label-grey ga-tooltip' : '' ); ?>" |
| 221 | for="checkbox_<?php echo esc_attr( $role_id ); ?>"> |
| 222 | <input id="checkbox_<?php echo esc_attr( $role_id ); ?>" type="checkbox" |
| 223 | <?php echo disabled( false === Ga_Helper::are_features_enabled() ); ?> |
| 224 | name="googleanalytics-ga4-exclude-roles[<?php echo esc_attr( str_replace( 'role-id-', '', $role_id ) ); ?>]" |
| 225 | id="<?php echo esc_attr( $role_id ); ?>" |
| 226 | <?php echo esc_attr( ( true === in_array( str_replace( 'role-id-', '', $role_id ), array_keys( $ga4_exclude_roles ), true ) ? 'checked="checked"' : '' ) ); ?> /> |
| 227 | <?php echo esc_html( $role_name ); ?> |
| 228 | <span class="ga-tooltiptext"><?php echo esc_html( $tooltip ); ?></span> |
| 229 | </label> |
| 230 | </div> |
| 231 | <?php |
| 232 | } |
| 233 | } |
| 234 | ?> |
| 235 | </td> |
| 236 | </tr> |
| 237 | <tr> |
| 238 | <th scope="row"><?php esc_html_e( 'Enable IP Anonymization' ); ?>:</th> |
| 239 | </tr> |
| 240 | <tr> |
| 241 | <td> |
| 242 | <label class="ga-switch <?php echo esc_attr( false === Ga_Helper::are_features_enabled() ? 'label-grey ga-tooltip' : '' ); ?>"> |
| 243 | <?php if ( true === Ga_Helper::are_features_enabled() ) : ?> |
| 244 | <input id="ga-anonymization" name="googleanalytics-ga4-ip-anon" |
| 245 | type="checkbox" <?php echo checked( $ga4_ip, 'on' ); ?>> |
| 246 | |
| 247 | <div id="ga-slider" class="ga-slider round"></div> |
| 248 | <?php else : ?> |
| 249 | <input id="ga-anonymization" name="googleanalytics-ga4-ip-anon" |
| 250 | type="checkbox" disabled="disabled"> |
| 251 | |
| 252 | <div id="ga-slider" class="ga-slider round"></div> |
| 253 | <span class="ga-tooltiptext ga-tt-abs"><?php echo esc_html( $tooltip ); ?></span> |
| 254 | <?php endif; ?> |
| 255 | </label> |
| 256 | </td> |
| 257 | </tr> |
| 258 | <tr> |
| 259 | <td> |
| 260 | <input name="googleanalytics-ga4-demo" value="<?php echo esc_attr( $ga4_demo ); ?>" type="hidden"> |
| 261 | </td> |
| 262 | </tr> |
| 263 | <tr> |
| 264 | <th scope="row"><?php esc_html_e( 'If using Google Optimize, enter optimize code here', 'googleanalytics' ); ?>:</th> |
| 265 | </tr> |
| 266 | <tr> |
| 267 | <td> |
| 268 | <label class="ga-text <?php echo esc_attr( false === Ga_Helper::are_features_enabled() ? 'label-grey ga-tooltip' : '' ); ?>"> |
| 269 | <?php if ( true === Ga_Helper::are_features_enabled() ) : ?> |
| 270 | <input id="ga-optimize" name="googleanalytics-ga4-optimize" |
| 271 | type="text" placeholder="GTM-XXXXXX" |
| 272 | value="<?php echo esc_attr( $ga4_optimize ); ?>"> |
| 273 | <?php else : ?> |
| 274 | <input id="ga-optimize" name="googleanalytics-ga4-optimize" |
| 275 | type="text" placeholder="GTM-XXXXXX" |
| 276 | value="<?php echo esc_attr( $ga4_optimize ); ?>" readonly> |
| 277 | <span class="ga-tooltiptext ga-tt-abs"><?php echo esc_html( $tooltip ); ?></span> |
| 278 | <?php endif; ?> |
| 279 | </label> |
| 280 | </td> |
| 281 | </tr> |
| 282 | <?php require $plugin_dir . 'templates/gdpr.php'; ?> |
| 283 | </table> |
| 284 | |
| 285 | <p class="submit"> |
| 286 | <input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes' ); ?>"/> |
| 287 | </p> |
| 288 | </form> |
| 289 | </div> |
| 290 | <?php endif; ?> |
| 291 |