PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0
Elementor Website Builder – more than just a page builder v4.3.0
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
elementor / vendor_prefixed / mixpanel / lib / Producers / MixpanelPeople.php

MixpanelPeople.php in Elementor Website Builder – more than just a page builder 4.3.0, at vendor_prefixed/mixpanel/lib/Producers/MixpanelPeople.php

160 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ElementorDeps;
4
5 require_once \dirname(__FILE__) . "/MixpanelBaseProducer.php";
6 /**
7 * Provides an API to create/update profiles on Mixpanel
8 */
9 class Producers_MixpanelPeople extends Producers_MixpanelBaseProducer
10 {
11 /**
12 * Internal method to prepare a message given the message data
13 * @param $distinct_id
14 * @param $operation
15 * @param $value
16 * @param null $ip
17 * @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
18 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
19 * @return array
20 */
21 private function _constructPayload($distinct_id, $operation, $value, $ip = null, $ignore_time = \false, $ignore_alias = \false)
22 {
23 $payload = array('$token' => $this->_token, '$distinct_id' => $distinct_id, '$time' => \microtime(\true), $operation => $value);
24 if ($ip !== null) {
25 $payload['$ip'] = $ip;
26 }
27 if ($ignore_time === \true) {
28 $payload['$ignore_time'] = \true;
29 }
30 if ($ignore_alias === \true) {
31 $payload['$ignore_alias'] = \true;
32 }
33 return $payload;
34 }
35 /**
36 * Set properties on a user record. If the profile does not exist, it creates it with these properties.
37 * If it does exist, it sets the properties to these values, overwriting existing values.
38 * @param string|int $distinct_id the distinct_id or alias of a user
39 * @param array $props associative array of properties to set on the profile
40 * @param string|null $ip the ip address of the client (used for geo-location)
41 * @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
42 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
43 */
44 public function set($distinct_id, $props, $ip = null, $ignore_time = \false, $ignore_alias = \false)
45 {
46 $payload = $this->_constructPayload($distinct_id, '$set', $props, $ip, $ignore_time, $ignore_alias);
47 $this->enqueue($payload);
48 }
49 /**
50 * Set properties on a user record. If the profile does not exist, it creates it with these properties.
51 * If it does exist, it sets the properties to these values but WILL NOT overwrite existing values.
52 * @param string|int $distinct_id the distinct_id or alias of a user
53 * @param array $props associative array of properties to set on the profile
54 * @param string|null $ip the ip address of the client (used for geo-location)
55 * @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
56 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
57 */
58 public function setOnce($distinct_id, $props, $ip = null, $ignore_time = \false, $ignore_alias = \false)
59 {
60 $payload = $this->_constructPayload($distinct_id, '$set_once', $props, $ip, $ignore_time, $ignore_alias);
61 $this->enqueue($payload);
62 }
63 /**
64 * Unset properties on a user record. If the profile does not exist, it creates it with no properties.
65 * If it does exist, it unsets these properties. NOTE: In other libraries we use 'unset' which is
66 * a reserved word in PHP.
67 * @param string|int $distinct_id the distinct_id or alias of a user
68 * @param array $props associative array of properties to unset on the profile
69 * @param string|null $ip the ip address of the client (used for geo-location)
70 * @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
71 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
72 */
73 public function remove($distinct_id, $props, $ip = null, $ignore_time = \false, $ignore_alias = \false)
74 {
75 $payload = $this->_constructPayload($distinct_id, '$unset', $props, $ip, $ignore_time, $ignore_alias);
76 $this->enqueue($payload);
77 }
78 /**
79 * Increments the value of a property on a user record. If the profile does not exist, it creates it and sets the
80 * property to the increment value.
81 * @param string|int $distinct_id the distinct_id or alias of a user
82 * @param $prop string the property to increment
83 * @param int $val the amount to increment the property by
84 * @param string|null $ip the ip address of the client (used for geo-location)
85 * @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
86 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
87 */
88 public function increment($distinct_id, $prop, $val, $ip = null, $ignore_time = \false, $ignore_alias = \false)
89 {
90 $payload = $this->_constructPayload($distinct_id, '$add', array("{$prop}" => $val), $ip, $ignore_time, $ignore_alias);
91 $this->enqueue($payload);
92 }
93 /**
94 * Adds $val to a list located at $prop. If the property does not exist, it will be created. If $val is a string
95 * and the list is empty or does not exist, a new list with one value will be created.
96 * @param string|int $distinct_id the distinct_id or alias of a user
97 * @param string $prop the property that holds the list
98 * @param string|array $val items to add to the list
99 * @param string|null $ip the ip address of the client (used for geo-location)
100 * @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
101 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
102 */
103 public function append($distinct_id, $prop, $val, $ip = null, $ignore_time = \false, $ignore_alias = \false)
104 {
105 $operation = \gettype($val) == "array" ? '$union' : '$append';
106 $payload = $this->_constructPayload($distinct_id, $operation, array("{$prop}" => $val), $ip, $ignore_time, $ignore_alias);
107 $this->enqueue($payload);
108 }
109 /**
110 * Adds a transaction to the user's profile for revenue tracking
111 * @param string|int $distinct_id the distinct_id or alias of a user
112 * @param string $amount the transaction amount e.g. "20.50"
113 * @param null $timestamp the timestamp of when the transaction occurred (default to current timestamp)
114 * @param string|null $ip the ip address of the client (used for geo-location)
115 * @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
116 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
117 */
118 public function trackCharge($distinct_id, $amount, $timestamp = null, $ip = null, $ignore_time = \false, $ignore_alias = \false)
119 {
120 $timestamp = $timestamp == null ? \time() : $timestamp;
121 $date_iso = \date("c", $timestamp);
122 $transaction = array('$time' => $date_iso, '$amount' => $amount);
123 $val = array('$transactions' => $transaction);
124 $payload = $this->_constructPayload($distinct_id, '$append', $val, $ip, $ignore_time, $ignore_alias);
125 $this->enqueue($payload);
126 }
127 /**
128 * Clear all transactions stored on a user's profile
129 * @param string|int $distinct_id the distinct_id or alias of a user
130 * @param string|null $ip the ip address of the client (used for geo-location)
131 * @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
132 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
133 */
134 public function clearCharges($distinct_id, $ip = null, $ignore_time = \false, $ignore_alias = \false)
135 {
136 $payload = $this->_constructPayload($distinct_id, '$set', array('$transactions' => array()), $ip, $ignore_time, $ignore_alias);
137 $this->enqueue($payload);
138 }
139 /**
140 * Delete this profile from Mixpanel
141 * @param string|int $distinct_id the distinct_id or alias of a user
142 * @param string|null $ip the ip address of the client (used for geo-location)
143 * @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
144 * @param boolean $ignore_alias If the $ignore_alias property is true, an alias look up will not be performed after ingestion. Otherwise, a lookup for the distinct ID will be performed, and replaced if a match is found
145 */
146 public function deleteUser($distinct_id, $ip = null, $ignore_time = \false, $ignore_alias = \false)
147 {
148 $payload = $this->_constructPayload($distinct_id, '$delete', "", $ip, $ignore_time, $ignore_alias);
149 $this->enqueue($payload);
150 }
151 /**
152 * Returns the "engage" endpoint
153 * @return string
154 */
155 function _getEndpoint()
156 {
157 return $this->_options['people_endpoint'];
158 }
159 }
160