@liquidcommerce/elements-sdk 2.6.0-beta.127 → 2.6.0-beta.129

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 (33) hide show
  1. package/README.md +4 -2
  2. package/dist/index.checkout.esm.js +9281 -8938
  3. package/dist/index.esm.js +13165 -12814
  4. package/dist/ssr-stub.esm.js +1 -0
  5. package/dist/types/core/client/actions/client-analytics-action.service.d.ts +35 -0
  6. package/dist/types/core/client/actions/client-checkout-action.service.d.ts +1 -0
  7. package/dist/types/core/client/client-action.service.d.ts +1 -0
  8. package/dist/types/core/client/client-config.service.d.ts +2 -0
  9. package/dist/types/core/google-tag-manager.service.d.ts +3 -2
  10. package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +4 -0
  11. package/dist/types/core/pubsub/interfaces/core.interface.d.ts +2 -1
  12. package/dist/types/enums/core.enum.d.ts +1 -0
  13. package/dist/types/index.checkout.d.ts +3 -2
  14. package/dist/types/index.d.ts +1 -0
  15. package/dist/types/interfaces/analytics.interface.d.ts +41 -0
  16. package/dist/types/interfaces/client.interface.d.ts +5 -0
  17. package/dist/types/interfaces/config.interface.d.ts +1 -0
  18. package/dist/types/modules/cart/cart.commands.d.ts +3 -1
  19. package/dist/types/modules/checkout/checkout.commands.d.ts +8 -0
  20. package/dist/types/modules/checkout/components/checkout-express-checkout.component.d.ts +1 -0
  21. package/dist/types/modules/product-list/product-list.commands.d.ts +5 -0
  22. package/dist/types/ssr/stub.checkout.d.ts +2 -1
  23. package/dist/types/ssr/stub.d.ts +2 -1
  24. package/docs/v1/README.md +1 -0
  25. package/docs/v1/api/actions/analytics-actions.md +326 -0
  26. package/docs/v1/api/actions/checkout-actions.md +5 -2
  27. package/docs/v1/api/client.md +7 -2
  28. package/docs/v1/api/configuration.md +4 -0
  29. package/docs/v1/api/typescript-types.md +73 -1
  30. package/docs/v1/guides/checkout-component.md +14 -2
  31. package/docs/v1/guides/events.md +22 -1
  32. package/docs/v1/reference/analytics.md +52 -9
  33. package/package.json +1 -1
@@ -142,6 +142,7 @@ const ELEMENTS_ACTIONS_EVENT = {
142
142
  CHECKOUT_PRODUCT_ADD_SUCCESS: 'checkout_product_add_success',
143
143
  CHECKOUT_PRODUCT_ADD_FAILED: 'checkout_product_add_failed',
144
144
  CHECKOUT_EXPRESS_CHECKOUT_AVAILABILITY: 'checkout_express_checkout_availability',
145
+ CHECKOUT_EXPRESS_CHECKOUT_STARTED: 'checkout_express_checkout_started',
145
146
  CHECKOUT_PAYMENT_FORM_FAILED: 'checkout_payment_form_failed',
146
147
  };
