由于我的货币尚未在Google Analytics和此wordpress插件(woocommerce google analytics pro)中定义,因此我想将我的网站货币发送到美元,因此我可以在google analytics中查看我的报告美元。
此插件将我的网站货币作为事件值,而我网站中的货币与两者都不同。
这是一个woocommerce google analytics pro插件的片段,我认为这种货币是定义的。
我应该如何更改代码并匹配网站和Google Analytics中的货币?
/**
* 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() );
}
}
}
答案 0 :(得分:0)
WooCommerce Google Analytic的Pro将使用whatever currency has been set by your default WooCommerce settings。如果您使用的是自定义货币,请在主题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;
}