简体   繁体   English

Firebase iOS 的分析——带有预定义事件的自定义参数 (Swift)

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

I'm trying to implement Firebase Analytics for Swift iOS app.我正在尝试为 Swift iOS 应用程序实施 Firebase 分析。 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 ?您能否解释一下,是否可以使用预定义的 AnalyticsEvent 传递自定义参数,例如 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.例如,我想为该事件添加“dicount_amount”、“delivery_type”。 Is it possible for AnalyticsEventEcommercePurchase? AnalyticsEventEcommercePurchase 有可能吗?

Also, is it possible to add 'items' array with the parameters of each item in purchase?另外,是否可以在购买的每件商品的参数中添加“items”数组? Is it possible to pass predefined parameters with custom events?是否可以通过自定义事件传递预定义参数? For example, pass AnalyticsParameterItemId with my own event view_product?例如,将 AnalyticsParameterItemId 与我自己的事件 view_product 一起传递?

Thank you so much.太感谢了。 I'd appreciate any recommendations and examples.我将不胜感激任何建议和示例。

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.您还可以在自定义事件中使用预定义参数,因为这些只是字符串。

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目前不可能,因为 firebase 仅支持Text or Number(Double, Int etc.) ,进一步的数字可以分为不同的类型

在此处输入图像描述

i create a new class to put all the Firebase Analytics functions我创建一个新的 class 来放置所有 Firebase 分析函数

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此功能的目的是记录用户的任何购买事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM