' . "\n"; } $bing = (string) ACSSEO_Settings::get( 'bing_verification', '' ); if ( '' !== $bing ) { echo '' . "\n"; } } /** * Whether the Google Analytics 4 tag should be printed on this request. * * @return bool */ public static function should_load_ga4() { if ( '' === (string) ACSSEO_Settings::get( 'ga4_id', '' ) ) { return false; } if ( is_user_logged_in() && current_user_can( 'edit_posts' ) && ACSSEO_Settings::get( 'ga4_skip_editors', 1 ) ) { return false; } return ! is_admin() && ! is_preview(); } /** * Enqueue the Google Analytics 4 tag. * * Nothing is loaded unless the site owner typed a measurement ID on the * settings screen. This is the only request to an outside service the * plugin can cause, and it is made by the visitor browser, not the server. * * @return void */ public function enqueue_ga4() { if ( ! self::should_load_ga4() ) { return; } $id = (string) ACSSEO_Settings::get( 'ga4_id', '' ); wp_enqueue_script( 'acsseo-ga4', add_query_arg( 'id', rawurlencode( $id ), 'https://www.googletagmanager.com/gtag/js' ), array(), ACSSEO_VERSION, array( 'in_footer' => true, 'strategy' => 'async', ) ); wp_add_inline_script( 'acsseo-ga4', 'window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag("js",new Date());gtag("config",' . wp_json_encode( $id ) . ');', 'before' ); } }