如何在WooCommerce谷歌分析专业版中更改我的货币



因为我的货币还没有在谷歌分析和这个wordpress插件(woocommerce谷歌分析专业版(中定义,所以我想将我的网站货币发送到美元,因此我可以在谷歌分析中看到我的报告为美元。

这个插件获取我的网站货币作为事件值,而我网站上的货币是不同的。

这是Woocommerce谷歌分析专业插件的一个片段,我认为货币是定义的。

我应该如何更改网站和谷歌分析中的代码并匹配货币?

    /**
 * Checks the Google Analytics profiles for correct settings.
 *
 * @since 1.0.0
 */
private function check_analytics_profile_settings() {
    if ( $this->has_run_analytics_profile_checks ) {
        return;
    }
    if ( ! $this->is_plugin_settings() ) {
        return;
    }
    $integration = $this->get_integration();
    if ( 'yes' === $integration->get_option( 'use_manual_tracking_id' ) ) {
        return;
    }
    if ( ! $integration->get_access_token() ) {
        return;
    }
    $analytics   = $integration->get_analytics();
    $account_id  = $integration->get_ga_account_id();
    $property_id = $integration->get_ga_property_id();
    if ( $account_id && $property_id ) {
        try {
            $profiles          = $analytics->management_profiles->listManagementProfiles( $account_id, $property_id );
            $ec_disabled       = array();
            $currency_mismatch = array();
            foreach ( $profiles as $profile ) {
                $profile_id           = $profile->getId();
                $property_internal_id = $profile->getInternalWebPropertyId();
                if ( ! $profile->getEnhancedECommerceTracking() ) {
                    $url  = "https://www.google.com/analytics/web/?hl=en#management/Settings/a{$account_id}w{$property_internal_id}p{$profile_id}/%3Fm.page%3DEcommerceSettings/";
                    $link = '<a href="' . $url . '" target="_blank">' . $profile->getName() . '</a>';
                    $ec_disabled[] = array(
                        'url'  => $url,
                        'link' => $link,
                    );
                }
                if ( $profile->getCurrency() !== get_woocommerce_currency() ) {
                    $url  = "https://www.google.com/analytics/web/?hl=en#management/Settings/a{$account_id}w{$property_internal_id}p{$profile_id}/%3Fm.page%3DProfileSettings/";
                    $link = '<a href="' . $url . '" target="_blank">' . $profile->getName() . '</a>';
                    $currency_mismatch[] = array(
                        'url'      => $url,
                        'link'     => $link,
                        'currency' => $profile->getCurrency(),
                    );
                }
            }
            if ( ! empty( $ec_disabled ) ) {
                if ( 1 === count( $ec_disabled ) ) {
                    /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
                    $message = sprintf( __( 'WooCommerce Google Analytics Pro requires Enhanced Ecommerce to be enabled. Please enable Enhanced Ecommerce on your %1$sGoogle Analytics View%2$s.', 'woocommerce-google-analytics-pro' ), '<a href="' . $ec_disabled[0]['url'] . '" target="_blank">', '</a>' );
                } else {
                    $views   = '<ul><li>' . implode( '</li><li>', wp_list_pluck( $ec_disabled, 'link' ) ) . '</li></ul>';
                    /* translators: Placeholders: %s - a list of links */
                    $message = sprintf( __( 'WooCommerce Google Analytics Pro requires Enhanced Ecommerce to be enabled. Please enable Enhanced Ecommerce on the following Google Analytics Views: %s', 'woocommerce-google-analytics-pro' ), $views );
                }
                $this->get_admin_notice_handler()->add_admin_notice(
                    '<strong>' . $this->get_plugin_name() . ':</strong> ' .
                    $message,
                    'enhanced-ecommerce-not-enabled'
                );
            }
            if ( ! empty( $currency_mismatch ) ) {
                if ( 1 === count( $currency_mismatch ) ) {
                    /* translators: Placeholders: %1$s and %2$s - currency code, e.g. USD, %3$s - <a> tag, %4$s - </a> tag */
                    $message = sprintf( __( 'Your Google Analytics View currency (%1$s) does not match WooCommerce currency (%2$s). You can change it %3$son your Google Analytics View%4$s.', 'woocommerce-google-analytics-pro' ), $profile->getCurrency(), get_woocommerce_currency(), '<a href="' . $url . '" target="_blank">', '</a>' );
                } else {
                    $views   = '<ul><li>' . implode( '</li><li>', wp_list_pluck( $currency_mismatch, 'link' ) ) . '</li></ul>';
                    /* translators: Placeholders: %1$s - currency code, %2$s - a list of links */
                    $message = sprintf( __( 'Your Google Analytics Views currencies does not match WooCommerce currency (%1$s). You can change it on the following Google Analytics Views: %2$s', 'woocommerce-google-analytics-pro' ), get_woocommerce_currency(), $views );
                }
                $this->get_admin_notice_handler()->add_admin_notice(
                    '<strong>' . $this->get_plugin_name() . ':</strong> ' .
                    $message,
                    'analytics-currency-mismatch',
                    array( 'dismissible' => true, 'always_show_on_settings' => false )
                );
            }
            $this->has_run_analytics_profile_checks = true;
        } catch ( Exception $e ) {
            $this->log( $e->getMessage() );
        }
    }
}

WooCommerce Google Analytic的Pro将使用您的默认WooCommerce设置设置的任何货币。如果您使用的是自定义货币,请在主题functions.php文件中尝试以下代码。

add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
     $currencies['ABC'] = __( 'Currency name', 'woocommerce' );
     return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
     switch( $currency ) {
          case 'ABC': $currency_symbol = '$'; break;
     }
     return $currency_symbol;
}

最新更新