Web SDK - Tracking Events
Simple Events
Section titled “Simple Events”FunnelMob.shared.trackEvent('level_complete');Events with Revenue
Section titled “Events with Revenue”import { FunnelMobRevenue } from '@funnelmob/sdk';
const revenue = FunnelMobRevenue.usd(29.99);FunnelMob.shared.trackEvent('purchase', revenue);
// Other currenciesconst eur = FunnelMobRevenue.eur(19.99);const gbp = FunnelMobRevenue.gbp(14.99);const jpy = new FunnelMobRevenue(2000, 'JPY');Events with Parameters
Section titled “Events with Parameters”import { FunnelMobEventParameters } from '@funnelmob/sdk';
// Fluent builder patternconst params = new FunnelMobEventParameters() .set('item_id', 'sku_123') .set('quantity', 2) .set('price', 29.99) .set('is_gift', false);
FunnelMob.shared.trackEvent('add_to_cart', params);
// Or create from an objectconst params = FunnelMobEventParameters.fromObject({ item_id: 'sku_123', quantity: 2, price: 29.99,});Events with Revenue and Parameters
Section titled “Events with Revenue and Parameters”const revenue = FunnelMobRevenue.usd(99.00);const params = new FunnelMobEventParameters() .set('plan', 'annual') .set('trial_days', 7);
FunnelMob.shared.trackEvent('subscribe', revenue, params);Standard Events
Section titled “Standard Events”import { StandardEvents } from '@funnelmob/sdk';
FunnelMob.shared.trackEvent(StandardEvents.REGISTRATION);FunnelMob.shared.trackEvent(StandardEvents.LOGIN);FunnelMob.shared.trackEvent(StandardEvents.PURCHASE);FunnelMob.shared.trackEvent(StandardEvents.SUBSCRIBE);FunnelMob.shared.trackEvent(StandardEvents.TUTORIAL_COMPLETE);FunnelMob.shared.trackEvent(StandardEvents.LEVEL_COMPLETE);FunnelMob.shared.trackEvent(StandardEvents.ADD_TO_CART);FunnelMob.shared.trackEvent(StandardEvents.CHECKOUT);| Event | Constant | Value |
|---|---|---|
| Registration | StandardEvents.REGISTRATION | fm_registration |
| Login | StandardEvents.LOGIN | fm_login |
| Purchase | StandardEvents.PURCHASE | fm_purchase |
| Subscribe | StandardEvents.SUBSCRIBE | fm_subscribe |
| Tutorial Complete | StandardEvents.TUTORIAL_COMPLETE | fm_tutorial_complete |
| Level Complete | StandardEvents.LEVEL_COMPLETE | fm_level_complete |
| Add to Cart | StandardEvents.ADD_TO_CART | fm_add_to_cart |
| Checkout | StandardEvents.CHECKOUT | fm_checkout |
Validation
Section titled “Validation”Event Names
Section titled “Event Names”- Must not be empty
- Maximum 100 characters
- Must match pattern:
^[a-zA-Z][a-zA-Z0-9_]*$
// ValidFunnelMob.shared.trackEvent('purchase'); // OKFunnelMob.shared.trackEvent('level_2_complete'); // OK
// Invalid (logged as errors, not thrown)FunnelMob.shared.trackEvent('2nd_level'); // Starts with numberFunnelMob.shared.trackEvent('my-event'); // Contains hyphenFunnelMob.shared.trackEvent(''); // EmptyCurrency
Section titled “Currency”- Must be a 3-letter ISO 4217 code
- Automatically converted to uppercase
new FunnelMobRevenue(29.99, 'USD'); // OKnew FunnelMobRevenue(29.99, 'usd'); // Converted to 'USD'
// Invalidnew FunnelMobRevenue(29.99, 'US'); // Too shortnew FunnelMobRevenue(29.99, 'USDD'); // Too long