import { BrowserPlugin } from "@snowplow/browser-tracker-core"; import { CommonEventProperties } from "@snowplow/tracker-core"; /** * Type/Schema for an ecommerce Action */ interface Action { /** * Standard ecommerce actions */ type: "add_to_cart" | "remove_from_cart" | "product_view" | "list_click" | "list_view" | "promo_click" | "promo_view" | "checkout_step" | "transaction" | "refund" | "trns_error"; /** * You can add a name for the list presented to the user. * E.g. product list, search results, shop the look, frequently bought with */ name?: string; } /** * Type/Schema for a checkout_step event in Ecommerce */ interface CheckoutStep { /* Checkout step index */ step: number; /* Shipping address postcode */ shipping_postcode?: string; /* Billing address postcode */ billing_postcode?: string; /* Full shipping address */ shipping_full_address?: string; /* Full billing address */ billing_full_address?: string; /* Can be used to discern delivery providers DHL, PostNL etc. */ delivery_provider?: string; /* Store pickup, standard delivery, express delivery, international */ delivery_method?: string; /* Coupon applied at checkout */ coupon_code?: string; /* Selection of 'existing user' or 'guest checkout' */ account_type?: string; /* Any kind of payment method the user selected to proceed. Card, PayPal, Alipay etc. */ payment_method?: string; /* Invoice or receipt */ proof_of_payment?: string; /* If opted in to marketing campaigns to the email address */ marketing_opt_in?: boolean; } /** * Type for a cart entity in Ecommerce */ interface Cart { /** * The unique ID representing this cart */ cart_id?: string; /** * The total value of the cart after this interaction */ total_value: number; /** * The currency used for this cart (ISO 4217) */ currency: string; /** * Array of products added/removed from cart */ products?: Product[]; } /** * Type/Schema for a page entity in Ecommerce */ interface Page { /** * The type of the page that was visited (e.g. homepage, product page, cart,checkout page, etc) */ type: string; /** * The language that the web page is based in */ language?: string; /** * The locale version of the site that is running */ locale?: string; } /** * Type/Schema for a product entity in Ecommerce */ type Product = { /** * The SKU or product ID */ id: string; /** * The name or title of the product */ name?: string; /** * The category the product belongs to. * Use a consistent separator to express multiple levels. E.g. Woman/Shoes/Sneakers */ category?: string; /** * The price of the product at the current time. */ price: number; /** * The recommended or list price of a product */ list_price?: number; /** * The quantity of the product taking part in the action. Used for Cart events. */ quantity?: number; /** * The size of the product */ size?: string; /** * The variant of the product */ variant?: string; /** * The brand of the product */ brand?: string; /** * The inventory status of the product (e.g. in stock, out of stock, preorder, backorder, etc) */ inventory_status?: string; /** * The position the product was presented in a list of products (search results, product list page, etc) */ position?: number; /** * The currency in which the product is being priced (ISO 4217) */ currency: string; /** * Identifier/Name/Url for the creative presented on a list or product view. */ creative_id?: string; }; /** * Type/Schema for a promotion entity in Ecommerce */ interface SPPromotion { /** * The ID of the promotion. */ id: string; /** * The name of the promotion. */ name?: string | null; /** * Array of SKUs or product IDs showcased in the promotion. */ product_ids?: string[] | null; /** * The position the promotion was presented in a list of promotions E.g. banner, slider. */ position?: number | null; /** * Identifier/Name/Url for the creative presented on the promotion. */ creative_id?: string | null; /** * Type of the promotion delivery mechanism. E.g. popup, banner, intra-content */ type?: string | null; /** * The website slot in which the promotional content was added to. */ slot?: string | null; } /** * Type/Schema for a transaction entity in Ecommerce */ interface SPTransaction { /** * The ID of the transaction */ transaction_id: string; /** * The total value of the transaction */ revenue: number; /** * The currency used for the transaction */ currency: string; /** * The payment method used for the transaction */ payment_method: string; /** * Total quantity of items in the transaction */ total_quantity?: number; /** * Total amount of tax on the transaction */ tax?: number; /** * Total cost of shipping on the transaction */ shipping?: number; /** * Discount code used */ discount_code?: string; /** * Discount amount taken off */ discount_amount?: number; /** * Whether the transaction is a credit order or not */ credit_order?: boolean; /** * Array of products on the transaction from cart */ products?: Product[]; } /** * Type/Schema for a refund entity in Ecommerce */ interface Refund { /** * The ID of the transaction. */ transaction_id: string; /** * The currency in which the product is being priced (ISO 4217). */ currency: string; /** * The monetary amount refunded. */ refund_amount: number; /** * Reason for refunding the whole or part of the transaction. */ refund_reason?: string | null; /** * Array of products on the refund. This is used when specific products are refunded. * If not present, the whole transaction and products will be marked as refunded. */ products?: Product[]; } /** * Type/Schema for a transaction error entity in Ecommerce */ interface TransactionError { /** * Error-identifying code for the transaction issue. E.g. E522 */ error_code?: string; /** * Shortcode for the error occurred in the transaction. E.g. declined_by_stock_api, declined_by_payment_method, card_declined, pm_card_radarBlock */ error_shortcode?: string; /** * Longer description for the error occurred in the transaction. */ error_description?: string; /** * Type of error. * Hard error types mean the customer must provide another form of payment e.g. an expired card. * Soft errors can be the result of temporary issues where retrying might be successful e.g. processor declined the transaction. */ error_type?: "hard" | "soft" | null; /** * The resolution selected for the error scenario. E.g. retry_allowed, user_blacklisted, block_gateway, contact_user, default */ resolution?: string; /** * The transaction object representing the transaction that ended up in an error. */ transaction: SPTransaction; } /** * Type/Schema for an user entity in Ecommerce */ interface User { /** * The user ID */ id: string; /** * Whether or not the user is a guest */ is_guest?: boolean; /** * The user's email address */ email?: string; } interface CommonEcommerceEventProperties> extends CommonEventProperties { /** Add context to an event by setting an Array of Self Describing JSON */ context?: Exclude["context"], null>; } type ListViewEvent = { name: string; products: Product[]; }; type ListClickEvent = { name: string; product: Product; }; type PageContext = Page; type UserContext = User; /** * Adds ecommerce tracking */ declare function SnowplowEcommercePlugin(): BrowserPlugin; /** * Track a checkout step * * @param checkoutStep - The checkout step index and the attributes the user filled in. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackCheckoutStep(checkoutStep: CheckoutStep & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a product list view * * @param listView - The list name along with the products which were viewed by the visitor. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackProductListView(listView: ListViewEvent & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a product list click event * * @param listClick - The list name together with the information of the product which was clicked. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackProductListClick(listClick: ListClickEvent & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a promotion view * * @param promotionView - The promotion viewed by the visitor. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackPromotionView(promotionView: SPPromotion & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a promotion click * * @param promotionClick - The promotion selected by the visitor. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackPromotionClick(promotionClick: SPPromotion & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a product view/detail * * @param productView - The product which was viewed in a product detail page. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackProductView(productView: Product & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a product addition to cart * * @param cart - The product/s which was/were added to the cart and the total value of the cart after the product was added. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackAddToCart(cart: Cart & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track removal of products from cart * * @param cart - The product/s which were removed from the cart and the total value of the cart after the product was removed. * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackRemoveFromCart(cart: Cart & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a transaction event * * @param transaction - The transaction information * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackTransaction(transaction: SPTransaction & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a refund event * * @param refund - The refund information * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackRefund(refund: Refund & CommonEcommerceEventProperties, trackers?: Array): void; /** * Track a transaction error event * * @param transactionError - The transaction error information * @param trackers - The tracker identifiers which the event will be sent to */ declare function trackTransactionError(transactionError: TransactionError & CommonEcommerceEventProperties, trackers?: Array): void; /** * Set Ecommerce Page context * * @param context - The ecommerce page context to be stored * @param trackers - The tracker identifiers which the context will be stored */ declare function setPageType(context: PageContext, trackers?: Array): void; /** * Set Ecommerce User context * * @param context - The ecommerce user context to be stored * @param trackers - The tracker identifiers which the context will be stored */ declare function setEcommerceUser(context: UserContext, trackers?: Array): void; interface UAEnhancedEcommerceObject { currencyCode?: string; } interface ProductListViewEvent { impressions: EEProduct[]; } interface ProductListClickEvent { click: { actionField: { list: string; }; products: EEProduct[]; }; } interface ProductDetailEvent { detail: { actionField: { list: string; }; products: EEProduct[]; }; } interface AddToCartEvent { add: { products: EEProduct[]; }; } interface RemoveFromCartEvent { remove: { products: EEProduct[]; }; } interface PromoViewEvent { promoView: { promotions: EEPromo[]; }; } interface PromoClickEvent { promoClick: { promotions: EEPromo[]; }; } interface CheckoutStepEvent { checkout: { actionField: { step: number; option?: string; }; products: EEProduct[]; }; } interface PurchaseEvent { purchase: { actionField: { id: string; revenue: number | string; tax?: number | string; shipping?: number | string; coupon?: string; affiliation?: string; }; products: EEProduct[]; }; } interface EEProduct { price?: number | string; id?: string; name?: string; brand?: string; category?: string; variant?: string; quantity?: number; position?: number; list?: string; } interface EEPromo { id: string; name: string; creative?: string; position?: string; } type Options = { currency?: string; }; declare function trackEnhancedEcommercePromoView(ecommerce: PromoViewEvent): void; declare function trackEnhancedEcommercePromoClick(ecommerce: PromoClickEvent): void; declare function trackEnhancedEcommerceAddToCart(ecommerce: UAEnhancedEcommerceObject & AddToCartEvent, opts: Options & { finalCartValue: number; }): void; declare function trackEnhancedEcommerceRemoveFromCart(ecommerce: UAEnhancedEcommerceObject & RemoveFromCartEvent, opts: Options & { finalCartValue: number; }): void; declare function trackEnhancedEcommerceProductDetail(ecommerce: UAEnhancedEcommerceObject & ProductDetailEvent, opts?: Options): void; declare function trackEnhancedEcommerceProductListView(ecommerce: UAEnhancedEcommerceObject & ProductListViewEvent, opts?: Options): void; declare function trackEnhancedEcommerceProductListClick(ecommerce: UAEnhancedEcommerceObject & ProductListClickEvent, opts?: Options): void; declare function trackEnhancedEcommerceCheckoutStep(ecommerce: CheckoutStepEvent, checkoutOption?: Omit): void; declare function trackEnhancedEcommercePurchase(ecommerce: UAEnhancedEcommerceObject & PurchaseEvent, opts: Options & { paymentMethod: string; }): void; interface GA4EcommerceObject { item_list_id?: string; item_list_name?: string; currency?: string; value?: number; coupon?: string; shipping_tier?: string; payment_type?: string; transaction_id?: string; tax?: number; shipping?: number; creative_name?: string; creative_slot?: string; promotion_id?: string; promotion_name?: string; items: Item[]; } interface Item { item_id: string; item_name?: string; affiliation?: string; coupon?: string; discount?: number; index?: number; item_brand?: string; item_category?: string; item_category2?: string; item_category3?: string; item_category4?: string; item_category5?: string; item_list_id?: string; item_list_name?: string; item_variant?: string; location_id?: string; price: number; quantity?: number; } interface Currency { currency: string; } interface ItemList { item_list_id: string; item_list_name: string; } interface Transaction { currency: string; transaction_id: string; value: number; tax: number; shipping: number; coupon: string; } interface Promotion { creative_name: string; creative_slot: string; promotion_id: string; promotion_name: string; } type Options$0 = { currency?: string; }; declare function trackGA4ViewCart(): void; declare function trackGA4ViewPromotion(ecommerce: GA4EcommerceObject & Promotion): void; declare function trackGA4SelectPromotion(ecommerce: GA4EcommerceObject & Promotion): void; declare function trackGA4AddToCart(ecommerce: GA4EcommerceObject & Currency & { finalCartValue?: number; }, opts: Options$0 & { finalCartValue: number; }): void; declare function trackGA4RemoveFromCart(ecommerce: GA4EcommerceObject & Currency & { finalCartValue?: number; }, opts: Options$0 & { finalCartValue: number; }): void; declare function trackGA4ViewItem(ecommerce: GA4EcommerceObject, opts?: Options$0): void; declare function trackGA4ViewItemList(ecommerce: GA4EcommerceObject & ItemList, opts?: Options$0): void; declare function trackGA4SelectItem(ecommerce: GA4EcommerceObject & ItemList, opts?: Options$0): void; declare function trackGA4BeginCheckout(opts?: { step?: number; }): void; declare function trackGA4AddShippingInfo(ecommerce: GA4EcommerceObject, opts: { step: number; }): void; declare function trackGA4AddPaymentOptions(ecommerce: GA4EcommerceObject, opts: { step: number; }): void; declare function trackGA4Transaction(ecommerce: GA4EcommerceObject & Transaction, opts: Options$0 & { paymentMethod: string; }): void; export { SnowplowEcommercePlugin, trackCheckoutStep, trackProductListView, trackProductListClick, trackPromotionView, trackPromotionClick, trackProductView, trackAddToCart, trackRemoveFromCart, trackTransaction, trackRefund, trackTransactionError, setPageType, setEcommerceUser, trackEnhancedEcommercePromoView, trackEnhancedEcommercePromoClick, trackEnhancedEcommerceAddToCart, trackEnhancedEcommerceRemoveFromCart, trackEnhancedEcommerceProductDetail, trackEnhancedEcommerceProductListView, trackEnhancedEcommerceProductListClick, trackEnhancedEcommerceCheckoutStep, trackEnhancedEcommercePurchase, trackGA4ViewCart, trackGA4ViewPromotion, trackGA4SelectPromotion, trackGA4AddToCart, trackGA4RemoveFromCart, trackGA4ViewItem, trackGA4ViewItemList, trackGA4SelectItem, trackGA4BeginCheckout, trackGA4AddShippingInfo, trackGA4AddPaymentOptions, trackGA4Transaction, Action, CheckoutStep, Cart, Page, Product, SPPromotion, SPTransaction, Refund, TransactionError, User, CommonEcommerceEventProperties, ListViewEvent, ListClickEvent };