Android SDK - Tracking Events
Simple Events
Section titled “Simple Events”FunnelMob.trackEvent("level_complete")Events with Revenue
Section titled “Events with Revenue”import com.funnelmob.sdk.FunnelMobRevenue
val revenue = FunnelMobRevenue.usd(29.99)FunnelMob.trackEvent("purchase", revenue)
// Other currenciesval eur = FunnelMobRevenue.eur(19.99)val gbp = FunnelMobRevenue.gbp(14.99)val jpy = FunnelMobRevenue.of(2000.0, "JPY")
// Using BigDecimal for precisionval precise = FunnelMobRevenue.usd(BigDecimal("99.99"))Events with Parameters
Section titled “Events with Parameters”import com.funnelmob.sdk.FunnelMobEventParameters
// Using Builderval params = FunnelMobEventParameters.Builder() .set("item_id", "sku_123") .set("quantity", 2) .set("price", 29.99) .set("is_gift", false) .build()
FunnelMob.trackEvent("add_to_cart", params)
// Using DSL (Kotlin)val params = FunnelMobEventParameters.build { set("item_id", "sku_123") set("quantity", 2) set("price", 29.99)}
// From a Mapval params = FunnelMobEventParameters.fromMap(mapOf( "item_id" to "sku_123", "quantity" to 2))Events with Revenue and Parameters
Section titled “Events with Revenue and Parameters”val revenue = FunnelMobRevenue.usd(99.00)val params = FunnelMobEventParameters.build { set("plan", "annual") set("trial_days", 7)}
FunnelMob.trackEvent("subscribe", revenue, params)Standard Events
Section titled “Standard Events”import com.funnelmob.sdk.FunnelMobStandardEvents
FunnelMob.trackEvent(FunnelMobStandardEvents.REGISTRATION)FunnelMob.trackEvent(FunnelMobStandardEvents.LOGIN)FunnelMob.trackEvent(FunnelMobStandardEvents.PURCHASE)FunnelMob.trackEvent(FunnelMobStandardEvents.SUBSCRIBE)FunnelMob.trackEvent(FunnelMobStandardEvents.TUTORIAL_COMPLETE)FunnelMob.trackEvent(FunnelMobStandardEvents.LEVEL_COMPLETE)FunnelMob.trackEvent(FunnelMobStandardEvents.ADD_TO_CART)FunnelMob.trackEvent(FunnelMobStandardEvents.CHECKOUT)| Event | Constant | Value |
|---|---|---|
| Registration | FunnelMobStandardEvents.REGISTRATION | fm_registration |
| Login | FunnelMobStandardEvents.LOGIN | fm_login |
| Purchase | FunnelMobStandardEvents.PURCHASE | fm_purchase |
| Subscribe | FunnelMobStandardEvents.SUBSCRIBE | fm_subscribe |
| Tutorial Complete | FunnelMobStandardEvents.TUTORIAL_COMPLETE | fm_tutorial_complete |
| Level Complete | FunnelMobStandardEvents.LEVEL_COMPLETE | fm_level_complete |
| Add to Cart | FunnelMobStandardEvents.ADD_TO_CART | fm_add_to_cart |
| Checkout | FunnelMobStandardEvents.CHECKOUT | fm_checkout |
Java Interoperability
Section titled “Java Interoperability”All public methods have @JvmStatic annotations:
import com.funnelmob.sdk.FunnelMob;import com.funnelmob.sdk.FunnelMobRevenue;import com.funnelmob.sdk.FunnelMobEventParameters;
// Track eventsFunnelMob.trackEvent("button_click");
// With revenueFunnelMobRevenue revenue = FunnelMobRevenue.usd(29.99);FunnelMob.trackEvent("purchase", revenue);
// With parametersFunnelMobEventParameters params = new FunnelMobEventParameters.Builder() .set("item_id", "sku_123") .set("quantity", 2) .build();FunnelMob.trackEvent("add_to_cart", params);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.trackEvent("purchase") // OKFunnelMob.trackEvent("level_2_complete") // OK
// Invalid (logged as errors)FunnelMob.trackEvent("2nd_level") // Starts with numberFunnelMob.trackEvent("my-event") // Contains hyphenFunnelMob.trackEvent("") // EmptyCurrency
Section titled “Currency”- Must be a 3-letter ISO 4217 code
- Automatically converted to uppercase with
FunnelMobRevenue.of()
FunnelMobRevenue.usd(29.99) // OKFunnelMobRevenue.of(29.99, "jpy") // Converted to "JPY"
// Invalid (throws IllegalArgumentException)FunnelMobRevenue.of(29.99, "US") // Too shortFunnelMobRevenue.of(29.99, "USDD") // Too long