@elevateab/sdk 1.4.1 → 1.4.3

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
@@ -9,7 +9,6 @@ npm install @elevateab/sdk
9
9
  ```
10
10
 
11
11
  **Peer Dependencies:**
12
-
13
12
  - `react` >= 18.0.0 or >= 19.0.0
14
13
  - `@shopify/hydrogen` >= 2023.10.0 (Hydrogen only)
15
14
  - `next` >= 13.0.0 (Next.js only)
@@ -23,23 +22,17 @@ Hydrogen uses automatic analytics tracking via Shopify's `useAnalytics()` hook.
23
22
  ```tsx
24
23
  // app/root.tsx
25
24
  import { ElevateProvider, ElevateAnalytics } from "@elevateab/sdk";
26
- import { Analytics, useNonce } from "@shopify/hydrogen";
25
+ import { Analytics } from "@shopify/hydrogen";
27
26
 
28
27
  export default function Root() {
29
28
  const data = useLoaderData<typeof loader>();
30
- const nonce = useNonce(); // Only needed if your store uses strict CSP
31
29
 
32
30
  return (
33
- <Analytics.Provider
34
- cart={data.cart}
35
- shop={data.shop}
36
- consent={data.consent}
37
- >
31
+ <Analytics.Provider cart={data.cart} shop={data.shop} consent={data.consent}>
38
32
  <ElevateProvider
39
33
  storeId="mystore.myshopify.com"
40
34
  storefrontAccessToken={env.PUBLIC_STOREFRONT_API_TOKEN}
41
35
  preventFlickering={true}
42
- nonce={nonce}
43
36
  >
44
37
  <ElevateAnalytics />
45
38
  <Outlet />
@@ -49,52 +42,10 @@ export default function Root() {
49
42
  }
50
43
  ```
51
44
 
52
- That's it! Analytics events are tracked automatically when users view pages, products, add to cart, etc.
45
+ That's it. Analytics events are tracked automatically when users view pages, products, add to cart, etc.
53
46
 
54
47
  The `preventFlickering={true}` prop prevents content flash while tests load.
55
48
 
56
- ### Content Security Policy Configuration
57
-
58
- This step is optional. Only add CSP directives if your store enforces a strict CSP
59
- and you see console errors about blocked scripts.
60
-
61
- **For Hydrogen stores:** Add Elevate CDN domains to your CSP in `app/entry.server.tsx`:
62
-
63
- ```tsx
64
- // app/entry.server.tsx
65
- export default async function handleRequest(
66
- request: Request,
67
- responseStatusCode: number,
68
- responseHeaders: Headers,
69
- reactRouterContext: EntryContext,
70
- context: HydrogenRouterContextProvider,
71
- ) {
72
- const {nonce, header, NonceProvider} = createContentSecurityPolicy({...});
73
-
74
- // Add Elevate domains to CSP
75
- let elevateCSP = header
76
- .replace(
77
- /script-src-elem\s+([^;]+)/,
78
- `script-src-elem $1 https://d19dz5bxptjmv5.cloudfront.net`
79
- )
80
- .replace(
81
- /connect-src\s+([^;]+)/,
82
- `connect-src $1 https://d19dz5bxptjmv5.cloudfront.net https://d339co84ntxcme.cloudfront.net https://configs.elevateab.com`
83
- );
84
-
85
- responseHeaders.set('Content-Security-Policy', elevateCSP);
86
- // ... rest of your code
87
- }
88
- ```
89
-
90
- **For other frameworks (Next.js, Gatsby, etc.):**
91
-
92
- Add the following CSP header:
93
-
94
- ```
95
- Content-Security-Policy: script-src 'self' https://d19dz5bxptjmv5.cloudfront.net; script-src-elem 'self' https://d19dz5bxptjmv5.cloudfront.net; connect-src 'self' https://d19dz5bxptjmv5.cloudfront.net https://d339co84ntxcme.cloudfront.net https://configs.elevateab.com
96
- ```
97
-
98
49
  ---
99
50
 
100
51
  ## Next.js Setup
@@ -125,7 +76,6 @@ export default function RootLayout({ children }) {
125
76
  ```
126
77
 
127
78
  The `ElevateNextProvider` automatically:
128
-
129
79
  - Tracks page views on route changes
130
80
  - Initializes analytics globally
131
81
  - Prevents content flicker (when `preventFlickering={true}`)
@@ -159,12 +109,12 @@ import { trackAddToCart } from "@elevateab/sdk";
159
109
  async function handleAddToCart() {
160
110
  // Shopify GIDs are automatically converted to numeric IDs
161
111
  await trackAddToCart({
162
- productId: product.id, // "gid://shopify/Product/123" works
163
- variantId: variant.id, // "gid://shopify/ProductVariant/456" works
112
+ productId: product.id, // "gid://shopify/Product/123" works
113
+ variantId: variant.id, // "gid://shopify/ProductVariant/456" works
164
114
  productPrice: 99.99,
165
115
  productQuantity: 1,
166
116
  currency: "USD",
167
- cartId: cart.id, // For cart attribute tagging
117
+ cartId: cart.id, // For cart attribute tagging
168
118
  });
169
119
  }
170
120
  ```
@@ -200,21 +150,6 @@ await trackCartView({
200
150
 
201
151
  // Search
202
152
  await trackSearchSubmitted({ searchQuery: "blue shirt" });
203
-
204
- // Checkout started
205
- await trackCheckoutStarted({
206
- cartTotalPrice: 199.99,
207
- currency: "USD",
208
- cartItems: [...],
209
- });
210
-
211
- // Checkout completed (order placed)
212
- await trackCheckoutCompleted({
213
- orderId: "order_123",
214
- cartTotalPrice: 199.99,
215
- currency: "USD",
216
- cartItems: [...],
217
- });
218
153
  ```
219
154
 
220
155
  ---
@@ -234,7 +169,7 @@ function PricingSection() {
234
169
  if (variant?.isControl) {
235
170
  return <Price amount={99.99} />;
236
171
  }
237
-
172
+
238
173
  return <Price amount={79.99} />;
239
174
  }
240
175
  ```
@@ -244,13 +179,13 @@ function PricingSection() {
244
179
  ```tsx
245
180
  const { variant } = useExperiment("test-id");
246
181
 
247
- variant?.isControl; // true if control group
248
- variant?.isA; // true if variant A
249
- variant?.isB; // true if variant B
250
- variant?.isC; // true if variant C
251
- variant?.isD; // true if variant D
252
- variant?.id; // variant ID
253
- variant?.name; // variant name
182
+ variant?.isControl // true if control group
183
+ variant?.isA // true if variant A
184
+ variant?.isB // true if variant B
185
+ variant?.isC // true if variant C
186
+ variant?.isD // true if variant D
187
+ variant?.id // variant ID
188
+ variant?.name // variant name
254
189
  ```
255
190
 
256
191
  ### Multiple Variants
@@ -278,7 +213,6 @@ https://yourstore.com/?eabUserPreview=true&abtid=<test-id>&eab_tests=<short-id>_
278
213
  ```
279
214
 
280
215
  Example:
281
-
282
216
  ```
283
217
  https://yourstore.com/products/shirt?eabUserPreview=true&abtid=abc123&eab_tests=c123_12345
284
218
  ```
@@ -299,16 +233,13 @@ if (isPreviewMode()) {
299
233
 
300
234
  Orders are attributed to A/B tests via cart attributes. This happens automatically when you provide `storefrontAccessToken` and `cartId`.
301
235
 
302
- For Hydrogen, pass `storefrontAccessToken` and `nonce` to the provider:
236
+ For Hydrogen, pass `storefrontAccessToken` to the provider:
303
237
 
304
238
  ```tsx
305
- const nonce = useNonce();
306
-
307
239
  <ElevateProvider
308
240
  storeId="mystore.myshopify.com"
309
241
  storefrontAccessToken={env.PUBLIC_STOREFRONT_API_TOKEN}
310
- nonce={nonce}
311
- />;
242
+ />
312
243
  ```
313
244
 
314
245
  For Next.js, pass `cartId` to `trackAddToCart`:
@@ -334,7 +265,7 @@ The Storefront Access Token is safe to use client-side - it's a public token des
334
265
  import { extractShopifyId, isShopifyGid } from "@elevateab/sdk";
335
266
 
336
267
  extractShopifyId("gid://shopify/Product/123456"); // "123456"
337
- isShopifyGid("gid://shopify/Product/123"); // true
268
+ isShopifyGid("gid://shopify/Product/123"); // true
338
269
  ```
339
270
 
340
271
  Note: Tracking functions automatically extract IDs, so you rarely need these directly.
@@ -347,25 +278,25 @@ Note: Tracking functions automatically extract IDs, so you rarely need these dir
347
278
 
348
279
  ```tsx
349
280
  interface ElevateProviderProps {
350
- storeId: string; // Required: your-store.myshopify.com
351
- storefrontAccessToken?: string; // For cart attribute tagging
352
- preventFlickering?: boolean; // Prevent content flash during test load (recommended)
353
- nonce?: string; // Only needed if you have strict CSP headers
281
+ storeId: string; // Required: your-store.myshopify.com
282
+ storefrontAccessToken?: string; // For cart attribute tagging
283
+ preventFlickering?: boolean; // Enable anti-flicker (default: false)
284
+ flickerTimeout?: number; // Max wait time in ms (default: 3000)
354
285
  children: React.ReactNode;
355
286
  }
356
287
  ```
357
288
 
358
289
  ### Analytics Events Summary
359
290
 
360
- | Event | Hydrogen | Next.js |
361
- | ------------------ | --------- | -------------------------- |
362
- | Page view | Automatic | Automatic |
363
- | Product view | Automatic | `ProductViewTracker` |
364
- | Add to cart | Automatic | `trackAddToCart()` |
365
- | Remove from cart | Automatic | `trackRemoveFromCart()` |
366
- | Cart view | Automatic | `trackCartView()` |
367
- | Search | Automatic | `trackSearchSubmitted()` |
368
- | Checkout started | Automatic | `trackCheckoutStarted()` |
291
+ | Event | Hydrogen | Next.js |
292
+ |-------|----------|---------|
293
+ | Page view | Automatic | Automatic |
294
+ | Product view | Automatic | `ProductViewTracker` |
295
+ | Add to cart | Automatic | `trackAddToCart()` |
296
+ | Remove from cart | Automatic | `trackRemoveFromCart()` |
297
+ | Cart view | Automatic | `trackCartView()` |
298
+ | Search | Automatic | `trackSearchSubmitted()` |
299
+ | Checkout started | Automatic | `trackCheckoutStarted()` |
369
300
  | Checkout completed | Automatic | `trackCheckoutCompleted()` |
370
301
 
371
302
  ---