@elevateab/sdk 1.4.9 → 1.4.10

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.
Files changed (2) hide show
  1. package/README.md +68 -28
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -9,6 +9,7 @@ npm install @elevateab/sdk
9
9
  ```
10
10
 
11
11
  **Peer Dependencies:**
12
+
12
13
  - `react` >= 18.0.0 or >= 19.0.0
13
14
  - `@shopify/hydrogen` >= 2023.10.0 (Hydrogen only)
14
15
  - `next` >= 13.0.0 (Next.js only)
@@ -19,22 +20,54 @@ npm install @elevateab/sdk
19
20
 
20
21
  Hydrogen uses automatic analytics tracking via Shopify's `useAnalytics()` hook.
21
22
 
23
+ ### 1. Content Security Policy (CSP) Setup (first)
24
+
25
+ If your store uses a strict CSP, allow Elevate domains before wiring the provider.
26
+
27
+ ```tsx
28
+ // app/entry.server.tsx
29
+ import { createContentSecurityPolicy } from "@shopify/hydrogen";
30
+
31
+ const { nonce, header, NonceProvider } = createContentSecurityPolicy({
32
+ shop: {
33
+ checkoutDomain: context.env.PUBLIC_CHECKOUT_DOMAIN,
34
+ storeDomain: context.env.PUBLIC_STORE_DOMAIN,
35
+ },
36
+ scriptSrc: [
37
+ "'self'",
38
+ "https://cdn.shopify.com",
39
+ "https://ds0wlyksfn0sb.cloudfront.net",
40
+ ],
41
+ connectSrc: [
42
+ "https://ds0wlyksfn0sb.cloudfront.net",
43
+ "https://bitter-river-9c62.support-67d.workers.dev",
44
+ "https://d339co84ntxcme.cloudfront.net",
45
+ "https://configs.elevateab.com",
46
+ ],
47
+ });
48
+ ```
49
+
50
+ ### 2. Add Elevate Provider + Hydrogen Analytics
51
+
22
52
  ```tsx
23
53
  // app/root.tsx
54
+ import { Analytics, useNonce } from "@shopify/hydrogen";
24
55
  import { ElevateProvider } from "@elevateab/sdk";
25
56
  import { ElevateHydrogenAnalytics } from "@elevateab/sdk/hydrogen";
26
- import { Analytics } from "@shopify/hydrogen";
57
+ import { Outlet, useLoaderData } from "@remix-run/react";
27
58
 
