1

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.

1
  • it would be great, if you can also write, what is your current approach to solve the issue? Commented Oct 8, 2019 at 8:36

3 Answers 3

2

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.

1
  • 1
    This is not working anymore. I'm trying to send a registered parameter to purchase event, like "number_of_passengers" and isn't being recorded in DebugView. I'm running out of options. Any suggestion? Commented Jan 13, 2021 at 15:13
0

Try this:

let parameter =["discount_amount": 5, "delivery_type" : COD] // put all your parameter here 

Analytics.logEvent(EventName, parameters: parameter) //replace EventName with your event name you want to log

is it possible to add 'items' array with the parameters of each item in purchase? Currently it's not possible as firebase only support Text or Number(Double, Int etc.) , further number can classified in different types

enter image description here

1
  • Abhi thanks a lot for the explanation! Could you please also clarify, if it is possible to use Bundles to pass that group of item parameters? There's a guide for Enhanced Ecommerce implementation via GTM link. The code examples are provided for Objective-c. Is it possible to do the same in Swift? Like here: nimb.ws/3CJOgc Commented Oct 10, 2019 at 5:38
0

i create a new class to put all the Firebase Analytics functions

this is example

class ClientAnalytics
{

    static func purchaseEvent(itemAdded : String , value : Double , currency : String)
{
    Analytics.logEvent(AnalyticsEventEcommercePurchase, parameters:
    [
        AnalyticsParameterItemID   : itemAdded as NSObject,
        AnalyticsParameterValue    : value,
        AnalyticsParameterCurrency : currency
    ])
}

how to call

ClientAnalytics.purchaseEvent(itemAdded: ToolName, value: toolValue, currency: "USD")

the purpose of this functions is to log any purchase Event the user

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.