@salla.sa/ecommerce-events-base
Version:
Base types and utilities for Salla ecommerce event tracking
426 lines (389 loc) • 9.78 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;
sorts?: string;
products: Product[];
}
export interface ProductListFilteredPayload extends ProductListViewedPayload {
filters?: Array<{
type: string;
value: string;
}>;
}
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 CartUpdatedPayload {
cart_id?: string;
value?: number;
revenue?: number;
tax?: number;
discount?: number;
shipping?: number;
currency?: string;
affiliation?: 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_code?: string;
coupon_name?: string;
discount?: number;
currency?: string;
}
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_code?: string;
coupon_name?: string;
discount?: number;
currency?: string;
}
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;
}
export interface WishlistProductAddedToCartPayload {
wishlist_id: string;
wishlist_name?: string;
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 SignedInPayload {
first_name?: string;
last_name?: string;
type?: string;
mobile?: string;
email?: string;
}
export interface SignedUpPayload extends SignedInPayload {}
export interface SignedOutPayload {}
export interface UserProfileUpdatedPayload extends SignedInPayload {}
// Union type for all event payloads
export type EcommerceEventPayload =
| ProductViewedPayload
| ProductListViewedPayload
| ProductListFilteredPayload
| ProductAddedPayload
| ProductRemovedPayload
| CartViewedPayload
| CartUpdatedPayload
| CheckoutStartedPayload
| CheckoutStepViewedPayload
| CheckoutStepCompletedPayload
| PaymentInfoEnteredPayload
| OrderCompletedPayload
| ProductClickedPayload
| ProductSharedPayload
| ProductReviewedPayload
| ProductsSearchedPayload
| PromotionViewedPayload
| PromotionClickedPayload
| CouponEnteredPayload
| CouponAppliedPayload
| CouponDeniedPayload
| CouponRemovedPayload
| WishlistProductAddedPayload
| WishlistProductRemovedPayload
| WishlistProductAddedToCartPayload
| SignedInPayload
| SignedUpPayload
| SignedOutPayload
| UserProfileUpdatedPayload;
// Event names enum
export enum EcommerceEvents {
PRODUCT_VIEWED = 'Product Viewed',
PRODUCT_LIST_VIEWED = 'Product List Viewed',
PRODUCT_LIST_FILTERED = 'Product List Filtered',
PRODUCT_ADDED = 'Product Added',
PRODUCT_REMOVED = 'Product Removed',
CART_VIEWED = 'Cart Viewed',
CART_UPDATED = 'Cart Updated',
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',
WISHLIST_PRODUCT_ADDED_TO_CART = 'Wishlist Product Added to Cart',
SIGNED_IN = 'Signed In',
SIGNED_UP = 'Signed Up',
SIGNED_OUT = 'Signed Out',
USER_PROFILE_UPDATED = 'User Profile Updated'
}