28
59
  export default function Root() {
29
60
  const data = useLoaderData<typeof loader>();
61
+ const nonce = useNonce();
30
62
 
31
63
  return (
32
64
  <Analytics.Provider cart={data.cart} shop={data.shop} consent={data.consent}>
33
65
  {/* ElevateProvider must be inside Analytics.Provider */}
34
66
  <ElevateProvider
35
67
  storeId="mystore.myshopify.com"
36
- storefrontAccessToken={env.PUBLIC_STOREFRONT_API_TOKEN}
68
+ storefrontAccessToken={data.consent?.storefrontAccessToken}
37
69
  preventFlickering={true}
70
+ nonce={nonce}
38
71
  >
39
72
  {/* ElevateHydrogenAnalytics must be inside ElevateProvider */}
40
73
  <ElevateHydrogenAnalytics />
@@ -79,6 +112,7 @@ export default function RootLayout({ children }) {
79
112
  ```
80
113
 
81
114
  The `ElevateNextProvider` automatically:
115
+
82
116
  - Tracks page views on route changes
83
117
  - Initializes analytics globally
84
118
  - Prevents content flicker (when `preventFlickering={true}`)
@@ -112,12 +146,12 @@ import { trackAddToCart } from "@elevateab/sdk";
112
146
  async function handleAddToCart() {
113
147
  // Shopify GIDs are automatically converted to numeric IDs
114
148
  await trackAddToCart({
115
- productId: product.id, // "gid://shopify/Product/123" works
116
- variantId: variant.id, // "gid://shopify/ProductVariant/456" works
149
+ productId: product.id, // "gid://shopify/Product/123" works
150
+ variantId: variant.id, // "gid://shopify/ProductVariant/456" works
117
151
  productPrice: 99.99,
118
152
  productQuantity: 1,
119
153
  currency: "USD",
120
- cartId: cart.id, // For cart attribute tagging
154
+ cartId: cart.id, // For cart attribute tagging
121
155
  });
122
156
  }
123
157
  ```
@@ -147,7 +181,12 @@ await trackCartView({
147
181
  cartTotalQuantity: 2,
148
182
  currency: "USD",
149
183
  cartItems: [
150
- { productId: "123", variantId: "456", productPrice: 99.99, productQuantity: 1 },
184
+ {
185
+ productId: "123",
186
+ variantId: "456",
187
+ productPrice: 99.99,
188
+ productQuantity: 1,
189
+ },
151
190
  ],
152
191
  });
153
192
 
@@ -174,7 +213,7 @@ function PricingSection() {
174
213
  if (variant?.isControl) {
175
214
  return <Price amount={99.99} />;
176
215
  }
177
-
216
+
178
217
  return <Price amount={79.99} />;
179
218
  }
180
219
  ```
@@ -184,13 +223,13 @@ function PricingSection() {
184
223
  ```tsx
185
224
  const { variant } = useExperiment("test-id");
186
225
 
187
- variant?.isControl // true if control group
188
- variant?.isA // true if variant A
189
- variant?.isB // true if variant B
190
- variant?.isC // true if variant C
191
- variant?.isD // true if variant D
192
- variant?.id // variant ID
193
- variant?.name // variant name
226
+ variant?.isControl; // true if control group
227
+ variant?.isA; // true if variant A
228
+ variant?.isB; // true if variant B
229
+ variant?.isC; // true if variant C
230
+ variant?.isD; // true if variant D
231
+ variant?.id; // variant ID
232
+ variant?.name; // variant name
194
233
  ```
195
234
 
196
235
  ### Multiple Variants
@@ -218,6 +257,7 @@ https://yourstore.com/?eabUserPreview=true&abtid=<test-id>&eab_tests=<short-id>_
218
257
  ```
219
258
 
220
259
  Example:
260
+
221
261
  ```
222
262
  https://yourstore.com/products/shirt?eabUserPreview=true&abtid=abc123&eab_tests=c123_12345
223
263
  ```
@@ -270,7 +310,7 @@ The Storefront Access Token is safe to use client-side - it's a public token des
270
310
  import { extractShopifyId, isShopifyGid } from "@elevateab/sdk";
271
311
 
272
312
  extractShopifyId("gid://shopify/Product/123456"); // "123456"
273
- isShopifyGid("gid://shopify/Product/123"); // true
313
+ isShopifyGid("gid://shopify/Product/123"); // true
274
314
  ```
275
315
 
276
316
  Note: Tracking functions automatically extract IDs, so you rarely need these directly.
@@ -283,25 +323,25 @@ Note: Tracking functions automatically extract IDs, so you rarely need these dir
283
323
 
284
324
  ```tsx
285
325
  interface ElevateProviderProps {
286
- storeId: string; // Required: your-store.myshopify.com
287
- storefrontAccessToken?: string; // For cart attribute tagging
288
- preventFlickering?: boolean; // Enable anti-flicker (default: false)
289
- flickerTimeout?: number; // Max wait time in ms (default: 3000)
326
+ storeId: string; // Required: your-store.myshopify.com
327
+ storefrontAccessToken?: string; // For cart attribute tagging
328
+ preventFlickering?: boolean; // Enable anti-flicker (default: false)
329
+ flickerTimeout?: number; // Max wait time in ms (default: 3000)
290
330
  children: React.ReactNode;
291
331
  }
292
332
  ```
293
333
 
294
334
  ### Analytics Events Summary
295
335
 
296
- | Event | Hydrogen | Next.js |
297
- |-------|----------|---------|
298
- | Page view | Automatic | Automatic |
299
- | Product view | Automatic | `ProductViewTracker` |
300
- | Add to cart | Automatic | `trackAddToCart()` |
301
- | Remove from cart | Automatic | `trackRemoveFromCart()` |
302
- | Cart view | Automatic | `trackCartView()` |
303
- | Search | Automatic | `trackSearchSubmitted()` |
304
- | Checkout started | Automatic | `trackCheckoutStarted()` |
336
+ | Event | Hydrogen | Next.js |
337
+ | ------------------ | --------- | -------------------------- |
338
+ | Page view | Automatic | Automatic |
339
+ | Product view | Automatic | `ProductViewTracker` |
340
+ | Add to cart | Automatic | `trackAddToCart()` |
341
+ | Remove from cart | Automatic | `trackRemoveFromCart()` |
342
+ | Cart view | Automatic | `trackCartView()` |
343
+ | Search | Automatic | `trackSearchSubmitted()` |
344
+ | Checkout started | Automatic | `trackCheckoutStarted()` |
305
345
  | Checkout completed | Automatic | `trackCheckoutCompleted()` |
306
346
 
307
347
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevateab/sdk",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "description": "Elevate AB Testing SDK for Hydrogen and Remix frameworks",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",