is_current_tracking_code() || ! self::$wp_piwik->get_option( 'tracking_code' ) || strpos( self::$wp_piwik->get_option( 'tracking_code' ), '{"result":"error",' ) !== false ) { self::$wp_piwik->update_tracking_code(); } $this->tracking_code = ( self::$wp_piwik->is_network_mode() && self::$wp_piwik->get_global_option( 'track_mode' ) === 'manually' ) ? get_site_option( 'wp-piwik-manually' ) : self::$wp_piwik->get_option( 'tracking_code' ); } public function get_tracking_code() { if ( $this->is_usertracking ) { $this->apply_user_tracking(); } if ( $this->is_404 ) { $this->apply_404_changes(); } if ( $this->is_search ) { $this->apply_search_changes(); } if ( is_single() || is_page() ) { $this->add_custom_values(); } // ignoring for BC // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores $this->tracking_code = apply_filters( 'wp-piwik_tracking_code', $this->tracking_code ); return $this->tracking_code; } /** * @param string $code * @param Settings $settings * @param Logger $logger * @return array */ public static function prepare_tracking_code( $code, $settings, $logger ) { global $current_user; $logger->log( 'Apply tracking code changes:' ); $settings->set_option( 'last_tracking_code_update', (string) time() ); if ( preg_match( '/var u="([^"]*)";/', $code, $hits ) ) { $fetched_proxy_url = $hits [1]; } else { $fetched_proxy_url = ''; } if ( $settings->get_global_option( 'remove_type_attribute' ) ) { $code = str_replace( array( ' type="text/javascript"', " type='text/javascript'" ), '', $code ); } if ( 'js' === $settings->get_global_option( 'track_mode' ) ) { $code = str_replace( array( 'piwik.js', 'piwik.php', 'matomo.js', 'matomo.php', ), 'js/index.php', $code ); } elseif ( 'proxy' === $settings->get_global_option( 'track_mode' ) ) { $code = str_replace( 'piwik.js', 'matomo.php', $code ); $code = str_replace( 'matomo.js', 'matomo.php', $code ); $code = str_replace( 'piwik.php', 'matomo.php', $code ); $proxy = str_replace( array( 'https://', 'http://', ), '//', plugins_url( 'wp-piwik' ) . '/proxy' ) . '/'; $code = preg_replace( '/var u="([^"]*)";/', 'var u="' . $proxy . '"', $code ); $code = preg_replace( '/img src="([^"]*)piwik.php/', 'img src="' . $proxy . 'matomo.php', $code ); $code = preg_replace( '/img src="([^"]*)matomo.php/', 'img src="' . $proxy . 'matomo.php', $code ); } if ( $settings->get_global_option( 'track_cdnurl' ) || $settings->get_global_option( 'track_cdnurlssl' ) ) { $code = str_replace( array( 'var d=doc', 'g.src=u+', ), array( "var ucdn=(('https:' == document.location.protocol) ? 'https://" . ( $settings->get_global_option( 'track_cdnurlssl' ) ? $settings->get_global_option( 'track_cdnurlssl' ) : $settings->get_global_option( 'track_cdnurl' ) ) . "/' : 'http://" . ( $settings->get_global_option( 'track_cdnurl' ) ? $settings->get_global_option( 'track_cdnurl' ) : $settings->get_global_option( 'track_cdnurlssl' ) ) . "/');\nvar d=doc", 'g.src=ucdn+', ), $code ); } if ( $settings->get_global_option( 'track_datacfasync' ) ) { $code = str_replace( '