Skip to content

Commit 7ab49cc

Browse files
authored
Merge pull request #72 from xwp/fix/71
Fix `ga_id` when using UI settings
2 parents 5955747 + 0243d3f commit 7ab49cc

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ All contributions are welcome! Please create [an issue](https://github.com/xwp/s
9999

100100
### Changelog
101101

102+
#### 1.1.6 - May 18, 2022
103+
104+
- Fix GA not tracking bug when using the UI.
105+
102106
#### 1.1.5 - March 17, 2022
103107

104108
- Adding TTFB.

php/src/class-plugin.php

+25
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ protected function register_hooks() {
9191
* Load only for modern browsers
9292
*/
9393
add_filter( 'script_loader_tag', array( $this, 'optimize_scripts' ), 10, 2 );
94+
95+
/**
96+
* Update and validate settings before updating
97+
*/
98+
add_filter( 'pre_update_option_spt_settings', array( $this, 'pre_update_option' ), 10, 1 );
9499
}
95100

96101
/**
@@ -222,4 +227,24 @@ public function optimize_scripts( $tag, $handle ) {
222227

223228
return $tag;
224229
}
230+
231+
/**
232+
* Filter the spt_settings options before updated
233+
*
234+
* @param array $value The new, unserialized option value.
235+
* @return array $value
236+
*/
237+
public function pre_update_option( $value ) {
238+
if ( isset( $value['analytics_types'] ) && 'ga_id' == $value['analytics_types'] ) {
239+
$value['ga_id'] = $value['gtag_id'];
240+
unset( $value['gtag_id'] );
241+
}
242+
243+
if ( isset( $value['analytics_types'] ) && 'ga4' == $value['analytics_types'] ) {
244+
$value['ga4_id'] = $value['gtag_id'];
245+
unset( $value['gtag_id'] );
246+
}
247+
248+
return $value;
249+
}
225250
}

php/views/settings.php

+5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ function analytics_id_render() {
145145
global $tracker_config;
146146
$set = false;
147147
$prop = 'gtag_id';
148+
149+
if ( isset( $options['ga_id'] ) ) {
150+
$options['gtag_id'] = $options['ga_id'];
151+
}
152+
148153
if ( isset( $tracker_config['ga_id'] ) ) {
149154
$options['gtag_id'] = $tracker_config['ga_id'];
150155
$prop = 'ga_id';

site-performance-tracker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Plugin Name: Site Performance Tracker
99
* Plugin URI: https://github.com/xwp/site-performance-tracker
1010
* Description: Allows you to detect and track site performance metrics.
11-
* Version: 1.1.5
11+
* Version: 1.1.6
1212
* Author: XWP.co
1313
* Author URI: https://xwp.co
1414
*/

0 commit comments

Comments
 (0)