@tolstoy-ai/react-native-sdk 0.2.0 → 0.3.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 +11 -2
- package/lib/TolstoyProvider.d.ts +1 -1
- package/lib/TolstoyProvider.js +1 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
<TolstoyProvider
|
|
34
34
|
appKey="<your Tolstoy app key>"
|
|
35
35
|
appUrl="<your-store>.myshopify.com"
|
|
36
|
+
anonymousId={anonymousId}
|
|
36
37
|
onProductPress={(productId, variantId, handle) => navigation.navigate('Product', { productId, variantId, handle })}
|
|
37
38
|
getAppSession={async () => customerAccessToken ?? null}
|
|
38
39
|
storefrontAccessToken="<your Storefront API public access token>"
|
|
@@ -55,13 +56,13 @@ Show the try-on screen full screen, for example in a modal or as its own route:
|
|
|
55
56
|
| --- | --- | --- |
|
|
56
57
|
| `appKey` | `TolstoyProvider` | Your Tolstoy app key. |
|
|
57
58
|
| `appUrl` | `TolstoyProvider` | Your store's `*.myshopify.com` domain. |
|
|
59
|
+
| `anonymousId` | `TolstoyProvider` | A UUID that names the shopper's device in Tolstoy analytics (see "Anonymous id"). |
|
|
58
60
|
| `onProductPress(productId, variantId?, handle?)` | `TolstoyProvider` | Opens your product screen. The ids are numeric Shopify ids. `handle` is the product handle. A product card always gives it; "View product" in try-on does not. |
|
|
59
61
|
| `getAppSession()` | `TolstoyProvider`, optional | Gives the signed-in shopper's token (see "Token contract"). Give `null` when no shopper is signed in. |
|
|
60
62
|
| `storefrontAccessToken` | `TolstoyProvider`, optional | Your store's Storefront API public access token. Set it when `getAppSession` gives a Storefront API customer access token (see "Token contract"). |
|
|
61
63
|
| `onAddToCart(lines)` | `TolstoyProvider`, optional | Adds lines (`variantId`, `quantity`) to your app's cart. Reject the promise when the add fails. Without this prop, add to cart from try-on shows an error. |
|
|
62
64
|
| `onOpenCart()` | `TolstoyProvider`, optional | Opens your cart screen. |
|
|
63
65
|
| `onEvent(event)` | `TolstoyProvider`, optional | Tells your app what the shopper does (see "Events"). |
|
|
64
|
-
| `anonymousId` | `TolstoyProvider`, optional | A UUID that names the shopper's device in Tolstoy analytics. Without it, the package makes one for each app session. |
|
|
65
66
|
| `environment` | `TolstoyProvider`, optional | `production` (default) or `dev`. |
|
|
66
67
|
| `publishId` | carousels | The publish id of a Tolstoy player. Tolstoy gives it to you. |
|
|
67
68
|
| `productId` | `TolstoyProductVideos`, `TolstoyTryOn` | The numeric Shopify product id. |
|
|
@@ -69,6 +70,14 @@ Show the try-on screen full screen, for example in a modal or as its own route:
|
|
|
69
70
|
|
|
70
71
|
`TolstoyProductVideos` shows nothing when the product has no videos. `useTolstoyVideos(publishId, productId?)` gives the same data for your own UI. `TolstoyFeed` needs the `publishId` of the player whose videos it shows.
|
|
71
72
|
|
|
73
|
+
## Anonymous id
|
|
74
|
+
|
|
75
|
+
Tolstoy counts viewers by `anonymousId`. The package makes no id of its own. Create a UUID once, keep it on the device in your app's own storage, and pass the same value on every launch. An id that changes on each launch makes each launch a new viewer, and an order no longer matches the events of an earlier launch.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
const anonymousId = await getOrCreateStoredUuid(); // your code: read the saved UUID, or make one and save it
|
|
79
|
+
```
|
|
80
|
+
|
|
72
81
|
## Videos and product cards
|
|
73
82
|
|
|
74
83
|
- A video plays from its HLS stream when Tolstoy has one, and from its MP4 file when it does not.
|
|
@@ -102,7 +111,7 @@ const { cartAttributes } = useTolstoy();
|
|
|
102
111
|
// Give them as `attributes` to the Storefront API cartCreate, or to cartAttributesUpdate.
|
|
103
112
|
```
|
|
104
113
|
|
|
105
|
-
The value is the `anonymousId` of the provider.
|
|
114
|
+
The value is the `anonymousId` of the provider. Keep the same `anonymousId` across launches, so that the events and the order have the same id.
|
|
106
115
|
|
|
107
116
|
## Use your own player
|
|
108
117
|
|
package/lib/TolstoyProvider.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type TolstoyProviderProps = {
|
|
|
33
33
|
appKey: string;
|
|
34
34
|
appUrl: string;
|
|
35
35
|
environment?: TolstoyEnvironment;
|
|
36
|
-
anonymousId
|
|
36
|
+
anonymousId: string;
|
|
37
37
|
onProductPress: (productId: string, variantId?: string, handle?: string) => void;
|
|
38
38
|
getAppSession?: () => Promise<string | null>;
|
|
39
39
|
storefrontAccessToken?: string;
|
package/lib/TolstoyProvider.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
-
import { createTolstoyId } from './analytics';
|
|
4
|
-
// Without an anonymousId from the app, the shopper is one Tolstoy visitor for the app session.
|
|
5
|
-
const sessionAnonymousId = createTolstoyId();
|
|
6
3
|
const TolstoyContext = createContext(null);
|
|
7
|
-
export function TolstoyProvider({ appKey, appUrl, environment = 'production', anonymousId
|
|
4
|
+
export function TolstoyProvider({ appKey, appUrl, environment = 'production', anonymousId, onProductPress, getAppSession, storefrontAccessToken, onAddToCart, onOpenCart, onEvent, children, }) {
|
|
8
5
|
const value = useMemo(() => ({
|
|
9
6
|
appKey,
|
|
10
7
|
appUrl,
|