@axceera/playstep-react 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,8 +24,10 @@ function Invoices() {
24
24
  }
25
25
  ```
26
26
 
27
- `usePlayStep()` returns the SDK (`start`, `complete`, `track`, `openLauncher`, `resetProgress`, `reset`, `pause`, `resume`). The
28
- provider initialises once and re-identifies when `user` changes; `<PlayStepProvider paused>` pauses guides for a user who should
27
+ `useTrack(event, props?)` reports when the component mounts and again when the event or its properties change
28
+ (properties go to add-ons such as Insights). `usePlayStep()` returns the SDK (`start`, `complete`, `track`, `openLauncher`, `resetProgress`, `reset`, `pause`, `resume`). The
29
+ provider initialises once and re-identifies when `user` changes, sending a trait that left `user.traits` as `null` so
30
+ it stops matching segments; `<PlayStepProvider paused>` pauses guides for a user who should
29
31
  not see them right now.
30
32
 
31
33
  Docs: https://playstep.app/docs/sdk/react
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnalyticsEvent, AppConfig, Guide, InitOptions, InitOptions as InitOptions$1, PlayStep, PlayStep as PlayStep$1, playstep } from "@axceera/playstep";
1
+ import { AnalyticsEvent, AppConfig, EventProps, EventProps as EventProps$1, Guide, InitOptions, InitOptions as InitOptions$1, PlayStep, PlayStep as PlayStep$1, PlayStepPlugin, playstep } from "@axceera/playstep";
2
2
  import { ReactNode } from "react";
3
3
  //#region src/index.d.ts
4
4
  export interface PlayStepUser {
@@ -26,11 +26,14 @@ export declare function PlayStepProvider({ appKey, user, paused, children, ...op
26
26
  * `resetProgress` (let users replay guides), `identify`, `reset`, `pause`, `resume`, `isPaused`.
27
27
  */
28
28
  export declare function usePlayStep(): PlayStep$1;
29
- /** Reports one of your events when the component mounts (and again whenever `event` changes). */
30
- export declare function useTrack(event: string | null | undefined): void;
29
+ /**
30
+ * Reports one of your events when the component mounts (and again whenever `event` or `props` change). `props` go to
31
+ * add-ons such as Insights; guides use only the name.
32
+ */
33
+ export declare function useTrack(event: string | null | undefined, props?: EventProps$1): void;
31
34
  /** Props that mark an element as a guide anchor: `<button {...guideAnchor('new-invoice-btn')}>`. */
32
35
  export declare function guideAnchor(id: string): {
33
36
  'data-guide': string;
34
37
  };
35
38
  //#endregion
36
- export { type AnalyticsEvent, type AppConfig, type Guide, type InitOptions, type PlayStep, playstep };
39
+ export { type AnalyticsEvent, type AppConfig, type EventProps, type Guide, type InitOptions, type PlayStep, type PlayStepPlugin, playstep };
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const Context = createContext(playstep);
8
8
  function PlayStepProvider({ appKey, user, paused, children, ...options }) {
9
9
  const optionsRef = useRef(options);
10
10
  const lastUser = useRef(null);
11
+ const lastTraits = useRef({});
11
12
  useEffect(() => {
12
13
  playstep.init({
13
14
  ...optionsRef.current,
@@ -18,11 +19,15 @@ function PlayStepProvider({ appKey, user, paused, children, ...options }) {
18
19
  const traits = JSON.stringify(user?.traits ?? {});
19
20
  useEffect(() => {
20
21
  if (user?.id) {
21
- playstep.identify(user.id, user.traits);
22
+ const next = { ...user.traits };
23
+ for (const k in lastTraits.current) if (!(k in next)) next[k] = null;
24
+ playstep.identify(user.id, next);
22
25
  lastUser.current = user.id;
26
+ lastTraits.current = { ...user.traits };
23
27
  } else if (user === null && lastUser.current) {
24
28
  playstep.reset();
25
29
  lastUser.current = null;
30
+ lastTraits.current = {};
26
31
  }
27
32
  }, [user?.id, traits]);
28
33
  useEffect(() => {
@@ -40,12 +45,20 @@ function PlayStepProvider({ appKey, user, paused, children, ...options }) {
40
45
  function usePlayStep() {
41
46
  return useContext(Context);
42
47
  }
43
- /** Reports one of your events when the component mounts (and again whenever `event` changes). */
44
- function useTrack(event) {
48
+ /**
49
+ * Reports one of your events when the component mounts (and again whenever `event` or `props` change). `props` go to
50
+ * add-ons such as Insights; guides use only the name.
51
+ */
52
+ function useTrack(event, props) {
45
53
  const ps = usePlayStep();
54
+ const key = JSON.stringify(props ?? null);
46
55
  useEffect(() => {
47
- if (event) ps.track(event);
48
- }, [event, ps]);
56
+ if (event) ps.track(event, props);
57
+ }, [
58
+ event,
59
+ key,
60
+ ps
61
+ ]);
49
62
  }
50
63
  /** Props that mark an element as a guide anchor: `<button {...guideAnchor('new-invoice-btn')}>`. */
51
64
  function guideAnchor(id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axceera/playstep-react",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "PlayStep for React: a provider and hooks around @axceera/playstep. Guides render in their own Shadow DOM, outside your React tree.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  "react": ">=18"
23
23
  },
24
24
  "dependencies": {
25
- "@axceera/playstep": "^0.9.0"
25
+ "@axceera/playstep": "^0.11.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@testing-library/react": "^16.3.3",