Skip to content

Commit

Permalink
Merge pull request #72 from xwp/fix/71
Browse files Browse the repository at this point in the history
Fix `ga_id` when using UI settings
  • Loading branch information
mehigh authored May 18, 2022
2 parents 5955747 + 0243d3f commit 7ab49cc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ All contributions are welcome! Please create [an issue](https://github.com/xwp/s

### Changelog

#### 1.1.6 - May 18, 2022

- Fix GA not tracking bug when using the UI.

#### 1.1.5 - March 17, 2022

- Adding TTFB.
Expand Down
25 changes: 25 additions & 0 deletions php/src/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ protected function register_hooks() {
* Load only for modern browsers
*/
add_filter( 'script_loader_tag', array( $this, 'optimize_scripts' ), 10, 2 );

/**
* Update and validate settings before updating
*/
add_filter( 'pre_update_option_spt_settings', array( $this, 'pre_update_option' ), 10, 1 );
}

/**
Expand Down Expand Up @@ -222,4 +227,24 @@ public function optimize_scripts( $tag, $handle ) {

return $tag;
}

/**
* Filter the spt_settings options before updated
*
* @param array $value The new, unserialized option value.
* @return array $value
*/
public function pre_update_option( $value ) {
if ( isset( $value['analytics_types'] ) && 'ga_id' == $value['analytics_types'] ) {
$value['ga_id'] = $value['gtag_id'];
unset( $value['gtag_id'] );
}

if ( isset( $value['analytics_types'] ) && 'ga4' == $value['analytics_types'] ) {
$value['ga4_id'] = $value['gtag_id'];
unset( $value['gtag_id'] );
}

return $value;
}
}
5 changes: 5 additions & 0 deletions php/views/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ function analytics_id_render() {
global $tracker_config;
$set = false;
$prop = 'gtag_id';

if ( isset( $options['ga_id'] ) ) {
$options['gtag_id'] = $options['ga_id'];
}

if ( isset( $tracker_config['ga_id'] ) ) {
$options['gtag_id'] = $tracker_config['ga_id'];
$prop = 'ga_id';
Expand Down
2 changes: 1 addition & 1 deletion site-performance-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Plugin Name: Site Performance Tracker
* Plugin URI: https://github.com/xwp/site-performance-tracker
* Description: Allows you to detect and track site performance metrics.
* Version: 1.1.5
* Version: 1.1.6
* Author: XWP.co
* Author URI: https://xwp.co
*/
Expand Down

0 comments on commit 7ab49cc

Please sign in to comment.