@salla.sa/ecommerce-events-base
Version:
Base types and utilities for Salla ecommerce event tracking
355 lines (326 loc) • 7.32 kB
text/typescript
// Base interfaces for Segment Ecommerce v2 events
export interface Product {
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
quantity?: number;
coupon?: string;
position?: number;
url?: string;
image_url?: string;
}
export interface Cart {
cart_id: string;
products: Product[];
}
export interface Order {
order_id: string;
affiliation?: string;
total: number;
revenue?: number;
shipping?: number;
tax?: number;
discount?: number;
coupon?: string;
currency: string;
products: Product[];
}
export interface Checkout {
checkout_id: string;
order_id?: string;
affiliation?: string;
total: number;
revenue?: number;
shipping?: number;
tax?: number;
discount?: number;
coupon?: string;
currency: string;
products: Product[];
step?: number;
option?: string;
}
export interface Promotion {
promotion_id: string;
creative?: string;
name?: string;
position?: string;
}
// Event payload interfaces
export interface ProductViewedPayload {
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
currency?: string;
value?: number;
quantity?: number;
coupon?: string;
position?: number;
url?: string;
image_url?: string;
}
export interface ProductListViewedPayload {
list_id?: string;
category?: string;
products: Product[];
}
export interface ProductAddedPayload {
cart_id?: string;
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
quantity?: number;
coupon?: string;
position?: number;
url?: string;
image_url?: string;
}
export interface ProductRemovedPayload {
cart_id?: string;
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
quantity?: number;
coupon?: string;
position?: number;
url?: string;
image_url?: string;
}
export interface CartViewedPayload {
cart_id: string;
products: Product[];
}
export interface CheckoutStartedPayload {
order_id?: string;
affiliation?: string;
value?: number;
revenue?: number;
shipping?: number;
tax?: number;
discount?: number;
coupon?: string;
currency?: string;
products: Product[];
}
export interface CheckoutStepViewedPayload {
checkout_id: string;
step: number;
shipping_method?: string;
payment_method?: string;
}
export interface CheckoutStepCompletedPayload {
checkout_id: string;
step: number;
shipping_method?: string;
payment_method?: string;
}
export interface PaymentInfoEnteredPayload {
checkout_id?: string;
order_id?: string;
step?: number;
shipping_method?: string;
payment_method?: string;
}
export interface OrderCompletedPayload {
checkout_id?: string;
order_id: string;
affiliation?: string;
total: number;
subtotal?: number;
revenue?: number;
shipping?: number;
tax?: number;
discount?: number;
coupon?: string;
currency: string;
products: Product[];
}
export interface ProductClickedPayload {
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
quantity?: number;
coupon?: string;
position?: number;
url?: string;
image_url?: string;
list_id?: string;
}
export interface ProductSharedPayload {
share_via: string;
share_message?: string;
recipient?: string;
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
url?: string;
image_url?: string;
}
export interface ProductReviewedPayload {
product_id: string;
review_id: string;
review_body?: string;
rating: number;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
url?: string;
image_url?: string;
}
export interface ProductsSearchedPayload {
query: string;
filters?: Record<string, any>;
sorts?: Array<{
field: string;
direction: 'asc' | 'desc';
}>;
products?: Product[];
}
export interface PromotionViewedPayload {
promotion_id: string;
creative?: string;
name?: string;
position?: string;
}
export interface PromotionClickedPayload {
promotion_id: string;
creative?: string;
name?: string;
position?: string;
}
export interface CouponEnteredPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
discount?: number;
}
export interface CouponAppliedPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
discount: number;
}
export interface CouponDeniedPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
reason?: string;
}
export interface CouponRemovedPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
discount?: number;
}
export interface WishlistProductAddedPayload {
wishlist_id: string;
wishlist_name?: string;
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
quantity?: number;
coupon?: string;
position?: number;
url?: string;
image_url?: string;
}
export interface WishlistProductRemovedPayload {
wishlist_id: string;
wishlist_name?: string;
product_id: string;
sku?: string;
category?: string;
name: string;
brand?: string;
variant?: string;
price: number;
quantity?: number;
coupon?: string;
position?: number;
url?: string;
image_url?: string;
}
// Union type for all event payloads
export type EcommerceEventPayload =
| ProductViewedPayload
| ProductListViewedPayload
| ProductAddedPayload
| ProductRemovedPayload
| CartViewedPayload
| CheckoutStartedPayload
| CheckoutStepViewedPayload
| CheckoutStepCompletedPayload
| PaymentInfoEnteredPayload
| OrderCompletedPayload
| ProductClickedPayload
| ProductSharedPayload
| ProductReviewedPayload
| ProductsSearchedPayload
| PromotionViewedPayload
| PromotionClickedPayload
| CouponEnteredPayload
| CouponAppliedPayload
| CouponDeniedPayload
| CouponRemovedPayload
| WishlistProductAddedPayload
| WishlistProductRemovedPayload;
// Event names enum
export enum EcommerceEvents {
PRODUCT_VIEWED = 'Product Viewed',
PRODUCT_LIST_VIEWED = 'Product List Viewed',
PRODUCT_ADDED = 'Product Added',
PRODUCT_REMOVED = 'Product Removed',
CART_VIEWED = 'Cart Viewed',
CHECKOUT_STARTED = 'Checkout Started',
CHECKOUT_STEP_VIEWED = 'Checkout Step Viewed',
CHECKOUT_STEP_COMPLETED = 'Checkout Step Completed',
PAYMENT_INFO_ENTERED = 'Payment Info Entered',
ORDER_COMPLETED = 'Order Completed',
PRODUCT_CLICKED = 'Product Clicked',
PRODUCT_SHARED = 'Product Shared',
PRODUCT_REVIEWED = 'Product Reviewed',
PRODUCTS_SEARCHED = 'Products Searched',
PROMOTION_VIEWED = 'Promotion Viewed',
PROMOTION_CLICKED = 'Promotion Clicked',
COUPON_ENTERED = 'Coupon Entered',
COUPON_APPLIED = 'Coupon Applied',
COUPON_DENIED = 'Coupon Denied',
COUPON_REMOVED = 'Coupon Removed',
WISHLIST_PRODUCT_ADDED = 'Wishlist Product Added',
WISHLIST_PRODUCT_REMOVED = 'Wishlist Product Removed'
}