Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Kit: prevent excluding logged-in users from GA if RA is enabled #1960

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions includes/plugins/google-site-kit/class-googlesitekit.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ class GoogleSiteKit {
public static function init() {
add_action( 'admin_init', [ __CLASS__, 'setup_sitekit_ga4' ] );
add_action( 'wp_footer', [ __CLASS__, 'insert_ga4_analytics' ] );
add_filter( 'option_googlesitekit_analytics_settings', [ __CLASS__, 'filter_ga_settings' ] );
}

/**
* Filter GA settings.
*
* @param array $googlesitekit_analytics_settings GA settings.
*/
public static function filter_ga_settings( $googlesitekit_analytics_settings ) {
if ( Reader_Activation::is_enabled() ) {
// If RA is enabled, readers will become logged in users. They should still be tracked in GA.
if ( in_array( 'loggedinUsers', $googlesitekit_analytics_settings['trackingDisabled'] ) ) {
$googlesitekit_analytics_settings['trackingDisabled'] = [ 'contentCreators' ];
}
}
return $googlesitekit_analytics_settings;
}

/**
Expand Down Expand Up @@ -85,11 +101,11 @@ private static function get_sitekit_ga4_settings_option_name() {
* Get Site Kit's GA4 settings.
*/
private static function get_sitekit_ga4_settings() {
$option_name = self::get_sitekit_ga4_settings_option_name();
if ( false === $option_name ) {
$googlesitekit_analytics_settingsion_name = self::get_sitekit_ga4_settings_option_name();
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
if ( false === $googlesitekit_analytics_settingsion_name ) {
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
return get_option( $option_name, false );
return get_option( $googlesitekit_analytics_settingsion_name, false );
adekbadek marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down