无法声明类Mixpanel,因为该名称已被使用?

时间:2019-06-09 14:14:39

标签: php wordpress mixpanel

我正在尝试使用Mixpanel php库,并在用户在我的网站上注册时尝试启动alias()方法。我在我的function.php中添加以下代码,当我启动mixpanel实例方法时,出现以下错误。我可能做错了什么?

Fatal error: Cannot declare class Mixpanel, because the name is already in use in /opt/bitnami/apps/wordpress/htdocs/wp-content/themes/lib/Mixpanel.php on line 97

functions.php

function on_wp_register_user( $user_id )
{
require_once( get_template_directory() . '/lib/Mixpanel.php');   
  $mp = Mixpanel::getInstance("------");
  $mp->track("My Event"); 

  $mp->people->set(12345, array(
  '$first_name'       => "John",
  '$last_name'        => "Doe",
  '$email'            => "john.doe@example.com",
  '$phone'            => "5555555555",
  'Favorite Color'    => "red"
  ));

}
add_action('user_register', 'on_wp_register_user', 10, 1 );

mixpanel.php

<?php

require_once(get_template_directory() . '/lib/Base/MixpanelBase.php');
require_once(get_template_directory() . '/lib/Producers/MixpanelPeople.php');
require_once(get_template_directory() . '/lib/Producers/MixpanelEvents.php');


class Mixpanel extends Base_MixpanelBase {


    /**
     * An instance of the MixpanelPeople class (used to create/update profiles)
     * @var MixpanelPeople
     */
    public $people;


    /**
     * An instance of the MixpanelEvents class
     * @var Producers_MixpanelEvents
     */
    private $_events;


    /**
     * An instance of the Mixpanel class (for singleton use)
     * @var Mixpanel
     */
    private static $_instance;


    /**
     * Instantiates a new Mixpanel instance.
     * @param $token
     * @param array $options
     */
    public function __construct($token, $options = array()) {
        parent::__construct($options);
        $this->people = new Producers_MixpanelPeople($token, $options);
        $this->_events = new Producers_MixpanelEvents($token, $options);
    }


    /**
     * Returns a singleton instance of Mixpanel
     * @param $token
     * @param array $options
     * @return Mixpanel
     */
    public static function getInstance($token, $options = array()) {
        if(!isset(self::$_instance)) {
            self::$_instance = new Mixpanel($token, $options);
        }
        return self::$_instance;
    }


    /**
     * Add an array representing a message to be sent to Mixpanel to the in-memory queue.
     * @param array $message
     */
    public function enqueue($message = array()) {
        $this->_events->enqueue($message);
    }


    /**
     * Add an array representing a list of messages to be sent to Mixpanel to a queue.
     * @param array $messages
     */
    public function enqueueAll($messages = array()) {
        $this->_events->enqueueAll($messages);
    }


    /**
     * Flush the events queue
     * @param int $desired_batch_size
     */
    public function flush($desired_batch_size = 50) {
        $this->_events->flush($desired_batch_size);
    }


    /**
     * Empty the events queue
     */
    public function reset() {
        $this->_events->reset();
    }


    /**
     * Identify the user you want to associate to tracked events
     * @param string|int $user_id
     */
    public function identify($user_id) {
        $this->_events->identify($user_id);
    }

    /**
     * Track an event defined by $event associated with metadata defined by $properties
     * @param string $event
     * @param array $properties
     */
    public function track($event, $properties = array()) {
        $this->_events->track($event, $properties);
    }


    /**
     * Register a property to be sent with every event.
     *
     * If the property has already been registered, it will be
     * overwritten. NOTE: Registered properties are only persisted for the life of the Mixpanel class instance.
     * @param string $property
     * @param mixed $value
     */
    public function register($property, $value) {
        $this->_events->register($property, $value);
    }


    /**
     * Register multiple properties to be sent with every event.
     *
     * If any of the properties have already been registered,
     * they will be overwritten. NOTE: Registered properties are only persisted for the life of the Mixpanel class
     * instance.
     * @param array $props_and_vals
     */
    public function registerAll($props_and_vals = array()) {
        $this->_events->registerAll($props_and_vals);
    }


    /**
     * Register a property to be sent with every event.
     *
     * If the property has already been registered, it will NOT be
     * overwritten. NOTE: Registered properties are only persisted for the life of the Mixpanel class instance.
     * @param $property
     * @param $value
     */
    public function registerOnce($property, $value) {
        $this->_events->registerOnce($property, $value);
    }


    /**
     * Register multiple properties to be sent with every event.
     *
     * If any of the properties have already been registered,
     * they will NOT be overwritten. NOTE: Registered properties are only persisted for the life of the Mixpanel class
     * instance.
     * @param array $props_and_vals
     */
    public function registerAllOnce($props_and_vals = array()) {
        $this->_events->registerAllOnce($props_and_vals);
    }


    /**
     * Un-register an property to be sent with every event.
     * @param string $property
     */
    public function unregister($property) {
        $this->_events->unregister($property);
    }


    /**
     * Un-register a list of properties to be sent with every event.
     * @param array $properties
     */
    public function unregisterAll($properties) {
        $this->_events->unregisterAll($properties);
    }


    /**
     * Get a property that is set to be sent with every event
     * @param string $property
     * @return mixed
     */
    public function getProperty($property)
    {
        return $this->_events->getProperty($property);
    }


    /**
     * Alias an existing id with a different unique id. This is helpful when you want to associate a generated id
     * (such as a session id) to a user id or username.
     * @param string|int $original_id
     * @param string|int $new_id
     */
    public function createAlias($original_id, $new_id) {
        $this->_events->createAlias($original_id, $new_id);
    }
}

0 个答案:

没有答案