@liquidcommerce/elements-sdk 2.7.1 → 2.7.2

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.
@@ -1,162 +1,895 @@
1
1
  # Events Guide
2
2
 
3
- The SDK publishes events for all user interactions and state changes.
3
+ The SDK publishes browser events for user interactions and state changes. Use them to react to product selections, cart updates, and checkout progress.
4
4
 
5
5
  ## Event Format
6
6
 
7
- All SDK events follow this pattern:
7
+ All SDK events are dispatched as native `CustomEvent` objects. The payload lives in `event.detail`:
8
8
 
9
9
  ```javascript
10
- window.addEventListener('lce:actions.event_name', (event) => {
10
+ window.addEventListener('lce:actions.client_ready', (event) => {
11
+ const { data, metadata } = event.detail;
12
+
11
13
  const {
12
- namespace, // 'lce:actions'
13
- event: eventName, // 'cart_item_added'
14
- timestamp, // Unix timestamp
15
- id, // Unique event ID
16
- data // Event-specific data
17
- } = event.detail;
14
+ event: eventName,
15
+ namespace,
16
+ originalEvent,
17
+ actionNamespace,
18
+ eventId,
19
+ timestamp
20
+ } = metadata;
18
21
  });
19
22
  ```
20
23
 
24
+ `data` is event-specific. `metadata` describes the event (name, namespace, timestamp, etc).
25
+
21
26
  ## Event Namespaces
22
27
 
23
28
  - `lce:actions.*` - User actions and state changes
24
- - `lce:forms.*` - Form interactions (checkout)
29
+ - `lce:forms.*` - Form field interactions (checkout)
30
+ - `lce:actions` - All action events (namespace-level listener)
31
+ - `lce:forms` - All form events (namespace-level listener)
32
+
33
+ Example: listen to every action event:
34
+
35
+ ```javascript
36
+ window.addEventListener('lce:actions', (event) => {
37
+ const { metadata } = event.detail;
38
+ console.log('Action event:', metadata.event);
39
+ });
40
+ ```
25
41
 
26
42
  ## Core Events
27
43
 
28
- ### Client Ready
44
+ ### `lce:actions.client_ready`
45
+
46
+ Fires once when the SDK finishes initializing and is ready for actions.
47
+
48
+ **Data includes:** `isReady`, `message`, `timestamp`, `version`.
49
+
50
+ **Example**
29
51
 
30
52
  ```javascript
31
53
  window.addEventListener('lce:actions.client_ready', (event) => {
32
- const { isReady, version, timestamp } = event.detail.data;
33
- console.log(`Elements SDK v${version} is ready`);
54
+ const { data } = event.detail;
55
+ if (data.isReady) {
56
+ console.log('Elements SDK ready', data.version);
57
+ }
34
58
  });
35
59
  ```
36
60
 
37
61
  ## Product Events
38
62
 
63
+ ### `lce:actions.product_loaded`
64
+
65
+ Fires when a product component finishes loading and product data is available.
66
+
67
+ **Data includes:** `identifier`, `name`, `price`, `selectedSizeId`, `selectedFulfillmentType`.
68
+
69
+ **Example**
70
+
39
71
  ```javascript
40
- // Product loaded
41
72
  window.addEventListener('lce:actions.product_loaded', (event) => {
42
- const { identifier, name, price } = event.detail.data;
73
+ const { data } = event.detail;
74
+ console.log(`Loaded ${data.name} (${data.identifier})`);
43
75
  });
76
+ ```
77
+
78
+ ### `lce:actions.product_add_to_cart`
79
+
80
+ Fires when the user triggers add-to-cart from a product component. Use cart events to confirm success or failure.
81
+
82
+ **Data includes:** `identifier`, `quantity`, `fulfillmentId`, `partNumber`, `engravingLines`.
83
+
84
+ **Example**
44
85
 
45
- // Add to cart clicked
86
+ ```javascript
46
87
  window.addEventListener('lce:actions.product_add_to_cart', (event) => {
47
- const { identifier, quantity, fulfillmentType } = event.detail.data;
88
+ const { data } = event.detail;
89
+ gtag('event', 'add_to_cart_click', { item_id: data.identifier, quantity: data.quantity });
48
90
  });
91
+ ```
92
+
93
+ ### `lce:actions.product_size_changed`
94
+
95
+ Fires when the user changes the selected size.
96
+
97
+ **Data includes:** `identifier`, `selectedSizeId`, `selectedSize`, `previousSizeId`, `previousSize`.
98
+
99
+ **Example**
49
100
 
