@webority/mobile-insights
v0.199.1
Published
Product feedback for Webority React Native apps: the NPS question and a feedback button that post to the product's Webority.Insights feedback API.
Maintainers
Readme
@webority/mobile-insights
Product feedback for Webority React Native apps. It gives the app the one NPS question and a
feedback button. Both post to the product's Webority Insights feedback API, which the product
maps on a prefix (/api/insights/feedback by default).
npm install @webority/mobile-insightsBuilds on @webority/mobile-core (the signed-in HTTP client, the error shape) and
@webority/mobile-ui (theme, components). Every visible string is a prop with a plain-English
default, so the app can translate or reword them.
Peers
| Package | Why | Required |
|---|---|---|
| expo | mobile-core's modules | yes |
| react-native-gesture-handler | mobile-ui needs it | yes |
Provider
Create the client over the app's own signed-in HTTP client, so every call carries the same bearer token, tenant header and refresh handling as the rest of the app.
import { userClient } from '@webority/mobile-core';
import { createInsightsFeedbackClient, InsightsFeedbackProvider } from '@webority/mobile-insights';
const feedbackClient = createInsightsFeedbackClient(userClient, { prefix: '/api/insights/feedback' });
export const App = () => (
<ThemeProvider>
<InsightsFeedbackProvider client={feedbackClient}>
<Navigation />
</InsightsFeedbackProvider>
</ThemeProvider>
);Components
import { FeedbackButton, NpsPrompt } from '@webority/mobile-insights';
<NpsPrompt />;
<FeedbackButton pagePath={route.name} />;- NpsPrompt asks the question once per mount, only when the server says it is due. It renders nothing while it loads, when it is not due, and after a load failure. Send is enabled once a score is chosen. Not now is a permanent answer, so the question does not come back.
- FeedbackButton opens a sheet with one multiline field. Send is disabled while the message is empty or longer than 1000 characters.
Failures show the message the server sends, written for the person. Branch on code if you need
to, never show it.
Wire contract
| Route | Body | Response |
|---|---|---|
| GET {prefix}/nps | | { due: boolean, trigger: string \| null } |
| POST {prefix}/nps | { trigger: string, score: number \| null, comment?: string \| null } | 204. A null score is "not now". |
| POST {prefix}/comments | { comment: string, pagePath?: string \| null } | 204 |
Every POST sends the header X-Webority-Surface: Mobile. Errors arrive as the standard error body
{ code, message } and are thrown as InsightsFeedbackApiError.
