@nosto/nosto-react 0.1.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/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2018, Mirumee Labs
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,295 @@
1
+ # React Nosto
2
+
3
+ React Nosto is a React component library to make it even easier to implement Nosto.
4
+
5
+ Nosto for React provides you everything to get started with personlisation on your React site. It's dead simple, and beginner friendly.
6
+
7
+
8
+
9
+ ### Why
10
+
11
+ You should be using React Nosto if you want to:
12
+
13
+ - Design personalisation experiences with best practices
14
+ - Customize your components at will
15
+ - Follow React principles
16
+
17
+
18
+
19
+ ### Features
20
+
21
+ - ✓ Lightweight. Almost zero bloat.
22
+ - ✓ Full support for the Facebook Pixel and Google Analytics
23
+ - ✓ Full support for leveraging overlays.
24
+ - ✓ Full support for placements and dynamic placements.
25
+ - ✓ Full support for the JS API.
26
+ - ✘ No support for Nosto's Debug Toolbar.
27
+ - ✘ No support for server-side rendering (SSR).
28
+
29
+
30
+
31
+ ### Installation
32
+
33
+ ##### Yarn:
34
+
35
+ yarn add react-nosto
36
+
37
+ ##### NPM:
38
+
39
+ npm install --save react-nosto
40
+
41
+
42
+
43
+ ### Getting Started
44
+
45
+ ##### The root widget
46
+
47
+ There’s one very specific widget in React Nosto and it is the `NostoProvider` one.
48
+
49
+ This widget is what we call the Nosto root widget, which is responsible for adding the actual Nosto script and the JS API stub. This widget wraps all other React Nosto widgets. Here’s how:
50
+
51
+ ```tsx
52
+ import { NostoProvider } from "@nosto/nosto-react";
53
+
54
+ <NostoProvider account="yqegfddy">
55
+ <App />
56
+ </NostoProvider>
57
+ ```
58
+
59
+ **Note:** the component also accepts a prop to configure the host `host="connect.nosto.com"`. In advanced use-cases, the need to configure the host may surface.
60
+
61
+
62
+
63
+ ##### Understanding Placements
64
+
65
+ React Nosto has a special component called `NostoPlacement`. The component is a simply a <u>hidden</u> DIV placeholder into which Nosto injects recommendations or personalises the content between the tags.
66
+
67
+ We recommend adding as many placements across your views as needed as these are hidden and only populated when a corresponding campaign (targeting that placement) is configured.
68
+
69
+
70
+
71
+ ##### Managing the session
72
+
73
+ React Nosto requires that you pass it the details of current cart contents and the details of the currently logged in customer (if any), on every route change.
74
+
75
+ The `NostoSession` component makes it very easy to keep the session up to date so long as the cart and the customer are provided.
76
+
77
+ The `cart` prop requires a value that adheres to the type `Cart`, while the `customer` prop requires a value that adheres to the type `Customer`.
78
+
79
+ ```tsx
80
+ import { Cart, Customer, Item, NostoSession } from "@nosto/nosto-react";
81
+
82
+ <>
83
+ <Meta/>
84
+ <header>
85
+ <MainMenu/>
86
+ <NostoSession cart={currentCart} customer={currentUser}/>
87
+ </header>
88
+ <Routes/>
89
+ <Footer/>
90
+ </>
91
+ ```
92
+
93
+
94
+
95
+
96
+
97
+ #### Adding Personalisation
98
+
99
+ React Nosto ships with canned components for the different page types. Each component contains all lifecycle methods to dispatch the necessary events.
100
+
101
+
102
+
103
+ ##### Personalising your home page
104
+
105
+ The `NostoHome` component must be used to personalise the home page. The component does not require any props.
106
+
107
+ By default, your account, when created, has <u>four</u> front-page placements named `frontpage-nosto-1`, `frontpage-nosto-2`, `frontpage-nosto-3` and `frontpage-nosto-4`. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
108
+
109
+ ```tsx
110
+ import { NostoHome, NostoPlacement } from "@nosto/nosto-react";
111
+
112
+ <div className="front-page">
113
+ ...
114
+ ...
115
+ ...
116
+ <NostoPlacement id="frontpage-nosto-1" />
117
+ <NostoPlacement id="frontpage-nosto-2" />
118
+ <NostoPlacement id="frontpage-nosto-3" />
119
+ <NostoPlacement id="frontpage-nosto-4" />
120
+ <NostoHome />
121
+ </div>
122
+ ```
123
+
124
+
125
+
126
+ ##### Personalising your product pages
127
+
128
+ The `NostoProduct` component must be used to personalise the product page. The component requires that you provide it the identifier of the current product being viewed.
129
+
130
+ By default, your account, when created, has <u>three</u> product-page placements named `productpage-nosto-1`, `productpage-nosto-2` and `productpage-nosto-3`. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
131
+
132
+ ```tsx
133
+ import { NostoPlacement, NostoProduct } from "@nosto/nosto-react";
134
+
135
+ <div className="product-page">
136
+ ...
137
+ ...
138
+ ...
139
+ <NostoPlacement id="productpage-nosto-1" />
140
+ <NostoPlacement id="productpage-nosto-2" />
141
+ <NostoPlacement id="productpage-nosto-3" />
142
+ <NostoProduct product={product.id} />
143
+ </div>
144
+ ```
145
+
146
+
147
+
148
+ ##### Personalising your search result pages
149
+
150
+ You can personalise your search pages by using the `NostoSearch` component. The component requires that you provide it the current search term.
151
+
152
+ By default, your account, when created, has <u>two</u> search-page placements named `searchpage-nosto-1` and `searchpage-nosto-2`. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
153
+
154
+ ```tsx
155
+ import { NostoPlacement, NostoSearch } from "@nosto/nosto-react";
156
+
157
+ <div className="search-page">
158
+ ...
159
+ ...
160
+ ...
161
+ <NostoPlacement id="searchpage-nosto-1" />
162
+ <NostoPlacement id="searchpage-nosto-2" />
163
+ <NostoSearch query={search} />
164
+ </div>
165
+ ```
166
+
167
+ **Note:** Do not encode the search term in any way. It should be provided an unencoded string. A query for "black shoes" must be provided as-is and not as "black+shoes". Doing so will lead to invalid results.
168
+
169
+
170
+
171
+ ##### Personalising your category list pages
172
+
173
+ You can personalise your category and collection pages by using the `NostoCategory` component. The component requires that you provide it the the slash-delimited slug representation of the current category.
174
+
175
+ By default, your account, when created, has <u>two</u> category placements named `categorypage-nosto-1` and `categorypage-nosto-2`. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
176
+
177
+ ```tsx
178
+ import { NostoCategory, NostoPlacement } from "@nosto/nosto-react";
179
+
180
+ <div className="category-page">
181
+ ...
182
+ ...
183
+ ...
184
+ <NostoPlacement id="categorypage-nosto-1" />
185
+ <NostoPlacement id="categorypage-nosto-2" />
186
+ <NostoCategory category={category.name} />
187
+ </div>
188
+ ```
189
+
190
+ **Note:** Be sure to pass in the correct category representation. If the category being viewed is Mens >> Jackets, you must provide the name as `/Mens/Jackets` . You must ensure that the category path provided here matches that of the categories tagged in your products.
191
+
192
+
193
+
194
+ ##### Personalising your cart checkout pages
195
+
196
+ You can personalise your cart and checkout pages by using the `NostoCheckout` component. The component does not require any props.
197
+
198
+ By default, your account, when created, has <u>two</u> cart-page placements named `categorypage-nosto-1` and `categorypage-nosto-2`. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
199
+
200
+ ```tsx
201
+ import { NostoCheckout, NostoPlacement } from "@nosto/nosto-react";
202
+
203
+ <div className="-page">
204
+ ...
205
+ ...
206
+ ...
207
+ <NostoPlacement id="categorypage-nosto-1" />
208
+ <NostoPlacement id="categorypage-nosto-2" />
209
+ <NostoCheckout />
210
+ </div>
211
+ ```
212
+
213
+
214
+
215
+ ##### Personalising your 404 error pages
216
+
217
+ You can personalise your cart and checkout pages by using the `Nosto404` component. The component does not require any props.
218
+
219
+ By default, your account, when created, has three 404-page placements named `notfound-nosto-1`, `notfound-nosto-2` and `notfound-nosto-2`. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
220
+
221
+ ```tsx
222
+ import { Nosto404, NostoPlacement } from "@nosto/nosto-react";
223
+
224
+ <div className="notfound-page">
225
+ ...
226
+ ...
227
+ ...
228
+ <NostoPlacement id="notfound-nosto-1" />
229
+ <NostoPlacement id="notfound-nosto-2" />
230
+ <NostoPlacement id="notfound-nosto-3" />
231
+ <Nosto404 />
232
+ </div>
233
+ ```
234
+
235
+
236
+
237
+ ##### Personalising your miscellaneous pages
238
+
239
+ You can personalise your miscellaneous pages by using the `NostoOther` component. The component does not require any props.
240
+
241
+ By default, your account, when created, has two other-page placements named `other-nosto-1` and `other-nosto-2`. You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
242
+
243
+ ```tsx
244
+ import { NostoOther, NostoPlacement } from "@nosto/nosto-react";
245
+
246
+ <div className="notfound-page">
247
+ ...
248
+ ...
249
+ ...
250
+ <NostoPlacement id="other-nosto-1" />
251
+ <NostoPlacement id="other-nosto-2" />
252
+ <NostoOther />
253
+ </div>
254
+ ```
255
+
256
+
257
+
258
+ ##### Personalising your order confirmation page
259
+
260
+ You can personalise your order-confirmation/thank-you page by using the `NostoOrder` component. The component requires that you provide it with the details of the order.
261
+
262
+ By default, your account, when created, has one other-page placement named `thankyou-nosto-1`. You may omit this and use any identifier you need. The identifier used here is simply provided to illustrate the example.
263
+
264
+ The `order` prop requires a value that adheres to the type `Purchase`.
265
+
266
+ ```tsx
267
+ import { Buyer, Item, NostoOrder, NostoPlacement, Purchase } from "@nosto/nosto-react";
268
+
269
+ <div className="thankyou-page">
270
+ ...
271
+ ...
272
+ ...
273
+ <NostoPlacement id="thankyou-nosto-1" />
274
+ <NostoOrder order={{ purchase: toOrder(order) }} />
275
+ </div>
276
+ ```
277
+
278
+
279
+ ### Feedback
280
+
281
+ If you've found a feature missing or you would like to report an issue, simply [open up an issue](https://github.com/nosto/nosto-react/issues/new) and let us know.
282
+
283
+ We're always collecting feedback and learning from your use-cases. If you find your self customising widgets and forking the repo to make patches - do drop a message. We'd love to know more and understand how we can make React Nosto an even slicker library for you.
284
+
285
+
286
+
287
+ ### Contributing
288
+
289
+ Please take a moment to review the guidelines for contributing.
290
+
291
+
292
+
293
+ ### License
294
+
295
+ MIT