50
- // Size changed
101
+ ```javascript
51
102
  window.addEventListener('lce:actions.product_size_changed', (event) => {
52
- const { identifier, selectedSize } = event.detail.data;
103
+ const { data } = event.detail;
104
+ console.log(`Size changed to ${data.selectedSize}`);
53
105
  });
106
+ ```
107
+
108
+ ### `lce:actions.product_fulfillment_type_changed`
109
+
110
+ Fires when the user switches between fulfillment types (for example shipping vs onDemand).
54
111
 
55
- // Fulfillment type changed
112
+ **Data includes:** `identifier`, `selectedFulfillmentType`, `previousFulfillmentType`, `selectedFulfillmentId`, `previousFulfillmentId`.
113
+
114
+ **Example**
115
+
116
+ ```javascript
56
117
  window.addEventListener('lce:actions.product_fulfillment_type_changed', (event) => {
57
- const { identifier, fulfillmentType } = event.detail.data;
118
+ const { data } = event.detail;
119
+ console.log('Fulfillment type:', data.selectedFulfillmentType);
58
120
  });
121
+ ```
122
+
123
+ ### `lce:actions.product_fulfillment_changed`
124
+
125
+ Fires when the user selects a different fulfillment option or retailer.
59
126
 
60
- // Retailer changed
127
+ **Data includes:** `identifier`, `selectedFulfillmentId`, `previousFulfillmentId`, `selectedFulfillmentType`, `previousFulfillmentType`.
128
+
129
+ **Example**
130
+
131
+ ```javascript
61
132
  window.addEventListener('lce:actions.product_fulfillment_changed', (event) => {
62
- const { identifier, selectedRetailer } = event.detail.data;
133
+ const { data } = event.detail;
134
+ console.log('Fulfillment changed:', data.selectedFulfillmentId);
63
135
  });
136
+ ```
137
+
138
+ ### `lce:actions.product_quantity_increase`
139
+
140
+ Fires when the product quantity is increased.
141
+
142
+ **Data includes:** `identifier`, `quantity`, `previousQuantity`.
143
+
144
+ **Example**
145
+
146
+ ```javascript
147
+ window.addEventListener('lce:actions.product_quantity_increase', (event) => {
148
+ const { data } = event.detail;
149
+ console.log('Quantity increased to', data.quantity);
150
+ });
151
+ ```
152
+
153
+ ### `lce:actions.product_quantity_decrease`
154
+
155
+ Fires when the product quantity is decreased.
156
+
157
+ **Data includes:** `identifier`, `quantity`, `previousQuantity`.
64
158
 
65
- // Quantity changed
66
- window.addEventListener('lce:actions.product_quantity_increase', (event) => {});
67
- window.addEventListener('lce:actions.product_quantity_decrease', (event) => {});
159
+ **Example**
160
+
161
+ ```javascript
162
+ window.addEventListener('lce:actions.product_quantity_decrease', (event) => {
163
+ const { data } = event.detail;
164
+ console.log('Quantity decreased to', data.quantity);
165
+ });
68
166
  ```
69
167
 
70
168
  ## Address Events
71
169
 
170
+ ### `lce:actions.address_updated`
171
+
172
+ Fires when an address is successfully set.
173
+
174
+ **Data includes:** `googlePlacesId`, `formattedAddress`, `address`, `coordinates`.
175
+
176
+ **Example**
177
+
72
178
  ```javascript
73
- // Address set
74
179
  window.addEventListener('lce:actions.address_updated', (event) => {
75
- const { address, coordinates, formattedAddress } = event.detail.data;
180
+ const { data } = event.detail;
181
+ console.log('Address set:', data.formattedAddress);
182
+ });
183
+ ```
184
+
185
+ ### `lce:actions.address_cleared`
186
+
187
+ Fires when the current address is cleared.
188
+
189
+ **Data includes:** `true`.
190
+
191
+ **Example**
192
+
193
+ ```javascript
194
+ window.addEventListener('lce:actions.address_cleared', () => {
195
+ console.log('Address cleared');
76
196
  });
197
+ ```
198
+
199
+ ### `lce:actions.address_failed`
77
200
 
78
- // Address cleared
79
- window.addEventListener('lce:actions.address_cleared', (event) => {});
201
+ Fires when setting the address fails.
80
202
 
