Question

Equivalent of mixpanel.people.remove in PHP

  • 14 February 2019
  • 3 replies
  • 38 views

Badge

I looked into PHP library and found that there's no equivalent of the following code in PHP. I want to remove an item from a list using PHP. Is there any possibility?

mixpanel.people.remove('School', 'UCB');


3 replies

Badge

There is a remove method in the latest Producers_MixpanelPeople class. Here's the method signature;

public function remove($distinct_id, $props, $ip = null, $ignore_time = false) {)

Ref: https://github.com/mixpanel/mixpanel-php/blob/master/lib/Producers/MixpanelPeople.php


Badge

Hi @blueworld, thanks for your response. Actually the method you've specified removes/unset the User property. What I intend to do is to remove specific value from a comma separated property list. Please see the description under 'mixpanel.people.remove' in this API Reference. https://mixpanel.com/help/reference/javascript-full-api-reference


Badge

I've created a duplicate of append() method and replaced '$append' with '$remove' and able to remove the list item from comma separated property. I think this method should be a part of main repository as well. Here's complete source code.


public function removeListItem($distinct_id, $prop, $val, $ip = null, $ignore_time = false) {
        $operation = gettype($val) == "array" ? '$union' : '$remove';
        $payload = $this->_constructPayload($distinct_id, $operation, array("$prop" => $val), $ip, $ignore_time);
        $this->enqueue($payload);
    }

Reply