【问题标题】:Segment.io NPM Package not working with MeteorSegment.io NPM 包不适用于 Meteor
【发布时间】:2016-04-20 09:50:00
【问题描述】:

我将 npm 包用于 Meteor 的分段服务器端

在我的 packages.json 文件夹中

"segmentio": "0.1.4"


if Meteor.isServer
  Meteor.startup ->
    @analytics = Meteor.npmRequire('segmentio')
    analytics.init(Meteor.settings.segmentio)

    analytics.track
      event: 'hello'
      userId: '2'

我用来跟踪分段服务器端事件的代码。但是该事件未显示在调试器中。有什么建议吗?我做错了什么?

我知道我使用了正确的 Meteor.settings.segmentio 密钥,因为我在客户端上使用了相同的密钥,并且这些事件被很好地跟踪。但是在服务器上,我在上面发布的 'hello' 事件将无法跟踪。上面的代码运行时不会抛出任何错误。

【问题讨论】:

  • 如果没有抛出错误,我会仔细检查Meteor.settings.segmentio 的值。也许它没有被正确读取或者你复制了错误的值。
  • 我在客户端上使用 Meteor.settings.segmentio 和 analytics.js,它正在工作。所以我知道关键是对的。所有客户端呼叫都通过。上面的代码是我用于服务器端的代码。没有错误被抛出。但我在调试器中没有看到该事件。

标签: meteor npm segment-io


【解决方案1】:

我的代码设置稍有错误。

范围问题。这是工作代码:

@analytics = null

if Meteor.isServer
  Meteor.startup ->
    analytics = Meteor.npmRequire('segmentio')
    analytics.init(Meteor.settings.segmentio)

    analytics.track
      event: 'hello'
      userId: '2'

【讨论】:

    猜你喜欢
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 2018-05-26
    • 2017-01-04
    • 1970-01-01
    • 2013-03-13
    • 2016-01-02
    相关资源
    最近更新 更多