Skip to content

Commit ea64501

Browse files
thomaswhyyouScoti Dodson
andauthored
chore: add KnockGuideLocationSensor page, plus a few guide edits (#1206)
* add a page for KnockGuideLocationSensor, along with a few guide edits * example viz, copy edits --------- Co-authored-by: Scoti Dodson <scoti@Mac.lan>
1 parent 684e72e commit ea64501

File tree

6 files changed

+92
-10
lines changed

6 files changed

+92
-10
lines changed

content/in-app-ui/guides/render-guides.mdx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Once you've [created a guide](/in-app-ui/guides/create-guides), you'll need to r
99

1010
## Fetching guides
1111

12-
You can fetch guides using Knock's client-side SDKs or by directly calling the [guides API](/api-reference/users/guides).
12+
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.
1313

1414
### Client-side SDKs
1515

@@ -53,17 +53,16 @@ Knock exposes a set of client SDKs that provide helpers and logic to make it eas
5353

5454
#### Key SDK resources
5555

56-
When working with Knock's SDKs to fetch and render guides, you'll use the following components and hooks:
56+
When working with Knock's SDKs to fetch and render guides, you'll use the following components and hooks for React:
5757

5858
- [**KnockGuideProvider**](/in-app-ui/react/sdk/components/knock-guide-provider). Provider component that fetches guides and manages guide state.
5959
- [**useGuide**](/in-app-ui/react/sdk/hooks/use-guide). Hook to fetch a single guide by type or key.
6060
- [**useGuides**](/in-app-ui/react/sdk/hooks/use-guides). Hook to fetch multiple guides.
6161
- [**useGuideContext**](/in-app-ui/react/sdk/hooks/use-guide-context). Hook to access the guide client for advanced use cases.
6262

6363
<Callout
64-
emoji="🚧"
64+
type="info"
6565
title="Additional SDK support."
66-
bgColor="blue"
6766
text={
6867
<>
6968
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
9897

9998
<AccordionGroup>
10099
<Accordion title="When should I use useGuide vs useGuides?">
101-
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.
100+
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.
102101

103-
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.
102+
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.
104103

105104
</Accordion>
106105
<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
116115
<div>
117116
{guides.map((guide) => (
118117
<div key={guide.key}>
119-
<h3>{guide.step.content.title}</h3>
120-
<p>{guide.step.content.body}</p>
118+
<h3>{guide.steps[0].content.title}</h3>
119+
<p>{guide.steps[0].content.body}</p>
121120
</div>
122121
))}
123122
</div>
@@ -142,5 +141,5 @@ The [`useGuides`](/in-app-ui/react/sdk/hooks/use-guides) hook fetches one or mor
142141

143142
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.
144143

145-
</Accordion>
144+
</Accordion>
146145
</AccordionGroup>

content/in-app-ui/react/headless/guide.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ Using our `@knocklabs/react` and `@knocklabs/client` libraries, you can create f
6464
};
6565
```
6666

67+
<Callout
68+
type="info"
69+
title="If you're using Next.js or Tanstack Router,"
70+
text={
71+
<>
72+
consider using the{" "}
73+
<a href="/in-app-ui/react/sdk/components/knock-guide-location-sensor">
74+
KnockGuideLocationSensor
75+
</a>
76+
{` `}
77+
helper component inside <code>KnockGuideProvider</code> to facilitate
78+
evaluating activation rules based on route changes.
79+
</>
80+
}
81+
/>
82+
>
6783
</Step>
6884
<Step title="Setup a custom message type.">
6985
If you're not using one of our pre-built message types, you'll need to set up a custom message type. You can learn more about how to do this in our [message types](/in-app-ui/message-types/create-message-types) documentation.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: KnockGuideLocationSensor
3+
description:
4+
section: SDKs
5+
---
6+
7+
<Typedoc file="react-core/components/knock-guide-location-sensor" />

data/sidebars/inAppSidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const SHARED_REACT_COMPONENTS = [
122122
{ slug: "/knock-provider", title: "KnockProvider" },
123123
{ slug: "/knock-feed-provider", title: "KnockFeedProvider" },
124124
{ slug: "/knock-guide-provider", title: "KnockGuideProvider" },
125+
{ slug: "/knock-guide-location-sensor", title: "KnockGuideLocationSensor" },
125126
{ slug: "/knock-slack-provider", title: "KnockSlackProvider" },
126127
{ slug: "/knock-ms-teams-provider", title: "KnockMsTeamsProvider" },
127128
{ slug: "/knock-i18n-provider", title: "KnockI18nProvider" },
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
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.
2+
3+
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.
4+
5+
Two important notes to keep in mind when implementing `KnockGuideLocationSensor`:
6+
7+
1. The import path is specific to the corresponding framework (e.g., `@knocklabs/react/next` for Next.js).
8+
2. `KnockGuideLocationSensor` must be placed inside `KnockGuideProvider`.
9+
10+
## Usage
11+
12+
### Next.js
13+
14+
```jsx title="Next.js implementation of KnockGuideLocationSensor."
15+
import { KnockProvider, KnockGuideProvider } from "@knocklabs/react-core";
16+
import { KnockGuideLocationSensor } from "@knocklabs/react/next";
17+
18+
function App() {
19+
return (
20+
<KnockProvider apiKey="pk_test_..." userId="user-123">
21+
<KnockGuideProvider
22+
channelId="..."
23+
readyToTarget={true}
24+
// Turn off default event listeners on window.
25+
trackLocationFromWindow={false}
26+
>
27+
<MyGuideComponent />
28+
// Must be placed inside KnockGuideProvider.
29+
<KnockGuideLocationSensor.AppRouter />
30+
// If you are using the Pages Router: // <KnockGuideLocationSensor.PagesRouter />
31+
</KnockGuideProvider>
32+
</KnockProvider>
33+
);
34+
}
35+
```
36+
37+
### Tanstack Router
38+
39+
```jsx title="Tanstack Router implementation of KnockGuideLocationSensor."
40+
import { KnockProvider, KnockGuideProvider } from "@knocklabs/react-core";
41+
import { KnockGuideLocationSensor } from "@knocklabs/react/tanstack";
42+
43+
function App() {
44+
return (
45+
<KnockProvider apiKey="pk_test_..." userId="user-123">
46+
<KnockGuideProvider
47+
channelId="..."
48+
readyToTarget={true}
49+
// Turn off default event listeners on window.
50+
trackLocationFromWindow={false}
51+
>
52+
<MyGuideComponent />
53+
// Must be placed inside KnockGuideProvider.
54+
<KnockGuideLocationSensor />
55+
</KnockGuideProvider>
56+
</KnockProvider>
57+
);
58+
}
59+
```

typedocs/react-core/components/knock-guide-provider.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function App() {
1515
colorMode="auto"
1616
trackLocationFromWindow={true}
1717
>
18-
<GuideRenderer />
18+
<MyGuideComponent />
1919
</KnockGuideProvider>
2020
</KnockProvider>
2121
);

0 commit comments

Comments
 (0)