Skip to content

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.

View as Markdown llms.txt

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. :::

Track when a user visits a page:

await SegmentifyEventManager().PageView({
category: 'home',
subCategory: 'main',
params: { page: 'homepage' },
});

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'],
});
await SegmentifyEventManager().BasketAdd({
productId: 'PROD-123',
price: 99.99,
quantity: 1,
});
await SegmentifyEventManager().BasketRemove({
productId: 'PROD-123',
price: 99.99,
quantity: 1,
});
await SegmentifyEventManager().BasketView({
totalPrice: 299.97,
productList: [
{ productId: 'PROD-123', price: 99.99, quantity: 2 },
{ productId: 'PROD-456', price: 99.99, quantity: 1 },
],
});
await SegmentifyEventManager().BasketClear({});

::: tip basketId is automatically generated from the user ID. You don’t need to pass it manually. :::

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,
});

Track checkout funnel progression for drop-off analysis:

// Step 1: Customer information
await SegmentifyEventManager().CustomerInformation({
totalPrice: 199.99,
productList: [{ productId: 'SKU-100', quantity: 1, price: 199.99 }],
});
// Step 2: Payment information
await SegmentifyEventManager().PaymentInformation({
totalPrice: 199.99,
orderNo: 'pending',
productList: [{ productId: 'SKU-100', quantity: 1, price: 199.99 }],
});
// Step 3: Purchase (see above)
await SegmentifyEventManager().Register({
email: 'newuser@example.com',
username: 'newuser',
});
await SegmentifyEventManager().LogIn({
email: 'user@example.com',
username: 'johndoe',
});
await SegmentifyEventManager().Logout({});

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 sets emailNtf: true
  • source: 'whatsapp-collection' automatically sets whatsappNtf: true

Record IYS consent for commercial communications:

await SegmentifyEventManager().IysPermission({
email: 'user@example.com',
phone: '+905551234567',
});
await SegmentifyEventManager().FavoriteAdd({
productId: 'SKU-999',
favoritesList: ['SKU-1', 'SKU-2', 'SKU-999'],
});
await SegmentifyEventManager().FavoriteRemove({
productId: 'SKU-999',
favoritesList: ['SKU-1', 'SKU-2'],
});
await SegmentifyEventManager().FavoriteView({
favoritesList: ['SKU-1', 'SKU-2'],
});
await SegmentifyEventManager().FavoriteDetail({
favoritesList: ['SKU-1', 'SKU-2', 'SKU-3'],
});

Track form submissions for lead capture and analytics:

await SegmentifyEventManager().Form({
formName: 'contact',
fields: { name: 'John', message: 'Hello' },
instanceId: 'contact-form-1',
});

Track clicks, scroll events, or custom UI interactions:

await SegmentifyEventManager().Interaction({
type: 'click',
instanceId: 'hero-banner-1',
interactionId: 'cta-button',
});
await SegmentifyEventManager().GamificationWof({
type: 'win',
win: '10%_discount',
instanceId: 'wof-banner-1',
});
await SegmentifyEventManager().GamificationScratch({
type: 'win',
win: 'free_shipping',
instanceId: 'scratch-card-1',
});

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' },
});

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
);

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
});
MethodInternal Event NameStep
PageViewPAGE_VIEW—
ProductViewPRODUCT_VIEW—
BasketViewCHECKOUTview-basket
BasketAddBASKET_OPERATIONSadd
BasketRemoveBASKET_OPERATIONSremove
BasketClearBASKET_OPERATIONSclear
PurchaseCHECKOUTpurchase
CustomerInformationCHECKOUTcustomer-info
PaymentInformationCHECKOUTpayment-info
RegisterUSER_OPERATIONSsignup
LogInUSER_OPERATIONSsignin
LogoutUSER_OPERATIONSsignout
IdentifyUSER_OPERATIONSupdate
IysPermissionUSER_OPERATIONSiyspermissions
FavoriteAddWISHLISTadd
FavoriteRemoveWISHLISTremove
FavoriteViewWISHLISTview-favorites
FavoriteDetailWISHLISTdetail
FormFORM—
InteractionINTERACTION—
GamificationWofGAMIFICATIONwin
GamificationScratchGAMIFICATIONwin
ErrorHandlerCUSTOM_EVENT—