google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.23k stars 287 forks source link

Provide support for different domains per language (when using WPML) #2864

Open jamesozzie opened 3 years ago

jamesozzie commented 3 years ago

Feature Description

As requested in the WordPress support forums consider allowing users to view statistics based on differing domains with a WPML multi domain setup. this would be useful for users to view statistics across a users site, and not just based on one domain.

At present when switching domains within the admin panel the user is encountering a "is no record to analyze" notice.

Awaiting additional information. Support to create a similar setup environment for further insights.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

Visual Regression Changes

QA Brief

Changelog entry

oratoran commented 3 years ago

Hi James This is Özgür from KentAjans.

This is the function I have defined in functions.php file for analytics per language:

/**

add_action( 'wp_head', 'my_own_analytics', 20 );
function my_own_analytics() { 

    if(ICL_LANGUAGE_CODE=='en') { ?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXXXXX-2');
</script>
<?php
    }
    if(ICL_LANGUAGE_CODE=='tr') { ?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXXXXXXXX-1');
</script>
<?php
    }
}
oratoran commented 3 years ago

And here is the screen shots from Site Kit 1) Example page which is Site Kit connected (.com.tr): https://yadi.sk/i/j8Yhfui9VjrZcQ

2) Example page which is not Site Kit connected (.com): https://yadi.sk/i/LaIHreMEtrmuJw

3) .com's detail report page (clicked 'more info') https://yadi.sk/i/L1PBiR3wB_nvAw

Hope these are helpful.

Good luck.

jamesozzie commented 3 years ago

@oratoran Many thanks for the additional insights. I'll check this with the team and report back to you here.

jamesozzie commented 3 years ago

@oratoran Just to let you know I've spoken with the team on this and it may be possible with the use of a canonical filter.

@adamsilverstein Escalated to L2 for you to review as per previous support sync.

mxbclang commented 3 years ago

@adamsilverstein Just following up here; let us know if need anything from us.

adamsilverstein commented 3 years ago

@bethanylang Apologies I haven't had a chance to look at this one again yet, on my list!

mxbclang commented 3 years ago

Moving this out of L1 and into Triage as it's not really an issue that requires engineering troubleshooting; instead, it requires discussion regarding adding this as a future feature. @oratoran We'll update here as we have more info or questions. Thank you for your patience!

mikezielonka commented 2 years ago

I'd love to see Sitekit support different domains and GA profiles per language. Maybe one day! For now, I have to manually insert my Analytics tags via WP conditionals.

VR51 commented 1 year ago

Hi guys, is there an update on this? There are many WP multilingual sites in the wild. Would be good if Site Kit were able to store and serve a different tag/tracking code per site language.

Maybe Site Kit could detect the presence of popular multilingual plugins, create one parent account then create a child property per site language, show stats in the WP admin area relevant to the property for the language? This would seem like the quick solution.

adamdunnage commented 1 year ago

@VR51 Thanks for dropping a comment on here. This feature is not actively being considered at this time, but we regularly reevaluate priorities and update GitHub accordingly. You can continue to follow along here for any updates.

VR51 commented 1 year ago

Thanks @adamdunnage. That doesn't sound promising but I will keep watching the change logs and will do a lot of hoping that the feature request gets consideration in the near future.

bryanjordin commented 1 year ago

Sure would be nice to be able to add multiple streams. Having to hack around this.

andreasaptum commented 1 year ago

Following this. Over one million sites use WPML.

slightlydiff commented 11 months ago

Try the following: ` add_action( 'init', function() { global $wpdb; $analytify_custiom_option_names = [ 'pa_google_token', 'wpa_allow_tracking', 'show_tracking_pointer_1', 'access_role_dashboard', 'dashboard_panels', 'wpa_current_version', 'profiles_list_summary', 'post_analytics_token', 'profiles_list_summary_backup', 'profiles_list_summary', 'ga4_update_number', 'ua_update_number', 'measurement_protocol_secret' ]; $analytify_option_names = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%analytify%' AND optionname NOT LIKE '%_lang_\'" ); $analytify_option_names = array_merge($analytify_option_names, $analytify_custiom_option_names);

foreach ( $analytify_option_names as $analytify_option_name ) {

    add_filter( "pre_update_option_{$analytify_option_name}", function($value, $old_value, $option){
        $lang = apply_filters( 'wpml_current_language', NULL );
        $default_lang = apply_filters('wpml_default_language', NULL );
        if (!empty($lang)) {
            $lang = str_replace('-', '_', $lang);
            update_option( $option . '_lang_' . $lang, $value );
        }
        if ($lang == $default_lang) {
            return $old_value;
        }
        return $value;
    }, 10, 3);

    add_filter( "option_{$analytify_option_name}", function($settings, $option){
        $lang = apply_filters( 'wpml_current_language', NULL );
        if (!empty($lang)) {
            $lang = str_replace('-', '_', $lang);
            $settings_lang = get_option( $option . '_lang_' . $lang, 'not-exists' );
            if ( 'not-exists' !== $settings_lang ) {
                return $settings_lang;
            }
        }
        return $settings;
    }, 10, 2);

}

}); `