Search code examples
iosswiftfirebasefirebase-analytics

Firebase Analytics for iOS — custom parameters with predefined events (Swift)


I'm trying to implement Firebase Analytics for Swift iOS app. Could you please explain, if it's possible to pass custom parameters with predefined AnalyticsEvent like AnalyticsEventEcommercePurchase https://firebase.google.com/docs/reference/swift/firebaseanalytics/api/reference/Constants#analyticseventecommercepurchase?

For instanse, I'd love to add 'dicount_amount', 'delivery_type' to that event. Is it possible for AnalyticsEventEcommercePurchase?

Also, is it possible to add 'items' array with the parameters of each item in purchase? Is it possible to pass predefined parameters with custom events? For example, pass AnalyticsParameterItemId with my own event view_product?

Thank you so much. I'd appreciate any recommendations and examples.


Solution

  • You can. Simply pass them along with the predefined parameters, like this:

    Analytics.logEvent(AnalyticsEventEcommercePurchase, parameters: [
      AnalyticsParameterCurrency: "aud",
      AnalyticsParameterValue: "999",
      "whatever_you_want": "foo"
    ])
    

    You can also used predefined parameters in custom events as these are just strings.