Skip to main content

Event Tracking

Log an Event​

B2MAnalytics.shared.logEvent(name: "product_viewed")

B2MAnalytics.shared.logEvent(
name: "purchase",
properties: [
"product_id": AnyCodable("SKU-123"),
"price": AnyCodable(49.90),
"currency": AnyCodable("TRY")
]
)

Event names must be non-empty and at most 255 characters. Property values must be JSON-compatible (String, finite Number, Bool, Date, arrays, dictionaries); anything else is dropped with a warning rather than being coerced to a string.

Item Properties​

Use itemProperties for row-level data such as cart lines or search results:

B2MAnalytics.shared.logEvent(
name: "add_to_cart",
properties: ["total": AnyCodable(3000)],
itemProperties: [
["id": AnyCodable("SKU-123"), "name": AnyCodable("Running Shoes")],
["id": AnyCodable("SKU-456"), "name": AnyCodable("Socks")]
]
)

Naming Conventions​

  • Use snake_case: user_signed_up, product_added_to_cart, video_playback_started
  • Avoid camelCase, kebab-case, or PascalCase event names