PixelYourSite – Facebook Pixel (Events, WooCommerce & Easy Digital Downloads) - Version 8.2.14

Version Description

Download this release

Release Info

Developer PixelYourSite
Plugin Icon 128x128 PixelYourSite – Facebook Pixel (Events, WooCommerce & Easy Digital Downloads)
Version 8.2.14
Comparing to
See all releases

Code changes from version 8.2.13 to 8.2.14

dist/scripts/public.js CHANGED
@@ -452,13 +452,13 @@ if (!Array.prototype.includes) {
452
 
453
  // fire event
454
  if ('facebook' === pixel) {
455
- fired = Facebook.fireEvent(eventName, eventData);
456
  } else if ('ga' === pixel) {
457
- fired = Analytics.fireEvent(eventName, eventData);
458
  } else if ('pinterest' === pixel) {
459
- fired = Pinterest.fireEvent(eventName, eventData);
460
  } else if ('bing' === pixel) {
461
- fired = Bing.fireEvent(eventName, eventData);
462
  }
463
 
464
  // prevent event double event firing
@@ -675,21 +675,33 @@ if (!Array.prototype.includes) {
675
  if(cs_cookie_val == 'yes') {
676
  if (categoryCookie === CS_Data.cs_script_cat.facebook) {
677
  Facebook.loadPixel();
678
- } else if (categoryCookie === CS_Data.cs_script_cat.bing) {
 
 
679
  Bing.loadPixel();
680
- } else if (categoryCookie === CS_Data.cs_script_cat.analytics) {
 
 
681
  Analytics.loadPixel();
682
- } else if (categoryCookie === CS_Data.cs_script_cat.pinterest) {
 
 
683
  Pinterest.loadPixel();
684
  }
685
  } else {
686
  if (categoryCookie === CS_Data.cs_script_cat.facebook) {
687
  Facebook.disable();
688
- } else if (categoryCookie === CS_Data.cs_script_cat.bing) {
 
 
689
  Bing.disable();
690
- } else if (categoryCookie === CS_Data.cs_script_cat.analytics) {
 
 
691
  Analytics.disable();
692
- } else if (categoryCookie === CS_Data.cs_script_cat.pinterest) {
 
 
693
  Pinterest.disable();
694
  }
695
  }
@@ -902,7 +914,7 @@ if (!Array.prototype.includes) {
902
  var isAddToCartFromJs = options.woo.hasOwnProperty("addToCartCatchMethod")
903
  && options.woo.addToCartCatchMethod === "add_cart_js";
904
 
905
- if(allData.name === "RemoveFromCart"
906
  || (isAddToCartFromJs && allData.e_id === "woo_add_to_cart_on_button_click"))
907
  {
908
  Facebook.updateEventId(allData.name);
@@ -1240,16 +1252,15 @@ if (!Array.prototype.includes) {
1240
  onTime: function (event) {
1241
  this.fireEvent(event.name, event);
1242
  },
1243
- initEventIdCookies: function () {
1244
- var ids = {
1245
- 'AddToCart':pys_generate_token(36)
1246
- };
1247
  Cookies.set('pys_fb_event_id', JSON.stringify(ids));
1248
  },
1249
  updateEventId:function(key) {
1250
  var cooData = Cookies.get("pys_fb_event_id")
1251
  if(data === undefined) {
1252
- this.initEventIdCookies();
1253
  } else {
1254
  var data = JSON.parse(cooData);
1255
  data[key] = pys_generate_token(36);
@@ -1260,7 +1271,7 @@ if (!Array.prototype.includes) {
1260
  getEventId:function (key) {
1261
  var data = Cookies.get("pys_fb_event_id");
1262
  if(data === undefined) {
1263
- this.initEventIdCookies();
1264
  data = Cookies.get("pys_fb_event_id");
1265
  }
1266
  return JSON.parse(data)[key];
@@ -1589,24 +1600,23 @@ if (!Array.prototype.includes) {
1589
  quantity = 0;
1590
  }
1591
  var childItem = window.pysWooProductData[product_id]['ga'].grouped[childId];
1592
-
1593
- if(options.woo.addToCartOnButtonValueEnabled &&
1594
- options.woo.addToCartOnButtonValueOption !== 'global') {
1595
-
1596
- event.params.items.forEach(function(el,index,array) {
1597
- if(el.id == childItem.content_id) {
1598
- if(quantity > 0){
1599
- el.quantity = quantity;
1600
- el.price = childItem.price * quantity;
1601
- } else {
1602
- array.splice(index, 1);
1603
- }
1604
  }
1605
- });
1606
-
1607
- }
1608
  groupValue += childItem.price * quantity;
1609
  });
 
 
 
 
 
1610
 
1611
  if(groupValue == 0) return; // skip if no items selected
1612
  } else {
@@ -1619,12 +1629,8 @@ if (!Array.prototype.includes) {
1619
  options.woo.addToCartOnButtonValueOption !== 'global' &&
1620
  product_type !== Utils.PRODUCT_GROUPED)
1621
  {
1622
- if(product_type === Utils.PRODUCT_BUNDLE) {
1623
- var data = $(".bundle_form .bundle_data").data("bundle_form_data");
1624
- var items_sum = getBundlePriceOnSingleProduct(data);
1625
- event.params.items[0].price = (parseInt(data.base_price) + items_sum )* qty;
1626
- } else {
1627
- event.params.items[0].price = event.params.items[0].price * qty;
1628
  }
1629
 
1630
  }
@@ -1700,6 +1706,20 @@ if (!Array.prototype.includes) {
1700
 
1701
  $(document).ready(function () {
1702
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1703
  var Pinterest = Utils.setupPinterestObject();
1704
  var Bing = Utils.setupBingObject();
1705
 
@@ -1843,7 +1863,8 @@ if (!Array.prototype.includes) {
1843
 
1844
  // Single Product
1845
  // tap try to https://stackoverflow.com/questions/30990967/on-tap-click-event-firing-twice-how-to-avoid-it
1846
- $(document).onFirst('click','button.single_add_to_cart_button,.single_add_to_cart_button',function (e) {
 
1847
 
1848
  var $button = $(this);
1849
 
452
 
453
  // fire event
454
  if ('facebook' === pixel) {
455
+ fired = Facebook.fireEvent(eventData.name, eventData);
456
  } else if ('ga' === pixel) {
457
+ fired = Analytics.fireEvent(eventData.name, eventData);
458
  } else if ('pinterest' === pixel) {
459
+ fired = Pinterest.fireEvent(eventData.name, eventData);
460
  } else if ('bing' === pixel) {
461
+ fired = Bing.fireEvent(eventData.name, eventData);
462
  }
463
 
464
  // prevent event double event firing
675
  if(cs_cookie_val == 'yes') {
676
  if (categoryCookie === CS_Data.cs_script_cat.facebook) {
677
  Facebook.loadPixel();
678
+ }
679
+
680
+ if (categoryCookie === CS_Data.cs_script_cat.bing) {
681
  Bing.loadPixel();
682
+ }
683
+
684
+ if (categoryCookie === CS_Data.cs_script_cat.analytics) {
685
  Analytics.loadPixel();
686
+ }
687
+
688
+ if (categoryCookie === CS_Data.cs_script_cat.pinterest) {
689
  Pinterest.loadPixel();
690
  }
691
  } else {
692
  if (categoryCookie === CS_Data.cs_script_cat.facebook) {
693
  Facebook.disable();
694
+ }
695
+
696
+ if (categoryCookie === CS_Data.cs_script_cat.bing) {
697
  Bing.disable();
698
+ }
699
+
700
+ if (categoryCookie === CS_Data.cs_script_cat.analytics) {
701
  Analytics.disable();
702
+ }
703
+
704
+ if (categoryCookie === CS_Data.cs_script_cat.pinterest) {
705
  Pinterest.disable();
706
  }
707
  }
914
  var isAddToCartFromJs = options.woo.hasOwnProperty("addToCartCatchMethod")
915
  && options.woo.addToCartCatchMethod === "add_cart_js";
916
 
917
+ if(allData.e_id === "woo_remove_from_cart"
918
  || (isAddToCartFromJs && allData.e_id === "woo_add_to_cart_on_button_click"))
919
  {
920
  Facebook.updateEventId(allData.name);
1252
  onTime: function (event) {
1253
  this.fireEvent(event.name, event);
1254
  },
1255
+ initEventIdCookies: function (key) {
1256
+ var ids = {};
1257
+ ids[key] = pys_generate_token(36)
 
1258
  Cookies.set('pys_fb_event_id', JSON.stringify(ids));
1259
  },
1260
  updateEventId:function(key) {
1261
  var cooData = Cookies.get("pys_fb_event_id")
1262
  if(data === undefined) {
1263
+ this.initEventIdCookies(key);
1264
  } else {
1265
  var data = JSON.parse(cooData);
1266
  data[key] = pys_generate_token(36);
1271
  getEventId:function (key) {
1272
  var data = Cookies.get("pys_fb_event_id");
1273
  if(data === undefined) {
1274
+ this.initEventIdCookies(key);
1275
  data = Cookies.get("pys_fb_event_id");
1276
  }
1277
  return JSON.parse(data)[key];
1600
  quantity = 0;
1601
  }
1602
  var childItem = window.pysWooProductData[product_id]['ga'].grouped[childId];
1603
+ // update quantity
1604
+ event.params.items.forEach(function(el,index,array) {
1605
+ if(el.id == childItem.content_id) {
1606
+ if(quantity > 0){
1607
+ el.quantity = quantity;
1608
+ } else {
1609
+ array.splice(index, 1);
 
 
 
 
 
1610
  }
1611
+ }
1612
+ });
 
1613
  groupValue += childItem.price * quantity;
1614
  });
1615
+ if(options.woo.addToCartOnButtonValueEnabled &&
1616
+ options.woo.addToCartOnButtonValueOption !== 'global' &&
1617
+ event.params.hasOwnProperty('ecomm_totalvalue')) {
1618
+ event.params.ecomm_totalvalue = groupValue;
1619
+ }
1620
 
1621
  if(groupValue == 0) return; // skip if no items selected
1622
  } else {
1629
  options.woo.addToCartOnButtonValueOption !== 'global' &&
1630
  product_type !== Utils.PRODUCT_GROUPED)
1631
  {
1632
+ if(event.params.hasOwnProperty('ecomm_totalvalue')) {
1633
+ event.params.ecomm_totalvalue = event.params.items[0].price * qty;
 
 
 
 
1634
  }
1635
 
1636
  }
1706
 
1707
  $(document).ready(function () {
1708
 
1709
+ if($("#pys_late_event").length > 0) {
1710
+ var events = JSON.parse($("#pys_late_event").attr("dir"));
1711
+ for(var key in events) {
1712
+ var event = {};
1713
+ event[events[key].e_id] = [events[key]];
1714
+ if(options.staticEvents.hasOwnProperty(key)) {
1715
+ Object.assign(options.staticEvents[key], event);
1716
+ } else {
1717
+ options.staticEvents[key] = event;
1718
+ }
1719
+
1720
+ }
1721
+ }
1722
+
1723
  var Pinterest = Utils.setupPinterestObject();
1724
  var Bing = Utils.setupBingObject();
1725
 
1863
 
1864
  // Single Product
1865
  // tap try to https://stackoverflow.com/questions/30990967/on-tap-click-event-firing-twice-how-to-avoid-it
1866
+ // $(document) not work
1867
+ $('body').onFirst('click','button.single_add_to_cart_button,.single_add_to_cart_button',function (e) {
1868
 
1869
  var $button = $(this);
1870
 
facebook-pixel-master.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: PixelYourSite
5
  * Plugin URI: http://www.pixelyoursite.com/
6
  * Description: No coding <strong>Facebook Pixel, Facebook Converion API,</strong> and <strong>Google Analytics</strong> install. Track key actions with our Signal event, or configure your own events. WooCommerce and EDD fully supported, with Facebook Dynamic Ads Pixel set-up and Google Analytics Enhanced Ecommerce. Insert any custom script with our Head & Footer option. Add the <strong>Pinterest Tag</strong> with our paid add-on. The PRO version adds support for the Google Ads tag plus a lot of extra stuff. Full support for <strong>ConsentMagic.com</strong>.
7
- * Version: 8.2.13
8
  * Author: PixelYourSite
9
  * Author URI: http://www.pixelyoursite.com
10
  * License: GPLv3
4
  * Plugin Name: PixelYourSite
5
  * Plugin URI: http://www.pixelyoursite.com/
6
  * Description: No coding <strong>Facebook Pixel, Facebook Converion API,</strong> and <strong>Google Analytics</strong> install. Track key actions with our Signal event, or configure your own events. WooCommerce and EDD fully supported, with Facebook Dynamic Ads Pixel set-up and Google Analytics Enhanced Ecommerce. Insert any custom script with our Head & Footer option. Add the <strong>Pinterest Tag</strong> with our paid add-on. The PRO version adds support for the Google Ads tag plus a lot of extra stuff. Full support for <strong>ConsentMagic.com</strong>.
7
+ * Version: 8.2.14
8
  * Author: PixelYourSite
9
  * Author URI: http://www.pixelyoursite.com
10
  * License: GPLv3
includes/class-events-manager-ajax_hook.php CHANGED
@@ -32,12 +32,7 @@ class AjaxHookEventManager {
32
  if(EventsWoo()->isEnabled()) {
33
 
34
  // use for fb server only because ajax request cause bugs in woo
35
- if(Facebook()->enabled()
36
- && Facebook()->isServerApiEnabled()
37
- && PYS()->getOption( 'woo_remove_from_cart_enabled')
38
- ) {
39
- add_action( 'woocommerce_remove_cart_item', array($this, 'trackRemoveFromCartEvent'), 10, 2);
40
- }
41
 
42
  if ( PYS()->getOption('woo_add_to_cart_on_button_click')
43
  && isEventEnabled('woo_add_to_cart_enabled')
@@ -47,13 +42,8 @@ class AjaxHookEventManager {
47
  if(PYS()->getOption('woo_add_to_cart_catch_method') == "add_cart_hook") {
48
  add_action( 'wp_footer', array( __CLASS__, 'addDivForAjaxPixelEvent') );
49
  add_action( 'woocommerce_add_to_cart',array(__CLASS__, 'trackWooAddToCartEvent'),40, 6);
50
- } else {
51
-
52
- if(Facebook()->enabled() && Facebook()->isServerApiEnabled()) {
53
- add_action( 'woocommerce_add_to_cart',array(__CLASS__, 'trackWooFacebookAddToCartEvent'),40, 6);
54
- }
55
-
56
  }
 
57
 
58
  }
59
  }
@@ -62,122 +52,6 @@ class AjaxHookEventManager {
62
 
63
  }
64
 
65
- /**
66
- * @param String $cart_item_key
67
- * @param \WC_Cart $cart
68
- */
69
-
70
- function trackRemoveFromCartEvent ($cart_item_key,$cart) {
71
- $eventId = 'woo_remove_from_cart';
72
-
73
- $url = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"], '?');
74
- $postId = url_to_postid($url);
75
- $cart_id = wc_get_page_id( 'cart' );
76
- $item = $cart->get_cart_item($cart_item_key);
77
- $is_ajax_request = wp_doing_ajax();
78
- if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yith_wacp_add_item_cart') {
79
- $is_ajax_request = true;
80
- }
81
-
82
- if(isset($item['variation_id'])) {
83
- $product_id = $item['variation_id'];
84
- } else {
85
- $product_id = $item['product_id'];
86
- }
87
-
88
-
89
- if( $cart_id==$postId) {
90
- PYS()->getLog()->debug('trackRemoveFromCartEvent send fb server with out browser event');
91
- $event = new SingleEvent("woo_remove_from_cart",EventTypes::$STATIC,'woo');
92
- $eventData = Facebook()->getEventData($eventId,$item);
93
- $event->addParams($eventData['data']);
94
- $event->addParams(getStandardParams());
95
- if(isset($_COOKIE['pys_landing_page'])){
96
- $event->addParams(['landing_page'=>$_COOKIE['pys_landing_page']]);
97
- }
98
-
99
- unset($eventData['data']);
100
- $event->addPayload($eventData);
101
-
102
- if(isset($_COOKIE["pys_fb_event_id"])) {
103
- $eventID = json_decode(stripslashes($_COOKIE["pys_fb_event_id"]))->RemoveFromCart;
104
- } else {
105
- $eventID = (new EventIdGenerator())->guidv4();
106
- }
107
-
108
- $data = $event->getData();
109
-
110
- $data = EventsManager::filterEventParams($data,"woo",[
111
- 'event_id'=>$event->getId(),
112
- 'pixel'=>Facebook()->getSlug(),
113
- 'product_id'=>$product_id
114
- ]);
115
-
116
- $serverEvent = FacebookServer()->createEvent($eventID,$data['name'],$data['params']);
117
- $ids = (array)$event->payload["pixelIds"];
118
-
119
- if($is_ajax_request) {
120
- FacebookServer()->sendEvent($ids,array($serverEvent));
121
- } else {
122
- FacebookServer()->addAsyncEvents(array(array("pixelIds" => $ids, "event" => $serverEvent )));
123
- }
124
- }
125
- }
126
-
127
- static function trackWooFacebookAddToCartEvent($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
128
- if(isset($cart_item_data['woosb_parent_id'])) return; // fix for WPC Product Bundles for WooCommerce (Premium) product
129
-
130
- $is_ajax_request = wp_doing_ajax();
131
- if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'yith_wacp_add_item_cart') {
132
- $is_ajax_request = true;
133
- }
134
- PYS()->getLog()->debug('trackWooFacebookAddToCartEvent is_ajax_request '.$is_ajax_request);
135
- if( !empty($variation_id)
136
- && $variation_id > 0
137
- && ( !Facebook()->getOption( 'woo_variable_as_simple' )
138
- || !Facebook\Helpers\isDefaultWooContentIdLogic() )
139
- ) {
140
- $_product_id = $variation_id;
141
- } else {
142
- $_product_id = $product_id;
143
- }
144
-
145
- $event = EventsWoo()->getEvent("woo_add_to_cart_on_button_click");
146
- if(is_array($event) && count($event) > 0) {
147
- $event = $event[0];
148
- }
149
- $event->args = ['productId' => $_product_id,'quantity' => $quantity];
150
- $isSuccess = Facebook()->addParamsToEvent( $event );
151
- if ( !$isSuccess ) {
152
- return; // event is disabled or not supported for the pixel
153
- }
154
-
155
- // prepare event data
156
- if(isset($_COOKIE['pys_landing_page']))
157
- $event->addParams(['landing_page'=>$_COOKIE['pys_landing_page']]);
158
- $eventData = $event->getData();
159
- $eventData = EventsManager::filterEventParams($eventData,"woo",[
160
- 'event_id'=>$event->getId(),
161
- 'pixel'=>Facebook()->getSlug(),
162
- 'product_id'=>$product_id
163
- ]);
164
-
165
- if(isset($_COOKIE["pys_fb_event_id"])) {
166
- $eventID = json_decode(stripslashes($_COOKIE["pys_fb_event_id"]))->AddToCart;
167
- } else {
168
- return; // not send if event id is empty
169
- }
170
-
171
- $ids = (array)$event->payload["pixelIds"];
172
- $serverEvent = FacebookServer()->createEvent($eventID,$eventData['name'],$eventData['params']);
173
-
174
- if($is_ajax_request) {
175
- FacebookServer()->sendEvent($ids,array($serverEvent));
176
- } else {
177
- FacebookServer()->addAsyncEvents(array(array("pixelIds" => $ids, "event" => $serverEvent )));
178
- }
179
- }
180
-
181
 
182
  static function trackWooAddToCartEvent($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
183
 
@@ -209,48 +83,28 @@ class AjaxHookEventManager {
209
 
210
  $event = new SingleEvent('woo_add_to_cart_on_button_click',EventTypes::$STATIC,'woo');
211
  $event->args = ['productId' => $_product_id,'quantity' => $quantity];
212
- $isSuccess = $pixel->addParamsToEvent( $event );
213
- if ( !$isSuccess ) {
214
- continue; // event is disabled or not supported for the pixel
215
- }
216
 
217
- if(count($event->params) == 0) {
218
- // add product params
219
- // use for not update bing and pinterest, need remove in next updates
220
- $eventData = $pixel->getEventData('woo_add_to_cart_on_button_click',$product_id);
221
- if($eventData) {
222
- $event->addParams($eventData['params']);
223
- unset($eventData['params']);
224
- $event->addPayload($eventData);
225
- }
226
  }
227
-
228
-
229
 
230
  // add standard params
231
  $event->addParams($standardParams);
232
 
233
  // prepare event data
234
  $eventData = $event->getData();
235
- $eventData = EventsManager::filterEventParams($eventData,"woo",[
236
- 'event_id'=>$event->getId(),
237
- 'pixel'=>$pixel->getSlug(),
238
- 'product_id'=>$product_id
239
- ]);
240
 
241
  AjaxHookEventManager::$pendingEvents["woo_add_to_cart_on_button_click"][ $pixel->getSlug() ] = $eventData;
242
 
243
  if($pixel->getSlug() == "facebook" && Facebook()->isServerApiEnabled()) {
244
- $name = $eventData['name'];
245
- $data = $eventData['params'];
246
- $eventID = isset($eventData['eventID']) ? $eventData['eventID'] : false;
247
- $ids = (array)$event->payload["pixelIds"];
248
- $event = FacebookServer()->createEvent($eventID,$name,$data);
249
 
250
  if($is_ajax_request) {
251
- FacebookServer()->sendEvent($ids,array($event));
252
  } else {
253
- FacebookServer()->addAsyncEvents(array(array("pixelIds" => $ids, "event" => $event )));
254
  }
255
  }
256
  }
32
  if(EventsWoo()->isEnabled()) {
33
 
34
  // use for fb server only because ajax request cause bugs in woo
35
+
 
 
 
 
 
36
 
37
  if ( PYS()->getOption('woo_add_to_cart_on_button_click')
38
  && isEventEnabled('woo_add_to_cart_enabled')
42
  if(PYS()->getOption('woo_add_to_cart_catch_method') == "add_cart_hook") {
43
  add_action( 'wp_footer', array( __CLASS__, 'addDivForAjaxPixelEvent') );
44
  add_action( 'woocommerce_add_to_cart',array(__CLASS__, 'trackWooAddToCartEvent'),40, 6);
 
 
 
 
 
 
45
  }
46
+ add_action( 'woocommerce_after_add_to_cart_button', 'PixelYourSite\EventsManager::setupWooSingleProductData' );
47
 
48
  }
49
  }
52
 
53
  }
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  static function trackWooAddToCartEvent($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
57
 
83
 
84
  $event = new SingleEvent('woo_add_to_cart_on_button_click',EventTypes::$STATIC,'woo');
85
  $event->args = ['productId' => $_product_id,'quantity' => $quantity];
86
+ $events = $pixel->generateEvents( $event );
 
 
 
87
 
88
+ if ( count($events) == 0 ) {
89
+ continue; // event is disabled or not supported for the pixel
 
 
 
 
 
 
 
90
  }
91
+ $event = $events[0];
 
92
 
93
  // add standard params
94
  $event->addParams($standardParams);
95
 
96
  // prepare event data
97
  $eventData = $event->getData();
98
+ $eventData = EventsManager::filterEventParams($eventData,"woo");
 
 
 
 
99
 
100
  AjaxHookEventManager::$pendingEvents["woo_add_to_cart_on_button_click"][ $pixel->getSlug() ] = $eventData;
101
 
102
  if($pixel->getSlug() == "facebook" && Facebook()->isServerApiEnabled()) {
 
 
 
 
 
103
 
104
  if($is_ajax_request) {
105
+ FacebookServer()->sendEventsNow([$event]);
106
  } else {
107
+ FacebookServer()->sendEventsAsync([$event]);
108
  }
109
  }
110
  }
includes/class-events-manager.php CHANGED
@@ -124,33 +124,33 @@ class EventsManager {
124
  $this->facebookServerEvents = array();
125
 
126
  // initial event
 
 
 
 
 
 
 
 
 
127
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
128
 
129
- $event = new SingleEvent('init_event',EventTypes::$STATIC,'');
130
- $params = array();
131
- if(get_post_type() == "post") {
132
- global $post;
133
- $catIds = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'names' ) );
134
- $params['post_category'] = implode(", ",$catIds) ;
135
- }
136
- $event->addParams($params);
137
- $isSuccess = $pixel->addParamsToEvent( $event );
138
- if ( !$isSuccess ) {
139
- continue; // event is disabled or not supported for the pixel
140
  }
141
- $event->addParams($this->standardParams);
142
- $this->addStaticEvent( $event,$pixel,"" );
143
  }
144
  // search event
145
  if ( PYS()->getOption('search_event_enabled' ) && is_search() ) {
 
 
146
  foreach (PYS()->getRegisteredPixels() as $pixel) {
147
- $event = new SingleEvent('search_event', EventTypes::$STATIC,'');
148
- $isSuccess = $pixel->addParamsToEvent( $event );
149
- if ( !$isSuccess ) {
150
- continue; // event is disabled or not supported for the pixel
151
  }
152
- $event->addParams($this->standardParams);
153
- $this->addStaticEvent( $event,$pixel,"" );
154
  }
155
  }
156
 
@@ -187,10 +187,8 @@ class EventsManager {
187
  }
188
 
189
 
190
-
191
-
192
  if(count($this->facebookServerEvents)>0 && Facebook()->enabled()) {
193
- FacebookServer()->addAsyncEvents($this->facebookServerEvents);
194
  }
195
  }
196
 
@@ -219,13 +217,7 @@ class EventsManager {
219
  $pixel = PYS()->getRegisteredPixels()[$pixelSlug];
220
  foreach ($events as $event) {
221
  // add standard params
222
- if(is_a($event,GroupedEvent::class)) {
223
- foreach ($event->getEvents() as $child) {
224
- $child->addParams($this->standardParams);
225
- }
226
- } else {
227
- $event->addParams($this->standardParams);
228
- }
229
  //save different types of events
230
  if($event->getType() == EventTypes::$STATIC) {
231
  $this->addStaticEvent( $event,$pixel,$slug );
@@ -243,18 +235,12 @@ class EventsManager {
243
 
244
  function addDynamicEvent($event,$pixel,$slug) {
245
 
246
- if(is_a($event,GroupedEvent::class)) {
247
- foreach ($event->getEvents() as $child) {
248
- $eventData = $child->getData();
249
- $eventData = $this->filterEventParams($eventData,$slug);
250
- //save static event data
251
- $this->dynamicEvents[ $event->getId() ][ $child->getId() ][ $pixel->getSlug() ] = $eventData;
252
- }
253
- } else {
254
 
255
- $eventData = $event->getData();
256
- $eventData = $this->filterEventParams($eventData,$slug);
257
- //save static event data
258
  $this->dynamicEvents[ $event->getId() ][ $pixel->getSlug() ] = $eventData;
259
  }
260
  }
@@ -279,58 +265,27 @@ class EventsManager {
279
  */
280
  function addStaticEvent($event,$pixel,$slug) {
281
 
282
- if(is_a($event,GroupedEvent::class)) {
283
- foreach ($event->getEvents() as $child) {
284
-
285
- $eventData = $child->getData();
286
- $eventData = $this->filterEventParams($eventData,$slug);
287
- // send only for FB Server events
288
- if($pixel->getSlug() == "facebook" &&
289
- ($event->getId() == "woo_complete_registration") &&
290
- Facebook()->isServerApiEnabled() &&
291
- Facebook()->getOption("woo_complete_registration_send_from_server") &&
292
- !$this->isGdprPluginEnabled() )
293
- {
294
- if($eventData['delay'] == 0) {
295
- $this->addEventToFacebookServerApi($child->payload["pixelIds"],null,$eventData);
296
- }
297
- continue;
298
- }
299
-
300
-
301
- //save static event data
302
- $this->staticEvents[ $pixel->getSlug() ][ $eventData['name'] ][] = $eventData;
303
- // fire fb server api event
304
- if($pixel->getSlug() == "facebook") {
305
- if( $eventData['delay'] == 0 && !Facebook()->getOption( "server_event_use_ajax" )) {
306
- $this->addEventToFacebookServerApi($child->payload["pixelIds"],$child,$eventData);
307
- }
308
- }
309
- }
310
- } else {
311
- $eventData = $event->getData();
312
- $eventData = $this->filterEventParams($eventData,$slug);
313
-
314
- // send only for FB Server events
315
- if($pixel->getSlug() == "facebook" &&
316
- ($event->getId() == "woo_complete_registration") &&
317
- Facebook()->isServerApiEnabled() &&
318
- Facebook()->getOption("woo_complete_registration_send_from_server") &&
319
- !$this->isGdprPluginEnabled() )
320
- {
321
- if($eventData['delay'] == 0) {
322
- $this->addEventToFacebookServerApi($event->payload["pixelIds"],null,$eventData);
323
- }
324
- return;
325
  }
 
 
326
 
327
- //save static event data
328
- $this->staticEvents[ $pixel->getSlug() ][ $eventData['name'] ][] = $eventData;
329
- // fire fb server api event
330
- if($pixel->getSlug() == "facebook") {
331
- if( $eventData['delay'] == 0 && !Facebook()->getOption( "server_event_use_ajax" )) {
332
- $this->addEventToFacebookServerApi($event->payload["pixelIds"],$event,$eventData);
333
- }
334
  }
335
  }
336
 
@@ -389,20 +344,6 @@ class EventsManager {
389
  isCookieLawInfoPluginActivated() && PYS()->getOption( 'gdpr_cookie_law_info_integration_enabled' );
390
  }
391
 
392
- function addEventToFacebookServerApi($pixelIds,$eventType,$eventData) {
393
-
394
- if(!Facebook()->isServerApiEnabled()) return;
395
- $isDisabled = $this->isGdprPluginEnabled();
396
-
397
- if( !$isDisabled ) {
398
- $name = $eventData['name'];
399
- $data = $eventData['params'];
400
- $eventID = isset($eventData['eventID']) ? $eventData['eventID'] : false;
401
- $serverEvent = FacebookServer()->createEvent($eventID,$name,$data);
402
- $this->facebookServerEvents[] = array("pixelIds" => $pixelIds, "event" => $serverEvent );
403
- }
404
- }
405
-
406
 
407
  public function setupWooLoopProductData()
408
  {
@@ -425,30 +366,20 @@ class EventsManager {
425
  $product_id = $product->get_id();
426
 
427
  $params = array();
 
 
428
 
429
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
430
  /** @var Pixel|Settings $pixel */
431
- $event = new SingleEvent('woo_add_to_cart_on_button_click',EventTypes::$STATIC,'woo');
432
- $event->args = ['productId' => $product_id,'quantity' => 1];
433
- $isSuccess = $pixel->addParamsToEvent( $event );
434
- if ( !$isSuccess ) {
435
- continue; // event is disabled or not supported for the pixel
436
- }
437
- if(count($event->params) == 0) {
438
- // add product params
439
- // use for not update bing and pinterest, need remove in next updates
440
- $eventData = $pixel->getEventData( 'woo_add_to_cart_on_button_click', $product_id );
441
- if ( false === $eventData ) {
442
- continue; // event is disabled or not supported for the pixel
443
- }
444
- $event->addParams($eventData['params']);
445
- }
446
 
447
- // prepare event data
448
- $eventData = $event->getData();
449
- $eventData = EventsManager::filterEventParams($eventData,"woo");
 
 
450
 
451
- $params[$pixel->getSlug()] = $eventData;
 
452
  }
453
 
454
  if ( empty( $params ) ) {
@@ -505,32 +436,22 @@ class EventsManager {
505
 
506
  $params = array();
507
  $eventType = 'woo_add_to_cart_on_button_click';
 
 
 
508
  foreach ( $product_ids as $product_id ) {
509
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
510
  /** @var Pixel|Settings $pixel */
511
 
512
- $event = new SingleEvent($eventType,EventTypes::$STATIC,'woo');
513
- $event->args = ['productId' => $product_id,'quantity' => 1];
514
- $isSuccess = $pixel->addParamsToEvent( $event );
515
- if ( !$isSuccess ) {
516
- continue; // event is disabled or not supported for the pixel
517
- }
518
- if(count($event->params) == 0) {
519
- // add product params
520
- // use for not update bing and pinterest, need remove in next updates
521
- $eventData = $pixel->getEventData( $eventType, $product_id );
522
- if ( false === $eventData ) {
523
- continue; // event is disabled or not supported for the pixel
524
- }
525
- $event->addParams($eventData['params']);
526
- }
527
-
528
- // prepare event data
529
- $eventData = $event->getData();
530
- $eventData = EventsManager::filterEventParams($eventData,"woo");
531
 
532
- $params[ $product_id ][ $pixel->getSlug() ] = $eventData;
 
 
 
 
533
 
 
 
534
  }
535
  }
536
 
@@ -573,32 +494,25 @@ class EventsManager {
573
  }
574
 
575
  $params = array();
576
-
577
  foreach ( $download_ids as $download_id ) {
 
 
578
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
579
  /** @var Pixel|Settings $pixel */
580
-
581
- $eventData = $pixel->getEventData( 'edd_add_to_cart_on_button_click', $download_id );
582
-
583
- if ( false === $eventData ) {
584
- continue; // event is disabled or not supported for the pixel
 
 
 
 
 
585
  }
586
- if(isset($eventData['params']))
587
- $eventData['params'] = sanitizeParams($eventData['params']);
588
- else $eventData['params'] = sanitizeParams($eventData['data']);
589
-
590
- $params[ $download_id ][ $pixel->getSlug() ] = $eventData;
591
  }
592
  }
593
 
594
- if ( empty( $params ) ) {
595
- return;
596
- }
597
-
598
- /**
599
- * Format is pysEddProductData[ id ][ id ] or pysEddProductData[ id ] [ id_1, id_2, ... ]
600
- */
601
-
602
  ?>
603
 
604
  <script type="application/javascript" style="display:none">
124
  $this->facebookServerEvents = array();
125
 
126
  // initial event
127
+ $initEvent = new SingleEvent('init_event',EventTypes::$STATIC,'');
128
+ if(get_post_type() == "post") {
129
+ global $post;
130
+ $catIds = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'names' ) );
131
+ $initEvent->addParams([
132
+ 'post_category' => implode(", ",$catIds)
133
+ ]);
134
+ }
135
+
136
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
137
 
138
+ $events = $pixel->generateEvents( $initEvent );
139
+ foreach ($events as $event) {
140
+ $event->addParams($this->standardParams);
141
+ $this->addStaticEvent( $event,$pixel,"" );
 
 
 
 
 
 
 
142
  }
 
 
143
  }
144
  // search event
145
  if ( PYS()->getOption('search_event_enabled' ) && is_search() ) {
146
+ $searchEvent = new SingleEvent('search_event', EventTypes::$STATIC,'');
147
+
148
  foreach (PYS()->getRegisteredPixels() as $pixel) {
149
+ $events = $pixel->generateEvents( $searchEvent );
150
+ foreach ($events as $event) {
151
+ $event->addParams($this->standardParams);
152
+ $this->addStaticEvent( $event,$pixel,"" );
153
  }
 
 
154
  }
155
  }
156
 
187
  }
188
 
189
 
 
 
190
  if(count($this->facebookServerEvents)>0 && Facebook()->enabled()) {
191
+ FacebookServer()->sendEventsAsync($this->facebookServerEvents);
192
  }
193
  }
194
 
217
  $pixel = PYS()->getRegisteredPixels()[$pixelSlug];
218
  foreach ($events as $event) {
219
  // add standard params
220
+ $event->addParams($this->standardParams);
 
 
 
 
 
 
221
  //save different types of events
222
  if($event->getType() == EventTypes::$STATIC) {
223
  $this->addStaticEvent( $event,$pixel,$slug );
235
 
236
  function addDynamicEvent($event,$pixel,$slug) {
237
 
238
+ $eventData = $event->getData();
239
+ $eventData = $this::filterEventParams($eventData,$slug);
 
 
 
 
 
 
240
 
241
+ if($event->getId() == 'edd_remove_from_cart' || $event->getId() == 'woo_remove_from_cart') {
242
+ $this->dynamicEvents[ $event->getId() ][ $event->args['key'] ][ $pixel->getSlug() ] = $eventData;
243
+ } else {
244
  $this->dynamicEvents[ $event->getId() ][ $pixel->getSlug() ] = $eventData;
245
  }
246
  }
265
  */
266
  function addStaticEvent($event,$pixel,$slug) {
267
 
268
+ $eventData = $event->getData();
269
+ $eventData = $this::filterEventParams($eventData,$slug);
270
+ // send only for FB Server events
271
+ if($pixel->getSlug() == "facebook" &&
272
+ ($event->getId() == "woo_complete_registration") &&
273
+ Facebook()->isServerApiEnabled() &&
274
+ Facebook()->getOption("woo_complete_registration_send_from_server") &&
275
+ !$this->isGdprPluginEnabled() )
276
+ {
277
+ if($eventData['delay'] == 0) {
278
+ $this->facebookServerEvents[] = $event;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  }
280
+ return;
281
+ }
282
 
283
+ //save static event data
284
+ $this->staticEvents[ $pixel->getSlug() ][ $event->getId() ][] = $eventData;
285
+ // fire fb server api event
286
+ if($pixel->getSlug() == "facebook") {
287
+ if( $eventData['delay'] == 0 && !Facebook()->getOption( "server_event_use_ajax" )) {
288
+ $this->facebookServerEvents[] = $event;
 
289
  }
290
  }
291
 
344
  isCookieLawInfoPluginActivated() && PYS()->getOption( 'gdpr_cookie_law_info_integration_enabled' );
345
  }
346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
 
348
  public function setupWooLoopProductData()
349
  {
366
  $product_id = $product->get_id();
367
 
368
  $params = array();
369
+ $event = new SingleEvent('woo_add_to_cart_on_button_click',EventTypes::$STATIC,'woo');
370
+ $event->args = ['productId' => $product_id,'quantity' => 1];
371
 
372
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
373
  /** @var Pixel|Settings $pixel */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
 
375
+ $events = $pixel->generateEvents( $event );
376
+ foreach ($events as $event) {
377
+ // prepare event data
378
+ $eventData = $event->getData();
379
+ $eventData = EventsManager::filterEventParams($eventData,"woo");
380
 
381
+ $params[$pixel->getSlug()] = $eventData; // replace data!!(now use only one event)
382
+ }
383
  }
384
 
385
  if ( empty( $params ) ) {
436
 
437
  $params = array();
438
  $eventType = 'woo_add_to_cart_on_button_click';
439
+ $event = new SingleEvent($eventType,EventTypes::$STATIC,'woo');
440
+ $event->args = ['productId' => $product_id,'quantity' => 1];
441
+
442
  foreach ( $product_ids as $product_id ) {
443
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
444
  /** @var Pixel|Settings $pixel */
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
 
447
+ $events = $pixel->generateEvents( $event );
448
+ foreach ($events as $event) {
449
+ // prepare event data
450
+ $eventData = $event->getData();
451
+ $eventData = EventsManager::filterEventParams($eventData,"woo");
452
 
453
+ $params[ $product_id ][ $pixel->getSlug() ] = $eventData; // replace (use only one event for product)
454
+ }
455
  }
456
  }
457
 
494
  }
495
 
496
  $params = array();
 
497
  foreach ( $download_ids as $download_id ) {
498
+ $event = EventsEdd()->getEvent('edd_add_to_cart_on_button_click');
499
+ $event->args = $download_id;
500
  foreach ( PYS()->getRegisteredPixels() as $pixel ) {
501
  /** @var Pixel|Settings $pixel */
502
+ $events = $pixel->generateEvents( $event );
503
+ foreach ($events as $singleEvent) {
504
+ $eventData = $singleEvent->getData();
505
+ $eventData = EventsManager::filterEventParams($eventData,"edd");
506
+ /**
507
+ * Format is pysEddProductData[ id ][ id ] or pysEddProductData[ id ] [ id_1, id_2, ... ]
508
+ */
509
+ $params[ $download_id ][ $pixel->getSlug() ] = [ // replace data there use only one event
510
+ 'params' => $eventData['params']
511
+ ];
512
  }
 
 
 
 
 
513
  }
514
  }
515
 
 
 
 
 
 
 
 
 
516
  ?>
517
 
518
  <script type="application/javascript" style="display:none">
includes/events/class-event-grouped.php CHANGED
@@ -1,6 +1,9 @@
1
  <?php
2
 
3
  namespace PixelYourSite;
 
 
 
4
  class GroupedEvent extends PYSEvent
5
  {
6
  private $events = array();
1
  <?php
2
 
3
  namespace PixelYourSite;
4
+ /**
5
+ * @deprecated
6
+ */
7
  class GroupedEvent extends PYSEvent
8
  {
9
  private $events = array();
includes/events/class-events-edd.php CHANGED
@@ -140,7 +140,7 @@ class EventsEdd extends EventsFactory {
140
  }
141
 
142
  case 'edd_remove_from_cart': {
143
- return new GroupedEvent($event,EventTypes::$DYNAMIC,'edd');
144
  }
145
  case 'edd_add_to_cart_on_button_click': {
146
 
@@ -178,6 +178,18 @@ class EventsEdd extends EventsFactory {
178
  return false;
179
  }
180
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  private function getEddCartActiveCategories($categoryPixels){
182
  $catIds = array();
183
  $keys = array_keys($categoryPixels);
140
  }
141
 
142
  case 'edd_remove_from_cart': {
143
+ return $this->getRemoveFromCartEvents($event);
144
  }
145
  case 'edd_add_to_cart_on_button_click': {
146
 
178
  return false;
179
  }
180
 
181
+ private function getRemoveFromCartEvents($eventId) {
182
+ $events = [];
183
+
184
+
185
+ foreach (edd_get_cart_contents() as $cart_item_key => $cart_item) {
186
+ $event = new SingleEvent($eventId,EventTypes::$DYNAMIC,self::getSlug());
187
+ $event->args = ['key'=>$cart_item_key,'item'=>$cart_item];
188
+ $events[]=$event;
189
+ }
190
+ return $events;
191
+ }
192
+
193
  private function getEddCartActiveCategories($categoryPixels){
194
  $catIds = array();
195
  $keys = array_keys($categoryPixels);
includes/events/class-events-woo.php CHANGED
@@ -174,8 +174,7 @@ class EventsWoo extends EventsFactory {
174
  {
175
  switch ($event) {
176
  case 'woo_remove_from_cart':{
177
- $event = new GroupedEvent($event,EventTypes::$DYNAMIC,'woo');
178
- return $event;
179
  }
180
 
181
  case 'woo_initiate_checkout':
@@ -239,6 +238,17 @@ class EventsWoo extends EventsFactory {
239
  }
240
  return false;
241
  }
 
 
 
 
 
 
 
 
 
 
 
242
  private function getWooCartActiveCategories($activeIds) {
243
  $fireForCategory = array();
244
  foreach (WC()->cart->cart_contents as $cart_item_key => $cart_item) {
174
  {
175
  switch ($event) {
176
  case 'woo_remove_from_cart':{
177
+ return $this->getRemoveFromCartEvents($event);
 
178
  }
179
 
180
  case 'woo_initiate_checkout':
238
  }
239
  return false;
240
  }
241
+
242
+ function getRemoveFromCartEvents($eventId) {
243
+ $events = [];
244
+ foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
245
+ $event = new SingleEvent($eventId,EventTypes::$DYNAMIC,self::getSlug());
246
+ $event->args = ['key'=>$cart_item_key,'item'=>$cart_item];
247
+ $events[]=$event;
248
+ }
249
+ return $events;
250
+ }
251
+
252
  private function getWooCartActiveCategories($activeIds) {
253
  $fireForCategory = array();
254
  foreach (WC()->cart->cart_contents as $cart_item_key => $cart_item) {
includes/events/interface-events.php CHANGED
@@ -37,10 +37,11 @@ abstract class EventsFactory {
37
  if(!is_array($events)) $events = array($events); // some type of events can return array
38
 
39
  foreach ($events as $event) {
40
- $isSuccess = $pixel->addParamsToEvent( $event );
41
- if(!$isSuccess || !apply_filters("pys_validate_pixel_event",true,$event,$pixel)) continue;
42
-
43
- $eventsList[$pixel->getSlug()][] = $event;
 
44
  }
45
  }
46
  }
37
  if(!is_array($events)) $events = array($events); // some type of events can return array
38
 
39
  foreach ($events as $event) {
40
+ $singleEvents = $pixel->generateEvents( $event );
41
+ foreach ($singleEvents as $singleEvent) {
42
+ if(!apply_filters("pys_validate_pixel_event",true,$singleEvent,$pixel)) continue;
43
+ $eventsList[$pixel->getSlug()][] = $singleEvent;
44
+ }
45
  }
46
  }
47
  }
includes/functions-woo.php CHANGED
@@ -32,7 +32,12 @@ function wooProductIsType( $product, $type ) {
32
  }
33
 
34
  }
35
-
 
 
 
 
 
36
  function getWooProductPriceToDisplay( $product_id, $qty = 1 ) {
37
 
38
  if ( ! $product = wc_get_product( $product_id ) ) {
@@ -46,18 +51,17 @@ function getWooProductPriceToDisplay( $product_id, $qty = 1 ) {
46
  return $salePrice['discounted_price'];
47
  }
48
  }
 
49
 
50
- if ( isWooCommerceVersionGte( '2.7' ) ) {
51
-
52
- return (float) wc_get_price_to_display( $product, array( 'qty' => $qty ) );
53
-
54
- } else {
55
-
56
- return 'incl' === get_option( 'woocommerce_tax_display_shop' )
57
- ? $product->get_price_including_tax( $qty )
58
- : $product->get_price_excluding_tax( $qty );
59
 
60
- }
61
  }
62
 
63
  function getWooCartSubtotal() {
32
  }
33
 
34
  }
35
+ function wooIsRequestContainOrderId() {
36
+ return isset( $_REQUEST['key'] ) && $_REQUEST['key'] != ""
37
+ || isset( $_REQUEST['referenceCode'] ) && $_REQUEST['referenceCode'] != ""
38
+ || isset( $_REQUEST['ref_venta'] ) && $_REQUEST['ref_venta'] != ""
39
+ || !empty( $_REQUEST['wcf-order'] );
40
+ }
41
  function getWooProductPriceToDisplay( $product_id, $qty = 1 ) {
42
 
43
  if ( ! $product = wc_get_product( $product_id ) ) {
51
  return $salePrice['discounted_price'];
52
  }
53
  }
54
+ $productPrice = "";
55
 
56
+ // take min price for variable product
57
+ if($product->get_type() == "variable") {
58
+ $prices = $product->get_variation_prices( true );
59
+ if(!empty( $prices['price'] )) {
60
+ $productPrice = current( $prices['price'] );
61
+ }
62
+ }
 
 
63
 
64
+ return (float) wc_get_price_to_display( $product, array( 'qty' => $qty,'price'=>$productPrice ) );
65
  }
66
 
67
  function getWooCartSubtotal() {
includes/views/html-main-general.php CHANGED
@@ -193,7 +193,7 @@ if ( ! defined( 'ABSPATH' ) ) {
193
  target="_blank">pro version</a>.
194
  <div class="small">TikTok Tag integration is in beta.</div>
195
  <div class="mt-3">
196
- How to install the TickTok tag and how to get the ID: <a href="https://www.youtube.com/watch?v=vWRZc66eaPo" target="_blank">watch video</a>
197
  </div>
198
  </div>
199
  </div>
193
  target="_blank">pro version</a>.
194
  <div class="small">TikTok Tag integration is in beta.</div>
195
  <div class="mt-3">
196
+ How to install the TikTok tag and how to get the ID: <a href="https://www.youtube.com/watch?v=vWRZc66eaPo" target="_blank">watch video</a>
197
  </div>
198
  </div>
199
  </div>
modules/facebook/PYSServerEventHelper.php CHANGED
@@ -1,14 +1,36 @@
1
  <?php
2
  namespace PixelYourSite;
3
 
 
4
  use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\Event;
5
  use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\UserData;
6
- use PixelYourSite;
7
-
8
  defined('ABSPATH') or die('Direct access not allowed');
9
 
 
10
  class ServerEventHelper {
11
- public static function newEvent($event_name,$eventId,$wooOrder = null,$eddOrder = null) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  $user_data = ServerEventHelper::getUserData($wooOrder,$eddOrder)
13
  ->setClientIpAddress(self::getIpAddress())
14
  ->setClientUserAgent(self::getHttpUserAgent());
@@ -16,22 +38,43 @@ class ServerEventHelper {
16
  $fbp = self::getFbp();
17
  $fbc = self::getFbc();
18
  if($fbp) {
19
- $user_data ->setFbp($fbp);
20
  }
21
  if($fbc) {
22
- $user_data ->setFbc($fbc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
  $event = (new Event())
26
- ->setEventName($event_name)
27
  ->setEventTime(time())
28
  ->setEventId($eventId)
29
- ->setEventSourceUrl(self::getRequestUri(PYS()->getOption("enable_remove_source_url_params")))
 
 
30
  ->setUserData($user_data);
31
 
 
32
  return $event;
33
  }
34
 
 
35
  private static function getIpAddress() {
36
  $HEADERS_TO_SCAN = array(
37
  'HTTP_CLIENT_IP',
@@ -77,7 +120,7 @@ class ServerEventHelper {
77
  return $user_agent;
78
  }
79
 
80
- private static function getRequestUri($removeQuery) {
81
  $request_uri = null;
82
 
83
  if (!empty($_SERVER['REQUEST_URI'])) {
@@ -88,6 +131,7 @@ class ServerEventHelper {
88
  $request_uri = str_replace("?".$_SERVER['QUERY_STRING'],"",$request_uri);
89
  }
90
 
 
91
  return $request_uri;
92
  }
93
 
@@ -118,11 +162,10 @@ class ServerEventHelper {
118
  * Add purchase WooCommerce Advanced Matching params
119
  */
120
  if ( PixelYourSite\isWooCommerceActive() && isEventEnabled( 'woo_purchase_enabled' ) &&
121
- ($wooOrder || (is_order_received_page() && isset( $_REQUEST['key']) && $_REQUEST['key'] != "" )) ) {
122
-
123
- if(isset( $_REQUEST['key']) && $_REQUEST['key'] != "") {
124
- $order_key = sanitize_key($_REQUEST['key']);
125
- $order_id = wc_get_order_id_by_order_key( $order_key );
126
  } else {
127
  $order_id = $wooOrder;
128
  }
@@ -232,4 +275,41 @@ class ServerEventHelper {
232
  return $userData;
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  }
1
  <?php
2
  namespace PixelYourSite;
3
 
4
+ use PixelYourSite;
5
  use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\Event;
6
  use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\UserData;
7
+ use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\CustomData;
8
+ use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\Content;
9
  defined('ABSPATH') or die('Direct access not allowed');
10
 
11
+
12
  class ServerEventHelper {
13
+
14
+ /**
15
+ * @param SingleEvent $event
16
+ * @return Event | null
17
+ */
18
+ public static function mapEventToServerEvent($event) {
19
+
20
+ $eventData = $event->getData();
21
+ $eventData = EventsManager::filterEventParams($eventData,$event->getCategory(),[
22
+ 'event_id'=>$event->getId(),
23
+ 'pixel'=>Facebook()->getSlug()
24
+ ]);
25
+
26
+ $eventName = $eventData['name'];
27
+ $eventParams = $eventData['params'];
28
+ $eventId = $event->payload['eventID'];
29
+ $wooOrder = isset($event->payload['woo_order']) ? $event->payload['woo_order'] : null;
30
+ $eddOrder = isset($event->payload['edd_order']) ? $event->payload['edd_order'] : null;
31
+
32
+ if(!$eventId) return null;
33
+
34
  $user_data = ServerEventHelper::getUserData($wooOrder,$eddOrder)
35
  ->setClientIpAddress(self::getIpAddress())
36
  ->setClientUserAgent(self::getHttpUserAgent());
38
  $fbp = self::getFbp();
39
  $fbc = self::getFbc();
40
  if($fbp) {
41
+ $user_data->setFbp($fbp);
42
  }
43
  if($fbc) {
44
+ $user_data->setFbc($fbc);
45
+ }
46
+
47
+ $customData = self::paramsToCustomData($eventParams);
48
+ $uri = self::getRequestUri(PYS()->getOption('enable_remove_source_url_params'));
49
+
50
+ // set custom uri use in ajax request
51
+ if(isset($_POST['url'])) {
52
+ if(PYS()->getOption('enable_remove_source_url_params')) {
53
+ $list = explode("?",$_POST['url']);
54
+ if(is_array($list) && count($list) > 0) {
55
+ $uri = $list[0];
56
+ } else {
57
+ $uri = $_POST['url'];
58
+ }
59
+ } else {
60
+ $uri = $_POST['url'];
61
+ }
62
  }
63
 
64
  $event = (new Event())
65
+ ->setEventName($eventName)
66
  ->setEventTime(time())
67
  ->setEventId($eventId)
68
+ ->setEventSourceUrl($uri)
69
+ ->setActionSource("website")
70
+ ->setCustomData($customData)
71
  ->setUserData($user_data);
72
 
73
+
74
  return $event;
75
  }
76
 
77
+
78
  private static function getIpAddress() {
79
  $HEADERS_TO_SCAN = array(
80
  'HTTP_CLIENT_IP',
120
  return $user_agent;
121
  }
122
 
123
+ private static function getRequestUri($removeQuery = false) {
124
  $request_uri = null;
125
 
126
  if (!empty($_SERVER['REQUEST_URI'])) {
131
  $request_uri = str_replace("?".$_SERVER['QUERY_STRING'],"",$request_uri);
132
  }
133
 
134
+
135
  return $request_uri;
136
  }
137
 
162
  * Add purchase WooCommerce Advanced Matching params
163
  */
164
  if ( PixelYourSite\isWooCommerceActive() && isEventEnabled( 'woo_purchase_enabled' ) &&
165
+ ($wooOrder || ( is_order_received_page() && wooIsRequestContainOrderId() ))
166
+ ) {
167
+ if(wooIsRequestContainOrderId()) {
168
+ $order_id = wooGetOrderIdFromRequest();
 
169
  } else {
170
  $order_id = $wooOrder;
171
  }
275
  return $userData;
276
  }
277
 
278
+ static function paramsToCustomData($data) {
279
+
280
+ if(isset($data['contents']) && is_array($data['contents'])) {
281
+ $contents = array();
282
+ foreach ($data['contents'] as $c) {
283
+ $contents[] = new Content([
284
+ 'product_id' => $c['id'],
285
+ 'quantity' => $c['quantity']
286
+ ]);
287
+ }
288
+ $data['contents'] = $contents;
289
+ } else {
290
+ $data['contents'] = array();
291
+ }
292
+
293
+ $customData = new CustomData($data);
294
+ $customProperties = array();
295
+
296
+
297
+ if(isset($data['category_name'])) {
298
+ $customData->setContentCategory($data['category_name']);
299
+ }
300
+
301
+ $custom_values = ['event_action','download_type','download_name','download_url','target_url','text','trigger','traffic_source','plugin','user_role','event_url','page_title',"post_type",'post_id','categories','tags','video_type',
302
+ 'video_id','video_title','event_trigger','link_type','tag_text',"URL",
303
+ 'form_id','form_class','form_submit_label','transactions_count','average_order',
304
+ 'shipping_cost','tax','total','shipping','coupon_used','post_category','landing_page'];
305
+ foreach ($custom_values as $val) {
306
+ if(isset($data[$val])){
307
+ $customProperties[$val] = $data[$val];
308
+ }
309
+ }
310
+
311
+ $customData->setCustomProperties($customProperties);
312
+ return $customData;
313
+ }
314
+
315
  }
modules/facebook/facebook-server-async-task.php CHANGED
@@ -11,8 +11,17 @@ class FacebookAsyncTask extends \WP_Async_Task {
11
  protected function prepare_data($data) {
12
  try {
13
  if (!empty($data)) {
14
- return array('data' => base64_encode(serialize($data)));
 
 
 
 
 
 
 
15
  }
 
 
16
  } catch (\Exception $ex) {
17
  error_log($ex);
18
  }
@@ -30,7 +39,7 @@ class FacebookAsyncTask extends \WP_Async_Task {
30
  }
31
 
32
  foreach ($events as $event) {
33
- FacebookServer()->sendEvent($event["pixelIds"],[$event["event"]]);
34
  }
35
 
36
  }
11
  protected function prepare_data($data) {
12
  try {
13
  if (!empty($data)) {
14
+ if(empty($this->_body_data)) {
15
+ return array('data' => base64_encode(serialize($data)));
16
+ } else {
17
+ //error_log("_body_data".print_r($this->_body_data,true));
18
+ $oldData = unserialize(base64_decode($this->_body_data['data']));
19
+ $data = [array_merge($oldData[0],$data[0])];
20
+ return array('data' => base64_encode(serialize($data)));
21
+ }
22
  }
23
+
24
+
25
  } catch (\Exception $ex) {
26
  error_log($ex);
27
  }
39
  }
40
 
41
  foreach ($events as $event) {
42
+ FacebookServer()->sendEvent($event["pixelIds"],$event["event"]);
43
  }
44
 
45
  }
modules/facebook/facebook-server.php CHANGED
@@ -15,9 +15,7 @@ require_once PYS_FREE_PATH . '/modules/facebook/PYSServerEventHelper.php';
15
  use PYS_PRO_GLOBAL\FacebookAds\Api;
16
  use PYS_PRO_GLOBAL\FacebookAds\Http\Exception\RequestException;
17
  use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\EventRequest;
18
- use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\Event;
19
- use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\CustomData;
20
- use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\Content;
21
 
22
  class FacebookServer {
23
 
@@ -50,139 +48,212 @@ class FacebookServer {
50
  if($this->isEnabled) {
51
  add_action( 'wp_ajax_pys_api_event',array($this,"catchAjaxEvent"));
52
  add_action( 'wp_ajax_nopriv_pys_api_event', array($this,"catchAjaxEvent"));
 
 
53
 
 
54
  // initialize the s2s event async task
55
  new FacebookAsyncTask();
56
  }
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
 
 
 
 
60
 
61
  /**
62
- * Send this events by FacebookAsyncTask
63
- * @param array $event List of raw event data
 
64
  */
65
- public function addAsyncEvents($events) {
66
- do_action('pys_send_server_event', $events);
 
 
 
 
 
 
67
  }
68
 
69
- /*
70
- * If server message is blocked by gprg or it dynamic
71
- * we send data by ajax request from js and send the same data like browser event
 
 
72
  */
73
- function catchAjaxEvent() {
74
 
75
- $event = $_POST['event'];
76
- $data = isset($_POST['data']) ? $_POST['data'] : array();
77
- $ids = $_POST['ids'];
78
- $eventID = $_POST['eventID'];
79
- $wooOrder = isset($_POST['woo_order']) ? $_POST['woo_order'] : null;
80
- $eddOrder = isset($_POST['edd_order']) ? $_POST['edd_order'] : null;
 
 
 
 
81
 
 
 
 
 
82
 
83
- if($event == "hCR") $event="CompleteRegistration"; // de mask completer registration event if it was hidden
 
84
 
85
- $event = $this->createEvent($eventID,$event,$data,$wooOrder,$eddOrder);
86
- if($event) {
87
- if(isset($_POST['url'])) {
88
- if(PYS()->getOption('enable_remove_source_url_params')) {
89
- $list = explode("?",$_POST['url']);
90
- if(is_array($list) && count($list) > 0) {
91
- $url = $list[0];
92
- } else {
93
- $url = $_POST['url'];
94
- }
95
- } else {
96
- $url = $_POST['url'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
- $event->setEventSourceUrl($url);
99
  }
100
 
101
- $this->sendEvent($ids,array($event));
102
  }
103
- wp_die();
104
- }
105
 
 
106
 
107
  /**
108
- * We prepare data from event for browser and create Facebook server event object
109
- * @param String $name Event name
110
- * @param $data Data for event
111
- * @return bool|\FacebookAds\Object\ServerSide\Event
112
  */
113
- function createEvent($eventID,$name, $data,$wooOrder = null ,$eddOrder=null) {
114
 
115
- if(!$eventID) return false;
 
116
 
117
- // create Server event
118
- $event = ServerEventHelper::newEvent($name,$eventID,$wooOrder,$eddOrder);
 
 
119
 
120
- $event->setEventTime(time());
121
- $event->setActionSource("website");
122
 
123
- // prepare data
124
- if(isset($data['contents']) && is_array($data['contents'])) {
125
- $contents = array();
126
- foreach ($data['contents'] as $c) {
127
- $content = array();
128
- $content['product_id'] = $c['id'];
129
- $content['quantity'] = $c['quantity'];
130
- // $content['item_price'] = $c->item_price;
131
- $contents[] = new Content($content);
132
- }
133
- $data['contents'] = $contents;
134
- } else {
135
- $data['contents'] = array();
136
- }
137
 
138
- // prepare custom data
139
- $customData = $this->getCustomData($data);
 
 
140
 
 
141
 
142
- if(isset($data['category_name'])) {
143
- $customData->setContentCategory($data['category_name']);
144
- }
145
-
 
 
 
 
146
 
147
- $event->setCustomData($customData);
148
 
149
- return $event;
 
150
  }
151
 
152
- function getCustomData($data) {
153
- $customData = new CustomData($data);
154
- $customProperties = getCommonEventParams();
155
- //$customProperties['event_day'] = date("l");
156
- // $customProperties['event_month'] = date("F");
157
- // $customProperties['event_hour'] = $this->hours[date("G")];
 
 
 
 
 
 
158
 
159
- if(isset($data['category_name'])) {
160
- $customData->setContentCategory($data['category_name']);
161
- }
162
 
163
 
164
- $custom_values = ['event_action','download_type','download_name','download_url','target_url','text','trigger','traffic_source','plugin','user_role','event_url','page_title',"post_type",'post_id','categories','tags','video_type',
165
- 'video_id','video_title','event_trigger','link_type','tag_text',"URL",
166
- 'form_id','form_class','form_submit_label','transactions_count','average_order',
167
- 'shipping_cost','tax','total','shipping','coupon_used'];
168
 
 
169
 
170
- foreach ($custom_values as $val) {
171
- if(isset($data[$val]))
172
- $customProperties[$val] = $data[$val];
173
- }
174
- $customData->setCustomProperties($customProperties);
175
- return $customData;
176
  }
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  /**
179
  * Send event for each pixel id
180
- * @param array $pixel_Ids array of facebook ids
181
- * @param array $events One Facebook event object
182
  */
183
- function sendEvent($pixel_Ids, $events) {
184
 
185
- if (empty($events)) {
186
  return;
187
  }
188
 
@@ -195,15 +266,18 @@ class FacebookServer {
195
 
196
  if(empty($this->access_token[$pixel_Id])) continue;
197
 
 
 
198
  $api = Api::init(null, null, $this->access_token[$pixel_Id],false);
199
 
200
- $request = (new EventRequest($pixel_Id))->setEvents($events);
201
  $request->setPartnerAgent("dvpixelyoursite");
202
- if(!empty($this->testCode[$pixel_Id]))
203
  $request->setTestEventCode($this->testCode[$pixel_Id]);
 
204
 
 
205
  try{
206
- PYS()->getLog()->debug('Send FB server event',$request);
207
  $response = $request->execute();
208
  PYS()->getLog()->debug('Response from FB server',$response);
209
  } catch (\Exception $e) {
@@ -213,42 +287,9 @@ class FacebookServer {
213
  PYS()->getLog()->error('Error send FB server event',$e);
214
  }
215
  }
216
-
217
  }
218
  }
219
 
220
- function getTrafficSource () {
221
- $referrer = "";
222
- $source = "";
223
- try {
224
- if (isset($_SERVER['HTTP_REFERER'])) {
225
- $referrer = $_SERVER['HTTP_REFERER'];
226
- }
227
-
228
- $direct = empty($referrer);
229
- $internal = $direct ? false : strpos(site_url(), $referrer) == 0;
230
- $external = !$direct && !$internal;
231
- $cookie = !isset($_COOKIE['pysTrafficSource']) ? false : $_COOKIE['pysTrafficSource'];
232
-
233
- if (!$external) {
234
- $source = $cookie ? $cookie : 'direct';
235
- } else {
236
- $source = $cookie && $cookie === $referrer ? $cookie : $referrer;
237
- }
238
-
239
- if ($source !== 'direct') {
240
- $parse = parse_url($source);
241
-
242
- // leave only domain (Issue #70)
243
- return $parse['host'];
244
-
245
- } else {
246
- return $source;
247
- }
248
- } catch (\Exception $e) {
249
- return "direct";
250
- }
251
- }
252
  }
253
 
254
  /**
15
  use PYS_PRO_GLOBAL\FacebookAds\Api;
16
  use PYS_PRO_GLOBAL\FacebookAds\Http\Exception\RequestException;
17
  use PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\EventRequest;
18
+
 
 
19
 
20
  class FacebookServer {
21
 
48
  if($this->isEnabled) {
49
  add_action( 'wp_ajax_pys_api_event',array($this,"catchAjaxEvent"));
50
  add_action( 'wp_ajax_nopriv_pys_api_event', array($this,"catchAjaxEvent"));
51
+ add_action( 'woocommerce_remove_cart_item', array($this, 'trackRemoveFromCartEvent'), 10, 2);
52
+ add_action( 'woocommerce_add_to_cart', array($this, 'trackAddToCartEvent'), 40, 4);
53
 
54
+ //add_action( 'woocommerce_order_status_completed', array( $this, 'completed_purchase' ) );
55
  // initialize the s2s event async task
56
  new FacebookAsyncTask();
57
  }
58
  }
59
 
60
+ /**
61
+ * Send event in shutdown hook (not work in ajax)
62
+ * @param SingleEvent[] $events
63
+ */
64
+ public function sendEventsAsync($events) {
65
+
66
+ $serverEvents = [];
67
+ foreach ($events as $event) {
68
+ $ids = $event->payload['pixelIds'];
69
+ $serverEvents[] = [
70
+ "pixelIds" => $ids,
71
+ "event" => ServerEventHelper::mapEventToServerEvent($event)
72
+ ];
73
+ }
74
 
75
+ if(count($serverEvents) > 0) {
76
+ do_action('pys_send_server_event', $serverEvents);
77
+ }
78
+ }
79
 
80
  /**
81
+ * Send Event Now
82
+ *
83
+ * @param SingleEvent[] $events
84
  */
85
+ public function sendEventsNow($events) {
86
+
87
+ foreach ($events as $event) {
88
+ $serverEvent = ServerEventHelper::mapEventToServerEvent($event);
89
+ $ids = $event->payload['pixelIds'];
90
+
91
+ $this->sendEvent($ids,$serverEvent);
92
+ }
93
  }
94
 
95
+
96
+ /**
97
+ * Tracks a completed purchase
98
+ *
99
+ * @param int $order_id the order ID
100
  */
101
+ function completed_purchase($order_id) {
102
 
103
+ if(get_post_meta( $order_id, '_pys_purchase_event_fired', true )
104
+ || !PYS()->getOption( 'woo_purchase_enabled' )) {
105
+ return;
106
+ }
107
+ add_filter("pys_woo_checkout_order_id",function () use ($order_id) {return $order_id;});
108
+ $event = EventsWoo()->getEvent('woo_purchase');
109
+ if ( $event == null ) {
110
+ return;
111
+ }
112
+ $events = Facebook()->generateEvents($event);
113
 
114
+ foreach ($events as $singleEvent) {
115
+ if(isset($_COOKIE['pys_landing_page']))
116
+ $singleEvent->addParams(['landing_page'=>$_COOKIE['pys_landing_page']]);
117
+ }
118
 
119
+ $this->sendEventsNow($events);
120
+ }
121
 
122
+ function trackAddToCartEvent($cart_item_key, $product_id, $quantity, $variation_id) {
123
+ if(EventsWoo()->isReadyForFire("woo_add_to_cart_on_button_click")
124
+ && PYS()->getOption('woo_add_to_cart_catch_method') == "add_cart_js")
125
+ {
126
+ PYS()->getLog()->debug('trackAddToCartEvent send fb server with out browser event');
127
+ if( !empty($variation_id)
128
+ && $variation_id > 0
129
+ && ( !Facebook()->getOption( 'woo_variable_as_simple' )
130
+ || ( Facebook()->getSlug() == "facebook"
131
+ && !Facebook\Helpers\isDefaultWooContentIdLogic()
132
+ )
133
+ )
134
+ ) {
135
+ $_product_id = $variation_id;
136
+ } else {
137
+ $_product_id = $product_id;
138
+ }
139
+
140
+ $event = new SingleEvent("woo_add_to_cart_on_button_click",EventTypes::$DYNAMIC,'woo');
141
+ $event->args = ['productId' => $_product_id,'quantity' => $quantity];
142
+ add_filter('pys_conditional_post_id', function($id) use ($product_id) { return $product_id; });
143
+ $events = Facebook()->generateEvents($event);
144
+ remove_all_filters('pys_conditional_post_id');
145
+
146
+ foreach ($events as $singleEvent) {
147
+
148
+ if(isset($_COOKIE['pys_landing_page']))
149
+ $singleEvent->addParams(['landing_page'=>$_COOKIE['pys_landing_page']]);
150
+
151
+ if(isset($_COOKIE["pys_fb_event_id"])) {
152
+ $singleEvent->payload['eventID'] = json_decode(stripslashes($_COOKIE["pys_fb_event_id"]))->AddToCart;
153
  }
 
154
  }
155
 
156
+ $this->sendEventsAsync($events);
157
  }
 
 
158
 
159
+ }
160
 
161
  /**
162
+ * @param String $cart_item_key
163
+ * @param \WC_Cart $cart
 
 
164
  */
 
165
 
166
+ function trackRemoveFromCartEvent ($cart_item_key,$cart) {
167
+ $eventId = 'woo_remove_from_cart';
168
 
169
+ $url = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"], '?');
170
+ $postId = url_to_postid($url);
171
+ $cart_id = wc_get_page_id( 'cart' );
172
+ $item = $cart->get_cart_item($cart_item_key);
173
 
 
 
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
+ if(PYS()->getOption( 'woo_remove_from_cart_enabled') && $cart_id==$postId) {
177
+ PYS()->getLog()->debug('trackRemoveFromCartEvent send fb server with out browser event');
178
+ $event = new SingleEvent("woo_remove_from_cart",EventTypes::$STATIC,'woo');
179
+ $event->args=['item'=>$item];
180
 
181
+ $events = Facebook()->generateEvents($event);
182
 
183
+ foreach ($events as $singleEvent) {
184
+ $singleEvent->addParams(getStandardParams());
185
+ if(isset($_COOKIE['pys_landing_page'])){
186
+ $singleEvent->addParams(['landing_page'=>$_COOKIE['pys_landing_page']]);
187
+ }
188
+ if(isset($_COOKIE["pys_fb_event_id"])) {
189
+ $singleEvent->payload['eventID'] = json_decode(stripslashes($_COOKIE["pys_fb_event_id"]))->RemoveFromCart;
190
+ }
191
 
192
+ }
193
 
194
+ $this->sendEventsAsync($events);
195
+ }
196
  }
197
 
198
+ /*
199
+ * If server message is blocked by gprg or it dynamic
200
+ * we send data by ajax request from js and send the same data like browser event
201
+ */
202
+ function catchAjaxEvent() {
203
+ PYS()->getLog()->debug('catchAjaxEvent send fb server from ajax');
204
+ $event = $_POST['event'];
205
+ $data = isset($_POST['data']) ? $_POST['data'] : array();
206
+ $ids = $_POST['ids'];
207
+ $eventID = $_POST['eventID'];
208
+ $wooOrder = isset($_POST['woo_order']) ? $_POST['woo_order'] : null;
209
+ $eddOrder = isset($_POST['edd_order']) ? $_POST['edd_order'] : null;
210
 
 
 
 
211
 
212
 
213
+ if($event == "hCR") $event="CompleteRegistration"; // de mask completer registration event if it was hidden
 
 
 
214
 
215
+ $singleEvent = $this->dataToSingleEvent($event,$data,$eventID,$ids,$wooOrder,$eddOrder);
216
 
217
+ $this->sendEventsNow([$singleEvent]);
218
+
219
+ wp_die();
 
 
 
220
  }
221
 
222
+ /**
223
+ * @param $eventName
224
+ * @param $params
225
+ * @param $eventID
226
+ * @param $ids
227
+ * @param $wooOrder
228
+ * @param $eddOrder
229
+ * @return SingleEvent
230
+ */
231
+ private function dataToSingleEvent($eventName,$params,$eventID,$ids,$wooOrder,$eddOrder) {
232
+ $singleEvent = new SingleEvent("","");
233
+
234
+ $payload = [
235
+ 'name' => $eventName,
236
+ 'eventID' => $eventID,
237
+ 'woo_order' => $wooOrder,
238
+ 'edd_order' => $eddOrder,
239
+ 'pixelIds' => $ids
240
+ ];
241
+ $singleEvent->addParams($params);
242
+ $singleEvent->addPayload($payload);
243
+
244
+ return $singleEvent;
245
+ }
246
+
247
+
248
+
249
  /**
250
  * Send event for each pixel id
251
+ * @param array $pixel_Ids //array of facebook ids
252
+ * @param \PYS_PRO_GLOBAL\FacebookAds\Object\ServerSide\Event $event //One Facebook event object
253
  */
254
+ function sendEvent($pixel_Ids, $event) {
255
 
256
+ if (!$event || apply_filters('pys_disable_server_event_filter',false)) {
257
  return;
258
  }
259
 
266
 
267
  if(empty($this->access_token[$pixel_Id])) continue;
268
 
269
+ $event->setEventId($event->getEventId());
270
+
271
  $api = Api::init(null, null, $this->access_token[$pixel_Id],false);
272
 
273
+ $request = (new EventRequest($pixel_Id))->setEvents([$event]);
274
  $request->setPartnerAgent("dvpixelyoursite");
275
+ if(!empty($this->testCode[$pixel_Id])) {
276
  $request->setTestEventCode($this->testCode[$pixel_Id]);
277
+ }
278
 
279
+ PYS()->getLog()->debug('Send FB server event',$request);
280
  try{
 
281
  $response = $request->execute();
282
  PYS()->getLog()->debug('Response from FB server',$response);
283
  } catch (\Exception $e) {
287
  PYS()->getLog()->error('Error send FB server event',$e);
288
  }
289
  }
 
290
  }
291
  }
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  }
294
 
295
  /**
modules/facebook/facebook.php CHANGED
@@ -62,8 +62,7 @@ class Facebook extends Settings implements Pixel {
62
  $pixel_id = $this->getPixelIDs();
63
  $this->configured = $this->enabled()
64
  && count( $pixel_id ) > 0
65
- && !empty($pixel_id[0])
66
- && ! apply_filters( 'pys_pixel_disabled', false, $this->getSlug() );
67
  }
68
 
69
  return $this->configured;
@@ -75,7 +74,6 @@ class Facebook extends Settings implements Pixel {
75
  $ids = (array) $this->getOption( 'pixel_id' );
76
  $ids = (array) reset( $ids );// return first id only
77
  return apply_filters("pys_facebook_ids",$ids);
78
-
79
  }
80
 
81
  public function getPixelOptions() {
@@ -96,6 +94,31 @@ class Facebook extends Settings implements Pixel {
96
 
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  // need refactoring
100
  private function addDataToEvent($eventData,&$event) {
101
  $params = $eventData["data"];
@@ -105,7 +128,11 @@ class Facebook extends Settings implements Pixel {
105
  $event->addPayload($eventData);
106
  }
107
 
108
- function addParamsToEvent($event) {
 
 
 
 
109
  if ( ! $this->configured() ) {
110
  return false;
111
  }
@@ -227,17 +254,7 @@ class Facebook extends Settings implements Pixel {
227
  }
228
  }break;
229
  case 'woo_remove_from_cart': {
230
- if(is_a($event,GroupedEvent::class)) {
231
- foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
232
- $eventData = $this->getWooRemoveFromCartParams( $cart_item );
233
- if ($eventData) {
234
- $child = new SingleEvent($cart_item_key,EventTypes::$DYNAMIC,'woo');
235
- $isActive = true;
236
- $this->addDataToEvent($eventData, $child);
237
- $event->addEvent($child);
238
- }
239
- }
240
- }
241
  }break;
242
  case 'woo_view_category':{
243
  $eventData = $this->getWooViewCategoryEventParams();
@@ -275,16 +292,10 @@ class Facebook extends Settings implements Pixel {
275
  }
276
  }break;
277
  case 'edd_remove_from_cart': {
278
- if(is_a($event,GroupedEvent::class)) {
279
- foreach ( edd_get_cart_contents() as $cart_item_key => $cart_item ) {
280
- $eventData = $this->getEddRemoveFromCartParams( $cart_item );
281
- if ($eventData) {
282
- $child = new SingleEvent($cart_item_key,EventTypes::$DYNAMIC,'edd');
283
- $isActive = true;
284
- $this->addDataToEvent($eventData, $child);
285
- $event->addEvent($child);
286
- }
287
- }
288
  }
289
  }break;
290
 
@@ -332,14 +343,19 @@ class Facebook extends Settings implements Pixel {
332
  }
333
  $event->addPayload(array(
334
  'name'=>"AddToCart",
335
- 'pixelIds' => isset($eventData["pixelIds"]) ? $eventData["pixelIds"] : null,
336
  ));
337
  }
338
  }break;
339
 
340
  case 'edd_add_to_cart_on_button_click':{
 
341
  if ( $this->getOption( 'edd_add_to_cart_enabled' ) && PYS()->getOption( 'edd_add_to_cart_on_button_click' ) ) {
342
  $isActive = true;
 
 
 
 
 
343
  $event->addPayload(array(
344
  'name'=>"AddToCart"
345
  ));
@@ -349,8 +365,6 @@ class Facebook extends Settings implements Pixel {
349
 
350
  }
351
  if($isActive) {
352
- if( !isset($event->payload['pixelIds']) )
353
- $event->payload['pixelIds'] = $this->getPixelIDs();
354
 
355
  if($this->isServerApiEnabled()) {
356
  $event->payload['eventID'] = EventIdGenerator::guidv4();
@@ -360,24 +374,8 @@ class Facebook extends Settings implements Pixel {
360
  }
361
 
362
  public function getEventData( $eventType, $args = null ) {
363
-
364
- if ( ! $this->configured() ) {
365
- return false;
366
- }
367
- $eventData = false;
368
-
369
- switch ( $eventType ) {
370
-
371
- case 'woo_add_to_cart_on_button_click':
372
- $eventData = $this->getWooAddToCartOnButtonClickEventParams( $args ); break;
373
 
374
- case 'edd_add_to_cart_on_button_click':
375
- $eventData = $this->getEddAddToCartOnButtonClickEventParams( $args ); break;
376
-
377
- default: return false; // event does not supported
378
- }
379
-
380
- return $eventData;
381
  }
382
 
383
  public function outputNoScriptEvents() {
@@ -388,14 +386,15 @@ class Facebook extends Settings implements Pixel {
388
 
389
  $eventsManager = PYS()->getEventsManager();
390
 
391
- foreach ( $eventsManager->getStaticEvents( 'facebook' ) as $eventName => $events ) {
392
- if($eventName == "hCR") continue;
393
  foreach ( $events as $event ) {
 
394
  foreach ( $this->getPixelIDs() as $pixelID ) {
395
 
396
  $args = array(
397
  'id' => $pixelID,
398
- 'ev' => urlencode( $eventName ),
399
  'noscript' => 1,
400
  );
401
 
@@ -654,7 +653,9 @@ class Facebook extends Settings implements Pixel {
654
  $data = array(
655
  'params' => $params,
656
  );
 
657
  $product = wc_get_product($product_id);
 
658
  if($product->get_type() == 'grouped') {
659
  $grouped = array();
660
  foreach ($product->get_children() as $childId) {
@@ -685,12 +686,16 @@ class Facebook extends Settings implements Pixel {
685
 
686
  }
687
 
688
- private function getWooRemoveFromCartParams( $cart_item ) {
 
 
 
 
689
 
690
  if ( ! $this->getOption( 'woo_remove_from_cart_enabled' ) ) {
691
  return false;
692
  }
693
-
694
  $product_id = Helpers\getFacebookWooCartItemId( $cart_item );
695
  $content_id = Helpers\getFacebookWooProductContentId( $product_id );
696
 
@@ -711,8 +716,12 @@ class Facebook extends Settings implements Pixel {
711
  //'item_price' => getWooProductPriceToDisplay( $product_id ),
712
  )
713
  ) ;
714
-
715
- return array( 'data' => $params );
 
 
 
 
716
 
717
  }
718
 
@@ -954,9 +963,6 @@ class Facebook extends Settings implements Pixel {
954
  private function getEddAddToCartOnButtonClickEventParams( $download_id ) {
955
  global $post;
956
 
957
- if ( ! $this->getOption( 'edd_add_to_cart_enabled' ) || ! PYS()->getOption( 'edd_add_to_cart_on_button_click' ) ) {
958
- return false;
959
- }
960
 
961
  // maybe extract download price id
962
  if ( strpos( $download_id, '_') !== false ) {
@@ -995,9 +1001,7 @@ class Facebook extends Settings implements Pixel {
995
  )
996
  );
997
 
998
- return array(
999
- 'params' => $params,
1000
- );
1001
 
1002
  }
1003
 
@@ -1153,7 +1157,10 @@ class Facebook extends Settings implements Pixel {
1153
  )
1154
  );
1155
 
1156
- return array( 'data' => $params );
 
 
 
1157
 
1158
  }
1159
 
62
  $pixel_id = $this->getPixelIDs();
63
  $this->configured = $this->enabled()
64
  && count( $pixel_id ) > 0
65
+ && !empty($pixel_id[0]);
 
66
  }
67
 
68
  return $this->configured;
74
  $ids = (array) $this->getOption( 'pixel_id' );
75
  $ids = (array) reset( $ids );// return first id only
76
  return apply_filters("pys_facebook_ids",$ids);
 
77
  }
78
 
79
  public function getPixelOptions() {
94
 
95
  }
96
 
97
+
98
+ /**
99
+ * Create pixel event and fill it
100
+ * @param SingleEvent $event
101
+ * @return SingleEvent[]
102
+ */
103
+ public function generateEvents($event) {
104
+ $pixelEvents = [];
105
+ if ( ! $this->configured() ) {
106
+ return [];
107
+ }
108
+
109
+ $pixelIds = $this->getPixelIDs();
110
+
111
+ if(count($pixelIds) > 0) {
112
+ $pixelEvent = clone $event;
113
+ if($this->addParamsToEvent($pixelEvent)) {
114
+ $pixelEvent->addPayload([ 'pixelIds' => $pixelIds ]);
115
+ $pixelEvents[] = $pixelEvent;
116
+ }
117
+ }
118
+
119
+ return $pixelEvents;
120
+ }
121
+
122
  // need refactoring
123
  private function addDataToEvent($eventData,&$event) {
124
  $params = $eventData["data"];
128
  $event->addPayload($eventData);
129
  }
130
 
131
+ /**
132
+ * @param SingleEvent $event
133
+ * @return bool|mixed|null
134
+ */
135
+ function addParamsToEvent(&$event) {
136
  if ( ! $this->configured() ) {
137
  return false;
138
  }
254
  }
255
  }break;
256
  case 'woo_remove_from_cart': {
257
+ $isActive = $this->getWooRemoveFromCartParams( $event);
 
 
 
 
 
 
 
 
 
 
258
  }break;
259
  case 'woo_view_category':{
260
  $eventData = $this->getWooViewCategoryEventParams();
292
  }
293
  }break;
294
  case 'edd_remove_from_cart': {
295
+ $eventData = $this->getEddRemoveFromCartParams( $event->args['item'] );
296
+ if ($eventData) {
297
+ $isActive = true;
298
+ $this->addDataToEvent($eventData, $event);
 
 
 
 
 
 
299
  }
300
  }break;
301
 
343
  }
344
  $event->addPayload(array(
345
  'name'=>"AddToCart",
 
346
  ));
347
  }
348
  }break;
349
 
350
  case 'edd_add_to_cart_on_button_click':{
351
+
352
  if ( $this->getOption( 'edd_add_to_cart_enabled' ) && PYS()->getOption( 'edd_add_to_cart_on_button_click' ) ) {
353
  $isActive = true;
354
+ if($event->args != null) {
355
+ $eventData = $this->getEddAddToCartOnButtonClickEventParams( $event->args );
356
+ $event->addParams($eventData);
357
+ }
358
+
359
  $event->addPayload(array(
360
  'name'=>"AddToCart"
361
  ));
365
 
366
  }
367
  if($isActive) {
 
 
368
 
369
  if($this->isServerApiEnabled()) {
370
  $event->payload['eventID'] = EventIdGenerator::guidv4();
374
  }
375
 
376
  public function getEventData( $eventType, $args = null ) {
 
 
 
 
 
 
 
 
 
 
377
 
378
+ return false;
 
 
 
 
 
 
379
  }
380
 
381
  public function outputNoScriptEvents() {
386
 
387
  $eventsManager = PYS()->getEventsManager();
388
 
389
+ foreach ( $eventsManager->getStaticEvents( 'facebook' ) as $eventId => $events ) {
390
+
391
  foreach ( $events as $event ) {
392
+ if( $event['name'] == "hCR") continue;
393
  foreach ( $this->getPixelIDs() as $pixelID ) {
394
 
395
  $args = array(
396
  'id' => $pixelID,
397
+ 'ev' => urlencode( $event['name'] ),
398
  'noscript' => 1,
399
  );
400
 
653
  $data = array(
654
  'params' => $params,
655
  );
656
+
657
  $product = wc_get_product($product_id);
658
+ if(!$product) return false;
659
  if($product->get_type() == 'grouped') {
660
  $grouped = array();
661
  foreach ($product->get_children() as $childId) {
686
 
687
  }
688
 
689
+ /**
690
+ * @param SingleEvent $event
691
+ * @return bool
692
+ */
693
+ private function getWooRemoveFromCartParams( $event ) {
694
 
695
  if ( ! $this->getOption( 'woo_remove_from_cart_enabled' ) ) {
696
  return false;
697
  }
698
+ $cart_item = $event->args['item'];
699
  $product_id = Helpers\getFacebookWooCartItemId( $cart_item );
700
  $content_id = Helpers\getFacebookWooProductContentId( $product_id );
701
 
716
  //'item_price' => getWooProductPriceToDisplay( $product_id ),
717
  )
718
  ) ;
719
+ $data = [
720
+ 'name' => "RemoveFromCart",
721
+ ];
722
+ $event->addParams($params);
723
+ $event->addPayload($data);
724
+ return true;
725
 
726
  }
727
 
963
  private function getEddAddToCartOnButtonClickEventParams( $download_id ) {
964
  global $post;
965
 
 
 
 
966
 
967
  // maybe extract download price id
968
  if ( strpos( $download_id, '_') !== false ) {
1001
  )
1002
  );
1003
 
1004
+ return $params;
 
 
1005
 
1006
  }
1007
 
1157
  )
1158
  );
1159
 
1160
+ return array(
1161
+ 'name' => 'RemoveFromCart',
1162
+ 'data' => $params
1163
+ );
1164
 
1165
  }
1166
 
modules/google_analytics/ga.php CHANGED
@@ -105,8 +105,31 @@ class GA extends Settings implements Pixel {
105
  'disableAdvertisingPersonalization' => $this->getOption( 'disable_advertising_personalization' ),
106
  'wooVariableAsSimple' => $this->getOption( 'woo_variable_as_simple' )
107
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
 
109
  }
 
110
  //refactor it
111
  private function addDataToEvent($eventData,&$event) {
112
  $params = $eventData["data"];
@@ -170,17 +193,8 @@ class GA extends Settings implements Pixel {
170
  }
171
  }break;
172
  case 'woo_remove_from_cart':{
173
- foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
174
- if(is_a($event,GroupedEvent::class)) {
175
- $eventData = $this->getWooRemoveFromCartParams( $cart_item );
176
- if ($eventData) {
177
- $child = new SingleEvent($cart_item_key,EventTypes::$DYNAMIC,'woo');
178
- $isActive = true;
179
- $this->addDataToEvent($eventData, $child);
180
- $event->addEvent($child);
181
- }
182
- }
183
- }
184
  }break;
185
  case 'woo_initiate_checkout':{
186
  $eventData = $this->getWooInitiateCheckoutEventParams();
@@ -219,18 +233,11 @@ class GA extends Settings implements Pixel {
219
  }
220
  }break;
221
  case 'edd_remove_from_cart': {
222
- if(is_a($event,GroupedEvent::class)) {
223
- foreach ( edd_get_cart_contents() as $cart_item_key => $cart_item ) {
224
- $eventData = $this->getEddRemoveFromCartParams( $cart_item );
225
- if ($eventData) {
226
- $child = new SingleEvent($cart_item_key,EventTypes::$DYNAMIC,'edd');
227
- $isActive = true;
228
- $this->addDataToEvent($eventData, $child);
229
- $event->addEvent($child);
230
- }
231
- }
232
  }
233
-
234
  }break;
235
 
236
  case 'edd_view_category': {
@@ -278,6 +285,10 @@ class GA extends Settings implements Pixel {
278
  case 'edd_add_to_cart_on_button_click': {
279
  if ( $this->getOption( 'edd_add_to_cart_enabled' ) && PYS()->getOption( 'edd_add_to_cart_on_button_click' ) ) {
280
  $isActive = true;
 
 
 
 
281
  $event->addPayload(array(
282
  'name'=>"add_to_cart"
283
  ));
@@ -290,22 +301,8 @@ class GA extends Settings implements Pixel {
290
 
291
 
292
  public function getEventData( $eventType, $args = null ) {
293
-
294
- if ( ! $this->configured() ) {
295
- return false;
296
- }
297
- $data = false;
298
- switch ( $eventType ) {
299
-
300
- case 'woo_add_to_cart_on_button_click':
301
- $data = $this->getWooAddToCartOnButtonClickEventParams( $args );break;
302
 
303
- case 'edd_add_to_cart_on_button_click':
304
- $data = $this->getEddAddToCartOnButtonClickEventParams( $args );break;
305
-
306
- }
307
-
308
- return $data;
309
  }
310
 
311
  public function outputNoScriptEvents() {
@@ -347,13 +344,17 @@ class GA extends Settings implements Pixel {
347
  if ( isset( $event['params']['items'] ) ) {
348
 
349
  foreach ( $event['params']['items'] as $key => $item ) {
350
-
351
- @$args["pr{$key}id" ] = urlencode( $item['id'] );
352
- @$args["pr{$key}nm"] = urlencode( $item['name'] );
353
- @$args["pr{$key}ca"] = urlencode( $item['category'] );
 
 
354
  //@$args["pr{$key}va"] = urlencode( $item['id'] ); // variant
355
- @$args["pr{$key}pr"] = urlencode( $item['price'] );
356
- @$args["pr{$key}qt"] = urlencode( $item['quantity'] );
 
 
357
 
358
  }
359
 
@@ -632,12 +633,16 @@ class GA extends Settings implements Pixel {
632
 
633
  }
634
 
635
- private function getWooRemoveFromCartParams( $cart_item ) {
 
 
 
 
636
 
637
  if ( ! $this->getOption( 'woo_remove_from_cart_enabled' ) ) {
638
  return false;
639
  }
640
-
641
  $product_id = $cart_item['product_id'];
642
 
643
  $product = wc_get_product( $product_id );
@@ -659,24 +664,27 @@ class GA extends Settings implements Pixel {
659
  $categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
660
  }
661
 
662
- return array(
663
- 'data' => array(
664
- 'event_category' => 'ecommerce',
665
- 'currency' => get_woocommerce_currency(),
666
- 'items' => array(
667
- array(
668
- 'id' => $product_id,
669
- 'name' => $name,
670
- 'category' => $categories,
671
- 'quantity' => $cart_item['quantity'],
672
- 'price' => getWooProductPriceToDisplay( $product_id, $cart_item['quantity'] ),
673
- 'variant' => $variation_name,
674
- ),
675
- ),
676
- 'non_interaction' => $this->getOption( 'woo_remove_from_cart_non_interactive' ),
677
- ),
678
- );
 
 
679
 
 
680
  }
681
 
682
  private function getWooInitiateCheckoutEventParams() {
@@ -877,11 +885,6 @@ class GA extends Settings implements Pixel {
877
  }
878
 
879
  private function getEddAddToCartOnButtonClickEventParams( $download_id ) {
880
-
881
- if ( ! $this->getOption( 'edd_add_to_cart_enabled' ) || ! PYS()->getOption( 'edd_add_to_cart_on_button_click' ) ) {
882
- return false;
883
- }
884
-
885
  // maybe extract download price id
886
  if ( strpos( $download_id, '_') !== false ) {
887
  list( $download_id, $price_index ) = explode( '_', $download_id );
@@ -905,9 +908,7 @@ class GA extends Settings implements Pixel {
905
  'non_interaction' => $this->getOption( 'edd_add_to_cart_non_interactive' ),
906
  );
907
 
908
- return array(
909
- 'params' => $params,
910
- );
911
 
912
  }
913
 
@@ -1023,6 +1024,7 @@ class GA extends Settings implements Pixel {
1023
  $price_index = ! empty( $cart_item['options'] ) ? $cart_item['options']['price_id'] : null;
1024
 
1025
  return array(
 
1026
  'data' => array(
1027
  'event_category' => 'ecommerce',
1028
  'currency' => edd_get_currency(),
105
  'disableAdvertisingPersonalization' => $this->getOption( 'disable_advertising_personalization' ),
106
  'wooVariableAsSimple' => $this->getOption( 'woo_variable_as_simple' )
107
  );
108
+ }
109
+ /**
110
+ * Create pixel event and fill it
111
+ * @param SingleEvent $event
112
+ * @return SingleEvent[]
113
+ */
114
+ public function generateEvents($event) {
115
+ $pixelEvents = [];
116
+ if ( ! $this->configured() ) {
117
+ return [];
118
+ }
119
+
120
+ $pixelIds = $this->getPixelIDs();
121
+
122
+ if(count($pixelIds) > 0) {
123
+ $pixelEvent = clone $event;
124
+ if($this->addParamsToEvent($pixelEvent)) {
125
+ $pixelEvent->addPayload([ 'trackingIds' => $pixelIds ]);
126
+ $pixelEvents[] = $pixelEvent;
127
+ }
128
+ }
129
 
130
+ return $pixelEvents;
131
  }
132
+
133
  //refactor it
134
  private function addDataToEvent($eventData,&$event) {
135
  $params = $eventData["data"];
193
  }
194
  }break;
195
  case 'woo_remove_from_cart':{
196
+ $isActive = $this->getWooRemoveFromCartParams( $event );
197
+
 
 
 
 
 
 
 
 
 
198
  }break;
199
  case 'woo_initiate_checkout':{
200
  $eventData = $this->getWooInitiateCheckoutEventParams();
233
  }
234
  }break;
235
  case 'edd_remove_from_cart': {
236
+ $eventData = $this->getEddRemoveFromCartParams( $event->args['item'] );
237
+ if ($eventData) {
238
+ $isActive = true;
239
+ $this->addDataToEvent($eventData, $event);
 
 
 
 
 
 
240
  }
 
241
  }break;
242
 
243
  case 'edd_view_category': {
285
  case 'edd_add_to_cart_on_button_click': {
286
  if ( $this->getOption( 'edd_add_to_cart_enabled' ) && PYS()->getOption( 'edd_add_to_cart_on_button_click' ) ) {
287
  $isActive = true;
288
+ if($event->args != null) {
289
+ $eventData = $this->getEddAddToCartOnButtonClickEventParams( $event->args );
290
+ $event->addParams($eventData);
291
+ }
292
  $event->addPayload(array(
293
  'name'=>"add_to_cart"
294
  ));
301
 
302
 
303
  public function getEventData( $eventType, $args = null ) {
 
 
 
 
 
 
 
 
 
304
 
305
+ return false;
 
 
 
 
 
306
  }
307
 
308
  public function outputNoScriptEvents() {
344
  if ( isset( $event['params']['items'] ) ) {
345
 
346
  foreach ( $event['params']['items'] as $key => $item ) {
347
+ if(isset($item['id']))
348
+ @$args["pr{$key}id" ] = urlencode( $item['id'] );
349
+ if(isset($item['name']))
350
+ @$args["pr{$key}nm"] = urlencode( $item['name'] );
351
+ if(isset($item['category']))
352
+ @$args["pr{$key}ca"] = urlencode( $item['category'] );
353
  //@$args["pr{$key}va"] = urlencode( $item['id'] ); // variant
354
+ if(isset($item['price']))
355
+ @$args["pr{$key}pr"] = urlencode( $item['price'] );
356
+ if(isset($item['quantity']))
357
+ @$args["pr{$key}qt"] = urlencode( $item['quantity'] );
358
 
359
  }
360
 
633
 
634
  }
635
 
636
+ /**
637
+ * @param SingleEvent $event
638
+ * @return bool
639
+ */
640
+ private function getWooRemoveFromCartParams( $event ) {
641
 
642
  if ( ! $this->getOption( 'woo_remove_from_cart_enabled' ) ) {
643
  return false;
644
  }
645
+ $cart_item = $event->args['item'];
646
  $product_id = $cart_item['product_id'];
647
 
648
  $product = wc_get_product( $product_id );
664
  $categories = implode( '/', getObjectTerms( 'product_cat', $product_id ) );
665
  }
666
 
667
+ $data = [
668
+ 'name' => "remove_from_cart"
669
+ ];
670
+ $params = [
671
+ 'event_category' => 'ecommerce',
672
+ 'currency' => get_woocommerce_currency(),
673
+ 'items' => array(
674
+ array(
675
+ 'id' => $product_id,
676
+ 'name' => $name,
677
+ 'category' => $categories,
678
+ 'quantity' => $cart_item['quantity'],
679
+ 'price' => getWooProductPriceToDisplay( $product_id, $cart_item['quantity'] ),
680
+ 'variant' => $variation_name,
681
+ ),
682
+ ),
683
+ 'non_interaction' => $this->getOption( 'woo_remove_from_cart_non_interactive' ),];
684
+ $event->addParams($params);
685
+ $event->addPayload($data);
686
 
687
+ return true;
688
  }
689
 
690
  private function getWooInitiateCheckoutEventParams() {
885
  }
886
 
887
  private function getEddAddToCartOnButtonClickEventParams( $download_id ) {
 
 
 
 
 
888
  // maybe extract download price id
889
  if ( strpos( $download_id, '_') !== false ) {
890
  list( $download_id, $price_index ) = explode( '_', $download_id );
908
  'non_interaction' => $this->getOption( 'edd_add_to_cart_non_interactive' ),
909
  );
910
 
911
+ return $params;
 
 
912
 
913
  }
914
 
1024
  $price_index = ! empty( $cart_item['options'] ) ? $cart_item['options']['price_id'] : null;
1025
 
1026
  return array(
1027
+ 'name' => 'remove_from_cart',
1028
  'data' => array(
1029
  'event_category' => 'ecommerce',
1030
  'currency' => edd_get_currency(),
pixelyoursite.php CHANGED
@@ -4,7 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) {
4
  exit; // Exit if accessed directly.
5
  }
6
 
7
- define( 'PYS_FREE_VERSION', '8.2.13' );
8
  define( 'PYS_FREE_PINTEREST_MIN_VERSION', '3.0.0' );
9
  define( 'PYS_FREE_BING_MIN_VERSION', '2.0.0' );
10
  define( 'PYS_FREE_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
4
  exit; // Exit if accessed directly.
5
  }
6
 
7
+ define( 'PYS_FREE_VERSION', '8.2.14' );
8
  define( 'PYS_FREE_PINTEREST_MIN_VERSION', '3.0.0' );
9
  define( 'PYS_FREE_BING_MIN_VERSION', '2.0.0' );
10
  define( 'PYS_FREE_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: Facebook Pixel, Facebook Conversion API, CAPI, Facebook Pixel Events, Face
4
  Requires at least: 3.0.1
5
  Requires PHP: 5.4
6
  Tested up to: 5.8
7
- Stable tag: 8.2.13
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -460,6 +460,14 @@ NO, absolutely not! We don't track any type of data about your website. We simpl
460
  == Changelog ==
461
 
462
 
 
 
 
 
 
 
 
 
463
  = PixelYourSite 8.2.13 =
464
 
465
  * Small UI changes to reflect TikTok Tag support with PixelYourSite Professional.
4
  Requires at least: 3.0.1
5
  Requires PHP: 5.4
6
  Tested up to: 5.8
7
+ Stable tag: 8.2.14
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
460
  == Changelog ==
461
 
462
 
463
+ = PixelYourSite 8.2.14 =
464
+
465
+ * Code refactoring to ensure compatibility with our extra add-ons.
466
+
467
+ * Code changes to ensure full compatibility with ConsentMagic.com.
468
+
469
+
470
+
471
  = PixelYourSite 8.2.13 =
472
 
473
  * Small UI changes to reflect TikTok Tag support with PixelYourSite Professional.