Events
The `Events` class provides methods for tracking all types of user interactions on your e-commerce site. Every event is enriched with device info, session data, referrer, and user context before being sent to the Segmentify API.
SegmentifyEventManager
Section titled “SegmentifyEventManager”Use the SegmentifyEventManager singleton to access the shared Events instance. This is the recommended approach — it guarantees a single instance across your app:
import { SegmentifyEventManager } from '@segmentify/integration';
SegmentifyEventManager().PageView({ category: 'home' });SegmentifyEventManager().ProductView({ productId: 'PROD-123', price: 99.99 });SegmentifyEventManager() creates an Events instance on first call and returns the same instance on subsequent calls.
::: tip
You can also create an instance directly with new Events(), but SegmentifyEventManager ensures all parts of your app share the same queue and config.
:::
Page View
Section titled “Page View”Track when a user visits a page:
await SegmentifyEventManager().PageView({ category: 'home', subCategory: 'main', params: { page: 'homepage' },});Product View
Section titled “Product View”Track when a user views a product. The library automatically detects the traffic source (social, paid, search, etc.):
await SegmentifyEventManager().ProductView({ productId: 'PROD-123', title: 'Amazing Product', price: 99.99, oldPrice: 129.99, category: 'electronics', brand: 'TechBrand', inStock: true, url: 'https://example.com/product/123', image: 'https://example.com/images/product-123.jpg', colors: ['red', 'blue'], sizes: ['S', 'M', 'L'],});Basket Operations
Section titled “Basket Operations”Add to Basket
Section titled “Add to Basket”await SegmentifyEventManager().BasketAdd({ productId: 'PROD-123', price: 99.99, quantity: 1,});Remove from Basket
Section titled “Remove from Basket”await SegmentifyEventManager().BasketRemove({ productId: 'PROD-123', price: 99.99, quantity: 1,});View Basket
Section titled “View Basket”await SegmentifyEventManager().BasketView({ totalPrice: 299.97, productList: [ { productId: 'PROD-123', price: 99.99, quantity: 2 }, { productId: 'PROD-456', price: 99.99, quantity: 1 }, ],});Clear Basket
Section titled “Clear Basket”await SegmentifyEventManager().BasketClear({});::: tip
basketId is automatically generated from the user ID. You don’t need to pass it manually.
:::
Purchase
Section titled “Purchase”Track completed purchases:
await SegmentifyEventManager().Purchase({ totalPrice: 299.97, orderNo: 'ORDER-789', productList: [ { productId: 'PROD-123', price: 99.99, quantity: 2 }, { productId: 'PROD-456', price: 99.99, quantity: 1 }, ], paymentType: 'credit_card', coupon: 'SAVE10', tax: 30.0, shipment: 5.99,});Checkout Steps
Section titled “Checkout Steps”Track checkout funnel progression for drop-off analysis:
// Step 1: Customer informationawait SegmentifyEventManager().CustomerInformation({ totalPrice: 199.99, productList: [{ productId: 'SKU-100', quantity: 1, price: 199.99 }],});
// Step 2: Payment informationawait SegmentifyEventManager().PaymentInformation({ totalPrice: 199.99, orderNo: 'pending', productList: [{ productId: 'SKU-100', quantity: 1, price: 199.99 }],});
// Step 3: Purchase (see above)User Operations
Section titled “User Operations”Register
Section titled “Register”await SegmentifyEventManager().Register({ email: 'newuser@example.com', username: 'newuser',});Log In
Section titled “Log In”await SegmentifyEventManager().LogIn({ email: 'user@example.com', username: 'johndoe',});Log Out
Section titled “Log Out”await SegmentifyEventManager().Logout({});Identify (Update Profile)
Section titled “Identify (Update Profile)”Update user profile data without triggering a login/register event:
await SegmentifyEventManager().Identify({ email: 'user@example.com', source: 'email-collection', isRegistered: true,});The Identify method also handles special source types:
source: 'email-collection'automatically setsemailNtf: truesource: 'whatsapp-collection'automatically setswhatsappNtf: true
IYS Permission (Turkey Compliance)
Section titled “IYS Permission (Turkey Compliance)”Record IYS consent for commercial communications:
await SegmentifyEventManager().IysPermission({ email: 'user@example.com', phone: '+905551234567',});Favorites / Wishlist
Section titled “Favorites / Wishlist”Add to Favorites
Section titled “Add to Favorites”await SegmentifyEventManager().FavoriteAdd({ productId: 'SKU-999', favoritesList: ['SKU-1', 'SKU-2', 'SKU-999'],});Remove from Favorites
Section titled “Remove from Favorites”await SegmentifyEventManager().FavoriteRemove({ productId: 'SKU-999', favoritesList: ['SKU-1', 'SKU-2'],});View Favorites
Section titled “View Favorites”await SegmentifyEventManager().FavoriteView({ favoritesList: ['SKU-1', 'SKU-2'],});Favorite Detail
Section titled “Favorite Detail”await SegmentifyEventManager().FavoriteDetail({ favoritesList: ['SKU-1', 'SKU-2', 'SKU-3'],});Form Tracking
Section titled “Form Tracking”Track form submissions for lead capture and analytics:
await SegmentifyEventManager().Form({ formName: 'contact', fields: { name: 'John', message: 'Hello' }, instanceId: 'contact-form-1',});Interaction Tracking
Section titled “Interaction Tracking”Track clicks, scroll events, or custom UI interactions:
await SegmentifyEventManager().Interaction({ type: 'click', instanceId: 'hero-banner-1', interactionId: 'cta-button',});Gamification
Section titled “Gamification”Wheel of Fortune
Section titled “Wheel of Fortune”await SegmentifyEventManager().GamificationWof({ type: 'win', win: '10%_discount', instanceId: 'wof-banner-1',});Scratch Card
Section titled “Scratch Card”await SegmentifyEventManager().GamificationScratch({ type: 'win', win: 'free_shipping', instanceId: 'scratch-card-1',});Advanced: sendEvent
Section titled “Advanced: sendEvent”All methods above are convenience wrappers around sendEvent. You can call it directly for custom events:
await SegmentifyEventManager().sendEvent({ name: 'CUSTOM_EVENT', type: 'my_custom_type', params: { key: 'value' },});Delayed Events
Section titled “Delayed Events”Send an event after a delay (e.g., engagement tracking):
await SegmentifyEventManager().sendEvent( { name: 'CUSTOM_EVENT', type: 'scroll-depth', params: { depth: 75 } }, { timeout: 3000 } // 3 second delay);Deferred Events
Section titled “Deferred Events”Queue an event for the next page load:
await SegmentifyEventManager().sendEvent({ name: 'PRODUCT_VIEW', productId: 'SKU-42', nextPage: true, // Saved to localStorage, sent on next page});Event Methods Summary
Section titled “Event Methods Summary”| Method | Internal Event Name | Step |
|---|---|---|
PageView | PAGE_VIEW | — |
ProductView | PRODUCT_VIEW | — |
BasketView | CHECKOUT | view-basket |
BasketAdd | BASKET_OPERATIONS | add |
BasketRemove | BASKET_OPERATIONS | remove |
BasketClear | BASKET_OPERATIONS | clear |
Purchase | CHECKOUT | purchase |
CustomerInformation | CHECKOUT | customer-info |
PaymentInformation | CHECKOUT | payment-info |
Register | USER_OPERATIONS | signup |
LogIn | USER_OPERATIONS | signin |
Logout | USER_OPERATIONS | signout |
Identify | USER_OPERATIONS | update |
IysPermission | USER_OPERATIONS | iyspermissions |
FavoriteAdd | WISHLIST | add |
FavoriteRemove | WISHLIST | remove |
FavoriteView | WISHLIST | view-favorites |
FavoriteDetail | WISHLIST | detail |
Form | FORM | — |
Interaction | INTERACTION | — |
GamificationWof | GAMIFICATION | win |
GamificationScratch | GAMIFICATION | win |
ErrorHandler | CUSTOM_EVENT | — |