问题描述
因为我的货币还没有在谷歌分析和wordpress插件(woocommerce google analytics pro)中定义,所以我想将我的网站货币发送到美元,因此我可以在谷歌分析中看到我的报告为美元。
Because my currency hasn't been defined in Google Analytics and also in this wordpress plugin ( woocommerce google analytics pro ) , so I'd like to send my website currency into dollar , consequently I could see my report in google analytics as dollar .
这个插件会将我的网站货币作为事件值,而我网站中的货币与它们两者都不相同。
this plugin get my website currency as a event value , whereas currency in my website is different with both of them.
这是woocommerce google analytics pro插件的一个片段,我认为这种货币是定义的。
this is a snippet of woocommerce google analytics pro plugin that I think that currency is defined .
应该怎么做我更改了代码并在网站和谷歌分析中匹配货币?
how should I change the code and match currency in website and 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() );
}
}
}
推荐答案
WooCommerce Google Analytic's Pro将使用。如果您使用的是自定义货币,请在主题 functions.php
文件中尝试以下代码。
WooCommerce Google Analytic's Pro will use whatever currency has been set by your default WooCommerce settings. If you're using a custom currency, try the code below in your themes functions.php
file.
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;
}
这篇关于如何在woocommerce google analytics pro中更改我的货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!