@salla.sa/ecommerce-events-base
Version:
Base types and utilities for Salla ecommerce event tracking
319 lines (316 loc) • 8.58 kB
text/typescript
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;
}
interface Cart {
cart_id: string;
products: Product[];
}
interface Order {
order_id: string;
affiliation?: string;
total: number;
revenue?: number;
shipping?: number;
tax?: number;
discount?: number;
coupon?: string;
currency: string;
products: Product[];
}
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;
}
interface Promotion {
promotion_id: string;
creative?: string;
name?: string;
position?: string;
}
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;
}
interface ProductListViewedPayload {
list_id?: string;
category?: string;
products: Product[];
}
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;
}
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;
}
interface CartViewedPayload {
cart_id: string;
products: Product[];
}
interface CheckoutStartedPayload {
order_id?: string;
affiliation?: string;
value?: number;
revenue?: number;
shipping?: number;
tax?: number;
discount?: number;
coupon?: string;
currency?: string;
products: Product[];
}
interface CheckoutStepViewedPayload {
checkout_id: string;
step: number;
shipping_method?: string;
payment_method?: string;
}
interface CheckoutStepCompletedPayload {
checkout_id: string;
step: number;
shipping_method?: string;
payment_method?: string;
}
interface PaymentInfoEnteredPayload {
checkout_id?: string;
order_id?: string;
step?: number;
shipping_method?: string;
payment_method?: string;
}
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[];
}
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;
}
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;
}
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;
}
interface ProductsSearchedPayload {
query: string;
filters?: Record<string, any>;
sorts?: Array<{
field: string;
direction: 'asc' | 'desc';
}>;
products?: Product[];
}
interface PromotionViewedPayload {
promotion_id: string;
creative?: string;
name?: string;
position?: string;
}
interface PromotionClickedPayload {
promotion_id: string;
creative?: string;
name?: string;
position?: string;
}
interface CouponEnteredPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
discount?: number;
}
interface CouponAppliedPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
discount: number;
}
interface CouponDeniedPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
reason?: string;
}
interface CouponRemovedPayload {
order_id?: string;
cart_id?: string;
coupon_id: string;
coupon_name?: string;
discount?: number;
}
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;
}
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;
}
type EcommerceEventPayload = ProductViewedPayload | ProductListViewedPayload | ProductAddedPayload | ProductRemovedPayload | CartViewedPayload | CheckoutStartedPayload | CheckoutStepViewedPayload | CheckoutStepCompletedPayload | PaymentInfoEnteredPayload | OrderCompletedPayload | ProductClickedPayload | ProductSharedPayload | ProductReviewedPayload | ProductsSearchedPayload | PromotionViewedPayload | PromotionClickedPayload | CouponEnteredPayload | CouponAppliedPayload | CouponDeniedPayload | CouponRemovedPayload | WishlistProductAddedPayload | WishlistProductRemovedPayload;
declare 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"
}
interface SallaTracker {
name: string;
track: (eventName: string, payload: EcommerceEventPayload) => void;
page?: (payload: any) => void;
}
declare global {
interface Window {
Salla: {
onReady: (callback: () => void) => void;
analytics: {
registerTracker: (tracker: SallaTracker) => void;
};
};
}
}
export { type Cart, type CartViewedPayload, type Checkout, type CheckoutStartedPayload, type CheckoutStepCompletedPayload, type CheckoutStepViewedPayload, type CouponAppliedPayload, type CouponDeniedPayload, type CouponEnteredPayload, type CouponRemovedPayload, type EcommerceEventPayload, EcommerceEvents, type Order, type OrderCompletedPayload, type PaymentInfoEnteredPayload, type Product, type ProductAddedPayload, type ProductClickedPayload, type ProductListViewedPayload, type ProductRemovedPayload, type ProductReviewedPayload, type ProductSharedPayload, type ProductViewedPayload, type ProductsSearchedPayload, type Promotion, type PromotionClickedPayload, type PromotionViewedPayload, type SallaTracker, type WishlistProductAddedPayload, type WishlistProductRemovedPayload };