PluginProbe ʕ •ᴥ•ʔ
PixelYourSite – Your smart PIXEL (TAG) & API Manager / 9.7.2
PixelYourSite – Your smart PIXEL (TAG) & API Manager v9.7.2
11.2.0.6 trunk 1.0 1.01 1.02 1.03 1.04 1.05 1.05.1 10.0.0 10.0.1 10.0.1.1 10.0.1.2 10.0.2 10.0.3 10.0.3.1 10.0.4 10.1.0 10.1.1 10.1.1.1 10.1.1.2 10.1.2.1 10.1.3 10.2.0 10.2.0.1 10.2.0.2 10.2.1 11.0.0 11.0.0.1 11.0.0.2 11.0.0.3 11.0.0.4 11.0.1 11.0.1.1 11.0.1.2 11.0.2 11.1.0 11.1.1 11.1.2 11.1.3 11.1.4 11.1.4.1 11.1.4.2 11.1.5 11.1.5.1 11.1.5.2 11.2.0 11.2.0.1 11.2.0.2 11.2.0.3 11.2.0.4 11.2.0.5 2.0 2.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.7 2.8.10 2.8.9 3.0 3.0.1 3.0.2 3.0.3 3.1.0 4.0.0 4.0.1 4.0.2 4.0.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5.2 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.2.0 5.2.1 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 7.0.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1.0 7.1.1 7.1.10 7.1.11 7.1.12 7.1.13 7.1.14 7.1.2 7.1.3 7.1.4 7.1.5 7.1.6 7.1.7 7.1.8 7.1.9 7.2.0 7.2.1 7.2.1.1 7.3.0 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.0.9 8.1.0 8.1.1 8.2.0 8.2.1 8.2.10 8.2.11 8.2.12 8.2.13 8.2.14 8.2.15 8.2.16 8.2.17 8.2.18 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.2.7 8.2.8 9.0.0 9.1.0 9.1.1 9.2.0 9.2.1 9.2.2 9.3.0 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.3.6 9.3.7 9.3.8 9.3.8.1 9.3.9 9.4.0 9.4.0.1 9.4.1 9.4.2 9.4.3 9.4.5 9.4.5.1 9.4.6 9.4.7 9.4.7.1 9.5.0 9.5.0.1 9.5.1 9.5.1.1 9.5.3 9.5.4 9.5.5 9.6.0 9.6.0.1 9.6.1 9.6.1.1 9.6.2 9.7.0 9.7.0.1 9.7.1 9.7.2
pixelyoursite / includes / class-custom-event.php
pixelyoursite / includes Last commit date
enrich 1 year ago events 1 year ago formEvents 1 year ago logger 1 year ago views 1 year ago class-custom-event-factory.php 7 years ago class-custom-event.php 1 year ago class-event-id-generator.php 5 years ago class-events-manager-ajax_hook.php 1 year ago class-events-manager.php 1 year ago class-fixed-notices.php 1 year ago class-pixel.php 7 years ago class-plugin-updater.php 1 year ago class-plugin.php 7 years ago class-pys.php 1 year ago class-settings.php 1 year ago functions-admin.php 1 year ago functions-common.php 1 year ago functions-custom-event.php 1 year ago functions-edd.php 1 year ago functions-gdpr.php 1 year ago functions-license.php 1 year ago functions-migrate.php 1 year ago functions-optin.php 1 year ago functions-promo-notices.php 1 year ago functions-system-report.php 7 years ago functions-update-plugin.php 6 years ago functions-woo.php 1 year ago options_defaults.json 1 year ago options_fields.json 1 year ago
class-custom-event.php
755 lines
1 <?php
2
3 namespace PixelYourSite;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 /**
10 * @property int post_id
11 * @property string title
12 * @property bool enabled
13 *
14 * @property int delay
15 * @property array triggers
16 * @property string trigger_type
17 *
18 * @property bool facebook_enabled
19 * @property string facebook_event_type
20 * @property string facebook_custom_event_type
21 * @property bool facebook_params_enabled
22 * @property array facebook_params
23 * @property array facebook_custom_params
24 *
25 * @property bool pinterest_enabled
26 * @property string pinterest_event_type
27 * @property string pinterest_custom_event_type
28 * @property bool pinterest_params_enabled
29 * @property array pinterest_custom_params
30 * @property array ga_custom_params
31 * @property array ga_params
32 *
33 * @property bool ga_enabled
34 * @property string ga_event_action
35 * @property string ga_custom_event_action
36 * @property string ga_event_category
37 * @property string ga_event_label
38 * @property string ga_event_value
39 *
40 * @property bool ga_ads_enabled
41 * @property string ga_ads_pixel_id
42 * @property string ga_ads_event_action
43 * @property string ga_ads_custom_event_action
44 * @property array ga_ads_custom_params
45 * @property array ga_ads_params
46 * @property string ga_ads_version
47 * @property string ga_ads_event_category
48 * @property string ga_ads_event_label
49 *
50 *
51 * @property bool bing_enabled
52 * @property string bing_event_action
53 * @property string bing_event_category
54 * @property string bing_event_label
55 * @property string bing_event_value
56 */
57 class CustomEvent {
58
59 private $post_id;
60
61 private $title = 'Untitled';
62
63 private $enabled = true;
64
65 public $GAEvents = array(
66 "" => array("CustomEvent"=>array()),
67 "All Properties" => array(
68 "earn_virtual_currency" => array("virtual_currency_name","value"),
69 "join_group" => array("group_id"),
70 "login" => array("method"),
71 "purchase" => array("transaction_id",'value','currency','tax','shipping','items','coupon'),
72 "refund" => array("transaction_id",'value','currency','tax','shipping','items'),
73 "search" => array("search_term"),
74 "select_content" => array("content_type",'item_id'),
75 "share" => array("content_type",'item_id'),
76 "sign_up" => array("method"),
77 "spend_virtual_currency" => array("item_name",'virtual_currency_name','value'),
78 "tutorial_begin" => array(),
79 "tutorial_complete" => array(),
80 ),
81 "Retail/Ecommerce" => array(
82 'add_payment_info' => array('coupon','currency','items','payment_type','value'),
83 'add_shipping_info' => array('coupon','currency','items','shipping_tier','value'),
84 'add_to_cart' => array('currency', 'items', 'value'),
85 'add_to_wishlist' => array('currency', 'items', 'value'),
86 'begin_checkout' => array('coupon','currency', 'items', 'value'),
87 'generate_lead' => array('value', 'currency'),
88 'purchase' => array('affiliation', 'coupon', 'currency', 'items', 'transaction_id', 'shipping', 'tax', 'value'),
89 'refund' => array('affiliation', 'coupon', 'currency', 'items', 'transaction_id', 'shipping', 'tax', 'value'),
90 'remove_from_cart' => array('currency', 'items', 'value'),
91 'select_item' => array('items', 'item_list_name', 'item_list_id'),
92 'select_promotion' => array('items', 'promotion_id', 'promotion_name', 'creative_name', 'creative_slot', 'location_id'),
93 'view_cart' => array('currency', 'items', 'value'),
94 'view_item' => array('currency', 'items', 'value'),
95 'view_item_list' => array('items', 'item_list_name', 'item_list_id'),
96 'view_promotion' => array('items', 'promotion_id', 'promotion_name', 'creative_name', 'creative_slot', 'location_id')
97 ),
98 "Jobs, Education, Local Deals, Real Estate" => array(
99 'add_payment_info' => array("coupon", 'currency', 'items', 'payment_type', 'value'),
100 'add_shipping_info' => array('coupon', 'currency', 'items', 'shipping_tier', 'value'),
101 'add_to_cart' => array('currency', 'items', 'value'),
102 'add_to_wishlist' => array('currency', 'items', 'value'),
103 'begin_checkout' => array('coupon','currency', 'items', 'value'),
104 'purchase' => array('affiliation', 'coupon', 'currency', 'items', 'transaction_id', 'shipping', 'tax', 'value'),
105 'refund' => array('affiliation', 'coupon', 'currency', 'items', 'transaction_id', 'shipping', 'tax', 'value'),
106 'remove_from_cart' => array('currency', 'items', 'value'),
107 'select_item' => array('items', 'item_list_name', 'item_list_id'),
108 'select_promotion' => array('items', 'promotion_id', 'promotion_name', 'creative_name', 'creative_slot', 'location_id'),
109 'view_cart' => array('currency', 'items', 'value'),
110 'view_item' => array('currency', 'items', 'value'),
111 'view_item_list' => array('items', 'item_list_name', 'item_list_id'),
112 'view_promotion' => array('items', 'promotion_id', 'promotion_name', 'creative_name', 'creative_slot', 'location_id')
113 ),
114 "Travel (Hotel/Air)" => array(
115 'add_payment_info' => array("coupon", 'currency', 'items', 'payment_type', 'value'),
116 'add_shipping_info' => array('coupon', 'currency', 'items', 'shipping_tier', 'value'),
117 'add_to_cart' => array('currency', 'items', 'value'),
118 'add_to_wishlist' => array('currency', 'items', 'value'),
119 'begin_checkout' => array('coupon','currency', 'items', 'value'),
120 'generate_lead' => array('value', 'currency'),
121 'purchase' => array('affiliation', 'coupon', 'currency', 'items', 'transaction_id', 'shipping', 'tax', 'value'),
122 'refund' => array('affiliation', 'coupon', 'currency', 'items', 'transaction_id', 'shipping', 'tax', 'value'),
123 'remove_from_cart' => array('currency', 'items', 'value'),
124 'select_item' => array('items', 'item_list_name', 'item_list_id'),
125 'select_promotion' => array('items', 'promotion_id', 'promotion_name', 'creative_name', 'creative_slot', 'location_id'),
126 'view_cart' => array('currency', 'items', 'value'),
127 'view_item' => array('currency', 'items', 'value'),
128 'view_item_list' => array('items', 'item_list_name', 'item_list_id'),
129 'view_promotion' => array('items', 'promotion_id', 'promotion_name', 'creative_name', 'creative_slot', 'location_id')
130 ),
131 "Games" => array(
132 'earn_virtual_currency' => array('virtual_currency_name', 'value'),
133 'join_group' => array('group_id'),
134 'level_end' => array('level_name', 'success'),
135 'level_start' => array('level_name'),
136 'level_up' => array('character', 'level'),
137 'post_score' => array('level', 'character', 'score'),
138 'select_content' => array('content_type', 'item_id'),
139 'spend_virtual_currency' => array('item_name', 'virtual_currency_name', 'value'),
140 'tutorial_begin' => array(),
141 'tutorial_complete' => array(),
142 'unlock_achievement' => array('achievement_id'),
143 )
144 );
145
146 private $data = array(
147 'delay' => null,
148 'trigger_type' => 'page_visit',
149 'triggers' => array(),
150
151 'facebook_enabled' => false,
152 'facebook_event_type' => 'ViewContent',
153 'facebook_custom_event_type' => null,
154 'facebook_params_enabled' => false,
155 'facebook_params' => array(),
156 'facebook_custom_params' => array(),
157
158 'pinterest_enabled' => false,
159 'pinterest_event_type' => 'ViewContent',
160 'pinterest_custom_event_type' => null,
161 'pinterest_params_enabled' => false,
162 'pinterest_custom_params' => array(),
163
164 'ga_enabled' => false,
165 'ga_event_action' => '_custom',
166 'ga_custom_event_action' => null,
167 'ga_event_category' => null,
168 'ga_event_label' => null,
169 'ga_event_value' => null,
170
171 //ver 4
172 'ga_params' => array(),
173 'ga_custom_params' => array(),
174 'ga_custom_params_enabled' => false,
175
176 'ga_ads_enabled' => false,
177 'ga_ads_event_action' => '_custom',
178 'ga_ads_custom_event_action' => null,
179 //ver 4
180 'ga_ads_params' => array(),
181 'ga_ads_custom_params' => array(),
182 'ga_ads_custom_params_enabled' => false,
183
184
185 'bing_enabled' => false,
186 'bing_event_action' => null,
187 'bing_event_category' => null,
188 'bing_event_label' => null,
189 'bing_event_value' => null,
190 );
191
192 public function __construct( $post_id = null ) {
193 $this->initialize( $post_id );
194 }
195
196 public function __get( $key ) {
197
198 if ( $key == 'post_id' ) {
199 return $this->post_id;
200 }
201
202 if ( $key == 'title' ) {
203 return $this->title;
204 }
205
206 if ( $key == 'enabled' ) {
207 return $this->enabled;
208 }
209
210 if ( isset( $this->data[ $key ] ) ) {
211 return $this->data[ $key ];
212 } else {
213 return null;
214 }
215
216 }
217
218 private function initialize( $post_id ) {
219
220 if ( $post_id ) {
221
222 $this->post_id = $post_id;
223 $this->title = get_the_title( $post_id );
224
225 $data = get_post_meta( $post_id, '_pys_event_data', true );
226 $this->data = is_array( $data ) ? $data : array();
227
228 $state = get_post_meta( $post_id, '_pys_event_state', true );
229 $this->enabled = $state == 'active' ? true : false;
230
231
232 if(count(GA()->getPixelIDs()) == 0) {
233 $this->data['ga_enabled'] = false;
234 $this->clearGa();
235 }
236
237 }
238
239 }
240
241 public function update( $args = null ) {
242
243 if ( ! is_array( $args ) ) {
244 $args = $this->data;
245 }
246
247 /**
248 * GENERAL
249 */
250
251 // title
252 wp_update_post( array(
253 'ID' => $this->post_id,
254 'post_title' => empty( $args['title'] ) ? $this->title : sanitize_text_field( $args['title'] )
255 ) );
256
257 // state
258 $state = isset( $args['enabled'] ) && $args['enabled'] ? 'active' : 'paused';
259 $this->enabled = $state == 'active' ? true : false;
260 update_post_meta( $this->post_id, '_pys_event_state', $state );
261
262 // trigger type
263 $this->data['trigger_type'] = 'page_visit';
264
265 // delay
266 $this->data['delay'] = isset( $args['delay'] ) && $args['delay'] ? (int) $args['delay'] : null;
267
268 /**
269 * TRIGGERS
270 */
271
272 // reset old triggers
273 $this->data['triggers'] = array();
274
275 // page visit triggers
276 if ( $this->trigger_type == 'page_visit' && isset( $args['page_visit_triggers'] )
277 && is_array( $args['page_visit_triggers'] ) ) {
278
279 foreach ( $args['page_visit_triggers'] as $trigger ) {
280
281 if ( ! empty( $trigger['value'] ) ) {
282
283 $this->data['triggers'][] = array(
284 'rule' => $trigger['rule'] == 'contains' ? 'contains' : 'match',
285 'value' => $trigger['value'],
286 );
287
288 }
289
290 }
291
292 }
293
294 // reset old url filters
295 $this->data['url_filters'] = array();
296
297 /**
298 * FACEBOOK
299 */
300
301 $facebook_event_types = array(
302 'ViewContent',
303 'AddToCart',
304 'AddToWishlist',
305 'InitiateCheckout',
306 'AddPaymentInfo',
307 'Purchase',
308 'Lead',
309 'CompleteRegistration',
310
311 'Subscribe',
312 'CustomizeProduct',
313 'FindLocation',
314 'StartTrial',
315 'SubmitApplication',
316 'Schedule',
317 'Contact',
318 'Donate',
319
320 'CustomEvent'
321 );
322
323 // enabled
324 $this->data['facebook_enabled'] = isset( $args['facebook_enabled'] ) && $args['facebook_enabled'] ? true : false;
325
326 // event type
327 $this->data['facebook_event_type'] = isset( $args['facebook_event_type'] ) && in_array( $args['facebook_event_type'], $facebook_event_types )
328 ? sanitize_text_field( $args['facebook_event_type'] )
329 : 'ViewContent';
330
331 // custom event type
332 $this->data['facebook_custom_event_type'] = $this->facebook_event_type == 'CustomEvent' && ! empty( $args['facebook_custom_event_type'] )
333 ? sanitizeKey( $args['facebook_custom_event_type'] )
334 : null;
335
336 // params enabled
337 $this->data['facebook_params_enabled'] = isset( $args['facebook_params_enabled'] ) && $args['facebook_params_enabled'] ? true : false;
338
339 // params
340 if ( $this->facebook_params_enabled && isset( $args['facebook_params'] ) && $this->facebook_event_type !== 'CustomEvent' ) {
341
342 $this->data['facebook_params'] = array(
343 'value' => ! empty( $args['facebook_params']['value'] ) ? sanitize_text_field( $args['facebook_params']['value'] ) : null,
344 'currency' => ! empty( $args['facebook_params']['currency'] ) ? sanitize_text_field( $args['facebook_params']['currency'] ) : null,
345 'content_name' => ! empty( $args['facebook_params']['content_name'] ) ? sanitize_text_field( $args['facebook_params']['content_name'] ) : null,
346 'content_ids' => ! empty( $args['facebook_params']['content_ids'] ) ? sanitize_text_field( $args['facebook_params']['content_ids'] ) : null,
347 'content_type' => ! empty( $args['facebook_params']['content_type'] ) ? sanitize_text_field( $args['facebook_params']['content_type'] ) : null,
348 'content_category' => ! empty( $args['facebook_params']['content_category'] ) ? sanitize_text_field( $args['facebook_params']['content_category'] ) : null,
349 'num_items' => ! empty( $args['facebook_params']['num_items'] ) ? (int) $args['facebook_params']['num_items'] : null,
350 'order_id' => ! empty( $args['facebook_params']['order_id'] ) ? sanitize_text_field( $args['facebook_params']['order_id'] ) : null,
351 'search_string' => ! empty( $args['facebook_params']['search_string'] ) ? sanitize_text_field( $args['facebook_params']['search_string'] ) : null,
352 'status' => ! empty( $args['facebook_params']['status'] ) ? sanitize_text_field( $args['facebook_params']['status'] ) : null,
353 'predicted_ltv' => ! empty( $args['facebook_params']['predicted_ltv'] ) ? sanitize_text_field( $args['facebook_params']['predicted_ltv'] ) : null,
354 );
355
356 // custom currency
357 if ( $this->data['facebook_params']['currency'] == 'custom' && ! empty( $args['facebook_params']['custom_currency'] )) {
358 $this->data['facebook_params']['custom_currency'] = sanitize_text_field( $args['facebook_params']['custom_currency'] );
359 } else {
360 $this->data['facebook_params']['custom_currency'] = null;
361 }
362
363 } else {
364
365 $this->data['facebook_params'] = array(
366 'value' => null,
367 'currency' => null,
368 'custom_currency' => null,
369 'content_name' => null,
370 'content_ids' => null,
371 'content_type' => null,
372 'content_category' => null,
373 'num_items' => null,
374 'order_id' => null,
375 'search_string' => null,
376 'status' => null,
377 'predicted_ltv' => null,
378 );
379
380 }
381
382 // reset old custom params
383 $this->data['facebook_custom_params'] = array();
384
385 // custom params
386 if ( $this->facebook_params_enabled && isset( $args['facebook_custom_params'] ) ) {
387
388 foreach ( $args['facebook_custom_params'] as $custom_param ) {
389
390 if ( ! empty( $custom_param['name'] ) && ! empty( $custom_param['value'] ) ) {
391
392 $this->data['facebook_custom_params'][] = array(
393 'name' => sanitize_text_field( $custom_param['name'] ),
394 'value' => sanitize_text_field( $custom_param['value'] ),
395 );
396
397 }
398
399 }
400
401 }
402
403 /**
404 * PINTEREST
405 */
406
407 $pinterest_event_types = array(
408 'pagevisit',
409 'viewcategory',
410 'search',
411 'addtocart',
412 'checkout',
413 'watchvideo',
414 'signup',
415 'lead',
416 'custom',
417 'CustomEvent',
418 );
419
420 // enabled
421 $this->data['pinterest_enabled'] = isset( $args['pinterest_enabled'] ) && $args['pinterest_enabled'] ? true
422 : false;
423
424 // event type
425 $this->data['pinterest_event_type'] = isset( $args['pinterest_event_type'] ) && in_array( $args['pinterest_event_type'],
426 $pinterest_event_types )
427 ? sanitize_text_field( $args['pinterest_event_type'] )
428 : 'pagevisit';
429
430 // custom event type
431 $this->data['pinterest_custom_event_type'] = $this->pinterest_event_type == 'CustomEvent' && ! empty( $args['pinterest_custom_event_type'] )
432 ? sanitizeKey( $args['pinterest_custom_event_type'] )
433 : null;
434
435 // params enabled
436 $this->data['pinterest_params_enabled'] = isset( $args['pinterest_params_enabled'] ) && $args['pinterest_params_enabled']
437 ? true : false;
438
439 // reset old custom params
440 $this->data['pinterest_custom_params'] = array();
441
442 // custom params
443 if ( $this->pinterest_params_enabled && isset( $args['pinterest_custom_params'] ) ) {
444
445 foreach ( $args['pinterest_custom_params'] as $custom_param ) {
446
447 if ( ! empty( $custom_param['name'] ) && ! empty( $custom_param['value'] ) ) {
448
449 $this->data['pinterest_custom_params'][] = array(
450 'name' => sanitize_text_field( $custom_param['name'] ),
451 'value' => sanitize_text_field( $custom_param['value'] ),
452 );
453
454 }
455
456 }
457
458 }
459
460 /**
461 * GOOGLE ANALYTICS
462 */
463 $this->updateGA($args);
464
465 /**
466 * BING
467 */
468
469 $this->data['bing_enabled'] = isset($args['bing_enabled']) && $args['bing_enabled'] ? true : false;
470 $this->data['bing_event_action'] = !empty($args['bing_event_action']) ? sanitize_text_field($args['bing_event_action']) : null;
471 $this->data['bing_event_category'] = !empty($args['bing_event_category']) ? sanitize_text_field($args['bing_event_category']) : null;
472 $this->data['bing_event_label'] = !empty($args['bing_event_label']) ? sanitize_text_field($args['bing_event_label']) : null;
473 $this->data['bing_event_value'] = !empty($args['bing_event_value']) ? sanitize_text_field($args['bing_event_value']) : null;
474
475 update_post_meta( $this->post_id, '_pys_event_data', $this->data );
476
477 }
478
479 public function enable() {
480
481 $this->enabled = true;
482 update_post_meta( $this->post_id, '_pys_event_state', 'active' );
483
484 }
485
486 public function disable() {
487
488 $this->enabled = false;
489 update_post_meta( $this->post_id, '_pys_event_state', 'paused' );
490
491 }
492
493 /**
494 * @return int
495 */
496 public function getPostId() {
497 return $this->post_id;
498 }
499
500 /**
501 * @return string
502 */
503 public function getTitle() {
504 return $this->title;
505 }
506
507 public function isEnabled() {
508 return $this->enabled;
509 }
510
511 public function getTriggerType() {
512 return $this->trigger_type;
513 }
514
515 public function getDelay() {
516 return $this->delay;
517 }
518
519 /**
520 * @return array
521 */
522 public function getPageVisitTriggers() {
523 return $this->trigger_type == 'page_visit' ? $this->triggers : array();
524 }
525
526 public function isFacebookEnabled() {
527 return (bool) $this->facebook_enabled;
528 }
529
530 public function getFacebookEventType() {
531 return $this->facebook_event_type == 'CustomEvent' ? $this->facebook_custom_event_type : $this->facebook_event_type;
532 }
533
534 public function isFacebookParamsEnabled() {
535 return (bool) $this->facebook_params_enabled;
536 }
537
538 public function getFacebookParam( $key ) {
539 return isset( $this->facebook_params[ $key ] ) ? $this->facebook_params[ $key ] : null;
540 }
541
542 public function getFacebookParams() {
543 return $this->facebook_params_enabled ? $this->facebook_params : array();
544 }
545
546 public function getFacebookCustomParams() {
547 return $this->facebook_params_enabled ? $this->facebook_custom_params : array();
548 }
549
550 public function isPinterestEnabled() {
551 return (bool) $this->pinterest_enabled;
552 }
553
554 public function getPinterestEventType() {
555 return $this->pinterest_event_type == 'CustomEvent'
556 ? $this->pinterest_custom_event_type
557 : $this->pinterest_event_type;
558 }
559
560 public function isPinterestParamsEnabled() {
561 return (bool) $this->pinterest_params_enabled;
562 }
563
564 public function getPinterestCustomParams() {
565 return $this->pinterest_params_enabled ? $this->pinterest_custom_params : array();
566 }
567
568 public function isGoogleAnalyticsEnabled() {
569 return (bool) $this->ga_enabled;
570 }
571 public function isUnifyAnalyticsEnabled(){
572 return (bool) $this->ga_ads_enabled;
573 }
574 public function getMergedGaParams() {
575 if(is_array($this->ga_ads_params)) {
576 return $this->ga_ads_params;
577 } else {
578 return [];
579 }
580 }
581 public function getGoogleAnalyticsAction() {
582 return $this->ga_event_action == '_custom' ||
583 $this->ga_event_action == 'CustomEvent' ? $this->ga_custom_event_action : $this->ga_event_action;
584 }
585 public function getMergedAction(){
586 return $this->ga_ads_event_action == '_custom' || $this->ga_ads_event_action == 'CustomEvent' ? $this->ga_ads_custom_event_action : $this->ga_ads_event_action;
587 }
588 public function isBingEnabled() {
589 return (bool) $this->bing_enabled;
590 }
591 public function isGaV4() {
592 $all = GA()->getPixelIDs();
593 if(count($all) == 0) {
594 return false;
595 }
596 return strpos($all[0], 'G') === 0;
597 }
598 private function clearGa() {
599 $this->data['ga_params'] = array();
600 $this->data['ga_custom_params'] = array();
601 $this->data['ga_event_action'] = 'CustomEvent';
602 $this->data['ga_custom_event_action']=null;
603 // old
604 $this->data['ga_event_category'] = null;
605 $this->data['ga_event_label'] = null;
606 $this->data['ga_event_value'] = null;
607 }
608 function migrateUnifyGA() {
609 $all = GA()->getPixelIDs();
610 $this->data['ga_ads_enabled'] = $this->isGoogleAnalyticsEnabled();
611 $pixel_ids = GA()->getPixelIDs();
612
613 if(!empty($this->data['ga_ads_pixel_id'])){ return; }
614 $this->data['ga_ads_pixel_id'] = array_map(function($pixelId) use ($all) {
615 if (in_array($pixelId, $all) || $pixelId == 'all') {
616 return $pixelId;
617 } else {
618 return '';
619 }
620 }, $pixel_ids);
621
622 $this->data['ga_ads_pixel_id'] = array_filter($this->data['ga_ads_pixel_id']);
623
624 $this->data['ga_ads_event_action'] = $this->ga_event_action;
625 $this->data['ga_ads_custom_event_action'] = $this->ga_event_action == '_custom' || $this->ga_event_action == 'CustomEvent' ? $this->ga_custom_event_action : '';
626 $this->data['ga_ads_params'] = $this->getGaParams();
627 $this->data['ga_ads_custom_params'] = $this->getGACustomParams();
628
629 $outputArray = [];
630
631 foreach ($this->data['ga_ads_custom_params'] as $item) {
632 $key = $item["name"];
633 if (!isset($outputArray[$key])) {
634 $outputArray[$key] = $item;
635 }
636 }
637 $this->data['ga_ads_custom_params'] = array_values($outputArray);
638 update_post_meta( $this->post_id, '_pys_event_data', $this->data );
639 }
640 private function updateGA( $args) {
641
642 $all = GA()->getPixelIDs();
643
644 $this->data['ga_ads_enabled'] = count($all) > 0
645 && isset( $args['ga_ads_enabled'] )
646 && $args['ga_ads_enabled'];
647
648 if(!$this->data['ga_ads_enabled']) {
649 $this->clearGa();
650 } else {
651 if($this->isGaV4()) {
652
653 $this->data['ga_ads_event_action'] = isset( $args['ga_ads_event_action'] )
654 ? sanitize_text_field( $args['ga_ads_event_action'] )
655 : 'view_item';
656
657 $this->data['ga_ads_custom_event_action'] = $this->ga_ads_event_action == '_custom' || $this->ga_ads_event_action == 'CustomEvent' && !empty( $args['ga_ads_custom_event_action'] )
658 ? sanitizeKey( $args['ga_ads_custom_event_action'] )
659 : null;
660
661 $this->data['ga_ads_params'] = array();
662
663
664 foreach ($this->GAEvents as $group) {
665 foreach ($group as $name => $fields) {
666 if($name == $this->data['ga_ads_event_action']) {
667 foreach ($fields as $field) {
668 $this->data['ga_ads_params'][$field] = isset($args['ga_ads_params'][$field]) ? $args['ga_ads_params'][$field] : "";
669 }
670 break;
671 }
672 }
673 }
674
675 if ( isset( $args['ga_ads_params'] ) ) {
676 foreach ($args['ga_ads_params'] as $key => $val) {
677 $this->data['ga_ads_params'][$key] = sanitize_text_field( $val );
678 }
679 }
680
681 // reset old custom params
682 $this->data['ga_ads_custom_params'] = array();
683
684 // custom params
685 if ( isset( $args['ga_ads_custom_params'] ) ) {
686
687 foreach ( $args['ga_ads_custom_params'] as $custom_param ) {
688
689 if ( ! empty( $custom_param['name'] ) && ! empty( $custom_param['value'] ) ) {
690
691 $this->data['ga_ads_custom_params'][] = array(
692 'name' => sanitize_text_field( $custom_param['name'] ),
693 'value' => sanitize_text_field( $custom_param['value'] ),
694 );
695
696 }
697
698 }
699
700 }
701 }
702 }
703 }
704 public function getGAMergedCustomParams() {
705 if(is_array($this->ga_ads_custom_params)) {
706 return $this->ga_ads_custom_params;
707 }
708 return [];
709 }
710 public function getGACustomParams() {
711 if($this->isGaV4()) {
712 if(is_array($this->ga_custom_params)) {
713 return $this->ga_custom_params;
714 }
715 return [];
716 }
717 $custom = array();
718 if($this->ga_event_category) {
719 $custom[] = array('name'=>"event_category",'value' => $this->ga_event_category);
720 }
721 if($this->ga_event_value){
722 $custom[] = array('name'=>"value",'value' => $this->ga_event_value);
723 }
724 if($this->ga_event_label){
725 $custom[] = array('name'=>"event_label",'value' => $this->ga_event_label);
726 }
727
728 return $custom;
729 }
730
731 public function getGaParams() {
732 if($this->isGaV4())
733 if(is_array($this->ga_params)) {
734 return $this->ga_params;
735 } else {
736 return [];
737 }
738 $list = array();
739 foreach ($this->GAEvents as $group) {
740 foreach ($group as $name => $fields) {
741 if($name == $this->data['ga_event_action']) {
742 foreach ($fields as $field) {
743 $list[$field] = "";
744 }
745 }
746 }
747 }
748
749 return $list;
750 }
751
752
753
754
755 }