81
- // Address error
203
+ **Data includes:** `googlePlacesId`, `formattedAddress`, `address`, `coordinates`, `error`.
204
+
205
+ **Example**
206
+
207
+ ```javascript
82
208
  window.addEventListener('lce:actions.address_failed', (event) => {
83
- const { error } = event.detail.data;
209
+ const { data } = event.detail;
210
+ console.error('Address error:', data.error);
84
211
  });
85
212
  ```
86
213
 
87
214
  ## Cart Events
88
215
 
216
+ ### `lce:actions.cart_loaded`
217
+
218
+ Fires when the cart is fully loaded or synced.
219
+
220
+ **Data includes:** `cartId`, `itemCount`, `subtotal`, `items`, `promoCodeDiscount`.
221
+
222
+ **Example**
223
+
89
224
  ```javascript
90
- // Cart loaded
91
225
  window.addEventListener('lce:actions.cart_loaded', (event) => {
92
- const { cartId, itemsCount } = event.detail.data;
226
+ const { data } = event.detail;
227
+ console.log(`Cart ${data.cartId} has ${data.itemCount} items`);
93
228
  });
229
+ ```
230
+
231
+ ### `lce:actions.cart_opened`
94
232
 
95
- // Cart opened/closed
96
- window.addEventListener('lce:actions.cart_opened', (event) => {});
97
- window.addEventListener('lce:actions.cart_closed', (event) => {});
233
+ Fires when the cart drawer opens.
98
234
 
99
- // Cart updated
235
+ **Data includes:** `true`.
236
+
237
+ **Example**
238
+
239
+ ```javascript
240
+ window.addEventListener('lce:actions.cart_opened', () => {
241
+ document.body.classList.add('cart-open');
242
+ });
243
+ ```
244
+
245
+ ### `lce:actions.cart_closed`
246
+
247
+ Fires when the cart drawer closes.
248
+
249
+ **Data includes:** `true`.
250
+
251
+ **Example**
252
+
253
+ ```javascript
254
+ window.addEventListener('lce:actions.cart_closed', () => {
255
+ document.body.classList.remove('cart-open');
256
+ });
257
+ ```
258
+
259
+ ### `lce:actions.cart_updated`
260
+
261
+ Fires when cart contents or totals change.
262
+
263
+ **Data includes:** `previous`, `current`.
264
+
265
+ **Example**
266
+
267
+ ```javascript
100
268
  window.addEventListener('lce:actions.cart_updated', (event) => {
101
- const { cartId, itemsCount, subtotal } = event.detail.data;
269
+ const { data } = event.detail;
270
+ const delta = data.current.itemCount - data.previous.itemCount;
271
+ if (delta !== 0) {
272
+ console.log('Item count changed by', delta);
273
+ }
274
+ });
275
+ ```
276
+
277
+ ### `lce:actions.cart_reset`
278
+
279
+ Fires when the cart is cleared.
280
+
281
+ **Data includes:** `true`.
282
+
283
+ **Example**
284
+
285
+ ```javascript
286
+ window.addEventListener('lce:actions.cart_reset', () => {
287
+ console.log('Cart reset');
288
+ });
289
+ ```
290
+
291
+ ### `lce:actions.cart_failed`
292
+
293
+ Fires when a cart operation fails.
294
+
295
+ **Data includes:** `cartId`, `message`.
296
+
297
+ **Example**
298
+
299
+ ```javascript
300
+ window.addEventListener('lce:actions.cart_failed', (event) => {
301
+ const { data } = event.detail;
302
+ console.error('Cart error:', data.message);
303
+ });
304
+ ```
305
+
306
+ ### `lce:actions.cart_item_added`
307
+
308
+ Fires when an item is added to the cart.
309
+
310
+ **Data includes:** `cartId`, `itemId`, `quantity`, `fulfillmentId`, `partNumber`.
311
+
312
+ **Example**
313
+
314
+ ```javascript
315
+ window.addEventListener('lce:actions.cart_item_added', (event) => {
316
+ const { data } = event.detail;
317
+ console.log(`Added item ${data.itemId} (qty ${data.quantity})`);
318
+ });
319
+ ```
320
+
321
+ ### `lce:actions.cart_item_removed`
322
+
323
+ Fires when an item is removed from the cart.
324
+
325
+ **Data includes:** `cartId`, `itemId`.
326
+
327
+ **Example**
328
+
329
+ ```javascript
330
+ window.addEventListener('lce:actions.cart_item_removed', (event) => {
331
+ const { data } = event.detail;
332
+ console.log('Removed item', data.itemId);
102
333
  });
334
+ ```
335
+
336
+ ### `lce:actions.cart_item_quantity_increase`
337
+
338
+ Fires when a cart item quantity increases.
339
+
340
+ **Data includes:** `cartId`, `itemId`, `quantity`, `previousQuantity`.
341
+
342
+ **Example**
343
+
344
+ ```javascript
345
+ window.addEventListener('lce:actions.cart_item_quantity_increase', (event) => {
346
+ const { data } = event.detail;
347
+ console.log('Quantity increased to', data.quantity);
348
+ });
349
+ ```
350
+
351
+ ### `lce:actions.cart_item_quantity_decrease`
352
+
353
+ Fires when a cart item quantity decreases.
354
+
355
+ **Data includes:** `cartId`, `itemId`, `quantity`, `previousQuantity`.
356
+
357
+ **Example**
358
+
359
+ ```javascript
360
+ window.addEventListener('lce:actions.cart_item_quantity_decrease', (event) => {
361
+ const { data } = event.detail;
362
+ console.log('Quantity decreased to', data.quantity);
363
+ });
364
+ ```
365
+
366
+ ### `lce:actions.cart_item_engraving_updated`
367
+
368
+ Fires when engraving text is updated for a cart item.
369
+
370
+ **Data includes:** `cartId`, `itemId`, `engravingLines`, `previousEngravingLines`.
371
+
372
+ **Example**
373
+
374
+ ```javascript
375
+ window.addEventListener('lce:actions.cart_item_engraving_updated', (event) => {
376
+ const { data } = event.detail;
377
+ console.log('Updated engraving for', data.itemId);
378
+ });
379
+ ```
103
380
 
104
- // Item added/removed
105
- window.addEventListener('lce:actions.cart_item_added', (event) => {});
106
- window.addEventListener('lce:actions.cart_item_removed', (event) => {});
381
+ ### `lce:actions.cart_promo_code_applied`
107
382
 
108
- // Quantity changed
109
- window.addEventListener('lce:actions.cart_item_quantity_increase', (event) => {});
110
- window.addEventListener('lce:actions.cart_item_quantity_decrease', (event) => {});
383
+ Fires when a promo code is applied to the cart.
111
384
 
112
- // Promo code events
385
+ **Data includes:** `cartId`, `discount`, `newSubtotal`.
386
+
387
+ **Example**
388
+
389
+ ```javascript
113
390
  window.addEventListener('lce:actions.cart_promo_code_applied', (event) => {
114
- const { discount, newSubtotal } = event.detail.data;
391
+ const { data } = event.detail;
392
+ console.log('Promo applied, discount:', data.discount);
393
+ });
394
+ ```
395
+
396
+ ### `lce:actions.cart_promo_code_removed`
397
+
398
+ Fires when a promo code is removed from the cart.
399
+
400
+ **Data includes:** `cartId`, `discount`, `newSubtotal`.
401
+
402
+ **Example**
403
+
404
+ ```javascript
405
+ window.addEventListener('lce:actions.cart_promo_code_removed', (event) => {
406
+ const { data } = event.detail;
407
+ console.log('Promo removed');
408
+ });
409
+ ```
410
+
411
+ ### `lce:actions.cart_promo_code_failed`
412
+
413
+ Fires when a promo code fails to apply.
414
+
415
+ **Data includes:** `cartId`, `error`.
416
+
417
+ **Example**
418
+
419
+ ```javascript
420
+ window.addEventListener('lce:actions.cart_promo_code_failed', (event) => {
421
+ const { data } = event.detail;
422
+ console.error('Promo code failed:', data.error);
115
423
  });
116
- window.addEventListener('lce:actions.cart_promo_code_removed', (event) => {});
117
- window.addEventListener('lce:actions.cart_promo_code_failed', (event) => {});
424
+ ```
118
425
 
119
- // Product add success/failure
426
+ ### `lce:actions.cart_product_add_success`
427
+
428
+ Fires when adding products via the actions API succeeds.
429
+
430
+ **Data includes:** `cartId`, `itemsAdded`, `identifiers`.
431
+
432
+ **Example**
433
+
434
+ ```javascript
120
435
  window.addEventListener('lce:actions.cart_product_add_success', (event) => {
121
- const { itemsAdded, identifiers } = event.detail.data;
436
+ const { data } = event.detail;
437
+ console.log(`Added ${data.itemsAdded} products`);
122
438
  });
439
+ ```
440
+
441
+ ### `lce:actions.cart_product_add_failed`
442
+
443
+ Fires when adding products via the actions API fails.
444
+
445
+ **Data includes:** `cartId`, `identifiers`, `error`.
446
+
447
+ **Example**
448
+
449
+ ```javascript
123
450
  window.addEventListener('lce:actions.cart_product_add_failed', (event) => {
124
- const { error } = event.detail.data;
451
+ const { data } = event.detail;
452
+ console.error('Product add failed:', data.error);
125
453
  });
126
454
  ```
127
455
 
128
456
  ## Checkout Events
129
457
 
458
+ ### `lce:actions.checkout_loaded`
459
+
460
+ Fires when checkout data loads.
461
+
462
+ **Data includes:** `cartId`, `amounts`, `itemCount`, `isGift`, `billingSameAsShipping`.
463
+
464
+ **Example**
465
+
466
+ ```javascript
467
+ window.addEventListener('lce:actions.checkout_loaded', (event) => {
468
+ const { data } = event.detail;
469
+ console.log('Checkout loaded for cart', data.cartId);
470
+ });
471
+ ```
472
+
473
+ ### `lce:actions.checkout_opened`
474
+
475
+ Fires when the checkout drawer opens.
476
+
477
+ **Data includes:** `true`.
478
+
479
+ **Example**
480
+
481
+ ```javascript
482
+ window.addEventListener('lce:actions.checkout_opened', () => {
483
+ console.log('Checkout opened');
484
+ });
485
+ ```
486
+
487
+ ### `lce:actions.checkout_closed`
488
+
489
+ Fires when the checkout drawer closes.
490
+
491
+ **Data includes:** `true`.
492
+
493
+ **Example**
494
+
495
+ ```javascript
496
+ window.addEventListener('lce:actions.checkout_closed', () => {
497
+ console.log('Checkout closed');
498
+ });
499
+ ```
500
+
501
+ ### `lce:actions.checkout_failed`
502
+
503
+ Fires when checkout fails to load or operate.
504
+
505
+ **Data includes:** `message`.
506
+
507
+ **Example**
508
+
509
+ ```javascript
510
+ window.addEventListener('lce:actions.checkout_failed', (event) => {
511
+ const { data } = event.detail;
512
+ console.error('Checkout error:', data.message);
513
+ });
514
+ ```
515
+
516
+ ### `lce:actions.checkout_customer_information_updated`
517
+
518
+ Fires when customer info (email, phone, name) is updated.
519
+
520
+ **Data includes:** `cartId`.
521
+
522
+ **Example**
523
+
130
524
  ```javascript
131
- // Lifecycle
132
- window.addEventListener('lce:actions.checkout_loaded', (event) => {});
133
- window.addEventListener('lce:actions.checkout_opened', (event) => {});
134
- window.addEventListener('lce:actions.checkout_closed', (event) => {});
525
+ window.addEventListener('lce:actions.checkout_customer_information_updated', (event) => {
526
+ const { data } = event.detail;
527
+ console.log('Customer info updated for cart', data.cartId);
528
+ });
529
+ ```
530
+
531
+ ### `lce:actions.checkout_billing_information_updated`
135
532
 
136
- // Form updates
137
- window.addEventListener('lce:actions.checkout_customer_information_updated', (event) => {});
138
- window.addEventListener('lce:actions.checkout_billing_information_updated', (event) => {});
139
- window.addEventListener('lce:actions.checkout_gift_information_updated', (event) => {});
533
+ Fires when billing info is updated.
534
+
535
+ **Data includes:** `cartId`.
536
+
537
+ **Example**
538
+
539
+ ```javascript
540
+ window.addEventListener('lce:actions.checkout_billing_information_updated', (event) => {
541
+ const { data } = event.detail;
542
+ console.log('Billing info updated for cart', data.cartId);
543
+ });
544
+ ```
140
545
 
141
- // Toggles
546
+ ### `lce:actions.checkout_gift_information_updated`
547
+
548
+ Fires when gift recipient info is updated.
549
+
550
+ **Data includes:** `cartId`.
551
+
552
+ **Example**
553
+
554
+ ```javascript
555
+ window.addEventListener('lce:actions.checkout_gift_information_updated', (event) => {
556
+ const { data } = event.detail;
557
+ console.log('Gift info updated for cart', data.cartId);
558
+ });
559
+ ```
560
+
561
+ ### `lce:actions.checkout_is_gift_toggled`
562
+
563
+ Fires when gift mode is toggled.
564
+
565
+ **Data includes:** `cartId`, `isActive`, `previousIsActive`.
566
+
567
+ **Example**
568
+
569
+ ```javascript
142
570
  window.addEventListener('lce:actions.checkout_is_gift_toggled', (event) => {
143
- const { isGift } = event.detail.data;
571
+ const { data } = event.detail;
572
+ console.log('Gift mode:', data.isActive);
573
+ });
574
+ ```
575
+
576
+ ### `lce:actions.checkout_billing_same_as_shipping_toggled`
577
+
578
+ Fires when the billing same-as-shipping option is toggled.
579
+
580
+ **Data includes:** `cartId`, `isActive`, `previousIsActive`.
581
+
582
+ **Example**
583
+
584
+ ```javascript
585
+ window.addEventListener('lce:actions.checkout_billing_same_as_shipping_toggled', (event) => {
586
+ const { data } = event.detail;
587
+ console.log('Billing same as shipping:', data.isActive);
588
+ });
589
+ ```
590
+
591
+ ### `lce:actions.checkout_marketing_preferences_toggled`
592
+
593
+ Fires when a marketing preference is toggled.
594
+
595
+ **Data includes:** `cartId`, `fieldName`, `isActive`, `previousIsActive`.
596
+
597
+ **Example**
598
+
599
+ ```javascript
600
+ window.addEventListener('lce:actions.checkout_marketing_preferences_toggled', (event) => {
601
+ const { data } = event.detail;
602
+ console.log(`Marketing ${data.fieldName}:`, data.isActive);
603
+ });
604
+ ```
605
+
606
+ ### `lce:actions.checkout_item_removed`
607
+
608
+ Fires when an item is removed during checkout.
609
+
610
+ **Data includes:** `cartId`, `cartItemId`.
611
+
612
+ **Example**
613
+
614
+ ```javascript
615
+ window.addEventListener('lce:actions.checkout_item_removed', (event) => {
616
+ const { data } = event.detail;
617
+ console.log('Checkout item removed', data.cartItemId);
618
+ });
619
+ ```
620
+
621
+ ### `lce:actions.checkout_item_quantity_increase`
622
+
623
+ Fires when a checkout item quantity increases.
624
+
625
+ **Data includes:** `cartId`, `cartItemId`, `quantity`, `previousQuantity`.
626
+
627
+ **Example**
628
+
629
+ ```javascript
630
+ window.addEventListener('lce:actions.checkout_item_quantity_increase', (event) => {
631
+ const { data } = event.detail;
632
+ console.log('Checkout quantity increased to', data.quantity);
633
+ });
634
+ ```
635
+
636
+ ### `lce:actions.checkout_item_quantity_decrease`
637
+
638
+ Fires when a checkout item quantity decreases.
639
+
640
+ **Data includes:** `cartId`, `cartItemId`, `quantity`, `previousQuantity`.
641
+
642
+ **Example**
643
+
644
+ ```javascript
645
+ window.addEventListener('lce:actions.checkout_item_quantity_decrease', (event) => {
646
+ const { data } = event.detail;
647
+ console.log('Checkout quantity decreased to', data.quantity);
648
+ });
649
+ ```
650
+
651
+ ### `lce:actions.checkout_item_engraving_updated`
652
+
653
+ Fires when engraving text is updated for a checkout item.
654
+
655
+ **Data includes:** `cartId`, `cartItemId`, `engravingLines`, `previousEngravingLines`.
656
+
657
+ **Example**
658
+
659
+ ```javascript
660
+ window.addEventListener('lce:actions.checkout_item_engraving_updated', (event) => {
661
+ const { data } = event.detail;
662
+ console.log('Checkout engraving updated for', data.cartItemId);
663
+ });
664
+ ```
665
+
666
+ ### `lce:actions.checkout_tip_updated`
667
+
668
+ Fires when delivery tips are updated.
669
+
670
+ **Data includes:** `cartId`, `deliveryTips`, `previousDeliveryTips`.
671
+
672
+ **Example**
673
+
674
+ ```javascript
675
+ window.addEventListener('lce:actions.checkout_tip_updated', (event) => {
676
+ const { data } = event.detail;
677
+ console.log('Tips updated for cart', data.cartId);
678
+ });
679
+ ```
680
+
681
+ ### `lce:actions.checkout_submit_started`
682
+
683
+ Fires when checkout submission starts.
684
+
685
+ **Data includes:** `started`.
686
+
687
+ **Example**
688
+
689
+ ```javascript
690
+ window.addEventListener('lce:actions.checkout_submit_started', (event) => {
691
+ const { data } = event.detail;
692
+ if (data.started) {
693
+ console.log('Checkout submission started');
694
+ }
144
695
  });
145
- window.addEventListener('lce:actions.checkout_billing_same_as_shipping_toggled', (event) => {});
146
- window.addEventListener('lce:actions.checkout_marketing_preferences_toggled', (event) => {});
696
+ ```
697
+
698
+ ### `lce:actions.checkout_submit_completed`
699
+
700
+ Fires when checkout submission completes successfully.
147
701
 
148
- // Submission
149
- window.addEventListener('lce:actions.checkout_submit_started', (event) => {});
702
+ **Data includes:** `orderNumber`, `orderTotal`.
703
+
704
+ **Example**
705
+
706
+ ```javascript
150
707
  window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
151
- const { orderId, total } = event.detail.data;
708
+ const { data } = event.detail;
709
+ console.log('Order completed:', data.orderNumber);
152
710
  });
711
+ ```
712
+
713
+ ### `lce:actions.checkout_submit_failed`
714
+
715
+ Fires when checkout submission fails.
716
+
717
+ **Data includes:** `message`.
718
+
719
+ **Example**
720
+
721
+ ```javascript
153
722
  window.addEventListener('lce:actions.checkout_submit_failed', (event) => {
154
- const { error } = event.detail.data;
723
+ const { data } = event.detail;
724
+ console.error('Checkout submit failed:', data.message);
725
+ });
726
+ ```
727
+
728
+ ### `lce:actions.checkout_promo_code_applied`
729
+
730
+ Fires when a promo code is applied during checkout.
731
+
732
+ **Data includes:** `cartId`, `discount`, `newTotal`.
733
+
734
+ **Example**
735
+
736
+ ```javascript
737
+ window.addEventListener('lce:actions.checkout_promo_code_applied', (event) => {
738
+ const { data } = event.detail;
739
+ console.log('Checkout promo applied:', data.discount);
740
+ });
741
+ ```
742
+
743
+ ### `lce:actions.checkout_promo_code_removed`
744
+
745
+ Fires when a promo code is removed during checkout.
746
+
747
+ **Data includes:** `cartId`, `discount`, `newTotal`.
748
+
749
+ **Example**
750
+
751
+ ```javascript
752
+ window.addEventListener('lce:actions.checkout_promo_code_removed', (event) => {
753
+ const { data } = event.detail;
754
+ console.log('Checkout promo removed');
755
+ });
756
+ ```
757
+
758
+ ### `lce:actions.checkout_promo_code_failed`
759
+
760
+ Fires when a promo code fails during checkout.
761
+
762
+ **Data includes:** `cartId`, `error`.
763
+
764
+ **Example**
765
+
766
+ ```javascript
767
+ window.addEventListener('lce:actions.checkout_promo_code_failed', (event) => {
768
+ const { data } = event.detail;
769
+ console.error('Checkout promo failed:', data.error);
770
+ });
771
+ ```
772
+
773
+ ### `lce:actions.checkout_gift_card_applied`
774
+
775
+ Fires when a gift card is applied during checkout.
776
+
777
+ **Data includes:** `cartId`, `newTotal`.
778
+
779
+ **Example**
780
+
781
+ ```javascript
782
+ window.addEventListener('lce:actions.checkout_gift_card_applied', (event) => {
783
+ const { data } = event.detail;
784
+ console.log('Gift card applied, new total:', data.newTotal);
785
+ });
786
+ ```
787
+
788
+ ### `lce:actions.checkout_gift_card_removed`
789
+
790
+ Fires when a gift card is removed during checkout.
791
+
792
+ **Data includes:** `cartId`, `newTotal`.
793
+
794
+ **Example**
795
+
796
+ ```javascript
797
+ window.addEventListener('lce:actions.checkout_gift_card_removed', (event) => {
798
+ const { data } = event.detail;
799
+ console.log('Gift card removed');
800
+ });
801
+ ```
802
+
803
+ ### `lce:actions.checkout_gift_card_failed`
804
+
805
+ Fires when a gift card fails during checkout.
806
+
807
+ **Data includes:** `cartId`, `error`.
808
+
809
+ **Example**
810
+
811
+ ```javascript
812
+ window.addEventListener('lce:actions.checkout_gift_card_failed', (event) => {
813
+ const { data } = event.detail;
814
+ console.error('Gift card failed:', data.error);
815
+ });
816
+ ```
817
+
818
+ ### `lce:actions.checkout_product_add_success`
819
+
820
+ Fires when products are added to checkout via the actions API.
821
+
822
+ **Data includes:** `cartId`, `itemsAdded`, `identifiers`, `isPresale`.
823
+
824
+ **Example**
825
+
826
+ ```javascript
827
+ window.addEventListener('lce:actions.checkout_product_add_success', (event) => {
828
+ const { data } = event.detail;
829
+ console.log(`Checkout added ${data.itemsAdded} products`);
155
830
  });
831
+ ```
156
832
 
