PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.2
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wp-media / wp-mixpanel / src / Classes / Producers / MixpanelPeople.php

MixpanelPeople.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.2, at vendor/wp-media/wp-mixpanel/src/Classes/Producers/MixpanelPeople.php

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