A site url with an internationalized domain name (IDN) will not show data for the Analytics portion of GSK
See original GitHub issueBug Description
A site url with an internationalized domain name (IDN) will not show data for the Analytics portion of GSK.
Steps to reproduce
If the web site url is an IDN such as this sample: (click here to convert IDN to ASCII)
unicodenáme.xxx (unicode)
xn–unicodenme-z4a.xxx (ASCII)
- Go to ‘G Site Kit’ on the WordPress Dashboard’
- Click on ‘Dashboard’ or ‘Analytics’
- See message:
‘Analytics Gathering Data Analytics data is not yet available, please check back’
Additional Context
This issue was presented to WordPress Support and I followed all instruction there with no avail.
By digging into the GSK plugin version 1.34.1 myself, I found the following temporary solution:
Sending site url in unicode shows the Analytics data. So, instead of sending xn–unicodenme-z4a.xxx, send unicodenáme.xxx
I accomplish that as a temporary solution by hardcoding
…\google-site-kit\includes\Modules\Analytics.php around line 613
/* Added by Horacio to make the IDN work on this plugin */
$request['dimensionFilterClauses'][0]->filters[0]->expressions[0] = 'unicodenáme.xxx';
$request['dimensionFilterClauses'][0]->filters[0]->expressions[1] = 'www.unicodenáme.xxx';
And now Analytics shows fine everywhere in my IDN web site.
Note: obviously my website’s url is not as shown here, this is just a sample of what an IDN url is.
Of course, a permanente solution will depend on Google developers to make Site Kit by Google compatible with IDN web sites. Perhaps by using the viewID instead of the url.
Please understand that this issue have nothing to do with environment (device, OS, platform, PHP and WordPress version, other plugins, etc.).
It is simply that the GSK plugin is sending information to the Analytics Reporting API that it does not understand and it reports no data.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The
Module::permute_site_url
method should be enhanced so that it also considers permutations for a Unicode or Punycode URL if needed.- If the site URL is an international URL with unicode characters, also create the punycode version.
- If the site URL is an international URL in punycode format, also create the unicode version.
- These permutations also need to go through the other permutation of considering HTTP vs HTTPS and
www.
vs non-www.
, so any site that uses an international URL now should end up with 8 permutations - non-international URLs should be kept as now (i.e. 4 permutations).
- In other words, the above change should result in Analytics and AdSense report requests correctly filtering by domain even for international site URLs (no matter whether stored in WordPress as unicode or punycode).
Implementation Brief
Update the Module::permute_site_url
method:
- Add a
hosts
array - add the
wp_parse_url
parsed hostname to thehosts
array - if the hostname is prepended by the IDN
xn--
string- convert the hostname to unicode
idn_to_utf8( $hostname, 0, INTL_IDNA_VARIANT_UTS46 )
- convert the hostname to unicode
- otherwise convert the hostname to IDN ASCII
idn_to_ascii( $hostname, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46 )
- if the
hosts
array does not already contain the converted hostname, add it to thehosts
array - for each of the items in the
hosts
array add the http, https and www permutations.
Test Coverage
- n/a
Visual Regression Changes
- n/a
QA Brief
- Create a release zip and upload it to a site which has an IDN domain name
- Check that Analytics data is being displayed in GSK @jamesozzie has a suitable site with an IDN.
Changelog entry
- Fix bug where the filter behavior used for Analytics and AdSense report data was not working for sites with a unicode or punycode domain.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:30 (7 by maintainers)
GSK Version 1.38.0 works fine with an internationalized domain name (IDN)!
Site: (something like) unicodenáme.xxx (unicode) Self hosted at home and on production with thousands of visitor a day. OS Windows Server 2019 - Microsoft-IIS/10.0 WordPress version 5.9-alpha-51524 MySQL version 8.0.26 for Windows PHP version 8.0.9 64bit Jetpack version 10.1-alpha:1627440389 Plus more than 70 other plugins, some of them mine not published anywhere else
Muchas gracias a todos
@aaemnnosttv Great find - using that sgtm.