swift - 如何在开发中禁用 swift-Mixpanel?

标签 swift mixpanel

在 appDelegate 上,我以前在 obj-c 上是这样写的,但是在 swift 中,当应用程序调用 Mixpanel.mainInstance().track(event: "") 时,它会在开发中崩溃

开发模式不发送mixpanel数据有什么好办法?

#if DEBUG
#else
    Mixpanel.initialize(token: Key.Mixpanel.token)
#endif

最佳答案

根据您的说法,我提出以下解决方案:

在 Mixpanel 中创建一个项目用于开发,并在 AppDelegate 中的 didFinishLaunchWithOptions 方法中创建一个项目,您可以执行如下操作:

#if DEBUG
  Mixpanel.initialize(token: Constants.APP.MIXPANEL.DEVELOPMENT_TOKEN)
#else
  Mixpanel.initialize(token: Constants.APP.MIXPANEL.PRODUCTION_TOKEN)
#endif

//Where Constants.APP.MIXPANEL.DEVELOPMENT_TOKEN and Constants.APP.MIXPANEL.PRODUCTION_TOKEN contain your Strings from your tokens of each of the mixpanel projects

这样您就可以保证您开发和测试的事件不会与生产中应用程序的事件混合

另一种解决方案可能是创建自己的通用方法来发送事件,在这些方法中您可以验证应用程序是在开发还是生产中,以防止调用从 Mixpanel 实例发送事件的方法,如下所示:

class MixpanelOwn {
  static func trackEventOwn(sbEventMixpanel:String, props:Properties?){
     #if !DEBUG
        if let properties = props {
          Mixpanel.mainInstance().track(event:sbEventMixpanel, properties: properties)
        }else{
          Mixpanel.mainInstance().track(event: sbEventMixpanel)
        }       
     #endif
  }
}

//To call it, it would be something like this
//Without props 
MixpanelOwn.trackEventOwn(sbEventMixpanel:"User entered to ProductsScreen", props:nil);
//With props
var props:Properties = Properties();
props["userId"] = 12345;
props["email"] = "email@mail.com"
MixpanelOwn.trackEventOwn(sbEventMixpanel:"User entered to ProductsScreen", props:props);

问候!

关于swift - 如何在开发中禁用 swift-Mixpanel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46358376/

相关文章:

ios - 将从图库中获取的图像设置为 UIImageView

ios - swift facebookSDK 检索用户的介绍?

objective-c - 子类 View 使用父类(super class) nib 文件

ios - 无法通过手动安装来安装Mixpanel iOS SDK-找不到Mixpanel/Mixpanel.h文件

ios - 为 iOS 构建时,cocoa-pods 库中出现重复符号

android - Mixpanel 推送通知文本不会在 Android 设备上放大

ios - 使用 numberformatter 将字符串快速转换为 double 返回 nil

ios - 警告 : Attempt to present UINavigationController whose view is not in the window hierarchy?

mixpanel - 使用 mixpanel 创建配置文件来跟踪不工作的用户

javascript - 使用 RequireJS 通过 GTM 自定义 HTML 标签注入(inject) jQuery 片段