| 1 |
<?php |
| 2 |
|
| 3 |
namespace ElementorDeps; |
| 4 |
|
| 5 |
require_once \dirname(__FILE__) . "/MixpanelBaseProducer.php"; |
| 6 |
/** |
| 7 |
* Provides an API to create/update group profiles on Mixpanel |
| 8 |
*/ |
| 9 |
class Producers_MixpanelGroups extends Producers_MixpanelBaseProducer |
| 10 |
{ |
| 11 |
/** |
| 12 |
* Internal method to prepare a message given the message data |
| 13 |
* @param $group_key |
| 14 |
* @param $group_id |
| 15 |
* @param $operation |
| 16 |
* @param $value |
| 17 |
* @param boolean $ignore_time If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the group Profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time |
| 18 |
* @return array |
| 19 |
*/ |
| 20 |
private function _constructPayload($group_key, $group_id, $operation, $value, $ignore_time = \false) |
| 21 |
{ |
| 22 |
$payload = array('$token' => $this->_token, '$group_key' => $group_key, '$group_id' => $group_id, '$time' => \microtime(\true), $operation => $value); |
| 23 |
if ($ignore_time === \true) { |
| 24 |
$payload['$ignore_time'] = \true; |
| 25 |
} |
| 26 |
return $payload; |
| 27 |
} |
| 28 |
/** |
| 29 |
* Set properties on a group profile. If the group profile does not exist, it creates it with these properties. |
| 30 |
* If it does exist, it sets the properties to these values, overwriting existing values. |
| 31 |
* @param string|int $group_key the group_key used for groups in Project Settings |
| 32 |
* @param string|int $group_id the group id used for the group profile |
| 33 |
* @param array $props associative array of properties to set on the group profile |
| 34 |
* @param boolean $ignore_time If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the group profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time |
| 35 |
*/ |
| 36 |
public function set($group_key, $group_id, $props, $ignore_time = \false) |
| 37 |
{ |
| 38 |
$payload = $this->_constructPayload($group_key, $group_id, '$set', $props, $ignore_time); |
| 39 |
$this->enqueue($payload); |
| 40 |
} |
| 41 |
/** |
| 42 |
* Set properties on a group profile. If the Group profile does not exist, it creates it with these properties. |
| 43 |
* If it does exist, it sets the properties to these values but WILL NOT overwrite existing values. |
| 44 |
* @param string|int $group_key the group_key used for groups in Project Settings |
| 45 |
* @param string|int $group_id the group id used for the group profile |
| 46 |
* @param array $props associative array of properties to set on the group profile |
| 47 |
* @param boolean $ignore_time If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the group profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time |
| 48 |
*/ |
| 49 |
public function setOnce($group_key, $group_id, $props, $ignore_time = \false) |
| 50 |
{ |
| 51 |
$payload = $this->_constructPayload($group_key, $group_id, '$set_once', $props, $ignore_time); |
| 52 |
$this->enqueue($payload); |
| 53 |
} |
| 54 |
/** |
| 55 |
* Unset properties on a group profile. If the group does not exist, it creates it with no properties. |
| 56 |
* If it does exist, it unsets these properties. NOTE: In other libraries we use 'unset' which is |
| 57 |
* a reserved word in PHP. |
| 58 |
* @param string|int $group_key the group_key used for groups in Project Settings |
| 59 |
* @param string|int $group_id the group id used for the group profile |
| 60 |
* @param array $props associative array of properties to unset on the group profile |
| 61 |
* @param boolean $ignore_time If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the group profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time |
| 62 |
*/ |
| 63 |
public function remove($group_key, $group_id, $props, $ignore_time = \false) |
| 64 |
{ |
| 65 |
$payload = $this->_constructPayload($group_key, $group_id, '$remove', $props, $ignore_time); |
| 66 |
$this->enqueue($payload); |
| 67 |
} |
| 68 |
/** |
| 69 |
* Adds $val to a list located at $prop. If the property does not exist, it will be created. If $val is a string |
| 70 |
* and the list is empty or does not exist, a new list with one value will be created. |
| 71 |
* @param string|int $group_key the group_key used for groups in Project Settings |
| 72 |
* @param string|int $group_id the group id used for the group profile |
| 73 |
* @param string $prop the property that holds the list |
| 74 |
* @param string|array $val items to add to the list |
| 75 |
* @param boolean $ignore_time If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the group profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time |
| 76 |
*/ |
| 77 |
public function union($group_key, $group_id, $prop, $val, $ignore_time = \false) |
| 78 |
{ |
| 79 |
$payload = $this->_constructPayload($group_key, $group_id, '$union', array("{$prop}" => $val), $ignore_time); |
| 80 |
$this->enqueue($payload); |
| 81 |
} |
| 82 |
/** |
| 83 |
* Delete this group profile from Mixpanel |
| 84 |
* @param string|int $group_key the group_key used for groups in Project Settings |
| 85 |
* @param string|int $group_id the group id used for the group profile |
| 86 |
* @param boolean $ignore_time If the $ignore_time property is true, Mixpanel will not automatically update the "Last Seen" property of the profile. Otherwise, Mixpanel will add a "Last Seen" property associated with the current time |
| 87 |
*/ |
| 88 |
public function deleteGroup($group_key, $group_id, $ignore_time = \false) |
| 89 |
{ |
| 90 |
$payload = $this->_constructPayload($group_key, $group_id, '$delete', "", $ignore_time); |
| 91 |
$this->enqueue($payload); |
| 92 |
} |
| 93 |
/** |
| 94 |
* Returns the "groups" endpoint |
| 95 |
* @return string |
| 96 |
*/ |
| 97 |
function _getEndpoint() |
| 98 |
{ |
| 99 |
return $this->_options['groups_endpoint']; |
| 100 |
} |
| 101 |
} |
| 102 |
|