@salla.sa/ecommerce-events-base
Version:
Base types and utilities for Salla ecommerce event tracking
378 lines (375 loc) • 10.4 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;
sorts?: string;
products: Product[];
}
interface ProductListFilteredPayload extends ProductListViewedPayload {
filters?: Array<{
type: string;
value: string;
}>;
}
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 CartUpdatedPayload {
cart_id?: string;
value?: number;
revenue?: number;
tax?: number;
discount?: number;
shipping?: number;
currency?: string;
affiliation?: 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_code?: string;
coupon_name?: string;
discount?: number;
currency?: string;
}
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_code?: string;
coupon_name?: string;
discount?: number;
currency?: string;
}
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;
}
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;
}
interface SignedInPayload {
first_name?: string;
last_name?: string;
type?: string;
mobile?: string;
email?: string;
}
interface SignedUpPayload extends SignedInPayload {
}
interface SignedOutPayload {
}
interface UserProfileUpdatedPayload extends SignedInPayload {
}
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;
declare 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"
}
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 CartUpdatedPayload, 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 ProductListFilteredPayload, type ProductListViewedPayload, type ProductRemovedPayload, type ProductReviewedPayload, type ProductSharedPayload, type ProductViewedPayload, type ProductsSearchedPayload, type Promotion, type PromotionClickedPayload, type PromotionViewedPayload, type SallaTracker, type SignedInPayload, type SignedOutPayload, type SignedUpPayload, type UserProfileUpdatedPayload, type WishlistProductAddedPayload, type WishlistProductAddedToCartPayload, type WishlistProductRemovedPayload };