Sponsored Content
The Wayback Machine - https://web.archive.org/web/20210817024711/https://github.com/google/site-kit-wp/issues/1968
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Bar Menu Icon does not show if the URL is not English v1.15.0 #1968

Closed
kabirbd89 opened this issue Aug 28, 2020 · 20 comments
Closed

Admin Bar Menu Icon does not show if the URL is not English v1.15.0 #1968

kabirbd89 opened this issue Aug 28, 2020 · 20 comments

Comments

@kabirbd89
Copy link

@kabirbd89 kabirbd89 commented Aug 28, 2020 •

Bug Description

Admin Bar Menu Icon does not show if the URL is not English.

Steps to reproduce

  1. Create a post or page & publish it
  2. Change URL to, "example.com/post-name" to another language. i.e.("example.com/পোস্টের-নাম/" or "example.com/पोस्ट-नाम/")
  3. Check Admin Bar And No Sit Kit Icon
  4. Check console if there is an error, I didn't get one.

Additional Context

  • PHP Version: 7.3.21
  • OS: MS Windows
  • Browser: Chrome
  • Plugin Version 1.15.0
  • Device: Windows

Acceptance Criteria

  • The wp-admin bar Site Kit should show for pages that include a unicode path (when they have data).

Implementation Brief

  • In Analytics::create_analytics_site_data_request passed URLs (in $args[ 'page' ] ) should be url-decoded before sending to APIs.

Change:
$dimension_filter->setExpressions( array( $args['page'] ) ); to
$dimension_filter->setExpressions( array( rawurldecode( $args['page'] ) ) );

Note: we should be applying esc_url_raw to the passed page arg here. in the previous line, we should apply that before first using the variable.

$args['page'] = str_replace( trim( $this->context->get_reference_site_url(), '/' ), '', $args['page'] ); becomes
$args['page'] = str_replace( trim( $this->context->get_reference_site_url(), '/' ), '', esc_url_raw( $args['page'] ) );

  • In Search_Console::create_search_analytics_data_request, passed URLs (in $args[ 'page' ] ) should be url-decoded before sending to APIs:

Change:
$single_url_filter->setExpression( esc_url_raw( $args['page'] ) ); to
$single_url_filter->setExpression( rawurldecode( esc_url_raw( $args['page'] ) ) );

QA Brief

  • Create a page on your test site: mytestsite.com/পোস্টের-নাম/
  • Make sure Site Kit is set up with Analytics tracking on.
  • Visit the site (not logged in) to collect Analytics data. Search for the site in Google search - some thing like "My Site Name পোস্টের-নাম" and click thru to the site.
  • Wait 24-48 hrs for data to be available via API.
  • Visit the test page and check the Admin bar for the Site Kit icon/menu.
  • Note that post data status is cached in transients for 1 hr (when no data), so clear transients to recheck for data.

Changelog entry

  • Fix issue where admin bar would not show for URLs with unicode paths.
@jamesozzie
Copy link
Collaborator

@jamesozzie jamesozzie commented Aug 31, 2020

If you've just created a new post there may be no data to report on just yet, in which case the plugin doesn't output any information in the toolbar. The same can occur using alphanumeric characters.

If you'd like to open a WordPress support topic we can follow up with you in a few days to ensure everything is working as expected.

I'll also check with the team whether we can add a more informative notice in situations whereby there is no data and we can revisit this GitHub issue if necessary.

@kabirbd89
Copy link
Author

@kabirbd89 kabirbd89 commented Sep 1, 2020

No, I talked about my all post. I have been checked with some of my old posts. When I change the URL to English everything works fine but when I revert it icon gone.

I am not going to open a thread in WordPress. I wish the sit kit team will follow this issue here.

@jamesozzie
Copy link
Collaborator

@jamesozzie jamesozzie commented Sep 2, 2020

Not a problem. I'll try and recreate the same experience using the same page title and slug. We'll keep you posted here.

@jamesozzie jamesozzie reopened this Sep 2, 2020
@kabirbd89
Copy link
Author

