Skip to content

Commit

Permalink
Rewrite hook logic in Site Kit class
Browse files Browse the repository at this point in the history
Avoids early database calls
  • Loading branch information
swissspidy committed May 23, 2024
1 parent 0a10307 commit 9447916
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions includes/Integrations/Site_Kit.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,29 @@ public function __construct( Analytics $analytics, Context $context, Plugin_Stat
public function register(): void {
add_filter( 'googlesitekit_amp_gtag_opt', [ $this, 'filter_site_kit_gtag_opt' ] );

$handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER );

if ( 'web-stories' === $handler ) {
add_filter(
'googlesitekit_analytics-4_tag_amp_blocked',
function ( $blocked ) {
if ( $this->context->is_web_story() ) {
return true;
}
return $blocked;
add_filter(
'googlesitekit_analytics-4_tag_amp_blocked',
function ( $blocked ) {
$handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER );

if ( 'web-stories' === $handler && $this->context->is_web_story() ) {
return true;
}
);
} elseif ( 'site-kit' === $handler && $this->is_analytics_module_active() ) {
remove_action( 'web_stories_print_analytics', [ $this->analytics, 'print_analytics_tag' ] );
}

return $blocked;
}
);

add_action(
'web_stories_print_analytics',
function () {

Check failure on line 113 in includes/Integrations/Site_Kit.php

View workflow job for this annotation

GitHub Actions / Lint

Closure does not have void return type hint.
$handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER );
if ( 'site-kit' === $handler && $this->is_analytics_module_active() ) {
remove_action( 'web_stories_print_analytics', [ $this->analytics, 'print_analytics_tag' ] );
}
},
5
);
}

/**
Expand Down

0 comments on commit 9447916

Please sign in to comment.