我的PHP CodeIgniter应用程序上的Mixpanel人员跟踪

我的PHP CodeIgniter应用程序上的Mixpanel人员跟踪,php,codeigniter,mixpanel,Php,Codeigniter,Mixpanel,我在PHP的CodeIgniter框架上运行了这个应用程序。我正在尝试使用Mixpanel设置人员跟踪。这样我就可以知道用户登录的时间和时间 我已经在我的application/libraries文件夹中安装了此库的文件,然后在我的controller login.php上调用它,如下所示: public function __construct(){ parent::__construct(); $this->load->model('login_model');

我在PHP的CodeIgniter框架上运行了这个应用程序。我正在尝试使用Mixpanel设置人员跟踪。这样我就可以知道用户登录的时间和时间

我已经在我的application/libraries文件夹中安装了此库的文件,然后在我的controller login.php上调用它,如下所示:

public function __construct(){
    parent::__construct();
    $this->load->model('login_model');
    $this->load->library('form_validation');
    // Mixpanel Config
    $this->load->library('Mixpanel');
    $this->Mixpanel->mp = Mixpanel::getInstance("9966a1a78b347f556a7cc0c9f298502b", array("use_ssl" => false));

}
之后,在同一控制器索引函数中,添加以下内容:

// Sends login information to Mixpanel
            $this->Mixpanel->mp->people->identify($aluno[0]->aluno_id, array(
        '$first_name'       => $aluno[0]->aluno_primeiro_nome,
        '$last_name'        => $aluno[0]->aluno_sobrenome,
        '$email'            => $aluno[0]->aluno_email,
            ));
整个功能是:

public function index(){
    $this->form_validation->set_error_delimiters('<p class="default_error">', '</p>');
    $this->form_validation->set_rules('user_email', 'E-mail', 'trim|required|valid_email|xss_clean');
    $this->form_validation->set_rules('user_password', 'Senha', 'trim|required|xss_clean');
    $this->form_validation->set_message('required', 'Campo de preenchimento obrigatório');
    $this->form_validation->set_message('valid_email', 'Por favor, digite um e-mail válido');
    if ($this->form_validation->run()){
        if($this->login_model->authenticate($this->input->post('user_email'), $this->input->post('user_password'))){
            $this->load->model('aluno_model');
            $aluno = $this->aluno_model->getStudentbyEmail($this->input->post('user_email'));
            if(!empty($aluno[0]->aluno_thumb_img)) :
            $login = array(
                        'id' => $aluno[0]->aluno_id, 
                        'primeiro_nome' => $aluno[0]->aluno_primeiro_nome, 
                        'sobrenome' => $aluno[0]->aluno_sobrenome,
                        'senha' => $aluno[0]->aluno_senha, 
                        'email' => $aluno[0]->aluno_email, 
                        'thumb' => base_url('student_images/'.$aluno[0]->aluno_thumb_img),
                        'large' => base_url('student_images/'.$aluno[0]->aluno_large_img),
                        'status' => $aluno[0]->aluno_status
                        );
            else :
            $login = array(
                        'id' => $aluno[0]->aluno_id, 
                        'primeiro_nome' => $aluno[0]->aluno_primeiro_nome, 
                        'sobrenome' => $aluno[0]->aluno_sobrenome,
                        'senha' => $aluno[0]->aluno_senha, 
                        'email' => $aluno[0]->aluno_email, 
                        'thumb' => base_url('student_images/'.$aluno[0]->aluno_large_img),
                        'large' => base_url('student_images/'.$aluno[0]->aluno_large_img),
                        'status' => $aluno[0]->aluno_status
                        );
            endif;

            // Sends login information to Mixpanel
            $this->Mixpanel->mp->people->identify($aluno[0]->aluno_id, array(
        '$first_name'       => $aluno[0]->aluno_primeiro_nome,
        '$last_name'        => $aluno[0]->aluno_sobrenome,
        '$email'            => $aluno[0]->aluno_email,
            ));

            $this->session->set_userdata('user', $login);

            if($this->input->post('url_checkout')){
                $this->set_flashdata('loginSuccess', 'loginSuccess', $this->input->post('url_checkout'));
            }else{
                $this->set_flashdata('loginSuccess', 'loginSuccess', base_url('aluno'));
            }
        }else{
            $this->set_flashdata('loginFailed', 'loginFailed', $this->input->post('url'));
        }
    }else{
        $errors = array('user_email'=>form_error('user_email'), 'user_password'=>form_error('user_password'));
        $this->set_flashdata('loginError', $errors, $this->input->post('url'));
    }

}
Mixpanel正在接收登录信息,因为我可以在仪表板中看到它,但我的应用程序返回了一些错误:

遇到一个PHP错误 严重性:警告

消息:Mixpanel缺少参数1::_构造,在第1099行的/Applications/MAMP/htdocs/descola rep/system/core/Loader.php中调用并定义

文件名:libraries/Mixpanel.php

电话号码:138

遇到一个PHP错误 严重性:通知

消息:未定义变量:令牌

文件名:libraries/Mixpanel.php

电话号码:140

遇到一个PHP错误 严重性:通知

消息:未定义变量:令牌

文件名:libraries/Mixpanel.php

电话号码:141

遇到一个PHP错误 严重性:警告

消息:从空值创建默认对象

文件名:controllers/login.php

电话号码:11

如果有人能告诉我我哪里出了问题,我会非常高兴。我仍在学习后端开发,我无法理解这一点


干杯

看起来,CodeIgniter中的库集成存在问题。也许这个链接会有所帮助:

看起来,CodeIgniter中的库集成存在问题。也许这个链接会有帮助:

所以,在Mixpanels的大力帮助下,顺便说一句,他们非常棒,我可以找到这个解决方案。对于那些将要面对同样问题的人,有一件事:

1在application/libraries/mixpanel_lib上安装库的

2在应用程序/库中创建一个名为Mixpanel_wrapper.php的新php文件。在那里,您将重新获取库路径,设置令牌并创建一些函数。下面的文件已经有一些功能,如跟踪、设置和识别。有关更多信息,请在此处添加函数

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
require 'application/libraries/mixpanel_lib/Mixpanel.php';

class Mixpanel_wrapper {

private $mixpanel = false;

public function __construct(){
  $mp = $this->getMixpanel();
    $mp = Mixpanel::getInstance("PLACE_YOUR_TOKEN_HERE");
    $this->setMixpanel($mp);
}

public function getMixpanel(){ return $this->mixpanel; }
public function setMixpanel($obj){ $this->mixpanel =  $obj; }

public function track_something($event = '', $properties = array()){
    $mp = $this->getMixpanel();

    $mp->track($event, $properties);

}// track_something function ends

public function people_set($distinct_id = '', $properties = array()){

    $mp = $this->getMixpanel();

    $mp->people->set($distinct_id, $properties);

}// people_set function ends

 public function identify($distinct_id){

  $mp = $this->getMixpanel();

  $mp->identify($distinct_id);

 }// identify function ends

}/* End of file mixpanel_wrapper.php */
跟踪什么

// Sends login information to mixpanel
            $this->mixpanel_wrapper->people_set($student[0]->student_id, array(
            '$first_name'       => $student[0]->student_first_name,
            '$last_name'        => $student[0]->student_last_name,
            '$email'            => $student[0]->student_email,
            ));
            $this->mixpanel_wrapper->identify($student[0]->student_id);
            $this->mixpanel_wrapper->track_something('Logged in');
            // ends mixpanel

我想就是这样

所以,在Mixpanels的大力帮助下,顺便说一句,他们太棒了,我可以找到这个解决方案。对于那些将要面对同样问题的人,有一件事:

1在application/libraries/mixpanel_lib上安装库的

2在应用程序/库中创建一个名为Mixpanel_wrapper.php的新php文件。在那里,您将重新获取库路径,设置令牌并创建一些函数。下面的文件已经有一些功能,如跟踪、设置和识别。有关更多信息,请在此处添加函数

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
require 'application/libraries/mixpanel_lib/Mixpanel.php';

class Mixpanel_wrapper {

private $mixpanel = false;

public function __construct(){
  $mp = $this->getMixpanel();
    $mp = Mixpanel::getInstance("PLACE_YOUR_TOKEN_HERE");
    $this->setMixpanel($mp);
}

public function getMixpanel(){ return $this->mixpanel; }
public function setMixpanel($obj){ $this->mixpanel =  $obj; }

public function track_something($event = '', $properties = array()){
    $mp = $this->getMixpanel();

    $mp->track($event, $properties);

}// track_something function ends

public function people_set($distinct_id = '', $properties = array()){

    $mp = $this->getMixpanel();

    $mp->people->set($distinct_id, $properties);

}// people_set function ends

 public function identify($distinct_id){

  $mp = $this->getMixpanel();

  $mp->identify($distinct_id);

 }// identify function ends

}/* End of file mixpanel_wrapper.php */
跟踪什么

// Sends login information to mixpanel
            $this->mixpanel_wrapper->people_set($student[0]->student_id, array(
            '$first_name'       => $student[0]->student_first_name,
            '$last_name'        => $student[0]->student_last_name,
            '$email'            => $student[0]->student_email,
            ));
            $this->mixpanel_wrapper->identify($student[0]->student_id);
            $this->mixpanel_wrapper->track_something('Logged in');
            // ends mixpanel

我想就是这样

谢谢你,丹尼斯。这个图书馆实际上很管用。但我无法追踪人,只能追踪事件。也许如果我做一些调整,它可能会做。谢谢丹尼斯。这个图书馆实际上很管用。但我无法追踪人,只能追踪事件。如果我做一些调整,也许可以。