@kabirbd89 kabirbd89 commented Sep 8, 2020

glad to hear that @jamesozzie

@jamesozzie
Copy link
Collaborator

@jamesozzie jamesozzie commented Sep 9, 2020

@jamesozzie No problem at all, we're still investigating this. I have a post with the same slug setup, just awaiting additional traffic to report on.

@jamesozzie
Copy link
Collaborator

@jamesozzie jamesozzie commented Sep 10, 2020 •

@kabirbd89 Thanks for your patience on this. I've been able to reproduce the same issue. Additional context from testing below:

  • Same slug used: পোস্টের-নাম
  • Site Kit toolbar doesn't appear (it does appear for newer posts with alphanumeric slugs)
  • The same URL (with পোস্টের-নাম) does appear in the "Most popular content" dashboard (Analytics source)
  • When checking the URL within Search Console via the URL Inspection tool the below appears
  • Happy to share login for test site

image
Referenced link: https://support.google.com/webmasters/answer/9012289#url_on_google_issues

url

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Sep 15, 2020

Doing some testing on my end, I can see that when we send URLs to verify if they have data (and thus whether to show the admin-bar menu), we are using the encoded string version of these unicode characters which might be the issue. Still working on testing both Search Console and Analytics APIs.

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Sep 15, 2020

I have confirmed that at least in the case of the Analytics API we need to decode (likely rawurldecode) the URL before checking for data. Likely also for retrieving data, I am still awaiting data to test.

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Sep 16, 2020

@felixarntz this issue here is related to other work with URLs, however the URL checking approach and code path are unique for this check. For that reason we can handle this issue on its own.

@aaemnnosttv aaemnnosttv self-assigned this Sep 17, 2020
@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Sep 17, 2020

@adamsilverstein @felixarntz while the proposed change does address the issue with the admin bar, to me this seems like just a symptom of a larger issue and that we need to be decoding URLs everywhere they are passed in an API request. We should repurpose this issue to cover all API requests to Google APIs which are scoped to a specific URL.

A few additional methods that seem relevant to attend to here would be:

  • Analytics::create_analytics_site_data_request
  • Search_Console::create_search_analytics_data_request

Also, I think we may want to reconsider where we apply the rawurldecode. Calling this before we call the is_active_in_admin_bar method with the decoded URL is efficient because it covers all modules using the Admin bar, but maybe we should apply this "late" in the definition of the request instead. E.g.

$reports = $this->get_data(
'report',
array(
'url' => $url,

That way it would be clear that the API would be getting the correct form. Initial testing seems to show that calling rawurldecode multiple times on the same string is safe, but it's worth considering where we apply this as it will inform future development.

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Sep 17, 2020

We should repurpose this issue to cover all API requests to Google APIs which are scoped to a specific URL.

That makes sense.

Also, I think we may want to reconsider where we apply the rawurldecode.

Right... my goal was to limit applying decode to the places where a URL is passed in a request.

@aaemnnosttv - What about moving it even higher up the stack to where we first extract the variable from the request - where we know it is encoded. By decoding the URL there, we will fix all the instances you mentioned, right?

Eg. here

$entity_url_query_param = $this->input()->filter( INPUT_GET, 'permaLink' );

$entity_url_query_param = rawurldecode( $this->input()->filter( INPUT_GET, 'permaLink' ) );

@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Sep 18, 2020

Also, I think we may want to reconsider where we apply the rawurldecode.

Right... my goal was to limit applying decode to the places where a URL is passed in a request.

@aaemnnosttv - What about moving it even higher up the stack to where we first extract the variable from the request - where we know it is encoded. By decoding the URL there, we will fix all the instances you mentioned, right?

That would only affect the dashboard details view, which is admin only, so that wouldn't fix the URL used for the admin bar in this case when viewed from the front end.

I think we need the reverse approach as the decoded URL is only needed when passing to the API. Everywhere else, the URL should be consistent with get_permalink( id ) as it is now which returns the encoded version. Perhaps it can return either, but I think a high-level change may have other consequences such as interfering with our lookup of URL -> Entity.
For now, I think the safest and most comprehensive fix would be to update it as close to the API request as possible.

Because both has_data_for_url methods call get_data internally so we really only need to update the way the request is prepared in the datapoint handlers which should fix the problem site-wide. Looking again, I don't know that we need to change it anywhere other than Analytics::create_analytics_site_data_request and Search_Console::create_search_analytics_data_request.

Thoughts @felixarntz ? Are there any other places where a URL should be decoded before we make a request with it?

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Sep 18, 2020

Looking again, I don't know that we need to change it anywhere other than Analytics::create_analytics_site_data_request and Search_Console::create_search_analytics_data_request.

Makes sense, I will update the IB accordingly.

@eclarke1 eclarke1 added this to the Sprint 33 milestone Sep 22, 2020
@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Oct 5, 2020

@aaemnnosttv IB updated - I verified this fix works as expected with the test URL.

I noticed a missing call to esc_url_raw in our handling of the page parameter and thought it would be worth adding here even though it isn't directly related to the original issue. Let me know if you would prefer we handle this in a follow up issue. (cc: @felixarntz)

@adamsilverstein adamsilverstein removed their assignment Oct 5, 2020
@aaemnnosttv aaemnnosttv self-assigned this Oct 6, 2020
@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Oct 6, 2020

IB ✅

@aaemnnosttv aaemnnosttv removed their assignment Oct 6, 2020
@asvinb asvinb self-assigned this Oct 7, 2020
@eclarke1 eclarke1 removed this from the Sprint 33 milestone Oct 12, 2020
@eclarke1 eclarke1 added this to the Sprint 34 milestone Oct 12, 2020
@asvinb
Copy link
Collaborator

@asvinb asvinb commented Oct 12, 2020

@aaemnnosttv Let me know if you were able to find a way on how to QA the ticket. thanks!

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Oct 12, 2020

@asvinb (Hi!) - To QA this ticket you will need a page on your test site with a unicode path and some data. In my case, I use my personal site to create this data, then I can test locally by running my local "AS" the test domain. So:

  1. Create a page on your test site: mytestsite.com/পোস্টের-নাম/
  2. Make sure Site Kit is set up with Analytics tracking on.
  3. Visit the site (not logged in) to collect Analytics data. Search for the site in Google search - some thing like "My Site Name পোস্টের-নাম" and click thru to the site.
  4. Wait 24-48 hrs for data to be available via API.
  5. Visit the test page and check the Admin bar for the Site Kit icon/menu.
@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Oct 12, 2020

@adamsilverstein do you have an account/view with this data already available that you could share to expedite the process? That way, we'd only need to update the custom URL, permalink structure, and a post's slug to test it.

@asvinb
Copy link
Collaborator

@asvinb asvinb commented Oct 13, 2020

Hey @adamsilverstein
Thanks for the details and thanks for adding me to your site in GA. I was able to test the fix and it works. Thanks again!

@asvinb asvinb removed their assignment Oct 13, 2020
@tofumatt tofumatt assigned tofumatt and unassigned tofumatt Oct 13, 2020
@cole10up cole10up self-assigned this Oct 15, 2020
@cole10up
Copy link
Collaborator

@cole10up cole10up commented Oct 22, 2020

Tested

Installed latest develop build, activated and setup SK. Activated Analytics module and created a page with the name পোস্টের-নাম/

Confirmed the admin bar is displayed and functions properly:
image

image

One thing to note, the URL is displayed below on the analytics details paged. https://hellogoodbye.today/%e0%a6%aa%e0%a7%8b%e0%a6%b8%e0%a7%8d%e0%a6%9f%e0%a7%87%e0%a6%b0-%e0%a6%a8%e0%a6%be%e0%a6%ae/

Passed QA ✅

@cole10up cole10up removed their assignment Oct 22, 2020
@felixarntz felixarntz closed this Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants