【问题标题】:Mixpanel Integration混合面板集成
【发布时间】:2014-08-11 21:31:38
【问题描述】:

我从 mixpanel 得到这个:

识别您的用户 要跟踪您的用户,您需要给他们一个身份。您可以使用用户独有的任何内容,例如数据库中的用户 ID 或电子邮件地址。 mixpanel.identify("12148"); 我们建议您使用与跟踪操作相同的唯一 ID。

我没有得到我应该在"12148" 中输入的内容。如果我想使用 userID 跟踪用户,我应该在里面放什么?另外,关于存储我不确定的数据的事情。

mixpanel.people.set({

    "$email": "jsmith@example.com",    // only special properties need the $

    "$created": "2011-03-16 16:53:54",
    "$last_login": new Date(),         // properties can be dates...

    "credits": 150,                    // ...or numbers

    "gender": "Male"                    // feel free to define your own properties
});

【问题讨论】:

    标签: ruby-on-rails ruby mixpanel


    【解决方案1】:

    正如描述中提到的那样:

    您可以使用用户独有的任何内容,例如来自 您的数据库或电子邮件地址

    我建议您为此使用用户 ID。

    为用户创建混合面板配置文件时,您需要对他们进行唯一标识。由于您已经有一个 User 模型,您可以在其中使用他们在 rails 中的 id 来识别用户,因此使用相同的 user.id 来识别 mixpanel 上的用户是一个很好的做法。

    现在我认为你的困惑是,12148 基本上是从哪里来的?

    再次如上所述,它是您的用户混合面板配置文件的唯一标识符,即您可以使用它获取有关用户的混合面板信息的东西或某个值。

    让我们看一下这个例子。 假设您的模型中有一些用户“amksg”。

    你将如何找回它?

    最好使用它的 id。

    user = User.find 1 #say 1 is the id for amksg
    

    user = User.find_by_email("amksg@example.com") # using the unique email id
    

    现在类似地为用户设置 mixpanel 配置文件:

    mixpanel = Mixpanel::Tracker.new(PROJECT_TOKEN)
    mixpanel.people.set(user.id, {    # we already have user object, setting its ID using the object
        '$first_name'       => 'John',
        '$last_name'        => 'Doe',
        '$email'            => 'john.doe@example.com',
        '$phone'            => '5555555555',
        'Favorite Color'    => 'red'
    });
    

    这将创建配置文件。

    或使用电子邮件作为标识符:

    mixpanel.people.set(user.email, {
            '$first_name'       => 'John',
            '$last_name'        => 'Doe',
            '$email'            => 'john.doe@example.com',
            '$phone'            => '5555555555',
            'Favorite Color'    => 'red'
        });
    

    【讨论】:

    • 那我应该放什么? mixpanel.identify("#{@user.id}"); ?我应该把这个放在哪里?视图还是控制器?
    • 我举了个例子。您应该输入用户 ID(我建议),但避免对其进行硬编码,而是使用 User 对象。像 mixpanel.people.set(user.id { ..});
    猜你喜欢
    • 2021-04-03
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多