site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

"Issue accessing data" notice appear when Analytics is added

Open jamesozzie opened this issue 7 years ago • 31 comments

Describe the bug After successfully connecting an Analytics account (using the same Google account OAuth which to verify the setup) an "Issue accessing data" notice appears.

While Analytics reporting in the dashboard is fine there the notice remains and trying to re authenticate your account via the button in the notice doesn't solve the issue, the notice reappears.

To Reproduce Steps to reproduce the behavior:

  1. Active Site Kit
  2. Settings > Connect more services > Analytics
  3. Complete setup procedure

Expected behavior Notice should not appear

Screen Shot 2019-06-20 at 3 49 23 PM

System information:

  • PHP Version: 7.2
  • OS: Mac
  • Browser : Chrome
  • Plugin Version: 1.0.0-beta.1
  • Host OS: Linux
  • Additional Plugins: TagDiv Composer

Additional context Another report of same issue from this issue: https://github.com/google/site-kit-wp/issues/1

Site Kit data module check: https://github.com/google/site-kit-wp/blob/develop/assets/js/components/data.js#L275-L280 insufficientPermission is because of oauth scopes, which happen in most of the cases. In this case the insufficientPermission is because user doesn't have access to the Analytics Goals.

Preliminary work here: https://github.com/google/site-kit-wp/compare/fix/insufficient-permission?expand=1


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

Changelog entry

Acceptance criteria

  • For every user who has successfully set up GA and metrics appear in the main plugin dashboard, no error notices should appear.
  • For users that do not have access to Goals, the goals datablock will show a CTA to request access.

Implementation Brief

  • Remove the insufficientPermission error check from the data module. insufficient scope check already in place elsewhere.

  • Handle insufficientPermission error specifically in AnalyticsDashboardWidgetTopLevel component https://github.com/google/site-kit-wp/blob/9a262cd18c33995ce5ec81bc300ff055dff2a153/assets/js/modules/analytics/dashboard/dashboard-widget-top-level.js#L362 - when the goals data point returns insufficientPermission show a CTA that the user cannot access Goals.

jamesozzie avatar Jun 20 '19 14:06 jamesozzie

@jamesozzie I'm unable to reproduce this. But from what I understand that alert is because an insufficientPermissions response from Google Service API. Can you please capture the response of the rest api in console log?

ivankristianto avatar Jun 21 '19 11:06 ivankristianto

Blocked script execution in '' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

See screenshots below. Screen Shot 2019-06-21 at 1 11 27 PM

In addition there is an error for this when I open in my Developer Console. Screen Shot 2019-06-21 at 1 09 18 PM

Both OAuth verification were complete via the same Google account. All other Site Kit on other sites processed fine from the same device and same Google account.

jamesozzie avatar Jun 21 '19 12:06 jamesozzie

Sorry I wasn't made myself clear. Can you give screenshot of the console > Network > filter with XHR only, from the Site Kit dashboard instead? So I know which service API has the insufficient permission.

And that blocked script execution is expected behavior since it's an iframe to check existing analytics/adsense tag from the front end. Although we have a plan to improve that in the future.

I'm more interested with the error you see in your developer console. seems like your GCP project has unknown issue.

I would suggest these following steps:

  1. Reset site kit
  2. Create the GCP project with different Google account, you can use the link from the first screen of the setup page
  3. Do the setup flow again, then activate Analytics

let me know if that works for you or not.

ivankristianto avatar Jun 21 '19 12:06 ivankristianto

There are no errors from the main Site Kit dashboard for that notice to appear, see below.

6qWn2ClnxV

Also it works fine with no errors or "issue accessing data" using an alternative Google account, exact same steps once I reset Sit Kit. (Creating GCP Project and verifying / connecting Analytics module from that same account). Once I reset Sit Kit again the same problem arises when I use the initial account I used when logging this issue

Using same browser, same procedure and incognito.

jamesozzie avatar Jun 21 '19 13:06 jamesozzie

@jamesozzie Yes we are moving in the right direction. Just one last detail I need. Can you expand the response from this request: Screen Shot 2019-06-21 at 20 59 17

And I would like to see from the preview tab, example: Screen Shot 2019-06-21 at 21 00 44

and if you can expand the one that has error "InsufficientPermission"

ivankristianto avatar Jun 21 '19 14:06 ivankristianto

The response from that request is below:

{"search-console::sc-site-analytics::last-28-days::d41d8cd98f00b204e9800998ecf8427e":[{"clicks":0,"ctr":0,"impressions":3,"keys":["2019-05-27"],"position":8.333333333333332},{"clicks":0,"ctr":0,"impressions":3,"keys":["2019-06-04"],"position":59.333333333333336},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-06-17"],"position":79},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-06-16"],"position":15},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-05-26"],"position":92},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-06-14"],"position":83},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-05-31"],"position":1},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-06-12"],"position":8},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-06-03"],"position":94},{"clicks":0,"ctr":0,"impressions":1,"keys":["2019-06-06"],"position":3}],"search-console::search-keywords-sort-by-impressions::last-28-days::d41d8cd98f00b204e9800998ecf8427e":[{"clicks":0,"ctr":0,"impressions":2,"keys":["amp accordion"],"position":75},{"clicks":0,"ctr":0,"impressions":2,"keys":["dfdsfds"],"position":81}],"analytics::traffic-sources::last-28-days::d41d8cd98f00b204e9800998ecf8427e":[{"nextPageToken":null,"columnHeader":{"dimensions":["ga:medium"],"metricHeader":{"metricHeaderEntries":[{"name":"Sessions","type":"INTEGER"},{"name":"Users","type":"INTEGER"},{"name":"New Users","type":"INTEGER"}]}},"data":{"dataLastRefreshed":null,"isDataGolden":null,"rowCount":3,"samplesReadCounts":null,"samplingSpaceSizes":null,"rows":[{"dimensions":["(none)"],"metrics":[{"values":["49","44","44"]}]},{"dimensions":["organic"],"metrics":[{"values":["20","17","17"]}]},{"dimensions":["referral"],"metrics":[{"values":["11","10","9"]}]}],"totals":[{"values":["80","71","70"]}],"minimums":[{"values":["11","10","9"]}],"maximums":[{"values":["49","44","44"]}]}}],"analytics::overview::last-28-days::d41d8cd98f00b204e9800998ecf8427e":[{"nextPageToken":null,"columnHeader":{"dimensions":null,"metricHeader":{"metricHeaderEntries":[{"name":"Users","type":"INTEGER"},{"name":"Sessions","type":"INTEGER"},{"name":"Bounce Rate","type":"PERCENT"},{"name":"Average Session Duration","type":"TIME"},{"name":"Goal Completions","type":"INTEGER"},{"name":"Pageviews","type":"INTEGER"}]}},"data":{"dataLastRefreshed":null,"isDataGolden":null,"rowCount":1,"samplesReadCounts":null,"samplingSpaceSizes":null,"rows":[{"dimensions":null,"metrics":[{"values":["71","80","78.75","39.25","0","114"]},{"values":["116","122","81.14754098360656","28.852459016393443","0","177"]}]}],"totals":[{"values":["71","80","78.75","39.25","0","114"]},{"values":["116","122","81.14754098360656","28.852459016393443","0","177"]}],"minimums":[{"values":["71","80","78.75","39.25","0","114"]},{"values":["116","122","81.14754098360656","28.852459016393443","0","177"]}],"maximums":[{"values":["71","80","78.75","39.25","0","114"]},{"values":["116","122","81.14754098360656","28.852459016393443","0","177"]}]}}],"analytics::site-analytics::last-28-days::d41d8cd98f00b204e9800998ecf8427e":[{"nextPageToken":null,"columnHeader":{"dimensions":["ga:date"],"metricHeader":{"metricHeaderEntries":[{"name":"Sessions","type":"INTEGER"},{"name":"Users","type":"INTEGER"},{"name":"Bounce Rate","type":"PERCENT"},{"name":"Average Session Duration","type":"TIME"},{"name":"Goal Completions","type":"INTEGER"}]}},"data":{"dataLastRefreshed":null,"isDataGolden":null,"rowCount":55,"samplesReadCounts":null,"samplingSpaceSizes":null,"rows":[{"dimensions":["20190426"],"metrics":[{"values":["2","2","50.0","91.0","0"]}]},{"dimensions":["20190427"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190428"],"metrics":[{"values":["3","3","66.66666666666666","12.666666666666666","0"]}]},{"dimensions":["20190429"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190430"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190501"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190502"],"metrics":[{"values":["2","2","50.0","25.0","0"]}]},{"dimensions":["20190503"],"metrics":[{"values":["3","3","100.0","0.0","0"]}]},{"dimensions":["20190504"],"metrics":[{"values":["4","4","50.0","188.25","0"]}]},{"dimensions":["20190505"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190506"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190507"],"metrics":[{"values":["54","54","96.29629629629629","3.5925925925925926","0"]}]},{"dimensions":["20190508"],"metrics":[{"values":["3","2","33.33333333333333","24.333333333333332","0"]}]},{"dimensions":["20190509"],"metrics":[{"values":["3","3","33.33333333333333","152.66666666666666","0"]}]},{"dimensions":["20190510"],"metrics":[{"values":["5","5","40.0","92.4","0"]}]},{"dimensions":["20190511"],"metrics":[{"values":["3","3","66.66666666666666","12.333333333333334","0"]}]},{"dimensions":["20190512"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190513"],"metrics":[{"values":["2","2","0.0","119.5","0"]}]},{"dimensions":["20190514"],"metrics":[{"values":["2","2","50.0","80.5","0"]}]},{"dimensions":["20190515"],"metrics":[{"values":["6","6","100.0","0.0","0"]}]},{"dimensions":["20190516"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190517"],"metrics":[{"values":["4","3","100.0","0.0","0"]}]},{"dimensions":["20190518"],"metrics":[{"values":["3","3","0.0","279.3333333333333","0"]}]},{"dimensions":["20190519"],"metrics":[{"values":["2","2","50.0","0.0","0"]}]},{"dimensions":["20190520"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190521"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190522"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190523"],"metrics":[{"values":["4","4","75.0","8.75","0"]}]},{"dimensions":["20190524"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190525"],"metrics":[{"values":["4","4","100.0","0.0","0"]}]},{"dimensions":["20190526"],"metrics":[{"values":["2","2","50.0","24.0","0"]}]},{"dimensions":["20190527"],"metrics":[{"values":["3","3","66.66666666666666","0.6666666666666666","0"]}]},{"dimensions":["20190528"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190529"],"metrics":[{"values":["4","4","50.0","50.5","0"]}]},{"dimensions":["20190531"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190601"],"metrics":[{"values":["3","3","100.0","0.0","0"]}]},{"dimensions":["20190602"],"metrics":[{"values":["4","4","75.0","10.5","0"]}]},{"dimensions":["20190603"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190604"],"metrics":[{"values":["2","2","100.0","0.0","0"]}]},{"dimensions":["20190605"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190606"],"metrics":[{"values":["2","2","50.0","2.5","0"]}]},{"dimensions":["20190607"],"metrics":[{"values":["7","5","85.71428571428571","24.428571428571427","0"]}]},{"dimensions":["20190608"],"metrics":[{"values":["4","4","75.0","182.5","0"]}]},{"dimensions":["20190609"],"metrics":[{"values":["6","6","100.0","0.0","0"]}]},{"dimensions":["20190610"],"metrics":[{"values":["3","2","66.66666666666666","6.0","0"]}]},{"dimensions":["20190611"],"metrics":[{"values":["6","6","83.33333333333334","5.666666666666667","0"]}]},{"dimensions":["20190612"],"metrics":[{"values":["4","4","75.0","408.25","0"]}]},{"dimensions":["20190613"],"metrics":[{"values":["4","4","75.0","0.25","0"]}]},{"dimensions":["20190614"],"metrics":[{"values":["3","3","100.0","0.0","0"]}]},{"dimensions":["20190615"],"metrics":[{"values":["3","3","100.0","0.0","0"]}]},{"dimensions":["20190616"],"metrics":[{"values":["2","2","50.0","17.0","0"]}]},{"dimensions":["20190617"],"metrics":[{"values":["2","2","50.0","11.0","0"]}]},{"dimensions":["20190618"],"metrics":[{"values":["1","1","0.0","36.0","0"]}]},{"dimensions":["20190619"],"metrics":[{"values":["1","1","100.0","0.0","0"]}]},{"dimensions":["20190620"],"metrics":[{"values":["2","2","0.0","81.0","0"]}]}],"totals":[{"values":["200","195","80.0","33.3","0"]}],"minimums":[{"values":["0","0","0.0","0.0","0"]}],"maximums":[{"values":["54","54","100.0","408.25","0"]}]}}],"analytics::goals::last-28-days::d41d8cd98f00b204e9800998ecf8427e":{"errors":{"403":["User does not have permission to perform this operation."]},"error_data":{"403":{"status":500,"reason":"insufficientPermissions"}}},"analytics::top-pages::last-28-days::d41d8cd98f00b204e9800998ecf8427e":[{"nextPageToken":"10","columnHeader":{"dimensions":["ga:pagePath","ga:pageTitle"],"metricHeader":{"metricHeaderEntries":[{"name":"Pageviews","type":"INTEGER"},{"name":"Unique Pageviews","type":"INTEGER"},{"name":"Bounce rate","type":"PERCENT"}]}},"data":{"dataLastRefreshed":null,"isDataGolden":null,"rowCount":15,"samplesReadCounts":null,"samplingSpaceSizes":null,"rows":[{"dimensions":["/","Mobile DJ Gorey, Wexford Wedding DJ, Gorey Wedding DJ | Floorfillers"],"metrics":[{"values":["83","71","80.28169014084507"]}]},{"dimensions":["/contact","Floorfillers - Contact | Floorfillers"],"metrics":[{"values":["5","3","0.0"]}]},{"dimensions":["/weddings","Floorfillers - Weddings | Floorfillers"],"metrics":[{"values":["5","4","0.0"]}]},{"dimensions":["/about","Floorfillers - About | Floorfillers"],"metrics":[{"values":["4","2","0.0"]}]},{"dimensions":["/contact/make-a-payment","Floorfillers - Make a Payment | Floorfillers"],"metrics":[{"values":["3","2","0.0"]}]},{"dimensions":["/about/experience","Floorfillers - Experience | Floorfillers"],"metrics":[{"values":["2","2","100.0"]}]},{"dimensions":["/about/testimonials?fbclid=IwAR3ADZ9ojuakA7QrPTr1fLPpK71RfS7PNkSdVyoraJmDXg4PXf6fFseTB90","Floorfillers - Testimonials | Floorfillers"],"metrics":[{"values":["2","1","0.0"]}]},{"dimensions":["/index.php/weddings","Floorfillers - Weddings | Floorfillers"],"metrics":[{"values":["2","1","0.0"]}]},{"dimensions":["/weddings/wedding-packages","Floorfillers - Wedding Packages | Floorfillers"],"metrics":[{"values":["2","2","100.0"]}]},{"dimensions":["/?fbclid=IwAR0DrEE9Un2JW3E17_3bURDVrnU4XmW0n8r6f68MJaB6-GRQsoa71XrKXRg","Floorfillers - Home | Floorfillers"],"metrics":[{"values":["1","1","100.0"]}]}],"totals":[{"values":["114","94","78.75"]}],"minimums":[{"values":["1","1","0.0"]}],"maximums":[{"values":["83","71","100.0"]}]}}]}

And the info from the preview tab below: Screen Shot 2019-06-21 at 5 16 51 PM

jamesozzie avatar Jun 21 '19 16:06 jamesozzie

@jamesozzie Thank you so much for the details. This definitely helpful. This case is because you haven't setup any goals in the analytics and it throw insufficientPermission. We should have better checking insufficientPermission to ensure the alert won't cause confusion.

I'll work on this.

ivankristianto avatar Jun 21 '19 17:06 ivankristianto

@felixarntz / @adamsilverstein The root cause of this issue is in our data module: https://github.com/google/site-kit-wp/blob/develop/assets/js/components/data.js#L275-L280 we check if insufficientPermission is because lack of oauth scopes, which could be happened in most of the cases. But in this case the insufficientPermission is because user doesn't have access to the Analytics Goal, could be a shared Analytics account.

Technical implementation: Moves the error checking from the data module, exactly these lines: https://github.com/google/site-kit-wp/blob/develop/assets/js/components/data.js#L275-L288 to withdata (HOC). So each request could define the error handler. By remove those lines also ensure the data module, only deal with data request and not adding logic intercept.

ivankristianto avatar Jun 27 '19 08:06 ivankristianto

@jamesozzie I'm trying to replicate the insufficientPermission error to test my fixes. Can you tell me how did you setup your Google Analytics account? Is it a Shared Google Analytics account?

ivankristianto avatar Jul 01 '19 09:07 ivankristianto

It's not a shared Google analytics account, but I do have 2FA setup, with a notice going to my phone to approve ("Yes, that was me"). Would that have any effect during initial setup - if I didn't notice on my phone.

jamesozzie avatar Jul 01 '19 09:07 jamesozzie

@jamesozzie I did try to fix the issue. But since I cannot replicate the issue with real data, can you please help me to test on your end? here is the zip package contain that fix specifically. google-site-kit.zip

ivankristianto avatar Jul 01 '19 14:07 ivankristianto

@ivankristianto It worked for me fine that time. I will check on other sites too and report if I see the same issue arising.

jamesozzie avatar Jul 01 '19 16:07 jamesozzie

@ivankristianto Just to let you know I am unable to reproduce the issue using your fix.

jamesozzie avatar Jul 02 '19 14:07 jamesozzie

Thanks @jamesozzie Can you please help me get the data again from what you did in this comment: https://github.com/google/site-kit-wp/issues/12#issuecomment-504486937

Please ensure you are in new tab so you won't hit browser cache.

ivankristianto avatar Jul 02 '19 15:07 ivankristianto

I deleted the project from Cloud Console, deleted Site Kit and installed again from incognito mode. I used the same Google profile for OAUTH and to verify, the same account that holds the Analytics account and profile which I connected to.

Console Error: JQMIGRATE: Migrate is installed, version 1.4.1 wp-polyfill.min.js?ver=7.0.0:1 @babel/polyfill is loaded more than once on this page. This is probably not desirable/intended and may have consequences if different versions of the polyfills are applied sequentially. If you do need to load the polyfill more than once, use @babel/polyfill/noConflict instead to bypass the warning.

Response message: {"analytics::goals::last-28-days::d41d8cd98f00b204e9800998ecf8427e":{"errors":{"403":["User does not have permission to perform this operation."]},"error_data":{"403":{"status":500,"reason":"insufficientPermissions"}}}}

Preview: {,…} analytics::goals::last-28-days::d41d8cd98f00b204e9800998ecf8427e: {errors: {403: ["User does not have permission to perform this operation."]},…} error_data: {403: {status: 500, reason: "insufficientPermissions"}} 403: {status: 500, reason: "insufficientPermissions"} reason: "insufficientPermissions" status: 500 errors: {403: ["User does not have permission to perform this operation."]} 403: ["User does not have permission to perform this operation."] 0: "User does not have permission to perform this operation."

Screen Shot 2019-07-03 at 9 57 05 AM

vRX5RjJYeb

When I go back to the Analytics module and change the dropdown to select "Setup a new Property" I don't see the error anymore, no console or network response errors. Revisiting that section the property field remains blank, see below: Screen Shot 2019-07-03 at 10 08 12 AM

jamesozzie avatar Jul 03 '19 09:07 jamesozzie

Same there.. :)

dominikbullo avatar Jul 05 '19 20:07 dominikbullo

@ivankristianto Regarding implementation brief:

Handle insufficientPermission error specifically in AnalyticsDashboardWidgetTopLevel component

Why does it need extra handling?

I have the preliminary work here: https://github.com/google/site-kit-wp/compare/fix/insufficient-permission?expand=1

The code there still adds the reauth notification - that shouldn't be there as the acceptance criteria say. The server already handles any mismatch in OAuth scopes, which is the sole purpose of the DashboardAuthAlert component.

felixarntz avatar Jul 09 '19 10:07 felixarntz

Handle insufficientPermission error specifically in AnalyticsDashboardWidgetTopLevel component

Why does it need extra handling?

Because in most cases when an API returns the insufficientPermission error it indicates that the user has insufficient scopes, which we handled by displaying the DashboardAuthAlert component.

In the case of Analytics however, even when the user has the correct scopes, they may not have access to view Goals (not 100% certain how to reproduce this state - probably by sharing read access to a property or view. Goals are created by users and can be shared).

In this case, the API returns the same insufficientPermission code we were watching for to indicate incorrect scopes. The user already has the correct scopes and does not need to re-Auth, they likely need to request additional access from the account owner.

Moving the error check from data.js to withData->getDataError enables overriding the default error handling on a per-component level. We can then extend the data object for AnalyticsDashboardWidgetTopLevel where the goal data is requested and add the custom behavior to handle the error code

The code there still adds the reauth notification - that shouldn't be there as the acceptance criteria say. The server already handles any mismatch in OAuth scopes, which is the sole purpose of the DashboardAuthAlert component.

Ah, I assume you are referring to here:

https://github.com/google/site-kit-wp/blob/9a262cd18c33995ce5ec81bc300ff055dff2a153/assets/js/components/notifications/index.js#L33-L39

So the handling of insufficientPermission doesn't need to be added to withData at all, we can remove that handling entirely. We may still want to handle the error for goals explicitly since we want to help the user set up / gain access to Goals or alternately show them some other data they do have access to. What do you think?

.

adamsilverstein avatar Jul 09 '19 18:07 adamsilverstein

@felixarntz & @adamsilverstein

Why does it need extra handling?

Same with Adam, since the response data back from the Analytics API when getting a goal return insufficientPermission and there is no way to differentiate that with lack of oauth scopes approved by user. see this response data sample:

{"analytics::goals::last-28-days::d41d8cd98f00b204e9800998ecf8427e":{"errors":{"403":["User does not have permission to perform this operation."]},"error_data":{"403":{"status":500,"reason":"insufficientPermissions"}}}}

So the handling of insufficientPermission doesn't need to be added to withDat at all, we can remove that handling entirely.

Yes I agree on this. And we still need to handle insufficientPermission case by case basis on some modules.

ivankristianto avatar Jul 10 '19 05:07 ivankristianto

@adamsilverstein - Can I assign this one back over to you to update the implementation brief, based on Ivan and Felix's latest comments?

lilybonney avatar Jul 12 '19 08:07 lilybonney