147
148
  const ELEMENTS_FORM = {
@@ -0,0 +1,35 @@
1
+ import type { IAnalyticsAddress, IAnalyticsAddressFailure, IAnalyticsAvailability, IAnalyticsFulfillmentAvailability, IAnalyticsItem, IAnalyticsItemList } from '@/interfaces/analytics.interface';
2
+ import { BaseActionService } from './base-action.service';
3
+ export interface IAnalyticsActions {
4
+ search: (searchTerm: string) => void;
5
+ viewItem: (item: IAnalyticsItem) => void;
6
+ viewItemList: (items: IAnalyticsItem[], list?: IAnalyticsItemList) => void;
7
+ selectItem: (item: IAnalyticsItem, list?: IAnalyticsItemList) => void;
8
+ addToCart: (item: IAnalyticsItem) => void;
9
+ removeFromCart: (item: IAnalyticsItem) => void;
10
+ viewCart: (items: IAnalyticsItem[]) => void;
11
+ beginCheckout: (items: IAnalyticsItem[], options?: {
12
+ coupon?: string;
13
+ }) => void;
14
+ addressUpdated: (address: IAnalyticsAddress) => void;
15
+ addressFailed: (failure: IAnalyticsAddressFailure) => void;
16
+ productNoAvailability: (details: IAnalyticsAvailability) => void;
17
+ productSizeNoAvailability: (details: IAnalyticsAvailability) => void;
18
+ productFulfillmentNoAvailability: (details: IAnalyticsFulfillmentAvailability) => void;
19
+ }
20
+ export declare class ClientAnalyticsActionService extends BaseActionService {
21
+ private readonly googleTagManager;
22
+ constructor();
23
+ static getInstance(): ClientAnalyticsActionService;
24
+ get actions(): IAnalyticsActions;
25
+ private report;
26
+ private check;
27
+ private toGtmItem;
28
+ private toGtmItems;
29
+ private toList;
30
+ private toAvailability;
31
+ private toOptionalString;
32
+ private toAddress;
33
+ private toCoordinates;
34
+ private validateItem;
35
+ }
@@ -53,6 +53,7 @@ export declare class ClientCheckoutActionService extends BaseActionService {
53
53
  private openCheckout;
54
54
  private closeCheckout;
55
55
  private toggleCheckout;
56
+ private reportCheckoutOpened;
56
57
  private exitCheckout;
57
58
  private setSavedPaymentMethod;
58
59
  private clearSavedPaymentMethod;
@@ -4,6 +4,7 @@ export declare class ClientActionService {
4
4
  private readonly addressActionService;
5
5
  private readonly cartActionService;
6
6
  private readonly checkoutActionService;
7
+ private readonly analyticsActionService;
7
8
  constructor();
8
9
  static getInstance(): ClientActionService;
9
10
  get actions(): ILiquidCommerceElementsActions;
@@ -23,6 +23,7 @@ export interface IClientConfigs {
23
23
  openShadowDom?: boolean;
24
24
  hasCustomApiUrl?: boolean;
25
25
  mockMode: boolean;
26
+ enableExpressCheckout: boolean;
26
27
  checkout: ILiquidCommerceElementsCheckoutConfig | null;
27
28
  isCheckoutOnly: boolean;
28
29
  }
@@ -38,6 +39,7 @@ export interface IClientConfigInput {
38
39
  customApiUrl?: string;
39
40
  openShadowDom?: boolean;
40
41
  mockMode?: boolean;
42
+ enableExpressCheckout?: boolean;
41
43
  };
42
44
  checkout?: ILiquidCommerceElementsCheckoutConfig;
43
45
  isCheckoutOnly?: boolean;
@@ -101,6 +101,7 @@ export declare class GoogleTagManagerService {
101
101
  gift_cards?: number;
102
102
  net_total?: number;
103
103
  }): void;
104
+ search(searchTerm: string): void;
104
105
  promoCodeAttempt(code: string): void;
105
106
  promoCodeApplied(code: string, discount?: number): void;
106
107
  promoCodeFailed(code: string, reason?: string): void;
@@ -108,8 +109,8 @@ export declare class GoogleTagManagerService {
108
109
  giftCardApplied(code: string, appliedAmount?: number): void;
109
110
  giftCardFailed(code: string, reason?: string): void;
110
111
  addressUpdated(addressData: {
111
- googlePlacesId: string;
112
- formattedAddress: string;
112
+ googlePlacesId?: string;
113
+ formattedAddress?: string;
113
114
  address: {
114
115
  one?: string;
115
116
  two?: string;
@@ -118,6 +118,10 @@ export interface ICheckoutExpressCheckoutAvailabilityEventData {
118
118
  available: boolean;
119
119
  wallets: string[];
120
120
  }
121
+ export interface ICheckoutExpressCheckoutStartedEventData {
122
+ cartId: string;
123
+ wallet: string;
124
+ }
121
125
  export interface ICheckoutPaymentFormFailedEventData {
122
126
  cartId: string;
123
127
  reason: 'blocked' | 'timeout' | 'error';
@@ -1,6 +1,6 @@
1
1
  import type { IAddressActionEventData, IAddressFailedEventData } from '@/core/pubsub/interfaces/address.interface';
2
2
  import type { ICartFailedEventData, ICartItemAddedEventData, ICartItemEngravingUpdatedEventData, ICartItemQuantityChangedEventData, ICartItemRemovedEventData, ICartLoadedEventData, ICartProductAddEventData, ICartProductAddFailedEventData, ICartPromoCodeEventData, ICartPromoCodeFailedEventData, ICartShopRetailerEventData, ICartUpdatedEventData } from '@/core/pubsub/interfaces/cart.interface';
3
- import type { ICheckoutBillingInformationUpdatedEventData, ICheckoutCustomerInformationUpdatedEventData, ICheckoutDeliveryMethodUpdatedEventData, ICheckoutExpressCheckoutAvailabilityEventData, ICheckoutFailedEventData, ICheckoutGiftCardEventData, ICheckoutGiftCardFailedEventData, ICheckoutGiftInformationUpdatedEventData, ICheckoutItemEngravingUpdatedEventData, ICheckoutItemQuantityChangedEventData, ICheckoutItemRemovedEventData, ICheckoutLoadedEventData, ICheckoutMarketingPreferencesToggleEventData, ICheckoutPaymentFormFailedEventData, ICheckoutProductAddEventData, ICheckoutProductAddFailedEventData, ICheckoutPromoCodeEventData, ICheckoutPromoCodeFailedEventData, ICheckoutSubmitCompletedEventData, ICheckoutSubmitFailedEventData, ICheckoutSubmitStartedEventData, ICheckoutTipUpdatedEventData, ICheckoutToggleEventData } from '@/core/pubsub/interfaces/checkout.interface';
3
+ import type { ICheckoutBillingInformationUpdatedEventData, ICheckoutCustomerInformationUpdatedEventData, ICheckoutDeliveryMethodUpdatedEventData, ICheckoutExpressCheckoutAvailabilityEventData, ICheckoutExpressCheckoutStartedEventData, ICheckoutFailedEventData, ICheckoutGiftCardEventData, ICheckoutGiftCardFailedEventData, ICheckoutGiftInformationUpdatedEventData, ICheckoutItemEngravingUpdatedEventData, ICheckoutItemQuantityChangedEventData, ICheckoutItemRemovedEventData, ICheckoutLoadedEventData, ICheckoutMarketingPreferencesToggleEventData, ICheckoutPaymentFormFailedEventData, ICheckoutProductAddEventData, ICheckoutProductAddFailedEventData, ICheckoutPromoCodeEventData, ICheckoutPromoCodeFailedEventData, ICheckoutSubmitCompletedEventData, ICheckoutSubmitFailedEventData, ICheckoutSubmitStartedEventData, ICheckoutTipUpdatedEventData, ICheckoutToggleEventData } from '@/core/pubsub/interfaces/checkout.interface';
4
4
  import type { IProductAddToCartEventData, IProductFulfillmentChangedEventData, IProductFulfillmentTypeChangedEventData, IProductLoadedEventData, IProductQuantityChangedEventData, IProductSizeChangedEventData } from '@/core/pubsub/interfaces/product.interface';
5
5
  import { ELEMENTS_ACTIONS_EVENT } from '@/enums';
6
6
  export interface IElementsClientIsReadyEventData {
@@ -83,6 +83,7 @@ export interface IElementsActionsEventsMap {
83
83
  [ELEMENTS_ACTIONS_EVENT.CHECKOUT_PRODUCT_ADD_SUCCESS]: ICheckoutProductAddEventData;
84
84
  [ELEMENTS_ACTIONS_EVENT.CHECKOUT_PRODUCT_ADD_FAILED]: ICheckoutProductAddFailedEventData;
85
85
  [ELEMENTS_ACTIONS_EVENT.CHECKOUT_EXPRESS_CHECKOUT_AVAILABILITY]: ICheckoutExpressCheckoutAvailabilityEventData;
86
+ [ELEMENTS_ACTIONS_EVENT.CHECKOUT_EXPRESS_CHECKOUT_STARTED]: ICheckoutExpressCheckoutStartedEventData;
86
87
  [ELEMENTS_ACTIONS_EVENT.CHECKOUT_PAYMENT_FORM_FAILED]: ICheckoutPaymentFormFailedEventData;
87
88
  }
88
89
  export type SpecificActionEvent = keyof IElementsActionsEventsMap;
@@ -61,6 +61,7 @@ export declare const ELEMENTS_ACTIONS_EVENT: {
61
61
  readonly CHECKOUT_PRODUCT_ADD_SUCCESS: "checkout_product_add_success";
62
62
  readonly CHECKOUT_PRODUCT_ADD_FAILED: "checkout_product_add_failed";
63
63
  readonly CHECKOUT_EXPRESS_CHECKOUT_AVAILABILITY: "checkout_express_checkout_availability";
64
+ readonly CHECKOUT_EXPRESS_CHECKOUT_STARTED: "checkout_express_checkout_started";
64
65
  readonly CHECKOUT_PAYMENT_FORM_FAILED: "checkout_payment_form_failed";
65
66
  };
66
67
  export declare const ELEMENTS_FORM: {
@@ -1,9 +1,10 @@
1
1
  import { ElementsCheckout } from '@/clients/checkout';
2
2
  import type { DebugMode, ElementsEnv } from '@/enums';
3
3
  import { DEBUG_MODE, ELEMENTS_ENV } from '@/enums';
4
- import type { IElementsCheckoutActions, IElementsCheckoutClient } from '@/interfaces/client.interface';
4
+ import type { IAnalyticsAddress, IAnalyticsAddressFailure, IAnalyticsAvailability, IAnalyticsFulfillmentAvailability, IAnalyticsItem, IAnalyticsItemList } from '@/interfaces/analytics.interface';
5
+ import type { IAnalyticsActions, IElementsCheckoutActions, IElementsCheckoutClient } from '@/interfaces/client.interface';
5
6
  import type { IInjectedComponent } from '@/interfaces/component.interface';
6
7
  import type { ILiquidCommerceElementsCheckoutClientConfig } from '@/interfaces/config.interface';
7
8
  import type { IInjectCheckoutParams, IInjectExpressCheckoutParams } from '@/interfaces/injection.interface';
8
- export type { DebugMode, ElementsEnv, IElementsCheckoutActions, IElementsCheckoutClient, IInjectCheckoutParams, IInjectExpressCheckoutParams, IInjectedComponent, ILiquidCommerceElementsCheckoutClientConfig, };
9
+ export type { DebugMode, ElementsEnv, IAnalyticsActions, IAnalyticsAddress, IAnalyticsAddressFailure, IAnalyticsAvailability, IAnalyticsFulfillmentAvailability, IAnalyticsItem, IAnalyticsItemList, IElementsCheckoutActions, IElementsCheckoutClient, IInjectCheckoutParams, IInjectExpressCheckoutParams, IInjectedComponent, ILiquidCommerceElementsCheckoutClientConfig, };
9
10
  export { DEBUG_MODE, ELEMENTS_ENV, ElementsCheckout };
@@ -3,6 +3,7 @@ export * from './clients/main';
3
3
  export * from './core/sdk-error-handler';
4
4
  export * from './enums';
5
5
  export type { LiquidCommerceGlobal } from './global';
6
+ export * from './interfaces/analytics.interface';
6
7
  export * from './interfaces/api';
7
8
  export * from './interfaces/client.interface';
8
9
  export * from './interfaces/component.interface';
@@ -0,0 +1,41 @@
1
+ import type { FulfillmentType } from '@/enums';
2
+ import type { IAddressAddress, IAddressCoordinates } from '@/interfaces/api/address.interface';
3
+ export interface IAnalyticsItem {
4
+ id: string;
5
+ name: string;
6
+ brand?: string;
7
+ size?: string;
8
+ categoryPath?: string;
9
+ price?: number;
10
+ quantity?: number;
11
+ type?: string;
12
+ subType?: string;
13
+ image?: string;
14
+ upc?: string;
15
+ groupingId?: string;
16
+ index?: number;
17
+ }
18
+ export interface IAnalyticsItemList {
19
+ id?: string;
20
+ name?: string;
21
+ }
22
+ export interface IAnalyticsAddress {
23
+ placesId?: string;
24
+ formattedAddress?: string;
25
+ address: Partial<IAddressAddress>;
26
+ coordinates?: IAddressCoordinates;
27
+ }
28
+ export interface IAnalyticsAddressFailure {
29
+ placesId?: string;
30
+ formattedAddress?: string;
31
+ address?: Partial<IAddressAddress>;
32
+ error: string;
33
+ }
34
+ export interface IAnalyticsAvailability {
35
+ item: IAnalyticsItem;
36
+ reason: string;
37
+ address?: Partial<IAddressAddress>;
38
+ }
39
+ export interface IAnalyticsFulfillmentAvailability extends IAnalyticsAvailability {
40
+ fulfillmentType: FulfillmentType;
41
+ }
@@ -1,4 +1,5 @@
1
1
  import type { IAddressActions } from '@/core/client/actions/client-address-action.service';
2
+ import type { IAnalyticsActions } from '@/core/client/actions/client-analytics-action.service';
2
3
  import type { ICartActions } from '@/core/client/actions/client-cart-action.service';
3
4
  import type { ICheckoutActions } from '@/core/client/actions/client-checkout-action.service';
4
5
  import type { IProductActions } from '@/core/client/actions/client-product-action.service';
@@ -7,6 +8,7 @@ import type { IAddressOptions } from '@/modules/address/address.interface';
7
8
  import type { IInjectedComponent } from './component.interface';
8
9
  import type { UpdateAddressComponent, UpdateCartComponent, UpdateCheckoutComponent, UpdateComponentGlobalConfigs, UpdateProductComponent, UpdateProductListComponent } from './configs';
9
10
  import type { IBuilderInjectElementParams, IInjectCheckoutBuilderParams, IInjectCheckoutParams, IInjectExpressCheckoutParams, IInjectProductElement, IInjectProductListFiltersParams, IInjectProductListParams, IInjectProductListSearchParams } from './injection.interface';
11
+ export type { IAnalyticsActions };
10
12
  export interface ILiquidCommerceElementsUIMethod {
11
13
  cartButton(containerId: string, showItemsCount?: boolean): void;
12
14
  floatingCartButton(showItemsCount?: boolean): void;
@@ -20,6 +22,7 @@ export interface ILiquidCommerceElementsActions {
20
22
  address: IAddressActions;
21
23
  cart: ICartActions;
22
24
  checkout: ICheckoutActions;
25
+ analytics: IAnalyticsActions;
23
26
  }
24
27
  export interface IElementsCheckoutActions extends Omit<ICheckoutActions, 'openCheckout' | 'closeCheckout' | 'toggleCheckout'> {
25
28
  }
@@ -28,6 +31,7 @@ export interface IElementsCheckoutClient {
28
31
  injectExpressCheckout: (params: IInjectExpressCheckoutParams) => Promise<IInjectedComponent | null>;
29
32
  actions: {
30
33
  checkout: IElementsCheckoutActions;
34
+ analytics: IAnalyticsActions;
31
35
  };
32
36
  destroy(): void;
33
37
  }
@@ -66,6 +70,7 @@ export interface ILiquidCommerceElementsCheckoutClient {
66
70
  injectCheckout(params: IInjectCheckoutParams): Promise<IInjectedComponent | null>;
67
71
  actions: {
68
72
  checkout: IElementsCheckoutActions;
73
+ analytics: IAnalyticsActions;
69
74
  };
70
75
  destroy(): void;
71
76
  }
@@ -14,6 +14,7 @@ export interface ILiquidCommerceElementsDevelopmentConfig {
14
14
  customApiUrl?: string;
15
15
  openShadowDom?: boolean;
16
16
  mockMode?: boolean;
17
+ enableExpressCheckout?: boolean;
17
18
  }
18
19
  export interface IClientCustomThemeConfig {
19
20
  global?: UpdateComponentGlobalConfigs;
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from '@/core/command/base-command.service';
2
2
  import type { IBaseCartEventData, ICartShopRetailerEventData } from '@/core/pubsub/interfaces/cart.interface';
3
+ import type { ICartStore } from '@/core/store/interfaces/cart.interface';
3
4
  export interface AddItemParams {
4
5
  fulfillmentId: string;
5
6
  partNumber: string;
@@ -19,7 +20,8 @@ export declare class CartCommands extends BaseCommand {
19
20
  updateItemEngraving(productItemId: string, engravingLines: string[]): Promise<void>;
20
21
  addItem(params: AddItemParams): Promise<void>;
21
22
  handleGoToCheckout(): Promise<void>;
22
- private trackBeginCheckout;
23
+ trackViewCart(): void;
24
+ trackBeginCheckout(cartStore: ICartStore): void;
23
25
  private resolveCheckoutRedirectUrl;
24
26
  applyPromoCode(promoCode: string): Promise<void>;
25
27
  removePromoCode(): Promise<void>;
@@ -135,4 +135,12 @@ export declare class CheckoutCommands extends BaseCommand {
135
135
  private dataForCheckoutPrepare;
136
136
  private normalizeForApi;
137
137
  getDetails(): ICheckoutDetailsEventData;
138
+ trackBeginCheckout(): void;
139
+ trackPresaleCheckoutStart(): void;
140
+ reportExpressCheckoutStarted({ wallet, reportBeginCheckout }: {
141
+ wallet: string;
142
+ reportBeginCheckout: boolean;
143
+ }): void;
144
+ private checkoutItemsForAnalytics;
145
+ private toAnalyticsItem;
138
146
  }
@@ -8,6 +8,7 @@ export declare class CheckoutExpressCheckoutComponent extends BaseComponent<IChe
8
8
  private section;
9
9
  private walletHost;
10
10
  private completionElement;
11
+ private beginCheckoutReported;
11
12
  private stripe;
12
13
  private stripeElements;
13
14
  private expressElement;
@@ -28,4 +28,9 @@ export declare class ProductListCommands extends BaseCommand {
28
28
  selectFulfillment: (slug: string, productId: string, selectedFulfillmentId: string) => Promise<void>;
29
29
  updateQuantity: (slug: string, productId: string, quantity: number) => void;
30
30
  saveEngravingLines(slug: string, productId: string, engravingLines: string[]): void;
31
+ private trackListPage;
32
+ trackSelectItem(slug: string, productId: string): void;
33
+ trackSearch(searchTerm: string): void;
34
+ private toAnalyticsItem;
35
+ private getListName;
31
36
  }
@@ -1,6 +1,7 @@
1
1
  export type { DebugMode, ElementsEnv } from '../enums/core.enum';
2
2
  export { DEBUG_MODE, ELEMENTS_ENV } from '../enums/core.enum';
3
- export type { IElementsCheckoutActions, IElementsCheckoutClient, } from '../interfaces/client.interface';
3
+ export type { IAnalyticsAddress, IAnalyticsAddressFailure, IAnalyticsAvailability, IAnalyticsFulfillmentAvailability, IAnalyticsItem, IAnalyticsItemList, } from '../interfaces/analytics.interface';
4
+ export type { IAnalyticsActions, IElementsCheckoutActions, IElementsCheckoutClient, } from '../interfaces/client.interface';
4
5
  export type { IInjectedComponent } from '../interfaces/component.interface';
5
6
  export type { ILiquidCommerceElementsCheckoutClientConfig } from '../interfaces/config.interface';
6
7
  export declare function ElementsCheckout(..._args: any[]): Promise<null>;
@@ -1,7 +1,8 @@
1
1
  export { SDKError, isSDKError } from '../core/sdk-error-handler';
2
2
  export type { CartEventLevel, CartEventType, CheckoutEventLevel, CheckoutEventType, ComponentType, DebugMode, DisplayModeType, ElementsEnv, FulfillmentType, NavigationSourceType, } from '../enums/core.enum';
3
3
  export { CART_EVENT_LEVEL, CART_EVENT_TYPE, CHECKOUT_EVENT_LEVEL, CHECKOUT_EVENT_TYPE, COMPONENT_TYPE, DEBUG_MODE, DISPLAY_MODE, ELEMENTS_ACTIONS_EVENT, ELEMENTS_ENV, ELEMENTS_FORM, FULFILLMENT_TYPE, NAVIGATION_SOURCE, } from '../enums/core.enum';
4
- export type { ILiquidCommerceElementsActions, ILiquidCommerceElementsBuilderClient, ILiquidCommerceElementsClient, } from '../interfaces/client.interface';
4
+ export type { IAnalyticsAddress, IAnalyticsAddressFailure, IAnalyticsAvailability, IAnalyticsFulfillmentAvailability, IAnalyticsItem, IAnalyticsItemList, } from '../interfaces/analytics.interface';
5
+ export type { IAnalyticsActions, ILiquidCommerceElementsActions, ILiquidCommerceElementsBuilderClient, ILiquidCommerceElementsClient, } from '../interfaces/client.interface';
5
6
  export type { IInjectedComponent } from '../interfaces/component.interface';
6
7
  export type { IElementsGTMConfig, IElementsProxyConfig, ILiquidCommerceElementsBuilderConfig, ILiquidCommerceElementsCheckoutConfig, ILiquidCommerceElementsConfig, ILiquidCommerceElementsDevelopmentConfig, } from '../interfaces/config.interface';
7
8
  export type * from '../interfaces/configs';
package/docs/v1/README.md CHANGED
@@ -52,6 +52,7 @@ Complete API documentation:
52
52
  - **[Address Actions](./api/actions/address-actions.md)** - `actions.address.*`
53
53
  - **[Cart Actions](./api/actions/cart-actions.md)** - `actions.cart.*`
54
54
  - **[Checkout Actions](./api/actions/checkout-actions.md)** - `actions.checkout.*`
55
+ - **[Analytics Actions](./api/actions/analytics-actions.md)** - `actions.analytics.*`
55
56
 
56
57
  ### Architecture (To Be Done In Future Versions)
57
58
 
@@ -0,0 +1,326 @@
1
+ # Analytics Actions API
2
+
3
+ Analytics actions report shopper steps that **your own UI** renders to the same Google Tag Manager /
4
+ GA4 stream that Elements components report to. Use them when you build part of the shopping
5
+ experience yourself — a product page, an address picker, a cart — and use Elements for the rest,
6
+ typically the checkout. They are available on the full client (`actions.analytics.*`) and on the
7
+ checkout-only client (`ElementsCheckout(...).actions.analytics.*`).
8
+
9
+ Each action pushes a GA4 event onto `window.dataLayer` in exactly the shape the SDK's own components
10
+ use — the same event name, the same `items[]` fields, the same `tenant_*` source fields and
11
+ `send_to` targets — so your reports and GTM triggers treat them like any other Elements event. See
12
+ [Analytics & Google Tag Manager](../../reference/analytics.md) for how the containers are loaded and
13
+ how events are queued.
14
+
15
+ ## What to report, and what not to
16
+
17
+ - **Report only steps your UI renders.** A step an Elements component renders is already reported
18
+ by that component: reporting it again counts it twice. A product shown with `injectProductElement`
19
+ sends its own `view_item`, and adding it to the cart from that component sends `add_to_cart` and
20
+ `view_cart`. A list placed with `injectProductList` sends `view_item_list`, `select_item` and, from
21
+ its search box, `search`. The Elements cart sends `view_cart` when it opens and `remove_from_cart`
22
+ when an item goes.
23
+ - **The checkout reports itself.** `add_shipping_info`, `add_payment_info`, `purchase`, and the promo
24
+ code and gift card events come from the Elements checkout, so there are no actions for them.
25
+ - **Report once per state, not once per render.** A framework that re-renders, or runs effects
26
+ twice in development, should guard each report with the state it describes (for example the
27
+ product and size a `view_item` was sent for).
28
+ - **Where events go.** Events are sent only in `production` and `staging`, never in Builder mode.
29
+ They target the partner's enabled LiquidCommerce and partner GTM containers through `send_to`.
30
+ When neither container is enabled, an event still goes onto a `window.dataLayer` that is already on
31
+ the page — your own GTM's, for example — without `send_to`, exactly as the SDK's own events do.
32
+ Events reported before GTM finishes initializing are queued and sent once it is ready.
33
+ - **Reporting never breaks your page.** Malformed input does not throw: the event is skipped and a
34
+ warning is logged (visible with `debugMode: 'console'`, and sent to LiquidCommerce telemetry).
35
+
36
+ ## The item
37
+
38
+ Every ecommerce action takes `IAnalyticsItem`, built from the product data your page already has:
39
+
40
+ ```typescript
41
+ interface IAnalyticsItem {
42
+ id: string; // the selected size's id → item_id and product_id
43
+ name: string; // → item_name
44
+ brand?: string;
45
+ size?: string; // "750 ML"
46
+ categoryPath?: string; // product catPath, "spirits > whiskey > bourbon" → item_category 1–3
47
+ price?: number; // unit price in CENTS, as product responses carry it → dollars
48
+ quantity?: number;
49
+ type?: string;
50
+ subType?: string;
51
+ image?: string;
52
+ upc?: string;
53
+ groupingId?: string; // product salsifyGrouping
54
+ index?: number; // position in a list (viewItemList / selectItem)
55
+ }
56
+ ```
57
+
58
+ From a product response (`getProductAvailabilityByState`, or the availability API your page loads
59
+ the product with):
60
+
61
+ ```javascript
62
+ const product = response.products[0];
63
+ const size = product.sizes[selectedSizeId];
64
+
65
+ const item = {
66
+ id: size.id,
67
+ name: product.name,
68
+ brand: product.brand,
69
+ size: size.size,
70
+ categoryPath: product.catPath,
71
+ price: selectedVariant ? selectedVariant.price : product.priceInfo.average,
72
+ type: product.type,
73
+ subType: product.subType,
74
+ image: size.image,
75
+ upc: size.upc,
76
+ groupingId: product.salsifyGrouping,
77
+ };
78
+ ```
79
+
80
+ `price` is in cents and is sent in dollars, like every Elements ecommerce event. Before the shopper
81
+ has an address, the SDK's own product component reports the product's average price; report the
82
+ selected variant's price once there is one.
83
+
84
+ An event is skipped, with a warning naming the problem, when an item has no `id` or `name`, a
85
+ negative or non-numeric `price`, a `quantity` that is not a positive integer, an `index` that is not
86
+ a non-negative integer, or a non-string text field; when a list of items is empty; when a list, an
87
+ option, an address field or coordinates have the wrong type; or when a `reason` / `error` is missing.
88
+ An omitted or empty `placesId` / `formattedAddress` is left out of the event rather than sent blank.
89
+
90
+ ---
91
+
92
+ ## actions.analytics.search()
93
+
94
+ `search` — the shopper searches the catalog with your own search box. Sent as `search_term`, trimmed.
95
+ A product list's own search box reports its searches itself.
96
+
97
+ ```typescript
98
+ search(searchTerm: string): void
99
+ ```
100
+
101
+ ```javascript
102
+ actions.analytics.search(input.value);
103
+ ```
104
+
105
+ ---
106
+
107
+ ## actions.analytics.viewItem()
108
+
109
+ `view_item` — the shopper sees a product. Report it when the product is shown and again when the
110
+ shopper switches size, as the SDK's product component does.
111
+
112
+ ```typescript
113
+ viewItem(item: IAnalyticsItem): void
114
+ ```
115
+
116
+ ```javascript
117
+ actions.analytics.viewItem(item);
118
+ ```
119
+
120
+ ---
121
+
122
+ ## actions.analytics.viewItemList()
123
+
124
+ `view_item_list` — the shopper sees a list of products.
125
+
126
+ ```typescript
127
+ viewItemList(items: IAnalyticsItem[], list?: { id?: string; name?: string }): void
128
+ ```
129
+
130
+ ```javascript
131
+ actions.analytics.viewItemList(
132
+ products.map((item, index) => ({ ...item, index })),
133
+ { id: 'holiday-gifts', name: 'Holiday Gifts' }
134
+ );
135
+ ```
136
+
137
+ ---
138
+
139
+ ## actions.analytics.selectItem()
140
+
141
+ `select_item` — the shopper picks a product from a list.
142
+
143
+ ```typescript
144
+ selectItem(item: IAnalyticsItem, list?: { id?: string; name?: string }): void
145
+ ```
146
+
147
+ ---
148
+
149
+ ## actions.analytics.addToCart()
150
+
151
+ `add_to_cart` — `item.quantity` is the quantity added (default 1). `value` is `price × quantity`.
152
+
153
+ ```typescript
154
+ addToCart(item: IAnalyticsItem): void
155
+ ```
156
+
157
+ Report it when the shopper commits to the product in your UI. `actions.cart.addProduct()` and
158
+ `actions.checkout.addProduct()` already report it (the latter reports `begin_checkout` too); `actions.checkout.addAnonymousProduct()` does
159
+ not, because hosts often call it ahead of time to prepare a checkout before the shopper commits.
160
+
161
+ ```javascript
162
+ actions.analytics.addToCart({ ...item, quantity: 2 });
163
+ ```
164
+
165
+ ---
166
+
167
+ ## actions.analytics.removeFromCart()
168
+
169
+ `remove_from_cart` — `item.quantity` is the quantity removed.
170
+
171
+ ```typescript
172
+ removeFromCart(item: IAnalyticsItem): void
173
+ ```
174
+
175
+ ---
176
+
177
+ ## actions.analytics.viewCart()
178
+
179
+ `view_cart` — the shopper sees a cart your UI renders.
180
+
181
+ ```typescript
182
+ viewCart(items: IAnalyticsItem[]): void
183
+ ```
184
+
185
+ ---
186
+
187
+ ## actions.analytics.beginCheckout()
188
+
189
+ `begin_checkout` — the shopper commits to buying `items`. `value` is the sum of `price × quantity`.
190
+
191
+ ```typescript
192
+ beginCheckout(items: IAnalyticsItem[], options?: { coupon?: string }): void
193
+ ```
194
+
195
+ ```javascript
196
+ // "Proceed to checkout" in your own UI, before injecting the Elements checkout
197
+ actions.analytics.addToCart({ ...item, quantity });
198
+ actions.analytics.beginCheckout([{ ...item, quantity }], { coupon: 'WELCOME10' });
199
+ await client.injectCheckout({ containerId: 'checkout', checkoutId });
200
+ ```
201
+
202
+ Report it when **you** inject the checkout (`injectCheckout()` / `injectCheckoutElement()`) after
203
+ your own "Proceed" control. Don't report it when Elements started the checkout — it reports these
204
+ itself:
205
+
206
+ - the Elements cart's Checkout button, including when it redirects to your checkout page
207
+ (`checkout.pageUrl`) — so a page that injects the checkout for a shopper arriving from that
208
+ button must not report it again;
209
+ - `actions.checkout.addProduct()`;
210
+ - `actions.checkout.openCheckout()` and `toggleCheckout()` when they open the drawer;
211
+ - a presale added from the product component, which goes straight to checkout;
212
+ - the first wallet tap on express buttons placed on their own (below).
213
+
214
+ Wallet (Apple Pay / Google Pay) buttons placed on their own with `injectExpressCheckout` /
215
+ `injectExpressCheckoutElement` report `begin_checkout` themselves on the first tap — a wallet order
216
+ never passes through your "Proceed" control. Don't report it for them. If the buttons sit on your
217
+ product page and the checkout behind them was created with `addAnonymousProduct`, report the add
218
+ when the shopper taps: the tap happens inside Stripe's frame, and
219
+ [`lce:actions.checkout_express_checkout_started`](../../guides/events.md) is how your page hears of
220
+ it.
221
+
222
+ ```javascript
223
+ window.addEventListener('lce:actions.checkout_express_checkout_started', () => {
224
+ actions.analytics.addToCart({ ...item, quantity });
225
+ });
226
+ ```
227
+
228
+ ---
229
+
230
+ ## actions.analytics.addressUpdated()
231
+
232
+ `address_updated` — an address the shopper chose in your UI resolved.
233
+
234
+ ```typescript
235
+ addressUpdated(address: {
236
+ placesId?: string; // → address_id
237
+ formattedAddress?: string;
238
+ address: Partial<IAddressAddress>;
239
+ coordinates?: IAddressCoordinates;
240
+ }): void
241
+ ```
242
+
243
+ ```javascript
244
+ actions.analytics.addressUpdated({
245
+ placesId,
246
+ formattedAddress: details.formattedAddress,
247
+ address: details.address,
248
+ coordinates: details.coordinates,
249
+ });
250
+ ```
251
+
252
+ `actions.address.setAddressByPlacesId()` and `setAddressManually()` already report it.
253
+
254
+ ---
255
+
256
+ ## actions.analytics.addressFailed()
257
+
258
+ `address_failed` — an address the shopper chose could not be resolved or used.
259
+
260
+ ```typescript
261
+ addressFailed(failure: {
262
+ placesId?: string;
263
+ formattedAddress?: string;
264
+ address?: Partial<IAddressAddress>;
265
+ error: string; // → address_error_message
266
+ }): void
267
+ ```
268
+
269
+ ---
270
+
271
+ ## actions.analytics.productNoAvailability()
272
+
273
+ `product_no_availability` — no size of the product sells where the shopper is.
274
+
275
+ ```typescript
276
+ productNoAvailability(details: {
277
+ item: IAnalyticsItem; // the product, keyed on the selected size
278
+ reason: string; // → availability_reason
279
+ address?: Partial<IAddressAddress>;
280
+ }): void
281
+ ```
282
+
283
+ The no-availability events carry `product_*` fields rather than an `items[]` array, as the SDK's own
284
+ do, and `product_price` is sent **in cents** (the raw `item.price`), matching them.
285
+
286
+ ---
287
+
288
+ ## actions.analytics.productSizeNoAvailability()
289
+
290
+ `product_size_no_availability` — the selected size has no fulfillment at the shopper's address,
291
+ though another size does. `item.id` and `item.size` are sent as `size_id` and `size_name`.
292
+
293
+ ```typescript
294
+ productSizeNoAvailability(details: { item: IAnalyticsItem; reason: string; address?: Partial<IAddressAddress> }): void
295
+ ```
296
+
297
+ ---
298
+
299
+ ## actions.analytics.productFulfillmentNoAvailability()
300
+
301
+ `product_fulfillment_no_availability` — one fulfillment method (`onDemand` or `shipping`) can't be
302
+ used for the selected size: not offered there, or the retailer is closed.
303
+
304
+ ```typescript
305
+ productFulfillmentNoAvailability(details: {
306
+ item: IAnalyticsItem;
307
+ reason: string;
308
+ address?: Partial<IAddressAddress>;
309
+ fulfillmentType: 'onDemand' | 'shipping';
310
+ }): void
311
+ ```
312
+
313
+ ```javascript
314
+ actions.analytics.productFulfillmentNoAvailability({
315
+ item,
316
+ reason: 'Not available in NY',
317
+ address: details.address,
318
+ fulfillmentType: 'onDemand',
319
+ });
320
+ ```
321
+
322
+ ## Related
323
+
324
+ - [Analytics & Google Tag Manager](../../reference/analytics.md)
325
+ - [Product Actions](./product-actions.md) · [Address Actions](./address-actions.md) · [Cart Actions](./cart-actions.md) · [Checkout Actions](./checkout-actions.md)
326
+ - [TypeScript Types](../typescript-types.md)