Best Practices
Event Naming Conventions
Use consistent, descriptive event names across your app. Use snake_case for consistency.
Good examples:
"user_signed_up"
"product_added_to_cart"
"video_playback_started"
Avoid:
"UserSignedUp" // camelCase
"product-added-to-cart" // kebab-case
"ProductAdded" // PascalCase
Property Naming Conventions
Keep property names consistent and meaningful:
B2MetricAnalytics.shared.logEvent(
name: "purchase_completed",
properties: [
"product_id": AnyCodable("SKU-123"),
"product_name": AnyCodable("Sneakers"),
"product_price": AnyCodable(299.90),
"order_id": AnyCodable("ORD-456"),
"order_total": AnyCodable(299.90)
]
)
Privacy & Sensitive Data
Never track personally identifiable information (PII) or sensitive data.
Never track:
- Passwords
- Credit card numbers
- Social security numbers
- Health information
Wrong:
// NEVER DO THIS
B2MetricAnalytics.shared.logEvent(
name: "payment_completed",
properties: [
"credit_card_number": AnyCodable("1234-5678-9012-3456") // NEVER!
]
)
Correct:
B2MetricAnalytics.shared.logEvent(
name: "payment_completed",
properties: [
"payment_method": AnyCodable("credit_card"),
"card_type": AnyCodable("visa"),
"last_four_digits": AnyCodable("3456") // Last 4 only
]
)