@elevateab/sdk 1.2.2 → 1.2.4
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 +77 -143
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +5 -5
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +57 -1
- package/dist/next.d.ts +57 -1
- package/dist/next.js +4 -4
- package/dist/next.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,37 +47,33 @@ That's it. Analytics events are tracked automatically when users view pages, pro
|
|
|
47
47
|
|
|
48
48
|
### 2. Add Anti-Flicker (Recommended)
|
|
49
49
|
|
|
50
|
-
Prevents content flash while tests load
|
|
50
|
+
Prevents content flash while tests load:
|
|
51
51
|
|
|
52
52
|
```tsx
|
|
53
53
|
// app/root.tsx
|
|
54
|
+
import { ElevateProvider, ElevateAnalytics, AntiFlickerScript } from "@elevateab/sdk";
|
|
55
|
+
|
|
54
56
|
export default function Root() {
|
|
55
57
|
return (
|
|
56
58
|
<html>
|
|
57
59
|
<head>
|
|
58
|
-
<
|
|
59
|
-
dangerouslySetInnerHTML={{
|
|
60
|
-
__html: `(function(){var d=document.documentElement;d.style.opacity='0';d.style.transition='opacity 0.2s';window.__eabReveal=function(){d.style.opacity='1'};setTimeout(window.__eabReveal,2000)})();`,
|
|
61
|
-
}}
|
|
62
|
-
/>
|
|
63
|
-
{/* other head elements */}
|
|
60
|
+
<AntiFlickerScript />
|
|
64
61
|
</head>
|
|
65
|
-
<body>
|
|
62
|
+
<body>
|
|
63
|
+
<ElevateProvider
|
|
64
|
+
storeId="mystore.myshopify.com"
|
|
65
|
+
storefrontAccessToken={env.PUBLIC_STOREFRONT_API_TOKEN}
|
|
66
|
+
preventFlickering={true}
|
|
67
|
+
>
|
|
68
|
+
<ElevateAnalytics />
|
|
69
|
+
<Outlet />
|
|
70
|
+
</ElevateProvider>
|
|
71
|
+
</body>
|
|
66
72
|
</html>
|
|
67
73
|
);
|
|
68
74
|
}
|
|
69
75
|
```
|
|
70
76
|
|
|
71
|
-
Then pass `preventFlickering` to the provider:
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
<ElevateProvider
|
|
75
|
-
storeId="mystore.myshopify.com"
|
|
76
|
-
storefrontAccessToken={env.PUBLIC_STOREFRONT_API_TOKEN}
|
|
77
|
-
preventFlickering={true}
|
|
78
|
-
>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
77
|
---
|
|
82
78
|
|
|
83
79
|
## Next.js Setup
|
|
@@ -88,18 +84,13 @@ Next.js requires manual tracking since it doesn't have Shopify's analytics syste
|
|
|
88
84
|
|
|
89
85
|
```tsx
|
|
90
86
|
// app/layout.tsx
|
|
91
|
-
import { ElevateNextProvider } from "@elevateab/sdk/next";
|
|
87
|
+
import { ElevateNextProvider, AntiFlickerScript } from "@elevateab/sdk/next";
|
|
92
88
|
|
|
93
89
|
export default function RootLayout({ children }) {
|
|
94
90
|
return (
|
|
95
91
|
<html>
|
|
96
92
|
<head>
|
|
97
|
-
|
|
98
|
-
<script
|
|
99
|
-
dangerouslySetInnerHTML={{
|
|
100
|
-
__html: `(function(){var d=document.documentElement;d.style.opacity='0';d.style.transition='opacity 0.2s';window.__eabReveal=function(){d.style.opacity='1'};setTimeout(window.__eabReveal,2000)})();`,
|
|
101
|
-
}}
|
|
102
|
-
/>
|
|
93
|
+
<AntiFlickerScript />
|
|
103
94
|
</head>
|
|
104
95
|
<body>
|
|
105
96
|
<ElevateNextProvider
|
|
@@ -159,6 +150,54 @@ async function handleAddToCart() {
|
|
|
159
150
|
}
|
|
160
151
|
```
|
|
161
152
|
|
|
153
|
+
### 4. Other Tracking Events
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
import {
|
|
157
|
+
trackRemoveFromCart,
|
|
158
|
+
trackCartView,
|
|
159
|
+
trackSearchSubmitted,
|
|
160
|
+
trackCheckoutStarted,
|
|
161
|
+
trackCheckoutCompleted,
|
|
162
|
+
} from "@elevateab/sdk";
|
|
163
|
+
|
|
164
|
+
// Remove from cart
|
|
165
|
+
await trackRemoveFromCart({
|
|
166
|
+
productId: product.id,
|
|
167
|
+
variantId: variant.id,
|
|
168
|
+
productPrice: 99.99,
|
|
169
|
+
productQuantity: 1,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Cart view
|
|
173
|
+
await trackCartView({
|
|
174
|
+
cartTotalPrice: 199.99,
|
|
175
|
+
cartTotalQuantity: 2,
|
|
176
|
+
currency: "USD",
|
|
177
|
+
cartItems: [
|
|
178
|
+
{ productId: "123", variantId: "456", productPrice: 99.99, productQuantity: 1 },
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Search
|
|
183
|
+
await trackSearchSubmitted({ searchQuery: "blue shirt" });
|
|
184
|
+
|
|
185
|
+
// Checkout started
|
|
186
|
+
await trackCheckoutStarted({
|
|
187
|
+
cartTotalPrice: 199.99,
|
|
188
|
+
currency: "USD",
|
|
189
|
+
cartItems: [...],
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Checkout completed (order placed)
|
|
193
|
+
await trackCheckoutCompleted({
|
|
194
|
+
orderId: "order_123",
|
|
195
|
+
cartTotalPrice: 199.99,
|
|
196
|
+
currency: "USD",
|
|
197
|
+
cartItems: [...],
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
162
201
|
---
|
|
163
202
|
|
|
164
203
|
## Using A/B Tests
|
|
@@ -236,29 +275,10 @@ if (isPreviewMode()) {
|
|
|
236
275
|
|
|
237
276
|
---
|
|
238
277
|
|
|
239
|
-
## Geo-Targeting
|
|
240
|
-
|
|
241
|
-
Get user's country for location-based tests:
|
|
242
|
-
|
|
243
|
-
```tsx
|
|
244
|
-
import { getUserCountry } from "@elevateab/sdk";
|
|
245
|
-
|
|
246
|
-
const country = getUserCountry(); // "US", "CA", "GB", etc.
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
Country is detected from:
|
|
250
|
-
1. `localization` cookie (set by Shopify)
|
|
251
|
-
2. Cloudflare `CF-IPCountry` header
|
|
252
|
-
3. Falls back to `null` if unavailable
|
|
253
|
-
|
|
254
|
-
---
|
|
255
|
-
|
|
256
278
|
## Cart Attribute Tagging
|
|
257
279
|
|
|
258
280
|
Orders are attributed to A/B tests via cart attributes. This happens automatically when you provide `storefrontAccessToken` and `cartId`.
|
|
259
281
|
|
|
260
|
-
### Automatic (Recommended)
|
|
261
|
-
|
|
262
282
|
For Hydrogen, pass `storefrontAccessToken` to the provider:
|
|
263
283
|
|
|
264
284
|
```tsx
|
|
@@ -279,17 +299,7 @@ trackAddToCart({
|
|
|
279
299
|
});
|
|
280
300
|
```
|
|
281
301
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
```tsx
|
|
285
|
-
import { updateCartAttributes } from "@elevateab/sdk";
|
|
286
|
-
|
|
287
|
-
await updateCartAttributes(cartId, {
|
|
288
|
-
storefrontAccessToken: process.env.NEXT_PUBLIC_STOREFRONT_TOKEN,
|
|
289
|
-
});
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
The Storefront Access Token is safe to use client-side. It's a public token designed for browser use.
|
|
302
|
+
The Storefront Access Token is safe to use client-side - it's a public token designed for browser use.
|
|
293
303
|
|
|
294
304
|
---
|
|
295
305
|
|
|
@@ -300,53 +310,12 @@ The Storefront Access Token is safe to use client-side. It's a public token desi
|
|
|
300
310
|
```tsx
|
|
301
311
|
import { extractShopifyId, isShopifyGid } from "@elevateab/sdk";
|
|
302
312
|
|
|
303
|
-
// Extract numeric ID from GID
|
|
304
313
|
extractShopifyId("gid://shopify/Product/123456"); // "123456"
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
// Check if string is a GID
|
|
308
|
-
isShopifyGid("gid://shopify/Product/123"); // true
|
|
309
|
-
isShopifyGid("123456"); // false
|
|
314
|
+
isShopifyGid("gid://shopify/Product/123"); // true
|
|
310
315
|
```
|
|
311
316
|
|
|
312
317
|
Note: Tracking functions automatically extract IDs, so you rarely need these directly.
|
|
313
318
|
|
|
314
|
-
### Visitor & Session
|
|
315
|
-
|
|
316
|
-
```tsx
|
|
317
|
-
import { getVisitorId, getSessionId, getTestList } from "@elevateab/sdk";
|
|
318
|
-
|
|
319
|
-
getVisitorId(); // Persistent visitor UUID
|
|
320
|
-
getSessionId(); // Session UUID
|
|
321
|
-
getTestList(); // { "test-1": "variant-a", "test-2": "control" }
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### Device & Traffic Detection
|
|
325
|
-
|
|
326
|
-
```tsx
|
|
327
|
-
import { getDeviceType, getTrafficSource } from "@elevateab/sdk";
|
|
328
|
-
|
|
329
|
-
getDeviceType(); // "desktop" | "tablet" | "mobile"
|
|
330
|
-
getTrafficSource(); // "facebook" | "google" | "instagram" | "direct" | "other"
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
---
|
|
334
|
-
|
|
335
|
-
## Analytics Events
|
|
336
|
-
|
|
337
|
-
The SDK tracks these events:
|
|
338
|
-
|
|
339
|
-
| Event | Hydrogen | Next.js |
|
|
340
|
-
|-------|----------|---------|
|
|
341
|
-
| `page_viewed` | Automatic | Automatic (via provider) |
|
|
342
|
-
| `product_viewed` | Automatic | `ProductViewTracker` or `trackProductView()` |
|
|
343
|
-
| `product_added_to_cart` | Automatic | `trackAddToCart()` |
|
|
344
|
-
| `product_removed_from_cart` | Automatic | `trackRemoveFromCart()` |
|
|
345
|
-
| `cart_viewed` | Automatic | `trackCartView()` |
|
|
346
|
-
| `search_submitted` | Automatic | `trackSearchSubmitted()` |
|
|
347
|
-
| `checkout_started` | Automatic | `trackCheckoutStarted()` |
|
|
348
|
-
| `checkout_completed` | Automatic | `trackCheckoutCompleted()` |
|
|
349
|
-
|
|
350
319
|
---
|
|
351
320
|
|
|
352
321
|
## API Reference
|
|
@@ -359,57 +328,22 @@ interface ElevateProviderProps {
|
|
|
359
328
|
storefrontAccessToken?: string; // For cart attribute tagging
|
|
360
329
|
preventFlickering?: boolean; // Enable anti-flicker (default: false)
|
|
361
330
|
hasLocalizedPaths?: boolean; // True if homepage is at /en-us/, /fr-ca/, etc.
|
|
362
|
-
workerUrl?: string; // Custom analytics endpoint
|
|
363
331
|
children: React.ReactNode;
|
|
364
332
|
}
|
|
365
333
|
```
|
|
366
334
|
|
|
367
|
-
###
|
|
335
|
+
### Analytics Events Summary
|
|
368
336
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
currency: "USD",
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// Add to cart
|
|
383
|
-
trackAddToCart({
|
|
384
|
-
productId: "123",
|
|
385
|
-
variantId: "456",
|
|
386
|
-
productPrice: 99.99,
|
|
387
|
-
productQuantity: 1,
|
|
388
|
-
currency: "USD",
|
|
389
|
-
cartId: "gid://shopify/Cart/abc", // Optional: enables cart tagging
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
// Other events
|
|
393
|
-
trackRemoveFromCart({ productId, variantId, ... });
|
|
394
|
-
trackCartView({ cartTotalPrice, cartItems, ... });
|
|
395
|
-
trackSearchSubmitted({ searchQuery });
|
|
396
|
-
trackCheckoutStarted({ cartTotalPrice, cartItems, ... });
|
|
397
|
-
trackCheckoutCompleted({ orderId, cartTotalPrice, cartItems, ... });
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
---
|
|
401
|
-
|
|
402
|
-
## Cookies & Storage
|
|
403
|
-
|
|
404
|
-
**Cookies (1 year):**
|
|
405
|
-
- `eabUserId` - Visitor ID
|
|
406
|
-
- `ABTL` - Test assignments
|
|
407
|
-
- `ABAU` - Unique test views
|
|
408
|
-
- `eabUserPreview` - Preview mode flag
|
|
409
|
-
|
|
410
|
-
**Session Storage:**
|
|
411
|
-
- `eabSessionId` - Session ID
|
|
412
|
-
- `ABAV` - Session test views
|
|
337
|
+
| Event | Hydrogen | Next.js |
|
|
338
|
+
|-------|----------|---------|
|
|
339
|
+
| Page view | Automatic | Automatic |
|
|
340
|
+
| Product view | Automatic | `ProductViewTracker` |
|
|
341
|
+
| Add to cart | Automatic | `trackAddToCart()` |
|
|
342
|
+
| Remove from cart | Automatic | `trackRemoveFromCart()` |
|
|
343
|
+
| Cart view | Automatic | `trackCartView()` |
|
|
344
|
+
| Search | Automatic | `trackSearchSubmitted()` |
|
|
345
|
+
| Checkout started | Automatic | `trackCheckoutStarted()` |
|
|
346
|
+
| Checkout completed | Automatic | `trackCheckoutCompleted()` |
|
|
413
347
|
|
|
414
348
|
---
|
|
415
349
|
|