GoogleWebComponents / google-analytics

Google Analytics web components
https://elements.polymer-project.org/elements/google-analytics
Other
184 stars 79 forks source link

Error messaging #21

Closed mattpolicastro closed 9 years ago

mattpolicastro commented 9 years ago

I suspect this might be outside the scope of this project, but is there any way to return error messages/codes back from the API as part the components' callbacks?

I've been mucking about with the components as a way to build simple dashboards for other folks in my organisation who are less knowledgable when it comes to Analytics but still want an idea of what's going on on our sites. As such, I've been trying to eliminate the view selector as a point of complexity (subbed in a single ids parameter to the Data component's query option. However, should someone end up on one of these dashboards and not have appropriate permissions for that profile/view, the dashboard fails silently (no errors, alerts, console logs, etc).

Is there a simple way to return an error message as part of the callback? Am I missing something obvious?

philipwalton commented 9 years ago

Yes, this is possible. The <google-analytics-chart> component extends the <google-analytics-query> component, which fires success and failure events. Check out the event section of the documentation for more details.

Here's a basic implementation example:

document.addEventListener('analytics-query-error', function(event) {
  console.log(event.detail);
});

If a user tries to query a view to which they don't have access, event.detail.message will be the following:

"User does not have sufficient permissions for this profile."
mattpolicastro commented 9 years ago

Aha, I figured I was missing something. Thanks for pointing me in the right direction.