157
- // Promo codes & gift cards
158
- window.addEventListener('lce:actions.checkout_promo_code_applied', (event) => {});
159
- window.addEventListener('lce:actions.checkout_gift_card_applied', (event) => {});
833
+ ### `lce:actions.checkout_product_add_failed`
834
+
835
+ Fires when adding products to checkout via the actions API fails.
836
+
837
+ **Data includes:** `cartId`, `identifiers`, `error`, `isPresale`.
838
+
839
+ **Example**
840
+
841
+ ```javascript
842
+ window.addEventListener('lce:actions.checkout_product_add_failed', (event) => {
843
+ const { data } = event.detail;
844
+ console.error('Checkout product add failed:', data.error);
845
+ });
846
+ ```
847
+
848
+ ## Form Events
849
+
850
+ ### `lce:forms.customer`
851
+
852
+ Fires when a customer form field changes in checkout.
853
+
854
+ **Data includes:** `fieldName`, `fieldValue`.
855
+
856
+ **Example**
857
+
858
+ ```javascript
859
+ window.addEventListener('lce:forms.customer', (event) => {
860
+ const { data } = event.detail;
861
+ console.log('Customer field changed:', data.fieldName);
862
+ });
863
+ ```
864
+
865
+ ### `lce:forms.billing`
866
+
867
+ Fires when a billing form field changes in checkout.
868
+
869
+ **Data includes:** `fieldName`, `fieldValue`.
870
+
871
+ **Example**
872
+
873
+ ```javascript
874
+ window.addEventListener('lce:forms.billing', (event) => {
875
+ const { data } = event.detail;
876
+ console.log('Billing field changed:', data.fieldName);
877
+ });
878
+ ```
879
+
880
+ ### `lce:forms.gift`
881
+
882
+ Fires when a gift form field changes in checkout.
883
+
884
+ **Data includes:** `fieldName`, `fieldValue`.
885
+
886
+ **Example**
887
+
888
+ ```javascript
889
+ window.addEventListener('lce:forms.gift', (event) => {
890
+ const { data } = event.detail;
891
+ console.log('Gift field changed:', data.fieldName);
892
+ });
160
893
  ```
161
894
 
162
895
  ## Use Cases
@@ -164,22 +897,24 @@ window.addEventListener('lce:actions.checkout_gift_card_applied', (event) => {})
164
897
  ### Analytics Integration
165
898
 
166
899
  ```javascript
167
- // Track page views
900
+ // Track product views
168
901
  window.addEventListener('lce:actions.product_loaded', (event) => {
902
+ const { data } = event.detail;
169
903
  gtag('event', 'view_item', {
170
904
  items: [{
171
- item_id: event.detail.data.identifier,
172
- item_name: event.detail.data.name,
173
- price: event.detail.data.price / 100
905
+ item_id: data.identifier,
906
+ item_name: data.name,
907
+ price: data.price / 100
174
908
  }]
175
909
  });
176
910
  });
177
911
 
178
912
  // Track purchases
179
913
  window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
914
+ const { data } = event.detail;
180
915
  gtag('event', 'purchase', {
181
- transaction_id: event.detail.data.orderId,
182
- value: event.detail.data.total / 100,
916
+ transaction_id: data.orderNumber,
917
+ value: data.orderTotal / 100,
183
918
  currency: 'USD'
184
919
  });
185
920
  });