-
Notifications
You must be signed in to change notification settings - Fork 5
chore: add KnockGuideLocationSensor page, plus a few guide edits #1206
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ Once you've [created a guide](/in-app-ui/guides/create-guides), you'll need to r | |
|
|
||
| ## Fetching guides | ||
|
|
||
| You can fetch guides using Knock's client-side SDKs or by directly calling the [guides API](/api-reference/users/guides). | ||
| There are two ways to fetch and render guides: using Knock's client-side SDKs, which provide built-in state management and helper methods, or by directly calling the [guides API](/api-reference/users/guides) to build a custom implementation. Our [step-by-step React example](/in-app-ui/react/headless/guide) demonstrates how to incorporate the SDK's guide provider into your application and render guide components to your users. | ||
|
|
||
| ### Client-side SDKs | ||
|
|
||
|
|
@@ -53,17 +53,16 @@ Knock exposes a set of client SDKs that provide helpers and logic to make it eas | |
|
|
||
| #### Key SDK resources | ||
|
|
||
| When working with Knock's SDKs to fetch and render guides, you'll use the following components and hooks: | ||
| When working with Knock's SDKs to fetch and render guides, you'll use the following components and hooks for React: | ||
|
|
||
| - [**KnockGuideProvider**](/in-app-ui/react/sdk/components/knock-guide-provider). Provider component that fetches guides and manages guide state. | ||
| - [**useGuide**](/in-app-ui/react/sdk/hooks/use-guide). Hook to fetch a single guide by type or key. | ||
| - [**useGuides**](/in-app-ui/react/sdk/hooks/use-guides). Hook to fetch multiple guides. | ||
| - [**useGuideContext**](/in-app-ui/react/sdk/hooks/use-guide-context). Hook to access the guide client for advanced use cases. | ||
|
|
||
| <Callout | ||
| emoji="🚧" | ||
| type="info" | ||
| title="Additional SDK support." | ||
| bgColor="blue" | ||
| text={ | ||
| <> | ||
| We're working on adding guides support to more of our client SDKs. Please | ||
|
|
@@ -98,9 +97,9 @@ When multiple guides exist for a single `type` (e.g, a generic "Banner" componen | |
|
|
||
| <AccordionGroup> | ||
| <Accordion title="When should I use useGuide vs useGuides?"> | ||
| The [`useGuide`](/in-app-ui/react/sdk/hooks/use-guide) hook fetches a single guide at a time. This is ideal for components that should only display one guide, like a banner or modal that occupies a specific location in your UI. | ||
| The [`useGuide`](/in-app-ui/react/sdk/hooks/use-guide) hook returns a single guide at a time, subject to eligibility criteria, throttling rules, and ordering. This is ideal for components that should only display one guide, like a banner or modal that occupies a specific location in your UI. | ||
|
|
||
| The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or more guides, subject to eligibility criteria. This is useful for components that can display multiple guides at once, like a list of changelog cards or announcements in a sidebar. | ||
| The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or more guides, subject to eligibility criteria, in the configured order. This is useful for components that can display multiple guides at once, like a list of changelog cards or announcements in a sidebar. The `useGuides` hook is designed to return multiple guides, so it does not apply throttling rules. | ||
|
|
||
| </Accordion> | ||
| <Accordion title="How do I render multiple guides in a single component?"> | ||
|
|
@@ -116,8 +115,8 @@ The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or mor | |
| <div> | ||
| {guides.map((guide) => ( | ||
| <div key={guide.key}> | ||
| <h3>{guide.step.content.title}</h3> | ||
| <p>{guide.step.content.body}</p> | ||
| <h3>{guide.steps[0].content.title}</h3> | ||
| <p>{guide.steps[0].content.body}</p> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaron from Everlab flagged this: https://knocklabs.slack.com/archives/C099EMLCXFG/p1762320552813749?thread_ts=1762318032.411729&cid=C099EMLCXFG |
||
| </div> | ||
| ))} | ||
| </div> | ||
|
|
@@ -142,5 +141,5 @@ The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or mor | |
|
|
||
| To see which guides are actually eligible to be rendered, check the `entries` array in the API response, which contains only the guides that match all criteria for the current user and context. | ||
|
|
||
| </Accordion> | ||
| </Accordion> | ||
| </AccordionGroup> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| title: KnockGuideLocationSensor | ||
| description: | ||
| section: SDKs | ||
| --- | ||
|
|
||
| <Typedoc file="react-core/components/knock-guide-location-sensor" /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| A React helper component intended for use with select supported frameworks, such as [Next.js](https://nextjs.org/) and [Tanstack Router](https://tanstack.com/router/), for detecting route changes. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new page covering the KnockGuideLocationSensor helper component. |
||
|
|
||
| Activation rules for guides are evaluated as a user's location changes in your application and, by default, [KnockGuideProvider](/in-app-ui/react/sdk/components/knock-guide-provider) listens for location change events from the global `window` object (enabled via the `trackLocationFromWindow` prop). However, modern frameworks often provide their own first class router APIs for detecting and reacting to route changes, which often works better and more reliably. | ||
|
|
||
| Two important notes to keep in mind when implementing `KnockGuideLocationSensor`: | ||
|
|
||
| 1. The import path is specific to the corresponding framework (e.g., `@knocklabs/react/next` for Next.js). | ||
| 2. `KnockGuideLocationSensor` must be placed inside `KnockGuideProvider`. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Next.js | ||
|
|
||
| ```jsx title="Next.js implementation of KnockGuideLocationSensor." | ||
| import { KnockProvider, KnockGuideProvider } from "@knocklabs/react-core"; | ||
| import { KnockGuideLocationSensor } from "@knocklabs/react/next"; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <KnockProvider apiKey="pk_test_..." userId="user-123"> | ||
| <KnockGuideProvider | ||
| channelId="..." | ||
| readyToTarget={true} | ||
| // Turn off default event listeners on window. | ||
| trackLocationFromWindow={false} | ||
| > | ||
| <MyGuideComponent /> | ||
| // Must be placed inside KnockGuideProvider. | ||
| <KnockGuideLocationSensor.AppRouter /> | ||
| // If you are using the Pages Router: // <KnockGuideLocationSensor.PagesRouter /> | ||
| </KnockGuideProvider> | ||
| </KnockProvider> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### Tanstack Router | ||
|
|
||
| ```jsx title="Tanstack Router implementation of KnockGuideLocationSensor." | ||
| import { KnockProvider, KnockGuideProvider } from "@knocklabs/react-core"; | ||
| import { KnockGuideLocationSensor } from "@knocklabs/react/tanstack"; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <KnockProvider apiKey="pk_test_..." userId="user-123"> | ||
| <KnockGuideProvider | ||
| channelId="..." | ||
| readyToTarget={true} | ||
| // Turn off default event listeners on window. | ||
| trackLocationFromWindow={false} | ||
| > | ||
| <MyGuideComponent /> | ||
| // Must be placed inside KnockGuideProvider. | ||
| <KnockGuideLocationSensor /> | ||
| </KnockGuideProvider> | ||
| </KnockProvider> | ||
| ); | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ function App() { | |
| colorMode="auto" | ||
| trackLocationFromWindow={true} | ||
| > | ||
| <GuideRenderer /> | ||
| <MyGuideComponent /> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "GuideRenderer" might sound like something included in the SDK, whereas "MyGuideComponent" communicates something you need to provide.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great callout 💯 |
||
| </KnockGuideProvider> | ||
| </KnockProvider> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these are React specific, so making that clear.