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

Version Description

Download this release

Release Info

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

Code changes from version 5.0.7 to 5.0.8

facebook-pixel-master.php CHANGED
@@ -1,63 +1,63 @@
1
- <?php
2
- /*
3
- Plugin Name: PixelYourSite
4
- Description: Add the Facebook Pixel code into your Wordpress site and set up standard events with just a few clicks. Fully compatible with Woocommerce, purchase event included.
5
- Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
- Author: PixelYourSite
7
- Author URI: http://www.pixelyoursite.com
8
- Version: 5.0.7
9
- License: GPLv3
10
- */
11
-
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit; // Exit if accessed directly.
14
- }
15
-
16
- define( 'PYS_FREE_VERSION', '5.0.7' );
17
-
18
- if ( ! function_exists( 'pys_is_pixelyoursite_pro_active' ) ) {
19
-
20
- /**
21
- * Check whatever PixelYourSite PRO version activated.
22
- *
23
- * @return bool
24
- */
25
- function pys_is_pixelyoursite_pro_active() {
26
-
27
- if ( ! function_exists( 'is_plugin_active' ) ) {
28
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
29
- }
30
-
31
- return is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' );
32
-
33
- }
34
-
35
- }
36
-
37
- if ( ! function_exists( 'pys_free_plugin_activated' ) ) {
38
-
39
- register_activation_hook( __FILE__, 'pys_free_plugin_activated' );
40
- function pys_free_plugin_activated() {
41
-
42
- if ( pys_is_pixelyoursite_pro_active() ) {
43
- wp_die( 'Please deactivate PixelYourSite PRO version first.', 'Plugin Activation', array(
44
- 'back_link' => true,
45
- ) );
46
- }
47
-
48
- $options = get_option( 'pixel_your_site' );
49
-
50
- if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
51
-
52
- require_once 'inc/general.php';
53
- pys_initialize_settings();
54
-
55
- }
56
-
57
- }
58
-
59
- }
60
-
61
- if ( ! pys_is_pixelyoursite_pro_active() ) {
62
- require_once 'inc/general.php';
63
  }
1
+ <?php
2
+ /*
3
+ Plugin Name: PixelYourSite
4
+ Description: Add the Facebook Pixel code into your Wordpress site and set up standard events with just a few clicks. Fully compatible with Woocommerce, purchase event included.
5
+ Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
+ Author: PixelYourSite
7
+ Author URI: http://www.pixelyoursite.com
8
+ Version: 5.0.8
9
+ License: GPLv3
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit; // Exit if accessed directly.
14
+ }
15
+
16
+ define( 'PYS_FREE_VERSION', '5.0.8' );
17
+
18
+ if ( ! function_exists( 'pys_is_pixelyoursite_pro_active' ) ) {
19
+
20
+ /**
21
+ * Check whatever PixelYourSite PRO version activated.
22
+ *
23
+ * @return bool
24
+ */
25
+ function pys_is_pixelyoursite_pro_active() {
26
+
27
+ if ( ! function_exists( 'is_plugin_active' ) ) {
28
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
29
+ }
30
+
31
+ return is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' );
32
+
33
+ }
34
+
35
+ }
36
+
37
+ if ( ! function_exists( 'pys_free_plugin_activated' ) ) {
38
+
39
+ register_activation_hook( __FILE__, 'pys_free_plugin_activated' );
40
+ function pys_free_plugin_activated() {
41
+
42
+ if ( pys_is_pixelyoursite_pro_active() ) {
43
+ wp_die( 'Please deactivate PixelYourSite PRO version first.', 'Plugin Activation', array(
44
+ 'back_link' => true,
45
+ ) );
46
+ }
47
+
48
+ $options = get_option( 'pixel_your_site' );
49
+
50
+ if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
51
+
52
+ require_once 'inc/general.php';
53
+ pys_initialize_settings();
54
+
55
+ }
56
+
57
+ }
58
+
59
+ }
60
+
61
+ if ( ! pys_is_pixelyoursite_pro_active() ) {
62
+ require_once 'inc/general.php';
63
  }
inc/admin_notices_content.php CHANGED
@@ -12,35 +12,35 @@ $GLOBALS['PYS_FREE_WOO_NOTICES'] = array(
12
  array(
13
  'from' => 1,
14
  'to' => 1,
15
- 'content' => '<strong>Customize WooCommerce Conversion Value:</strong> With PixelYourSite Pro you can <strong>fine tune WooCommerce Events Values</strong> and improve conversion tracking. Include/Exclude Tax or Shipping, turn ON/OFF and fine-tune WooCommerce Events Value (full product price, price percent or a global value). Advance Purchase Event with super-useful parameters for Custom Audiences and retargeting.<br><a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-woo1" target="_blank"><strong>Click to download PixelYourSite Pro for a serious discount</strong></a>.',
16
  'visible' => true
17
  ),
18
 
19
  array(
20
  'from' => 2,
21
  'to' => 2,
22
- 'content' => '<strong>PixelYourSite PRO + Product Catalog Feed Plugin Bundle:</strong> Track Conversion Value and start with Facebook Dynamic Ads for WooCommerce in minutes. <br>Get <strong>PixelYourSite Pro</strong> (<em>fine tune Conversion Value</em>, optimize WooCommerce events for Custom Audiences, track tags, product tags, <strong>Traffic Source</strong> and UTM, enable Advanced Matching and use <em>Dynamic Events</em>)<br>Get <strong>Product Catalog Feed Plugin</strong> (create WooCommerce Dynamic Ads Product Catalog XML feeds)<br><a href="http://www.pixelyoursite.com/bundle-offer?utm_source=wp-woo-bundle&utm_medium=wp&utm_campaign=wp-woo-bundle2" target="_blank"><strong>Click For The Bundle Offer (best deal)</strong></a>.',
23
  'visible' => true
24
  ),
25
 
26
  array(
27
  'from' => 3,
28
  'to' => 3,
29
- 'content' => '<strong>Secret Offer for WordPress Users: </strong> Get PixelYourSite PRO for WooCommerce with <a href="http://www.pixelyoursite.com/secret-offer?utm_source=wp-secret-offer-woo&utm_medium=wp&utm_campaign=secret-offer-woo3" target="_blank">this Exclusive Secret Offer</a>.',
30
  'visible' => true
31
  ),
32
 
33
  array(
34
  'from' => 4,
35
  'to' => 7,
36
- 'content' => '<strong>PixelYourSite PRO Secret Offer:</strong> With PixelYourSite PRO you can build super-powerful Custom Audiences for improved retargeting. Track <strong>Traffic Source</strong> and <strong>URL Parameters,</strong> product name, category and tags, or the use of coupons. Enable <strong>Advanced Matching</strong> for better conversion attribution.<br><a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wp-secret-offer-woo&utm_medium=wp&utm_campaign=secret-offer-woo4-7" target="_blank">Discover Your Secret Offer</a>.',
37
  'visible' => true
38
  ),
39
 
40
  array(
41
  'from' => 8,
42
  'to' => 12,
43
- 'content' => '<strong>Your Facebook Pixel FREE Guide:</strong> After <em>more than 25 000 users</em> and many hours spent on answering questions, we decided to make a comprehensive guide about the new Facebook Pixel. <br>Have you got it yet? <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wp-pixel-guide&utm_medium=wp&utm_campaign=wp-pixel-guide" target="_blank">Click here for your own FREE copy</a>.',
44
  'visible' => true
45
  ),
46
 
@@ -52,35 +52,35 @@ $GLOBALS['PYS_FREE_EDD_NOTICES'] = array(
52
  array(
53
  'from' => 1,
54
  'to' => 1,
55
- 'content' => '<strong>Customize Easy Digital Downloads Conversion Value:</strong> With PixelYourSite Pro you can <strong>fine tune EDD Events Values</strong> and improve conversion tracking. Include/Exclude Tax, turn ON/OFF and fine-tune EDD Events Value (full product price, price percent or a global value). Advance Purchase Event with super-useful parameters for Custom Audiences and retargeting.<br><a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpa-edd&utm_medium=wp&utm_campaign=wp-edd1" target="_blank"><strong>Click to download PixelYourSite Pro for a serious discount</strong></a>.',
56
  'visible' => true
57
  ),
58
 
59
  array(
60
  'from' => 2,
61
  'to' => 2,
62
- 'content' => '<strong>Secret Offer for WordPress Users:</strong> Get PixelYourSite PRO for Easy Digital Downloads with this exclusive secret offer: <a href="http://www.pixelyoursite.com/secret-offer?utm_source=wp-secret-offer-edd&utm_medium=wp&utm_campaign=secret-offer-edd2" target="_blank">this Exclusive Secret Offer</a>.',
63
  'visible' => true
64
  ),
65
 
66
  array(
67
  'from' => 3,
68
  'to' => 3,
69
- 'content' => '<strong>PixelYourSite PRO Secret Offer:</strong> With PixelYourSite PRO you can build super-powerful EDD Custom Audiences for improved retargeting. Track <strong>Traffic Source</strong> and <strong>URL Parameters,</strong> product name, category and tags, or the use of discount codes. Enable <strong>Advanced Matching</strong> for better conversion attribution.<br><a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wp-secret-offer-edd&utm_medium=wp&utm_campaign=secret-offer-edd3" target="_blank">Discover Your Secret Offer</a>.',
70
  'visible' => true
71
  ),
72
 
73
  array(
74
  'from' => 4,
75
  'to' => 7,
76
- 'content' => '<strong>Your Facebook Pixel FREE Guide:</strong> After <em>more than 25 000 users</em> and many hours spent on answering questions, we decided to make a comprehensive guide about the new Facebook Pixel.</br>Have you got it yet? <strong>Download it now for free:</strong> <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wp-pixel-guide&utm_medium=wp&utm_campaign=wp-pixel-guide" target="_blank">Click here for your Guide</a>.',
77
  'visible' => true
78
  ),
79
 
80
  array(
81
  'from' => 8,
82
  'to' => 12,
83
- 'content' => '<strong>PixelYourSite PRO Secret Offer:</strong> Get your FREE guide about the new Facebook Pixel, because it will help you to make better ads.</br> Make sure you read it too: <a href="http://www.pixelyoursite.com/secret-offer?utm_source=wp-secret-offer-edd&utm_medium=wp&utm_campaign=secret-offer-edd7-12" target="_blank">Click to find more</a>.',
84
  'visible' => true
85
  ),
86
 
@@ -92,35 +92,35 @@ $GLOBALS['PYS_FREE_NO_WOO_NO_EDD_NOTICES'] = array(
92
  array(
93
  'from' => 1,
94
  'to' => 1,
95
- 'content' => '<strong>Upgrade to PixelYourSite PRO</strong> and optimize your FB ads for clicks on links or buttons with <strong>Dynamic Events</strong>. Improve conversion attribution and retargeting reach by using <strong>Advanced Matching</strong>. Track the <strong>Traffic Source</strong> and URL parameters (UTM) for better retargeting with Custom Audiences. Don’t miss this limited discount:<br> <a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wp-non-woo-non-edd&utm_medium=wp&utm_campaign=wp1" target="_blank"><strong>Click to download PixelYourSite Pro for a serious discount</strong></a>.',
96
  'visible' => true
97
  ),
98
 
99
  array(
100
  'from' => 2,
101
  'to' => 2,
102
- 'content' => '<strong>Secret Offer for WordPress Users:</strong> Upgrade to PixelYourSite PRO with <a href="http://www.pixelyoursite.com/secret-offer?utm_source=wp-secret-offer-non-woo-non-edd&utm_medium=wp&utm_campaign=secret-offer-wp2" target="_blank">this Exclusive Secret Offer</a>.',
103
  'visible' => true
104
  ),
105
 
106
  array(
107
  'from' => 3,
108
  'to' => 3,
109
- 'content' => '<strong>PixelYourSite Secret Offer:</strong> Optimize your FB ads for key actions on your site wit Dynamic Events (fired on clicks, page scroll, or mouse over). Create super-powerful Custom Audiences based on Traffic Source or URL Parameters - <a href="http://www.pixelyoursite.com/secret-offer?utm_source=wp-secret-offer-non-woo-non-edd&utm_medium=wp&utm_campaign=secret-offer-wp3" target="_blank">Discover Your Secret Offer</a>.',
110
  'visible' => true
111
  ),
112
 
113
  array(
114
  'from' => 4,
115
  'to' => 7,
116
- 'content' => '<strong>Your Facebook Pixel FREE Guide:</strong> After <em>more than 25 000 users</em> and many hours spent on answering questions, we decided to make a comprehensive guide about the new Facebook Pixel.</br>Have you got it yet? <strong>Download it now for free:</strong> <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wp-pixel-guide&utm_medium=wp&utm_campaign=wp-pixel-guide" target="_blank">Click here for your Guide</a>.',
117
  'visible' => true
118
  ),
119
 
120
  array(
121
  'from' => 8,
122
  'to' => 12,
123
- 'content' => '<strong>PixelYourSite FREE Guide:</strong> Get your FREE guide about the new Facebook Pixel, because it will help you to make better ads.</br> Make sure you read it too: <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wp-pixel-guide&utm_medium=wp&utm_campaign=wp-pixel-guide" target="_blank">Download it now for free</a>.',
124
  'visible' => true
125
  ),
126
 
12
  array(
13
  'from' => 1,
14
  'to' => 1,
15
+ 'content' => '<strong>Customize WooCommerce Conversion Value:</strong> With PixelYourSite Pro you can fine-tune WooCommerce Events Values. This can improve your Facebook ads delivery and ROI: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/woocommerce-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-woo1" target="_blank"><strong>FIND MORE</strong></a>',
16
  'visible' => true
17
  ),
18
 
19
  array(
20
  'from' => 2,
21
  'to' => 2,
22
+ 'content' => 'Our expert users have improved their Facebook ads ROI by <strong>fine-tuning WooCommerce events value</strong> (using a price percent). This is one of the many PixelYourSite Pro killer options: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/woocommerce-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-woo2" target="_blank"><strong>FIND MORE</strong></a>',
23
  'visible' => true
24
  ),
25
 
26
  array(
27
  'from' => 3,
28
  'to' => 3,
29
+ 'content' => 'Reach new clients with Lifetime Value (LTV) Lookalikes. With PixelYourSite Pro, you can export an <strong>LTV customers file</strong> and use it for LTV Lookalikes (Facebook recommended strategy): <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/woocommerce-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-woo3" target="_blank"><strong>FIND MORE</strong></a>',
30
  'visible' => true
31
  ),
32
 
33
  array(
34
  'from' => 4,
35
  'to' => 7,
36
+ 'content' => 'PixelYourSite: our pro users are able to do some <strong>extraordinary remarketing campaigns</strong> using all the parameters that the pro version tracks: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/woocommerce-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-woo4" target="_blank"><strong>FIND MORE</strong></a>',
37
  'visible' => true
38
  ),
39
 
40
  array(
41
  'from' => 8,
42
  'to' => 12,
43
+ 'content' => '<strong>Your Facebook Pixel FREE Guide by PixelYourSite:</strong> After <em>more than 65 000 users</em> and many hours spent on answering questions, we decided to make a comprehensive guide about the Facebook Pixel. <br>Have you got it yet? <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wp-pixel-guide&utm_medium=wp&utm_campaign=wp-pixel-guide-woo" target="_blank">Click here for your own FREE copy</a>',
44
  'visible' => true
45
  ),
46
 
52
  array(
53
  'from' => 1,
54
  'to' => 1,
55
+ 'content' => '<strong>Customize EDD Conversion Value:</strong> With PixelYourSite Pro you can <strong>fine tune EDD Events Values</strong>. This can improve your ads delivery and ROI. <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/easy-digital-downloads-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-edd1" target="_blank"><strong>FIND MORE</strong></a>',
56
  'visible' => true
57
  ),
58
 
59
  array(
60
  'from' => 2,
61
  'to' => 2,
62
+ 'content' => 'Our expert users have improved their Facebook ads ROI by <strong>fine-tuning EDD events value</strong> (using a price percent). This is one of the many pro version options: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/easy-digital-downloads-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-edd2" target="_blank"><strong>FIND MORE</strong></a>',
63
  'visible' => true
64
  ),
65
 
66
  array(
67
  'from' => 3,
68
  'to' => 3,
69
+ 'content' => 'Reach new clients with Lifetime Value (LTV) Lookalikes. With PixelYourSite Pro, you can export an <strong>LTV customers file</strong> and use it for LTV Lookalikes (Facebook recommended strategy): <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/easy-digital-downloads-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-edd3" target="_blank"><strong>FIND MORE</strong></a>',
70
  'visible' => true
71
  ),
72
 
73
  array(
74
  'from' => 4,
75
  'to' => 7,
76
+ 'content' => 'Fire the Purchase event on transaction only to improve conversion tracking. This way, when a client revisits the "thank you page" it will not mess up your ads reports: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/easy-digital-downloads-facebook-pixel?utm_source=wpa-woo&utm_medium=wp&utm_campaign=wp-edd4" target="_blank"><strong>FIND MORE</strong></a>',
77
  'visible' => true
78
  ),
79
 
80
  array(
81
  'from' => 8,
82
  'to' => 12,
83
+ 'content' => '<strong>Your Facebook Pixel FREE Guide by PixelYourSite:</strong> After <em>more than 65 000 users</em> and many hours spent on answering questions, we decided to make a comprehensive guide about the Facebook Pixel. <br>Have you got it yet? <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wp-pixel-guide&utm_medium=wp&utm_campaign=wp-pixel-guide-edd" target="_blank">Click here for your own FREE copy</a>',
84
  'visible' => true
85
  ),
86
 
92
  array(
93
  'from' => 1,
94
  'to' => 1,
95
+ 'content' => 'Most PixelYourSite Pro users are doing some incredible <strong>retargeting campaings</strong> using our Custom Audiences optimization features: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/custom-audiences-conversions?utm_source=wp1-non-woo-non-edd&utm_medium=wp&utm_campaign=wp1" target="_blank">Find out how the pro version can help you</a>',
96
  'visible' => true
97
  ),
98
 
99
  array(
100
  'from' => 2,
101
  'to' => 2,
102
+ 'content' => 'PixelYourSite: Our most succesful clients use <strong>Dynamic Events</strong> for ads optimization and retargeting campaigns: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/facebook-pixel-events?utm_source=wp2-non-woo-non-edd&utm_medium=wp&utm_campaign=wp2" target="_blank">FIND MORE</a>',
103
  'visible' => true
104
  ),
105
 
106
  array(
107
  'from' => 3,
108
  'to' => 3,
109
+ 'content' => '<strong>The WatchVideo Event:</strong> optimize your ads and retarget embedded videos with this super-useful PixelYourSite Pro feature: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/watchvideo-event?utm_source=wp3-non-woo-non-edd&utm_medium=wp&utm_campaign=wp3" target="_blank">FIND MORE</a>',
110
  'visible' => true
111
  ),
112
 
113
  array(
114
  'from' => 4,
115
  'to' => 7,
116
+ 'content' => '<strong>The ClickEvent:</strong> Track every single click and use this event for Custom Audiences or Custom Conversions. This is a PixelYourSite Pro feature: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin/custom-audiences-conversions?utm_source=wp3-non-woo-non-edd&utm_medium=wp&utm_campaign=wp4" target="_blank">FIND MORE</a>',
117
  'visible' => true
118
  ),
119
 
120
  array(
121
  'from' => 8,
122
  'to' => 12,
123
+ 'content' => '<strong>Your Facebook Pixel FREE Guide by PixelYourSite:</strong> After <em>more than 65 000 users</em> and many hours spent on answering questions, we decided to make a comprehensive guide about the Facebook Pixel. <br>Have you got it yet? <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wp-pixel-guide&utm_medium=wp&utm_campaign=wp-pixel-guide-no-woo-no-edd" target="_blank">Click here for your own FREE copy</a>',
124
  'visible' => true
125
  ),
126
 
inc/common.php CHANGED
@@ -1,1509 +1,1511 @@
1
- <?php
2
- /**
3
- * Common functions for both versions.
4
- */
5
-
6
- if ( ! defined( 'ABSPATH' ) ) {
7
- exit; // Exit if accessed directly.
8
- }
9
-
10
- /**
11
- * Check if WooCommerce plugin is installed and activated.
12
- */
13
- if( !function_exists( 'pys_is_woocommerce_active' ) ) {
14
-
15
- function pys_is_woocommerce_active() {
16
- return class_exists( 'WooCommerce' ) == true ? true : false;
17
- }
18
-
19
- }
20
-
21
- /**
22
- * Check if Easy Digital Downloads plugin is installed and activated.
23
- */
24
- if( !function_exists( 'pys_is_edd_active' ) ) {
25
-
26
- function pys_is_edd_active() {
27
- return class_exists( 'Easy_Digital_Downloads' ) == true ? true : false;
28
- }
29
-
30
- }
31
-
32
- if ( ! function_exists( 'pys_is_pcf_pro_active' ) ) {
33
-
34
- function pys_is_pcf_pro_active() {
35
- return class_exists( 'wpwoof_product_catalog' ) == true ? true : false;
36
- }
37
-
38
- }
39
-
40
- if( !function_exists( 'pys_get_option' ) ) {
41
-
42
- /**
43
- * Return option value.
44
- *
45
- * @param string $section Options section, eg. 'general', 'woo', etc.
46
- * @param string $option Option name
47
- * @param mixed|string $default Default option value
48
- *
49
- * @return mixed Option or default option value
50
- */
51
- function pys_get_option( $section, $option, $default = '' ) {
52
-
53
- $options = get_option( 'pixel_your_site' );
54
-
55
- return isset( $options[ $section ][ $option ] ) ? $options[ $section ][ $option ] : $default;
56
-
57
- }
58
-
59
- }
60
-
61
- if( !function_exists( 'pys_checkbox_state' ) ) {
62
-
63
- /**
64
- * @param string $section Option section name
65
- * @param string $option Option name
66
- * @param bool $echo Echo or return value
67
- * @param int $checked Value to state compare
68
- *
69
- * @return string
70
- */
71
- function pys_checkbox_state( $section, $option, $echo = true, $checked = 1 ) {
72
-
73
- $options = get_option( 'pixel_your_site' );
74
-
75
- if ( isset( $options[ $section ][ $option ] ) ) {
76
- $value = $options[ $section ][ $option ] == $checked ? 'checked' : '';
77
- } else {
78
- $value = '';
79
- }
80
-
81
- if( $echo ) {
82
- echo $value;
83
- }
84
-
85
- return $value;
86
-
87
- }
88
-
89
- }
90
-
91
- if ( ! function_exists( 'pys_checkbox' ) ) {
92
-
93
- /**
94
- * Echos checkbox input.
95
- *
96
- * @param string $section Input section name
97
- * @param string $option Input option name
98
- * @param string $classes Class names (optional)
99
- * @param int $value Input value (optional)
100
- */
101
- function pys_checkbox( $section, $option, $classes = '', $value = 1 ) {
102
-
103
- $state = pys_checkbox_state( $section, $option, false, $value );
104
- $value = esc_attr( $value );
105
-
106
- echo "<input type='checkbox' value='$value' name='pys[$section][$option]' class='$classes' $state>";
107
-
108
- }
109
-
110
- }
111
-
112
- if ( ! function_exists( 'pys_text_field' ) ) {
113
-
114
- /**
115
- * Echos text input.
116
- *
117
- * @param string $section Input section name
118
- * @param string $option Input option name
119
- */
120
- function pys_text_field( $section, $option ) {
121
-
122
- $value = pys_get_option( $section, $option );
123
- $value = esc_attr( $value );
124
-
125
- echo "<input type='text' value='$value' name='pys[$section][$option]'>";
126
-
127
- }
128
-
129
- }
130
-
131
- if ( ! function_exists( 'pys_radio_box' ) ) {
132
-
133
- /**
134
- * Echos radio box input.
135
- *
136
- * @param string $section Input section name
137
- * @param string $option Input option name
138
- * @param string $value Option value
139
- */
140
- function pys_radio_box( $section, $option, $value ) {
141
-
142
- $state = pys_radio_state( $section, $option, $value );
143
- echo "<input type='radio' value='$value' name='pys[$section][$option]' $state>";
144
-
145
- }
146
-
147
- }
148
-
149
- /**
150
- * Return radio box state.
151
- */
152
- if( !function_exists( 'pys_radio_state' ) ) {
153
-
154
- function pys_radio_state( $section, $option, $value ) {
155
-
156
- $options = get_option( 'pixel_your_site' );
157
-
158
- if ( isset( $options[ $section ][ $option ] ) ) {
159
-
160
- return $options[ $section ][ $option ] == $value ? 'checked' : '';
161
-
162
- } else {
163
-
164
- $defaults = pys_get_default_options();
165
- return $defaults[ $section ][ $option ] == $value ? 'checked' : '';
166
-
167
- }
168
-
169
- }
170
-
171
- }
172
-
173
- /**
174
- * Facebook Pixel Event types options html.
175
- */
176
- if( !function_exists( 'pys_event_types_select_options' ) ) {
177
-
178
- function pys_event_types_select_options( $current = null, $full = true ) {
179
- ?>
180
-
181
- <option <?php selected( null, $current ); ?> disabled>Select Type</option>
182
- <option <?php selected( 'ViewContent', $current ); ?> value="ViewContent">ViewContent</option>
183
-
184
- <?php if ( $full ) : ?>
185
-
186
- <option <?php selected( 'Search', $current ); ?> value="Search">Search</option>
187
-
188
- <?php endif; ?>
189
-
190
- <option <?php selected( 'AddToCart', $current ); ?> value="AddToCart">AddToCart</option>
191
- <option <?php selected( 'AddToWishlist', $current ); ?> value="AddToWishlist">AddToWishlist</option>
192
- <option <?php selected( 'InitiateCheckout', $current ); ?> value="InitiateCheckout">InitiateCheckout</option>
193
- <option <?php selected( 'AddPaymentInfo', $current ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
194
- <option <?php selected( 'Purchase', $current ); ?> value="Purchase">Purchase</option>
195
- <option <?php selected( 'Lead', $current ); ?> value="Lead">Lead</option>
196
- <option <?php selected( 'CompleteRegistration', $current ); ?> value="CompleteRegistration">CompleteRegistration</option>
197
-
198
- <?php if ( $full ) : ?>
199
-
200
- <option disabled></option>
201
- <option <?php selected( 'CustomEvent', $current ); ?> value="CustomEvent">Custom event</option>
202
- <option <?php selected( 'CustomCode', $current); ?> value="CustomCode">Custom event code</option>
203
-
204
- <?php endif; ?>
205
-
206
- <?php
207
- }
208
-
209
- }
210
-
211
- /**
212
- * Current Page Full URL without trailing slash
213
- */
214
- if( !function_exists( 'pys_get_current_url' ) ) {
215
-
216
- function pys_get_current_url() {
217
-
218
- $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
219
- $current_url = rtrim( $current_url, '/' );
220
-
221
- return $current_url;
222
-
223
- }
224
-
225
- }
226
-
227
- /**
228
- * Returns relative path without protocol, host, slashes.
229
- */
230
- if( !function_exists( 'pys_get_relative_path' ) ) {
231
-
232
- function pys_get_relative_path( $url ) {
233
-
234
- $host = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', home_url() );
235
-
236
- $url = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', $url );
237
- $url = str_replace( $host, '', $url );
238
-
239
- $url = trim( $url );
240
- $url = ltrim( $url, '/' );
241
- $url = rtrim( $url, '/' );
242
-
243
- return $url;
244
-
245
- }
246
-
247
- }
248
-
249
- /**
250
- * Check if needle URL (full or relative) matches with current.
251
- */
252
- if( !function_exists( 'pys_match_url' ) ) {
253
-
254
- function pys_match_url( $match_url, $current_url = '' ) {
255
-
256
- // use current url by default
257
- if ( ! isset( $current_url ) || empty( $current_url ) ) {
258
- $current_url = pys_get_current_url();
259
- }
260
-
261
- $current_url = pys_get_relative_path( $current_url );
262
- $match_url = pys_get_relative_path( $match_url );
263
-
264
- if ( substr( $match_url, - 1 ) == '*' ) {
265
- // if match_url ends with wildcard
266
-
267
- $match_url = rtrim( $match_url, '*' );
268
-
269
- if ( pys_startsWith( $current_url, $match_url ) ) {
270
- return true;
271
- }
272
-
273
- } else {
274
- // exact url
275
-
276
- if ( $current_url == $match_url ) {
277
- return true;
278
- }
279
-
280
- }
281
-
282
- return false;
283
-
284
- }
285
-
286
- }
287
-
288
- if( !function_exists( 'pys_startsWith' ) ) {
289
-
290
- function pys_startsWith( $haystack, $needle ) {
291
- // search backwards starting from haystack length characters from the end
292
- return $needle === "" || strrpos( $haystack, $needle, - strlen( $haystack ) ) !== false;
293
- }
294
-
295
- }
296
-
297
- if( !function_exists( 'pys_endsWith' ) ) {
298
-
299
- function pys_endsWith( $haystack, $needle ) {
300
- // search forward starting from end minus needle length characters
301
- return $needle === "" || ( ( $temp = strlen( $haystack ) - strlen( $needle ) ) >= 0 && strpos( $haystack, $needle, $temp ) !== false );
302
- }
303
-
304
- }
305
-
306
- if( !function_exists( 'pys_currency_options' ) ) {
307
-
308
- function pys_currency_options( $current = 'USD' ) {
309
-
310
- $currencies = apply_filters( 'pys_currencies_list', array(
311
- 'AUD' => 'Australian Dollar',
312
- 'BRL' => 'Brazilian Real',
313
- 'CAD' => 'Canadian Dollar',
314
- 'CZK' => 'Czech Koruna',
315
- 'DKK' => 'Danish Krone',
316
- 'EUR' => 'Euro',
317
- 'HKD' => 'Hong Kong Dollar',
318
- 'HUF' => 'Hungarian Forint',
319
- 'IDR' => 'Indonesian Rupiah',
320
- 'ILS' => 'Israeli New Sheqel',
321
- 'JPY' => 'Japanese Yen',
322
- 'KRW' => 'Korean Won',
323
- 'MYR' => 'Malaysian Ringgit',
324
- 'MXN' => 'Mexican Peso',
325
- 'NOK' => 'Norwegian Krone',
326
- 'NZD' => 'New Zealand Dollar',
327
- 'PHP' => 'Philippine Peso',
328
- 'PLN' => 'Polish Zloty',
329
- 'RON' => 'Romanian Leu',
330
- 'GBP' => 'Pound Sterling',
331
- 'SGD' => 'Singapore Dollar',
332
- 'SEK' => 'Swedish Krona',
333
- 'CHF' => 'Swiss Franc',
334
- 'TWD' => 'Taiwan New Dollar',
335
- 'THB' => 'Thai Baht',
336
- 'TRY' => 'Turkish Lira',
337
- 'USD' => 'U.S. Dollar',
338
- 'ZAR' => 'South African Rands'
339
- ) );
340
-
341
- foreach( $currencies as $symbol => $name ) {
342
- echo '<option ' . selected( $symbol, $current, false ) . ' value="' . esc_attr( $symbol ) . '">' . esc_html( $name ) . '</option>';
343
- }
344
-
345
- }
346
-
347
- }
348
-
349
- /**
350
- * Extract Object taxonomies list.
351
- */
352
- if( !function_exists( 'pys_get_content_taxonomies' ) ) {
353
-
354
- function pys_get_content_taxonomies( $taxonomy = 'category', $post_id = null ) {
355
-
356
- $post_id = isset( $post_id ) ? $post_id : get_the_ID();
357
- $terms = get_the_terms( $post_id, $taxonomy );
358
-
359
- if ( is_wp_error( $terms ) || empty ( $terms ) ) {
360
- return false;
361
- }
362
-
363
- $list = array();
364
-
365
- foreach( $terms as $term ) {
366
- $list[ $term->term_id ] = html_entity_decode( $term->name );
367
- }
368
-
369
- return implode( ', ', $list );
370
-
371
- }
372
-
373
- }
374
-
375
- if( !function_exists( 'pys_add_event' ) ) {
376
-
377
- /**
378
- * Add event with params to global events list.
379
- *
380
- * @param string $event Event name, eg. "PageView"
381
- * @param array $params Optional. Associated array of event parameters in 'param_name' => 'param_value' format.
382
- * @param int $delay Optional. If set, event will be fired with desired delay in seconds.
383
- */
384
- function pys_add_event( $event, $params = array(), $delay = 0 ) {
385
- global $pys_events;
386
-
387
- $params = apply_filters( 'pys_event_params', $params, $event );
388
-
389
- $sanitized = array();
390
-
391
- // sanitize param names and its values
392
- foreach ( $params as $name => $value ) {
393
-
394
- // skip empty but not zero values
395
- if ( empty( $value ) && ! is_numeric( $value ) ) {
396
- continue;
397
- }
398
-
399
- $key = esc_js( $name );
400
- $sanitized[ $key ] = $value;
401
-
402
- }
403
-
404
- $pys_events[] = array(
405
- 'type' => pys_is_standard_event( $event ) ? 'track' : 'trackCustom',
406
- 'name' => $event,
407
- 'params' => $sanitized,
408
- 'delay' => $delay
409
- );
410
-
411
- }
412
-
413
- }
414
-
415
- if ( ! function_exists( 'pys_get_product_content_id' ) ) {
416
-
417
- /**
418
- * Return product id or sku.
419
- */
420
- function pys_get_product_content_id( $product_id ) {
421
-
422
- $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
423
-
424
- if ( pys_get_option( 'woo', 'content_id' ) == 'sku' ) {
425
- $content_id = get_post_meta( $product_id, '_sku', true );
426
- } else {
427
- $content_id = intval( $product_id );
428
- }
429
-
430
- return apply_filters( 'pys_fb_pixel_woo_product_content_id', array( $content_id ), $product_id,
431
- $content_id_format );
432
-
433
- }
434
-
435
- }
436
-
437
- if ( ! function_exists( 'pys_get_woo_cart_item_product_id' ) ) {
438
-
439
- /**
440
- * Return main or variation product id.
441
- */
442
- function pys_get_woo_cart_item_product_id( $cart_item ) {
443
-
444
- $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
445
-
446
- if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
447
- $product_id = $cart_item['variation_id'];
448
- } else {
449
- $product_id = $cart_item['product_id'];
450
- }
451
-
452
- return apply_filters( 'pys_fb_pixel_woo_cart_item_product_id', $product_id, $cart_item, $content_id_format );
453
-
454
- }
455
-
456
- }
457
-
458
- if ( ! function_exists( 'pys_insert_attribute' ) ) {
459
-
460
- /**
461
- * Add attribute with value to a HTML tag.
462
- *
463
- * @param string $attr_name Attribute name, eg. "class"
464
- * @param string $attr_value Attribute value
465
- * @param string $content HTML content where attribute should be inserted
466
- * @param bool $overwrite Override existing value of attribute or append it
467
- * @param string $tag Selector name, eg. "button". Default "a"
468
- *
469
- * @return string Modified HTML content
470
- */
471
- function pys_insert_attribute( $attr_name, $attr_value, $content, $overwrite = false, $tag = 'a' ) {
472
-
473
- ## do not modify js attributes
474
- if( $attr_name == 'on' ) {
475
- return $content;
476
- }
477
-
478
- $attr_value = trim( $attr_value );
479
-
480
- try {
481
-
482
- $doc = new DOMDocument();
483
-
484
- /**
485
- * Old libxml does not support options parameter.
486
- *
487
- * @since 3.2.0
488
- */
489
- if ( defined( 'LIBXML_DOTTED_VERSION' ) && version_compare( LIBXML_DOTTED_VERSION, '2.6.0', '>=' ) &&
490
- version_compare( phpversion(), '5.4.0', '>=' )
491
- ) {
492
- @$doc->loadHTML( '<?xml encoding="UTF-8">' . $content, LIBXML_NOEMPTYTAG );
493
- } else {
494
- @$doc->loadHTML( '<?xml encoding="UTF-8">' . $content );
495
- }
496
-
497
- /**
498
- * Select top-level tag if it is not specified in args.
499
- *
500
- * @since: 5.0.6
501
- */
502
- if ( $tag == 'any' ) {
503
-
504
- /** @var DOMNodeList $node */
505
- $node = $doc->getElementsByTagName( 'body' );
506
-
507
- if ( $node->length == 0 ) {
508
- throw new Exception( 'Empty or wrong tag passed to filter.' );
509
- }
510
-
511
- $node = $node->item( 0 )->childNodes->item( 0 );
512
-
513
- } else {
514
- $node = $doc->getElementsByTagName( $tag )->item( 0 );
515
- }
516
-
517
- if ( is_null( $node ) ) {
518
- return $content;
519
- }
520
-
521
- /** @noinspection PhpUndefinedMethodInspection */
522
- $attribute = $node->getAttribute( $attr_name );
523
-
524
- // add attribute or override old one
525
- if ( empty( $attribute ) || $overwrite ) {
526
-
527
- /** @noinspection PhpUndefinedMethodInspection */
528
- $node->setAttribute( $attr_name, $attr_value );
529
-
530
- return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
531
-
532
- }
533
-
534
- // append value to exist attribute
535
- if ( $overwrite == false ) {
536
-
537
- $value = $attribute . ' ' . $attr_value;
538
- /** @noinspection PhpUndefinedMethodInspection */
539
- $node->setAttribute( $attr_name, $value );
540
-
541
- return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
542
-
543
- }
544
-
545
- } catch ( Exception $e ) {
546
-
547
- error_log( $e );
548
-
549
- }
550
-
551
- return $content;
552
-
553
- }
554
-
555
- }
556
-
557
- if ( ! function_exists( 'pys_is_disabled_for_role' ) ) {
558
-
559
- function pys_is_disabled_for_role() {
560
-
561
- $options = get_option( 'pixel_your_site' );
562
- $disabled_roles = $options['general'];
563
-
564
- $user = wp_get_current_user();
565
- foreach ( (array) $user->roles as $role ) {
566
-
567
- if ( array_key_exists( "disable_for_$role", $disabled_roles ) ) {
568
-
569
- add_action( 'wp_head', 'pys_head_message', 1 );
570
- return true;
571
-
572
- }
573
-
574
- }
575
-
576
- if( empty( $user->roles ) && isset( $disabled_roles['disable_for_guest'] ) ) {
577
-
578
- add_action( 'wp_head', 'pys_head_message', 1 );
579
- return true;
580
-
581
- }
582
-
583
- return false;
584
-
585
- }
586
-
587
- }
588
-
589
- if( ! function_exists( 'pys_head_message' ) ) {
590
-
591
- /**
592
- * Output "disabled for role" and version number message to document head.
593
- */
594
- function pys_head_message() {
595
- echo "<!-- Facebook Pixel Code disabled for current role ( " . pys_get_version() . " ) -->\r\n";
596
- }
597
-
598
- }
599
-
600
- if( ! function_exists( 'pys_get_version' ) ) {
601
-
602
- function pys_get_version() {
603
-
604
- if( defined('PYS_PRO_VERSION') ) {
605
- $version = "PixelYourSite PRO v".PYS_PRO_VERSION;
606
- } elseif( defined('PYS_FREE_VERSION') ) {
607
- $version = "PixelYourSite FREE v".PYS_FREE_VERSION;
608
- } else {
609
- $version = null;
610
- }
611
-
612
- return $version;
613
-
614
- }
615
-
616
- }
617
-
618
- if( ! function_exists( 'pys_page_view_event' ) ) {
619
-
620
- /*
621
- * PageView event. Present on each page if pixel setup is enabled.
622
- */
623
- function pys_page_view_event() {
624
- pys_add_event( 'PageView' );
625
- }
626
-
627
- }
628
-
629
- if( ! function_exists( 'pys_general_event' ) ) {
630
-
631
- function pys_general_event() {
632
- global $post;
633
-
634
- if ( pys_get_option( 'general', 'general_event_enabled' ) == false ) {
635
- return;
636
- }
637
-
638
- $params = array();
639
- $event_name = pys_get_option( 'general', 'general_event_name' );
640
- $post_type = get_post_type();
641
- $delay = floatval( pys_get_option( 'general', 'general_event_delay', 0 ) );
642
-
643
- $on_posts_enabled = pys_get_option( 'general', 'general_event_on_posts_enabled' );
644
- $on_pages_enables = pys_get_option( 'general', 'general_event_on_pages_enabled' );
645
- $on_taxonomies_enabled = pys_get_option( 'general', 'general_event_on_tax_enabled' );
646
- $on_cpt_enabled = pys_get_option( 'general', 'general_event_on_' . $post_type . '_enabled' );
647
- $on_woo_enabled = pys_get_option( 'general', 'general_event_on_woo_enabled' );
648
- $on_edd_enabled = pys_get_option( 'general', 'general_event_on_edd_enabled' );
649
- $track_tags_enabled = pys_get_option( 'general', 'general_event_add_tags', false );
650
-
651
- // Posts
652
- if ( $on_posts_enabled && is_singular( 'post' ) ) {
653
-
654
- $params['post_type'] = 'post';
655
- $params['content_name'] = $post->post_title;
656
- $params['post_id'] = $post->ID;
657
-
658
- if ( $terms = pys_get_content_taxonomies() ) {
659
- $params['content_category'] = $terms;
660
- }
661
-
662
- if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
663
- $params['tags'] = implode( ', ', $tags );
664
- }
665
-
666
- pys_add_event( $event_name, $params, $delay );
667
-
668
- return;
669
-
670
- }
671
-
672
- // Pages or Front Page
673
- if ( $on_pages_enables && ( is_singular( 'page' ) || is_home() ) ) {
674
-
675
- // exclude WooCommerce Cart page
676
- if ( pys_is_woocommerce_active() && is_cart() ) {
677
- return;
678
- }
679
-
680
- $params['post_type'] = 'page';
681
- $params['content_name'] = is_home() == true ? get_bloginfo( 'name' ) : $post->post_title;
682
-
683
- is_home() != true ? $params['post_id'] = $post->ID : null;
684
-
685
- pys_add_event( $event_name, $params, $delay );
686
-
687
- return;
688
-
689
- }
690
-
691
- // WooCommerce Shop page
692
- if ( $on_pages_enables && pys_is_woocommerce_active() && is_shop() ) {
693
-
694
- $page_id = wc_get_page_id( 'shop' );
695
-
696
- $params['post_type'] = 'page';
697
- $params['post_id'] = $page_id;
698
- $params['content_name'] = get_the_title( $page_id );;
699
-
700
- pys_add_event( $event_name, $params, $delay );
701
-
702
- return;
703
-
704
- }
705
-
706
- // Taxonomies (built-in and custom)
707
- if ( $on_taxonomies_enabled && ( is_category() || is_tax() || is_tag() ) ) {
708
-
709
- $term = null;
710
- $type = null;
711
-
712
- if ( is_category() ) {
713
-
714
- $cat = get_query_var( 'cat' );
715
- $term = get_category( $cat );
716
-
717
- $params['post_type'] = 'category';
718
- $params['content_name'] = $term->name;
719
- $params['post_id'] = $cat;
720
-
721
- } elseif ( is_tag() ) {
722
-
723
- $slug = get_query_var( 'tag' );
724
- $term = get_term_by( 'slug', $slug, 'post_tag' );
725
-
726
- $params['post_type'] = 'tag';
727
- $params['content_name'] = $term->name;
728
- $params['post_id'] = $term->term_id;
729
-
730
- } else {
731
-
732
- $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
733
-
734
- $params['post_type'] = get_query_var( 'taxonomy' );
735
- $params['content_name'] = $term->name;
736
- $params['post_id'] = $term->term_id;
737
-
738
- }
739
-
740
- pys_add_event( $event_name, $params, $delay );
741
-
742
- return;
743
-
744
- }
745
-
746
- // Custom Post Type
747
- if ( $on_cpt_enabled && $post_type != 'post' && $post_type != 'page' ) {
748
-
749
- // skip products and downloads is plugins are activated
750
- if ( ( pys_is_woocommerce_active() && $post_type == 'product' ) || ( pys_is_edd_active() && $post_type == 'download' ) ) {
751
- return;
752
- }
753
-
754
- $params['post_type'] = $post_type;
755
- $params['content_name'] = $post->post_title;
756
- $params['post_id'] = $post->ID;
757
-
758
- $taxonomies = get_post_taxonomies( get_post() );
759
- $terms = pys_get_content_taxonomies( $taxonomies[0] );
760
- if ( $terms ) {
761
- $params['content_category'] = $terms;
762
- }
763
-
764
- if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
765
- $params['tags'] = implode( ', ', $tags );
766
- }
767
-
768
- pys_add_event( $event_name, $params, $delay );
769
-
770
- return;
771
-
772
- }
773
-
774
- ## WooCommerce Products
775
- if ( $on_woo_enabled && pys_is_woocommerce_active() && $post_type == 'product' ) {
776
-
777
- pys_general_woo_event( $post, $track_tags_enabled, $delay, $event_name );
778
- return;
779
-
780
- }
781
-
782
- ## Easy Digital Downloads
783
- if ( $on_edd_enabled && pys_is_edd_active() && $post_type == 'download' ) {
784
-
785
- pys_general_edd_event( $post, $track_tags_enabled, $delay, $event_name );
786
- return;
787
-
788
- }
789
-
790
- }
791
-
792
- }
793
-
794
- if( ! function_exists( 'pys_search_event' ) ) {
795
-
796
- function pys_search_event() {
797
-
798
- if ( pys_get_option( 'general', 'search_event_enabled' ) == false || is_search() == false || ! isset( $_REQUEST['s'] ) ) {
799
- return;
800
- }
801
-
802
- pys_add_event( 'Search', array(
803
- 'search_string' => $_REQUEST['s']
804
- ) );
805
-
806
- }
807
-
808
- }
809
-
810
- if( ! function_exists( 'pys_standard_events' ) ) {
811
-
812
- function pys_standard_events() {
813
- global $pys_custom_events;
814
-
815
- $std_events = get_option( 'pixel_your_site_std_events', array() );
816
-
817
- if ( pys_get_option( 'std', 'enabled' ) == false || empty( $std_events ) ) {
818
- return;
819
- }
820
-
821
- foreach ( $std_events as $event ) {
822
-
823
- // skip wrong events
824
- if( ! isset( $event['pageurl'] ) || ! isset( $event['eventtype'] ) ) {
825
- continue;
826
- }
827
-
828
- // skip if current page does not match URL filter
829
- if ( pys_match_url( $event['pageurl'] ) == false ) {
830
- continue;
831
- }
832
-
833
- if ( $event['eventtype'] == 'CustomCode' ) {
834
-
835
- $custom_code = $event['code'];
836
- $custom_code = stripcslashes( $custom_code );
837
- $custom_code = trim( $custom_code );
838
-
839
- // add custom code to global custom events array
840
- $pys_custom_events[] = $custom_code;
841
-
842
- } else {
843
-
844
- $type = $event['eventtype'];
845
- $params = pys_clean_system_event_params( $event );
846
-
847
- pys_add_event( $type, $params );
848
-
849
- }
850
-
851
- }
852
-
853
- }
854
-
855
- }
856
-
857
- if( !function_exists( 'pys_pixel_init_event' ) ) {
858
-
859
- function pys_pixel_init_event() {
860
- global $pys_events;
861
-
862
- $pys_events[] = array(
863
- 'type' => 'init',
864
- 'name' => pys_get_option( 'general', 'pixel_id' ),
865
- 'params' => pys_pixel_init_params()
866
- );
867
-
868
- }
869
-
870
- }
871
-
872
- if( ! function_exists( 'pys_output_noscript_code' ) ) {
873
-
874
- function pys_output_noscript_code() {
875
- global $pys_events;
876
-
877
- if( empty( $pys_events ) ) {
878
- return;
879
- }
880
-
881
- foreach( $pys_events as $event ) {
882
-
883
- $args = array();
884
-
885
- if( $event['type'] == 'init' ) {
886
- continue;
887
- }
888
-
889
- $args['id'] = pys_get_option( 'general', 'pixel_id' );
890
- $args['ev'] = $event['name'];
891
- $args['noscript'] = 1;
892
-
893
- foreach ( $event['params'] as $param => $value ) {
894
- @$args[ 'cd[' . $param . ']' ] = urlencode( $value );
895
- }
896
-
897
- $src_attr = add_query_arg( $args, 'https://www.facebook.com/tr' );
898
-
899
- // note: ALT tag used to pass ADA compliance
900
- // @see: issue #63 for details
901
-
902
- echo "<noscript><img height='1' width='1' style='display: none;' src='{$src_attr}' alt='facebook_pixel'></noscript>";
903
-
904
- }
905
-
906
- }
907
-
908
- }
909
-
910
- if( ! function_exists( 'pys_output_js_events_code' ) ) {
911
-
912
- function pys_output_js_events_code() {
913
- global $pys_events;
914
-
915
- // allow external plugins modify events
916
- $pys_events = apply_filters( 'pys_prepared_events', $pys_events );
917
-
918
- if( empty( $pys_events ) ) {
919
- return;
920
- }
921
-
922
- wp_localize_script( 'pys-public', 'pys_events', $pys_events );
923
-
924
- }
925
-
926
- }
927
-
928
- if( ! function_exists( 'pys_output_custom_events_code' ) ) {
929
-
930
- function pys_output_custom_events_code() {
931
- global $pys_custom_events;
932
-
933
- if( empty( $pys_custom_events ) ) {
934
- return;
935
- }
936
-
937
- wp_localize_script( 'pys-public', 'pys_customEvents', $pys_custom_events );
938
-
939
- }
940
-
941
- }
942
-
943
- if( !function_exists( 'pys_clean_system_event_params' ) ) {
944
-
945
- function pys_clean_system_event_params( $params ) {
946
-
947
- // remove unused params
948
- unset( $params['pageurl'] );
949
- unset( $params['eventtype'] );
950
- unset( $params['code'] );
951
- unset( $params['trigger_type'] ); // pro
952
- unset( $params['custom_currency'] ); // pro
953
- unset( $params['url'] ); // pro
954
- unset( $params['css'] ); // pro
955
- unset( $params['custom_name'] ); // custom events
956
- unset( $params['scroll_pos'] ); // pro
957
- unset( $params['url_filter'] ); // pro - dynamic events
958
-
959
- return $params;
960
-
961
- }
962
-
963
- }
964
-
965
- if( !function_exists( 'pys_get_woo_checkout_params' ) ) {
966
-
967
- function pys_get_woo_checkout_params( $additional_params_enabled ) {
968
- global $woocommerce;
969
-
970
- // set defaults params
971
- $params = array();
972
- $params['content_type'] = 'product';
973
-
974
- $ids = array(); // cart items ids or sku
975
- $names = ''; // cart items names
976
- $categories = ''; // cart items categories
977
-
978
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
979
-
980
- $product_id = pys_get_woo_cart_item_product_id( $item );
981
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
982
-
983
- // content_name, category_name for each cart item
984
- if ( $additional_params_enabled ) {
985
-
986
- $temp = array();
987
- pys_get_additional_woo_params( $product_id, $temp );
988
-
989
- $names .= isset( $temp['content_name'] ) ? $temp['content_name'] . ' ' : null;
990
- $categories .= isset( $temp['category_name'] ) ? $temp['category_name'] . ' ' : null;
991
-
992
- }
993
-
994
- }
995
-
996
- if ( $additional_params_enabled ) {
997
- $params['num_items'] = $woocommerce->cart->get_cart_contents_count();
998
- }
999
-
1000
- $params['content_ids'] = json_encode( $ids );
1001
-
1002
- if ( ! empty( $names ) ) {
1003
- $params['content_name'] = $names;
1004
- }
1005
-
1006
- if ( ! empty( $categories ) ) {
1007
- $params['category_name'] = $categories;
1008
- }
1009
-
1010
- return $params;
1011
-
1012
- }
1013
-
1014
- }
1015
-
1016
- if( !function_exists( 'pys_get_default_options' ) ) {
1017
-
1018
- function pys_get_default_options() {
1019
-
1020
- $options = array();
1021
-
1022
- $options['general']['pixel_id'] = '';
1023
- $options['general']['enabled'] = 0;
1024
- $options['general']['add_traffic_source'] = 1;
1025
- $options['general']['enable_advance_matching'] = 1;
1026
- $options['general']['in_footer'] = 0;
1027
-
1028
- $options['general']['general_event_enabled'] = 1;
1029
- $options['general']['general_event_name'] = 'GeneralEvent';
1030
- $options['general']['general_event_on_posts_enabled'] = 1;
1031
- $options['general']['general_event_on_pages_enabled'] = 1;
1032
- $options['general']['general_event_on_tax_enabled'] = 1;
1033
- $options['general']['general_event_on_woo_enabled'] = 0;
1034
- $options['general']['general_event_on_edd_enabled'] = 0;
1035
- $options['general']['general_event_add_tags'] = 0;
1036
-
1037
- $options['general']['timeonpage_enabled'] = 1;
1038
-
1039
- $options['general']['search_event_enabled'] = 1;
1040
-
1041
- $options['std']['enabled'] = 0;
1042
-
1043
- $options['dyn']['enabled'] = 0;
1044
- $options['dyn']['enabled_on_content'] = 0;
1045
- $options['dyn']['enabled_on_widget'] = 0;
1046
-
1047
- $options['woo']['enabled'] = pys_is_woocommerce_active() ? 1 : 0;
1048
-
1049
- $options['woo']['content_id'] = 'id';
1050
- $options['woo']['variation_id'] = 'variation';
1051
-
1052
- $options['woo']['enable_additional_params'] = 1;
1053
- $options['woo']['enable_tags'] = 1;
1054
- $options['woo']['tax'] = 'incl';
1055
-
1056
- $options['woo']['on_view_content'] = 1;
1057
- $options['woo']['enable_view_content_value'] = 1;
1058
- $options['woo']['view_content_value_option'] = 'price';
1059
- $options['woo']['view_content_percent_value'] = '';
1060
- $options['woo']['view_content_global_value'] = '';
1061
-
1062
- $options['woo']['on_add_to_cart_btn'] = 1;
1063
- $options['woo']['on_cart_page'] = 1;
1064
- $options['woo']['enable_add_to_cart_value'] = 1;
1065
- $options['woo']['add_to_cart_value_option'] = 'price';
1066
- $options['woo']['add_to_cart_percent_value'] = '';
1067
- $options['woo']['add_to_cart_global_value'] = '';
1068
-
1069
- $options['woo']['on_checkout_page'] = 1;
1070
- $options['woo']['enable_checkout_value'] = 1;
1071
- $options['woo']['checkout_value_option'] = 'price';
1072
- $options['woo']['checkout_percent_value'] = '';
1073
- $options['woo']['checkout_global_value'] = '';
1074
-
1075
- $options['woo']['on_thank_you_page'] = 1;
1076
- $options['woo']['enable_purchase_value'] = 1;
1077
- $options['woo']['purchase_fire_once'] = 1;
1078
- $options['woo']['purchase_transport'] = 'included';
1079
- $options['woo']['purchase_value_option'] = 'total';
1080
- $options['woo']['purchase_percent_value'] = '';
1081
- $options['woo']['purchase_global_value'] = '';
1082
-
1083
- $options['woo']['purchase_add_address'] = 1;
1084
- $options['woo']['purchase_add_payment_method'] = 1;
1085
- $options['woo']['purchase_add_shipping_method'] = 1;
1086
- $options['woo']['purchase_add_coupons'] = 1;
1087
-
1088
- $options['woo']['enable_aff_event'] = 0;
1089
- $options['woo']['aff_event'] = 'predefined';
1090
- $options['woo']['aff_predefined_value'] = 'Lead';
1091
- $options['woo']['aff_custom_value'] = '';
1092
- $options['woo']['aff_value_option'] = 'none';
1093
- $options['woo']['aff_global_value'] = '';
1094
-
1095
- $options['woo']['enable_paypal_event'] = 0;
1096
- $options['woo']['pp_event'] = 'predefined';
1097
- $options['woo']['pp_predefined_value'] = 'InitiatePayment';
1098
- $options['woo']['pp_custom_value'] = '';
1099
- $options['woo']['pp_value_option'] = 'none';
1100
- $options['woo']['pp_global_value'] = '';
1101
-
1102
- /**
1103
- * Easy Digital Downloads
1104
- */
1105
-
1106
- $options['edd']['enabled'] = pys_is_edd_active() ? 1 : 0;
1107
-
1108
- $options['edd']['content_id'] = 'id';
1109
- $options['edd']['enable_additional_params'] = 1;
1110
- $options['edd']['enable_tags'] = 1;
1111
- $options['edd']['tax'] = 'incl';
1112
-
1113
- $options['edd']['on_view_content'] = 1;
1114
- $options['edd']['on_view_content_delay'] = null;
1115
- $options['edd']['enable_view_content_value'] = 1;
1116
- $options['edd']['view_content_value_option'] = 'price';
1117
- $options['edd']['view_content_percent_value'] = null;
1118
- $options['edd']['view_content_global_value'] = null;
1119
-
1120
- $options['edd']['on_add_to_cart_btn'] = 1;
1121
- $options['edd']['enable_add_to_cart_value'] = 1;
1122
- $options['edd']['add_to_cart_value_option'] = 'price';
1123
- $options['edd']['add_to_cart_percent_value'] = null;
1124
- $options['edd']['add_to_cart_global_value'] = null;
1125
-
1126
- $options['edd']['on_checkout_page'] = 1;
1127
- $options['edd']['enable_checkout_value'] = 1;
1128
- $options['edd']['checkout_value_option'] = 'price';
1129
- $options['edd']['checkout_percent_value'] = null;
1130
- $options['edd']['checkout_global_value'] = null;
1131
-
1132
- $options['edd']['on_success_page'] = 1;
1133
- $options['edd']['enable_purchase_value'] = 1;
1134
- $options['edd']['purchase_fire_once'] = 1;
1135
- $options['edd']['purchase_value_option'] = 'total';
1136
- $options['edd']['purchase_percent_value'] = null;
1137
- $options['edd']['purchase_global_value'] = null;
1138
-
1139
- $options['edd']['purchase_add_address'] = true;
1140
- $options['edd']['purchase_add_payment_method'] = true;
1141
- $options['edd']['purchase_add_coupons'] = true;
1142
-
1143
- return apply_filters( 'pys_fb_pixel_setting_defaults', $options );
1144
-
1145
- }
1146
-
1147
- }
1148
-
1149
- if( ! function_exists( 'pys_get_custom_params' ) ) {
1150
-
1151
- /**
1152
- * Extract non-system params array
1153
- */
1154
- function pys_get_custom_params( $event ) {
1155
-
1156
- if( !is_array( $event ) || empty( $event ) ) {
1157
- return array();
1158
- }
1159
-
1160
- $system_params = array(
1161
- 'trigger_type',
1162
- 'url_filter',
1163
- 'url',
1164
- 'css',
1165
- 'pageurl',
1166
- 'eventtype',
1167
- 'value',
1168
- 'currency',
1169
- 'custom_currency',
1170
- 'content_name',
1171
- 'content_ids',
1172
- 'content_type',
1173
- 'content_category',
1174
- 'num_items',
1175
- 'order_id',
1176
- 'search_string',
1177
- 'status',
1178
- 'code',
1179
- 'custom_name',
1180
- 'scroll_pos'
1181
- );
1182
-
1183
- $custom_params = array();
1184
- foreach( $event as $param => $value ) {
1185
-
1186
- // skip standard params
1187
- if( in_array( $param, $system_params ) ) {
1188
- continue;
1189
- }
1190
-
1191
- $custom_params[ $param ] = $value;
1192
-
1193
- }
1194
-
1195
-
1196
- return $custom_params;
1197
-
1198
- }
1199
-
1200
- }
1201
-
1202
- if( ! function_exists( 'pys_is_standard_event' ) ) {
1203
-
1204
- function pys_is_standard_event( $eventtype ) {
1205
-
1206
- $std_events = array(
1207
- 'PageView',
1208
- 'ViewContent',
1209
- 'Search',
1210
- 'AddToCart',
1211
- 'AddToWishlist',
1212
- 'InitiateCheckout',
1213
- 'AddPaymentInfo',
1214
- 'Purchase',
1215
- 'Lead'
1216
- );
1217
-
1218
- return in_array( $eventtype, $std_events );
1219
-
1220
- }
1221
-
1222
- }
1223
-
1224
- if( ! function_exists( 'pys_pixel_init_params' ) ) {
1225
-
1226
- /**
1227
- * Add extra params to FB init call.
1228
- */
1229
- function pys_pixel_init_params() {
1230
-
1231
- $params = array();
1232
- $params = apply_filters( 'pys_pixel_init_params', $params );
1233
-
1234
- $sanitized = array();
1235
-
1236
- // sanitize params
1237
- foreach ( $params as $name => $value ) {
1238
-
1239
- if ( empty( $value ) ) {
1240
- continue;
1241
- }
1242
-
1243
- $key = esc_js( $name );
1244
- $sanitized[ $key ] = $value;
1245
-
1246
- }
1247
-
1248
- return $sanitized;
1249
-
1250
- }
1251
-
1252
- }
1253
-
1254
- if( ! function_exists( 'pys_woocommerce_events' ) ) {
1255
-
1256
- function pys_woocommerce_events() {
1257
-
1258
- if ( pys_get_option( 'woo', 'enabled' ) == false || pys_is_woocommerce_active() == false ) {
1259
- return;
1260
- }
1261
-
1262
- pys_get_woo_code();
1263
-
1264
- // WooCommerce non-ajax AddToCart Event handler
1265
- if ( isset( $_REQUEST['add-to-cart'] ) ) {
1266
-
1267
- if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $_REQUEST['variation_id'] ) ) {
1268
- $product_id = $_REQUEST['variation_id'];
1269
- } else {
1270
- $product_id = isset( $_REQUEST['add-to-cart'] ) ? $_REQUEST['add-to-cart'] : null;
1271
- }
1272
-
1273
- $params = pys_get_woo_ajax_addtocart_params( $product_id );
1274
-
1275
- pys_add_event( 'AddToCart', $params );
1276
-
1277
- }
1278
-
1279
- }
1280
-
1281
- }
1282
-
1283
- if( ! function_exists( 'pys_output_woo_ajax_events_code' ) ) {
1284
-
1285
- function pys_output_woo_ajax_events_code() {
1286
- global $pys_woo_ajax_events;
1287
-
1288
- if( empty( $pys_woo_ajax_events ) ) {
1289
- return;
1290
- }
1291
-
1292
- $events = array();
1293
-
1294
- foreach ( $pys_woo_ajax_events as $id => $event ) {
1295
-
1296
- $params = pys_clean_system_event_params( $event['params'] );
1297
-
1298
- // sanitize params
1299
- $sanitized = array();
1300
- foreach ( $params as $name => $value ) {
1301
-
1302
- // skip empty but not zero values
1303
- if ( empty( $value ) && ! is_numeric( $value ) ) {
1304
- continue;
1305
- }
1306
-
1307
- $key = esc_js( $name );
1308
- $sanitized[ $key ] = $value;
1309
-
1310
- }
1311
-
1312
- $name = $event['name'];
1313
-
1314
- $events[ $id ] = array(
1315
- 'type' => pys_is_standard_event( $name ) ? 'track' : 'trackCustom',
1316
- 'name' => $name,
1317
- 'params' => $sanitized
1318
- );
1319
-
1320
- }
1321
-
1322
- ?>
1323
-
1324
- <script type="text/javascript">
1325
- /* <![CDATA[ */
1326
- var pys_woo_ajax_events = <?php echo json_encode( $events ); ?>;
1327
- /* ]]> */
1328
- </script>
1329
-
1330
- <?php
1331
-
1332
- }
1333
-
1334
- }
1335
-
1336
- if( ! function_exists( 'pys_output_options' ) ) {
1337
-
1338
- function pys_output_options() {
1339
-
1340
- $options = array(
1341
- 'site_url' => get_site_url(),
1342
- 'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
1343
- );
1344
-
1345
- wp_localize_script( 'pys-public', 'pys_options', $options );
1346
-
1347
- }
1348
-
1349
- }
1350
-
1351
- if( ! function_exists( 'pys_head_comments' ) ) {
1352
-
1353
- function pys_head_comments() {
1354
-
1355
- if( defined( 'PYS_PRO_VERSION' ) ) {
1356
- $version = "PRO v" . PYS_PRO_VERSION;
1357
- } elseif( defined( 'PYS_FREE_VERSION' ) ) {
1358
- $version = "FREE v" . PYS_FREE_VERSION;
1359
- } else {
1360
- $version = null;
1361
- }
1362
-
1363
- ?>
1364
-
1365
- <!-- Facebook Pixel code is added on this page by PixelYourSite <?php echo esc_attr( $version ); ?> plugin. You can test it with Pixel Helper Chrome Extension. -->
1366
-
1367
- <?php
1368
- }
1369
-
1370
- }
1371
-
1372
- if( ! function_exists( 'pys_render_event_code' ) ) {
1373
-
1374
- /**
1375
- * Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
1376
- */
1377
- function pys_render_event_code( $event_name, $params ) {
1378
-
1379
- $event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
1380
-
1381
- $params = pys_clean_system_event_params( $params );
1382
-
1383
- $event_params = '';
1384
- foreach( $params as $name => $value ) {
1385
-
1386
- if( empty( $value ) && $value !== "0" ) {
1387
- continue;
1388
- }
1389
-
1390
- $event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
1391
-
1392
- }
1393
-
1394
- $event_params = ltrim( $event_params );
1395
- $event_params = rtrim( $event_params, "," );
1396
-
1397
- return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
1398
-
1399
- }
1400
-
1401
- }
1402
-
1403
- if( !function_exists( 'pys_add_domain_param' ) ) {
1404
-
1405
- function pys_add_domain_param( $params, $event ) {
1406
-
1407
- // get home URL without protocol
1408
- $params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
1409
- return $params;
1410
-
1411
- }
1412
-
1413
- }
1414
-
1415
- if ( ! function_exists( 'pys_get_additional_post_params' ) ) {
1416
-
1417
- function pys_get_additional_post_params( $post, &$params, $taxonomy ) {
1418
-
1419
- // get WP_Post object
1420
- if ( is_numeric( $post ) ) {
1421
- $id = absint( $post );
1422
- $_post = get_post( $id );
1423
- } elseif ( $post instanceof WC_Product ) {
1424
- $_post = $post->post;
1425
- } elseif ( isset( $post->ID ) ) {
1426
- $_post = $post;
1427
- } else {
1428
- return;
1429
- }
1430
-
1431
- $params['content_name'] = $_post->post_title;
1432
-
1433
- $terms = pys_get_content_taxonomies( $taxonomy, $_post->ID );
1434
- if ( $terms ) {
1435
- $params['category_name'] = $terms;
1436
- }
1437
-
1438
- }
1439
-
1440
- }
1441
-
1442
- if ( ! function_exists( 'pys_get_object_tags' ) ) {
1443
-
1444
- /**
1445
- * @param int|WP_Post $post Post ID or object
1446
- * @param string $taxonomy Taxonomy name
1447
- *
1448
- * @return array Array of terms titles on success or empty array
1449
- */
1450
- function pys_get_object_tags( $post, $taxonomy ) {
1451
-
1452
- $tags = array();
1453
- $terms = get_the_terms( $post, $taxonomy );
1454
-
1455
- if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
1456
-
1457
- foreach ( $terms as $term ) {
1458
- $tags[] = html_entity_decode( $term->name );
1459
- }
1460
-
1461
- }
1462
-
1463
- return $tags;
1464
-
1465
- }
1466
-
1467
- }
1468
-
1469
- if ( ! function_exists( 'pys_delete_events' ) ) {
1470
-
1471
- function pys_delete_events( $events_ids, $events_type ) {
1472
-
1473
- if ( $events_type == 'standard' ) {
1474
- $option_name = 'pixel_your_site_std_events';
1475
- } else {
1476
- $option_name = 'pixel_your_site_dyn_events';
1477
- }
1478
-
1479
- $events = (array) get_option( $option_name );
1480
-
1481
- if ( empty( $events ) ) {
1482
- return;
1483
- }
1484
-
1485
- foreach ( $events_ids as $id ) {
1486
- unset( $events[ $id ] );
1487
- }
1488
-
1489
- update_option( $option_name, $events );
1490
-
1491
- }
1492
-
1493
- }
1494
-
1495
- if( ! function_exists( 'pys_is_wc_version_gte' ) ) {
1496
-
1497
- function pys_is_wc_version_gte( $version ) {
1498
-
1499
- if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
1500
- return version_compare( WC_VERSION, $version, '>=' );
1501
- } else if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
1502
- return version_compare( WOOCOMMERCE_VERSION, $version, '>=' );
1503
- } else {
1504
- return false;
1505
- }
1506
-
1507
- }
1508
-
 
 
1509
  }
1
+ <?php
2
+ /**
3
+ * Common functions for both versions.
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit; // Exit if accessed directly.
8
+ }
9
+
10
+ /**
11
+ * Check if WooCommerce plugin is installed and activated.
12
+ */
13
+ if( !function_exists( 'pys_is_woocommerce_active' ) ) {
14
+
15
+ function pys_is_woocommerce_active() {
16
+ return class_exists( 'WooCommerce' ) == true ? true : false;
17
+ }
18
+
19
+ }
20
+
21
+ /**
22
+ * Check if Easy Digital Downloads plugin is installed and activated.
23
+ */
24
+ if( !function_exists( 'pys_is_edd_active' ) ) {
25
+
26
+ function pys_is_edd_active() {
27
+ return class_exists( 'Easy_Digital_Downloads' ) == true ? true : false;
28
+ }
29
+
30
+ }
31
+
32
+ if ( ! function_exists( 'pys_is_pcf_pro_active' ) ) {
33
+
34
+ function pys_is_pcf_pro_active() {
35
+ return class_exists( 'wpwoof_product_catalog' ) == true ? true : false;
36
+ }
37
+
38
+ }
39
+
40
+ if( !function_exists( 'pys_get_option' ) ) {
41
+
42
+ /**
43
+ * Return option value.
44
+ *
45
+ * @param string $section Options section, eg. 'general', 'woo', etc.
46
+ * @param string $option Option name
47
+ * @param mixed|string $default Default option value
48
+ *
49
+ * @return mixed Option or default option value
50
+ */
51
+ function pys_get_option( $section, $option, $default = '' ) {
52
+
53
+ $options = get_option( 'pixel_your_site' );
54
+
55
+ return isset( $options[ $section ][ $option ] ) ? $options[ $section ][ $option ] : $default;
56
+
57
+ }
58
+
59
+ }
60
+
61
+ if( !function_exists( 'pys_checkbox_state' ) ) {
62
+
63
+ /**
64
+ * @param string $section Option section name
65
+ * @param string $option Option name
66
+ * @param bool $echo Echo or return value
67
+ * @param int $checked Value to state compare
68
+ *
69
+ * @return string
70
+ */
71
+ function pys_checkbox_state( $section, $option, $echo = true, $checked = 1 ) {
72
+
73
+ $options = get_option( 'pixel_your_site' );
74
+
75
+ if ( isset( $options[ $section ][ $option ] ) ) {
76
+ $value = $options[ $section ][ $option ] == $checked ? 'checked' : '';
77
+ } else {
78
+ $value = '';
79
+ }
80
+
81
+ if( $echo ) {
82
+ echo $value;
83
+ }
84
+
85
+ return $value;
86
+
87
+ }
88
+
89
+ }
90
+
91
+ if ( ! function_exists( 'pys_checkbox' ) ) {
92
+
93
+ /**
94
+ * Echos checkbox input.
95
+ *
96
+ * @param string $section Input section name
97
+ * @param string $option Input option name
98
+ * @param string $classes Class names (optional)
99
+ * @param int $value Input value (optional)
100
+ */
101
+ function pys_checkbox( $section, $option, $classes = '', $value = 1 ) {
102
+
103
+ $state = pys_checkbox_state( $section, $option, false, $value );
104
+ $value = esc_attr( $value );
105
+
106
+ echo "<input type='checkbox' value='$value' name='pys[$section][$option]' class='$classes' $state>";
107
+
108
+ }
109
+
110
+ }
111
+
112
+ if ( ! function_exists( 'pys_text_field' ) ) {
113
+
114
+ /**
115
+ * Echos text input.
116
+ *
117
+ * @param string $section Input section name
118
+ * @param string $option Input option name
119
+ */
120
+ function pys_text_field( $section, $option ) {
121
+
122
+ $value = pys_get_option( $section, $option );
123
+ $value = esc_attr( $value );
124
+
125
+ echo "<input type='text' value='$value' name='pys[$section][$option]'>";
126
+
127
+ }
128
+
129
+ }
130
+
131
+ if ( ! function_exists( 'pys_radio_box' ) ) {
132
+
133
+ /**
134
+ * Echos radio box input.
135
+ *
136
+ * @param string $section Input section name
137
+ * @param string $option Input option name
138
+ * @param string $value Option value
139
+ */
140
+ function pys_radio_box( $section, $option, $value ) {
141
+
142
+ $state = pys_radio_state( $section, $option, $value );
143
+ echo "<input type='radio' value='$value' name='pys[$section][$option]' $state>";
144
+
145
+ }
146
+
147
+ }
148
+
149
+ /**
150
+ * Return radio box state.
151
+ */
152
+ if( !function_exists( 'pys_radio_state' ) ) {
153
+
154
+ function pys_radio_state( $section, $option, $value ) {
155
+
156
+ $options = get_option( 'pixel_your_site' );
157
+
158
+ if ( isset( $options[ $section ][ $option ] ) ) {
159
+
160
+ return $options[ $section ][ $option ] == $value ? 'checked' : '';
161
+
162
+ } else {
163
+
164
+ $defaults = pys_get_default_options();
165
+ return $defaults[ $section ][ $option ] == $value ? 'checked' : '';
166
+
167
+ }
168
+
169
+ }
170
+
171
+ }
172
+
173
+ /**
174
+ * Facebook Pixel Event types options html.
175
+ */
176
+ if( !function_exists( 'pys_event_types_select_options' ) ) {
177
+
178
+ function pys_event_types_select_options( $current = null, $full = true ) {
179
+ ?>
180
+
181
+ <option <?php selected( null, $current ); ?> disabled>Select Type</option>
182
+ <option <?php selected( 'ViewContent', $current ); ?> value="ViewContent">ViewContent</option>
183
+
184
+ <?php if ( $full ) : ?>
185
+
186
+ <option <?php selected( 'Search', $current ); ?> value="Search">Search</option>
187
+
188
+ <?php endif; ?>
189
+
190
+ <option <?php selected( 'AddToCart', $current ); ?> value="AddToCart">AddToCart</option>
191
+ <option <?php selected( 'AddToWishlist', $current ); ?> value="AddToWishlist">AddToWishlist</option>
192
+ <option <?php selected( 'InitiateCheckout', $current ); ?> value="InitiateCheckout">InitiateCheckout</option>
193
+ <option <?php selected( 'AddPaymentInfo', $current ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
194
+ <option <?php selected( 'Purchase', $current ); ?> value="Purchase">Purchase</option>
195
+ <option <?php selected( 'Lead', $current ); ?> value="Lead">Lead</option>
196
+ <option <?php selected( 'CompleteRegistration', $current ); ?> value="CompleteRegistration">CompleteRegistration</option>
197
+
198
+ <?php if ( $full ) : ?>
199
+
200
+ <option disabled></option>
201
+ <option <?php selected( 'CustomEvent', $current ); ?> value="CustomEvent">Custom event</option>
202
+ <option <?php selected( 'CustomCode', $current); ?> value="CustomCode">Custom event code</option>
203
+
204
+ <?php endif; ?>
205
+
206
+ <?php
207
+ }
208
+
209
+ }
210
+
211
+ /**
212
+ * Current Page Full URL without trailing slash
213
+ */
214
+ if( !function_exists( 'pys_get_current_url' ) ) {
215
+
216
+ function pys_get_current_url() {
217
+
218
+ $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
219
+ $current_url = rtrim( $current_url, '/' );
220
+
221
+ return $current_url;
222
+
223
+ }
224
+
225
+ }
226
+
227
+ /**
228
+ * Returns relative path without protocol, host, slashes.
229
+ */
230
+ if( !function_exists( 'pys_get_relative_path' ) ) {
231
+
232
+ function pys_get_relative_path( $url ) {
233
+
234
+ $host = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', home_url() );
235
+
236
+ $url = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', $url );
237
+ $url = str_replace( $host, '', $url );
238
+
239
+ $url = trim( $url );
240
+ $url = ltrim( $url, '/' );
241
+ $url = rtrim( $url, '/' );
242
+
243
+ return $url;
244
+
245
+ }
246
+
247
+ }
248
+
249
+ /**
250
+ * Check if needle URL (full or relative) matches with current.
251
+ */
252
+ if( !function_exists( 'pys_match_url' ) ) {
253
+
254
+ function pys_match_url( $match_url, $current_url = '' ) {
255
+
256
+ // use current url by default
257
+ if ( ! isset( $current_url ) || empty( $current_url ) ) {
258
+ $current_url = pys_get_current_url();
259
+ }
260
+
261
+ $current_url = pys_get_relative_path( $current_url );
262
+ $match_url = pys_get_relative_path( $match_url );
263
+
264
+ if ( substr( $match_url, - 1 ) == '*' ) {
265
+ // if match_url ends with wildcard
266
+
267
+ $match_url = rtrim( $match_url, '*' );
268
+
269
+ if ( pys_startsWith( $current_url, $match_url ) ) {
270
+ return true;
271
+ }
272
+
273
+ } else {
274
+ // exact url
275
+
276
+ if ( $current_url == $match_url ) {
277
+ return true;
278
+ }
279
+
280
+ }
281
+
282
+ return false;
283
+
284
+ }
285
+
286
+ }
287
+
288
+ if( !function_exists( 'pys_startsWith' ) ) {
289
+
290
+ function pys_startsWith( $haystack, $needle ) {
291
+ // search backwards starting from haystack length characters from the end
292
+ return $needle === "" || strrpos( $haystack, $needle, - strlen( $haystack ) ) !== false;
293
+ }
294
+
295
+ }
296
+
297
+ if( !function_exists( 'pys_endsWith' ) ) {
298
+
299
+ function pys_endsWith( $haystack, $needle ) {
300
+ // search forward starting from end minus needle length characters
301
+ return $needle === "" || ( ( $temp = strlen( $haystack ) - strlen( $needle ) ) >= 0 && strpos( $haystack, $needle, $temp ) !== false );
302
+ }
303
+
304
+ }
305
+
306
+ if( !function_exists( 'pys_currency_options' ) ) {
307
+
308
+ function pys_currency_options( $current = 'USD' ) {
309
+
310
+ $currencies = apply_filters( 'pys_currencies_list', array(
311
+ 'AUD' => 'Australian Dollar',
312
+ 'BRL' => 'Brazilian Real',
313
+ 'CAD' => 'Canadian Dollar',
314
+ 'CZK' => 'Czech Koruna',
315
+ 'DKK' => 'Danish Krone',
316
+ 'EUR' => 'Euro',
317
+ 'HKD' => 'Hong Kong Dollar',
318
+ 'HUF' => 'Hungarian Forint',
319
+ 'IDR' => 'Indonesian Rupiah',
320
+ 'ILS' => 'Israeli New Sheqel',
321
+ 'JPY' => 'Japanese Yen',
322
+ 'KRW' => 'Korean Won',
323
+ 'MYR' => 'Malaysian Ringgit',
324
+ 'MXN' => 'Mexican Peso',
325
+ 'NOK' => 'Norwegian Krone',
326
+ 'NZD' => 'New Zealand Dollar',
327
+ 'PHP' => 'Philippine Peso',
328
+ 'PLN' => 'Polish Zloty',
329
+ 'RON' => 'Romanian Leu',
330
+ 'GBP' => 'Pound Sterling',
331
+ 'SGD' => 'Singapore Dollar',
332
+ 'SEK' => 'Swedish Krona',
333
+ 'CHF' => 'Swiss Franc',
334
+ 'TWD' => 'Taiwan New Dollar',
335
+ 'THB' => 'Thai Baht',
336
+ 'TRY' => 'Turkish Lira',
337
+ 'USD' => 'U.S. Dollar',
338
+ 'ZAR' => 'South African Rands'
339
+ ) );
340
+
341
+ foreach( $currencies as $symbol => $name ) {
342
+ echo '<option ' . selected( $symbol, $current, false ) . ' value="' . esc_attr( $symbol ) . '">' . esc_html( $name ) . '</option>';
343
+ }
344
+
345
+ }
346
+
347
+ }
348
+
349
+ /**
350
+ * Extract Object taxonomies list.
351
+ */
352
+ if( !function_exists( 'pys_get_content_taxonomies' ) ) {
353
+
354
+ function pys_get_content_taxonomies( $taxonomy = 'category', $post_id = null ) {
355
+
356
+ $post_id = isset( $post_id ) ? $post_id : get_the_ID();
357
+ $terms = get_the_terms( $post_id, $taxonomy );
358
+
359
+ if ( is_wp_error( $terms ) || empty ( $terms ) ) {
360
+ return false;
361
+ }
362
+
363
+ $list = array();
364
+
365
+ foreach( $terms as $term ) {
366
+ $list[ $term->term_id ] = html_entity_decode( $term->name );
367
+ }
368
+
369
+ return implode( ', ', $list );
370
+
371
+ }
372
+
373
+ }
374
+
375
+ if( !function_exists( 'pys_add_event' ) ) {
376
+
377
+ /**
378
+ * Add event with params to global events list.
379
+ *
380
+ * @param string $event Event name, eg. "PageView"
381
+ * @param array $params Optional. Associated array of event parameters in 'param_name' => 'param_value' format.
382
+ * @param int $delay Optional. If set, event will be fired with desired delay in seconds.
383
+ */
384
+ function pys_add_event( $event, $params = array(), $delay = 0 ) {
385
+ global $pys_events;
386
+
387
+ $params = apply_filters( 'pys_event_params', $params, $event );
388
+
389
+ $sanitized = array();
390
+
391
+ // sanitize param names and its values
392
+ foreach ( $params as $name => $value ) {
393
+
394
+ // skip empty but not zero values
395
+ if ( empty( $value ) && ! is_numeric( $value ) ) {
396
+ continue;
397
+ }
398
+
399
+ $key = esc_js( $name );
400
+ $sanitized[ $key ] = $value;
401
+
402
+ }
403
+
404
+ $pys_events[] = array(
405
+ 'type' => pys_is_standard_event( $event ) ? 'track' : 'trackCustom',
406
+ 'name' => $event,
407
+ 'params' => $sanitized,
408
+ 'delay' => $delay
409
+ );
410
+
411
+ }
412
+
413
+ }
414
+
415
+ if ( ! function_exists( 'pys_get_product_content_id' ) ) {
416
+
417
+ /**
418
+ * Return product id or sku.
419
+ */
420
+ function pys_get_product_content_id( $product_id ) {
421
+
422
+ $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
423
+
424
+ if ( pys_get_option( 'woo', 'content_id' ) == 'sku' ) {
425
+ $content_id = get_post_meta( $product_id, '_sku', true );
426
+ } else {
427
+ $content_id = intval( $product_id );
428
+ }
429
+
430
+ return apply_filters( 'pys_fb_pixel_woo_product_content_id', array( $content_id ), $product_id,
431
+ $content_id_format );
432
+
433
+ }
434
+
435
+ }
436
+
437
+ if ( ! function_exists( 'pys_get_woo_cart_item_product_id' ) ) {
438
+
439
+ /**
440
+ * Return main or variation product id.
441
+ */
442
+ function pys_get_woo_cart_item_product_id( $cart_item ) {
443
+
444
+ $content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
445
+
446
+ if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
447
+ $product_id = $cart_item['variation_id'];
448
+ } else {
449
+ $product_id = $cart_item['product_id'];
450
+ }
451
+
452
+ return apply_filters( 'pys_fb_pixel_woo_cart_item_product_id', $product_id, $cart_item, $content_id_format );
453
+
454
+ }
455
+
456
+ }
457
+
458
+ if ( ! function_exists( 'pys_insert_attribute' ) ) {
459
+
460
+ /**
461
+ * Add attribute with value to a HTML tag.
462
+ *
463
+ * @param string $attr_name Attribute name, eg. "class"
464
+ * @param string $attr_value Attribute value
465
+ * @param string $content HTML content where attribute should be inserted
466
+ * @param bool $overwrite Override existing value of attribute or append it
467
+ * @param string $tag Selector name, eg. "button". Default "a"
468
+ *
469
+ * @return string Modified HTML content
470
+ */
471
+ function pys_insert_attribute( $attr_name, $attr_value, $content, $overwrite = false, $tag = 'a' ) {
472
+
473
+ ## do not modify js attributes
474
+ if( $attr_name == 'on' ) {
475
+ return $content;
476
+ }
477
+
478
+ $attr_value = trim( $attr_value );
479
+
480
+ try {
481
+
482
+ $doc = new DOMDocument();
483
+
484
+ /**
485
+ * Old libxml does not support options parameter.
486
+ *
487
+ * @since 3.2.0
488
+ */
489
+ if ( defined( 'LIBXML_DOTTED_VERSION' ) && version_compare( LIBXML_DOTTED_VERSION, '2.6.0', '>=' ) &&
490
+ version_compare( phpversion(), '5.4.0', '>=' )
491
+ ) {
492
+ @$doc->loadHTML( '<?xml encoding="UTF-8">' . $content, LIBXML_NOEMPTYTAG );
493
+ } else {
494
+ @$doc->loadHTML( '<?xml encoding="UTF-8">' . $content );
495
+ }
496
+
497
+ /**
498
+ * Select top-level tag if it is not specified in args.
499
+ *
500
+ * @since: 5.0.6
501
+ */
502
+ if ( $tag == 'any' ) {
503
+
504
+ /** @var DOMNodeList $node */
505
+ $node = $doc->getElementsByTagName( 'body' );
506
+
507
+ if ( $node->length == 0 ) {
508
+ throw new Exception( 'Empty or wrong tag passed to filter.' );
509
+ }
510
+
511
+ $node = $node->item( 0 )->childNodes->item( 0 );
512
+
513
+ } else {
514
+ $node = $doc->getElementsByTagName( $tag )->item( 0 );
515
+ }
516
+
517
+ if ( is_null( $node ) ) {
518
+ return $content;
519
+ }
520
+
521
+ /** @noinspection PhpUndefinedMethodInspection */
522
+ $attribute = $node->getAttribute( $attr_name );
523
+
524
+ // add attribute or override old one
525
+ if ( empty( $attribute ) || $overwrite ) {
526
+
527
+ /** @noinspection PhpUndefinedMethodInspection */
528
+ $node->setAttribute( $attr_name, $attr_value );
529
+
530
+ return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
531
+
532
+ }
533
+
534
+ // append value to exist attribute
535
+ if ( $overwrite == false ) {
536
+
537
+ $value = $attribute . ' ' . $attr_value;
538
+ /** @noinspection PhpUndefinedMethodInspection */
539
+ $node->setAttribute( $attr_name, $value );
540
+
541
+ return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
542
+
543
+ }
544
+
545
+ } catch ( Exception $e ) {
546
+
547
+ error_log( $e );
548
+
549
+ }
550
+
551
+ return $content;
552
+
553
+ }
554
+
555
+ }
556
+
557
+ if ( ! function_exists( 'pys_is_disabled_for_role' ) ) {
558
+
559
+ function pys_is_disabled_for_role() {
560
+
561
+ $options = get_option( 'pixel_your_site' );
562
+ $disabled_roles = $options['general'];
563
+
564
+ $user = wp_get_current_user();
565
+ foreach ( (array) $user->roles as $role ) {
566
+
567
+ if ( array_key_exists( "disable_for_$role", $disabled_roles ) ) {
568
+
569
+ add_action( 'wp_head', 'pys_head_message', 1 );
570
+ return true;
571
+
572
+ }
573
+
574
+ }
575
+
576
+ if( empty( $user->roles ) && isset( $disabled_roles['disable_for_guest'] ) ) {
577
+
578
+ add_action( 'wp_head', 'pys_head_message', 1 );
579
+ return true;
580
+
581
+ }
582
+
583
+ return false;
584
+
585
+ }
586
+
587
+ }
588
+
589
+ if( ! function_exists( 'pys_head_message' ) ) {
590
+
591
+ /**
592
+ * Output "disabled for role" and version number message to document head.
593
+ */
594
+ function pys_head_message() {
595
+ echo "<!-- Facebook Pixel Code disabled for current role ( " . pys_get_version() . " ) -->\r\n";
596
+ }
597
+
598
+ }
599
+
600
+ if( ! function_exists( 'pys_get_version' ) ) {
601
+
602
+ function pys_get_version() {
603
+
604
+ if( defined('PYS_PRO_VERSION') ) {
605
+ $version = "PixelYourSite PRO v".PYS_PRO_VERSION;
606
+ } elseif( defined('PYS_FREE_VERSION') ) {
607
+ $version = "PixelYourSite FREE v".PYS_FREE_VERSION;
608
+ } else {
609
+ $version = null;
610
+ }
611
+
612
+ return $version;
613
+
614
+ }
615
+
616
+ }
617
+
618
+ if( ! function_exists( 'pys_page_view_event' ) ) {
619
+
620
+ /*
621
+ * PageView event. Present on each page if pixel setup is enabled.
622
+ */
623
+ function pys_page_view_event() {
624
+ pys_add_event( 'PageView' );
625
+ }
626
+
627
+ }
628
+
629
+ if( ! function_exists( 'pys_general_event' ) ) {
630
+
631
+ function pys_general_event() {
632
+ global $post;
633
+
634
+ if ( pys_get_option( 'general', 'general_event_enabled' ) == false ) {
635
+ return;
636
+ }
637
+
638
+ $params = array();
639
+ $event_name = pys_get_option( 'general', 'general_event_name' );
640
+ $post_type = get_post_type();
641
+ $delay = floatval( pys_get_option( 'general', 'general_event_delay', 0 ) );
642
+
643
+ $on_posts_enabled = pys_get_option( 'general', 'general_event_on_posts_enabled' );
644
+ $on_pages_enables = pys_get_option( 'general', 'general_event_on_pages_enabled' );
645
+ $on_taxonomies_enabled = pys_get_option( 'general', 'general_event_on_tax_enabled' );
646
+ $on_cpt_enabled = pys_get_option( 'general', 'general_event_on_' . $post_type . '_enabled' );
647
+ $on_woo_enabled = pys_get_option( 'general', 'general_event_on_woo_enabled' );
648
+ $on_edd_enabled = pys_get_option( 'general', 'general_event_on_edd_enabled' );
649
+ $track_tags_enabled = pys_get_option( 'general', 'general_event_add_tags', false );
650
+
651
+ // Posts
652
+ if ( $on_posts_enabled && is_singular( 'post' ) ) {
653
+
654
+ $params['post_type'] = 'post';
655
+ $params['content_name'] = $post->post_title;
656
+ $params['post_id'] = $post->ID;
657
+
658
+ if ( $terms = pys_get_content_taxonomies() ) {
659
+ $params['content_category'] = $terms;
660
+ }
661
+
662
+ if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
663
+ $params['tags'] = implode( ', ', $tags );
664
+ }
665
+
666
+ pys_add_event( $event_name, $params, $delay );
667
+
668
+ return;
669
+
670
+ }
671
+
672
+ // Pages or Front Page
673
+ if ( $on_pages_enables && ( is_singular( 'page' ) || is_home() ) ) {
674
+
675
+ // exclude WooCommerce Cart page
676
+ if ( pys_is_woocommerce_active() && is_cart() ) {
677
+ return;
678
+ }
679
+
680
+ $params['post_type'] = 'page';
681
+ $params['content_name'] = is_home() == true ? get_bloginfo( 'name' ) : $post->post_title;
682
+
683
+ is_home() != true ? $params['post_id'] = $post->ID : null;
684
+
685
+ pys_add_event( $event_name, $params, $delay );
686
+
687
+ return;
688
+
689
+ }
690
+
691
+ // WooCommerce Shop page
692
+ if ( $on_pages_enables && pys_is_woocommerce_active() && is_shop() ) {
693
+
694
+ $page_id = wc_get_page_id( 'shop' );
695
+
696
+ $params['post_type'] = 'page';
697
+ $params['post_id'] = $page_id;
698
+ $params['content_name'] = get_the_title( $page_id );;
699
+
700
+ pys_add_event( $event_name, $params, $delay );
701
+
702
+ return;
703
+
704
+ }
705
+
706
+ // Taxonomies (built-in and custom)
707
+ if ( $on_taxonomies_enabled && ( is_category() || is_tax() || is_tag() ) ) {
708
+
709
+ $term = null;
710
+ $type = null;
711
+
712
+ if ( is_category() ) {
713
+
714
+ $cat = get_query_var( 'cat' );
715
+ $term = get_category( $cat );
716
+
717
+ $params['post_type'] = 'category';
718
+ $params['content_name'] = $term->name;
719
+ $params['post_id'] = $cat;
720
+
721
+ } elseif ( is_tag() ) {
722
+
723
+ $slug = get_query_var( 'tag' );
724
+ $term = get_term_by( 'slug', $slug, 'post_tag' );
725
+
726
+ $params['post_type'] = 'tag';
727
+ $params['content_name'] = $term->name;
728
+ $params['post_id'] = $term->term_id;
729
+
730
+ } else {
731
+
732
+ $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
733
+
734
+ $params['post_type'] = get_query_var( 'taxonomy' );
735
+ $params['content_name'] = $term->name;
736
+ $params['post_id'] = $term->term_id;
737
+
738
+ }
739
+
740
+ pys_add_event( $event_name, $params, $delay );
741
+
742
+ return;
743
+
744
+ }
745
+
746
+ // Custom Post Type
747
+ if ( $on_cpt_enabled && $post_type != 'post' && $post_type != 'page' ) {
748
+
749
+ // skip products and downloads is plugins are activated
750
+ if ( ( pys_is_woocommerce_active() && $post_type == 'product' ) || ( pys_is_edd_active() && $post_type == 'download' ) ) {
751
+ return;
752
+ }
753
+
754
+ $params['post_type'] = $post_type;
755
+ $params['content_name'] = $post->post_title;
756
+ $params['post_id'] = $post->ID;
757
+
758
+ $taxonomies = get_post_taxonomies( get_post() );
759
+ $terms = pys_get_content_taxonomies( $taxonomies[0] );
760
+ if ( $terms ) {
761
+ $params['content_category'] = $terms;
762
+ }
763
+
764
+ if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
765
+ $params['tags'] = implode( ', ', $tags );
766
+ }
767
+
768
+ pys_add_event( $event_name, $params, $delay );
769
+
770
+ return;
771
+
772
+ }
773
+
774
+ ## WooCommerce Products
775
+ if ( $on_woo_enabled && pys_is_woocommerce_active() && $post_type == 'product' ) {
776
+
777
+ pys_general_woo_event( $post, $track_tags_enabled, $delay, $event_name );
778
+ return;
779
+
780
+ }
781
+
782
+ ## Easy Digital Downloads
783
+ if ( $on_edd_enabled && pys_is_edd_active() && $post_type == 'download' ) {
784
+
785
+ pys_general_edd_event( $post, $track_tags_enabled, $delay, $event_name );
786
+ return;
787
+
788
+ }
789
+
790
+ }
791
+
792
+ }
793
+
794
+ if( ! function_exists( 'pys_search_event' ) ) {
795
+
796
+ function pys_search_event() {
797
+
798
+ if ( pys_get_option( 'general', 'search_event_enabled' ) == false || is_search() == false || ! isset( $_REQUEST['s'] ) ) {
799
+ return;
800
+ }
801
+
802
+ pys_add_event( 'Search', array(
803
+ 'search_string' => $_REQUEST['s']
804
+ ) );
805
+
806
+ }
807
+
808
+ }
809
+
810
+ if( ! function_exists( 'pys_standard_events' ) ) {
811
+
812
+ function pys_standard_events() {
813
+ global $pys_custom_events;
814
+
815
+ $std_events = get_option( 'pixel_your_site_std_events', array() );
816
+
817
+ if ( pys_get_option( 'std', 'enabled' ) == false || empty( $std_events ) ) {
818
+ return;
819
+ }
820
+
821
+ foreach ( $std_events as $event ) {
822
+
823
+ // skip wrong events
824
+ if( ! isset( $event['pageurl'] ) || ! isset( $event['eventtype'] ) ) {
825
+ continue;
826
+ }
827
+
828
+ // skip if current page does not match URL filter
829
+ if ( pys_match_url( $event['pageurl'] ) == false ) {
830
+ continue;
831
+ }
832
+
833
+ if ( $event['eventtype'] == 'CustomCode' ) {
834
+
835
+ $custom_code = $event['code'];
836
+ $custom_code = stripcslashes( $custom_code );
837
+ $custom_code = trim( $custom_code );
838
+
839
+ // add custom code to global custom events array
840
+ $pys_custom_events[] = $custom_code;
841
+
842
+ } else {
843
+
844
+ $type = $event['eventtype'];
845
+ $params = pys_clean_system_event_params( $event );
846
+
847
+ pys_add_event( $type, $params );
848
+
849
+ }
850
+
851
+ }
852
+
853
+ }
854
+
855
+ }
856
+
857
+ if( !function_exists( 'pys_pixel_init_event' ) ) {
858
+
859
+ function pys_pixel_init_event() {
860
+ global $pys_events;
861
+
862
+ $pys_events[] = array(
863
+ 'type' => 'init',
864
+ 'name' => pys_get_option( 'general', 'pixel_id' ),
865
+ 'params' => pys_pixel_init_params()
866
+ );
867
+
868
+ }
869
+
870
+ }
871
+
872
+ if( ! function_exists( 'pys_output_noscript_code' ) ) {
873
+
874
+ function pys_output_noscript_code() {
875
+ global $pys_events;
876
+
877
+ if( empty( $pys_events ) ) {
878
+ return;
879
+ }
880
+
881
+ foreach( $pys_events as $event ) {
882
+
883
+ $args = array();
884
+
885
+ if( $event['type'] == 'init' ) {
886
+ continue;
887
+ }
888
+
889
+ $args['id'] = pys_get_option( 'general', 'pixel_id' );
890
+ $args['ev'] = $event['name'];
891
+ $args['noscript'] = 1;
892
+
893
+ foreach ( $event['params'] as $param => $value ) {
894
+ @$args[ 'cd[' . $param . ']' ] = urlencode( $value );
895
+ }
896
+
897
+ $src_attr = add_query_arg( $args, 'https://www.facebook.com/tr' );
898
+
899
+ // note: ALT tag used to pass ADA compliance
900
+ // @see: issue #63 for details
901
+
902
+ echo "<noscript><img height='1' width='1' style='display: none;' src='{$src_attr}' alt='facebook_pixel'></noscript>";
903
+
904
+ }
905
+
906
+ }
907
+
908
+ }
909
+
910
+ if( ! function_exists( 'pys_output_js_events_code' ) ) {
911
+
912
+ function pys_output_js_events_code() {
913
+ global $pys_events;
914
+
915
+ // allow external plugins modify events
916
+ $pys_events = apply_filters( 'pys_prepared_events', $pys_events );
917
+
918
+ if( empty( $pys_events ) ) {
919
+ return;
920
+ }
921
+
922
+ wp_localize_script( 'pys-public', 'pys_events', $pys_events );
923
+
924
+ }
925
+
926
+ }
927
+
928
+ if( ! function_exists( 'pys_output_custom_events_code' ) ) {
929
+
930
+ function pys_output_custom_events_code() {
931
+ global $pys_custom_events;
932
+
933
+ if( empty( $pys_custom_events ) ) {
934
+ return;
935
+ }
936
+
937
+ wp_localize_script( 'pys-public', 'pys_customEvents', $pys_custom_events );
938
+
939
+ }
940
+
941
+ }
942
+
943
+ if( !function_exists( 'pys_clean_system_event_params' ) ) {
944
+
945
+ function pys_clean_system_event_params( $params ) {
946
+
947
+ // remove unused params
948
+ unset( $params['pageurl'] );
949
+ unset( $params['eventtype'] );
950
+ unset( $params['code'] );
951
+ unset( $params['trigger_type'] ); // pro
952
+ unset( $params['custom_currency'] ); // pro
953
+ unset( $params['url'] ); // pro
954
+ unset( $params['css'] ); // pro
955
+ unset( $params['custom_name'] ); // custom events
956
+ unset( $params['scroll_pos'] ); // pro
957
+ unset( $params['url_filter'] ); // pro - dynamic events
958
+
959
+ return $params;
960
+
961
+ }
962
+
963
+ }
964
+
965
+ if( !function_exists( 'pys_get_woo_checkout_params' ) ) {
966
+
967
+ function pys_get_woo_checkout_params( $additional_params_enabled ) {
968
+ global $woocommerce;
969
+
970
+ // set defaults params
971
+ $params = array();
972
+ $params['content_type'] = 'product';
973
+
974
+ $ids = array(); // cart items ids or sku
975
+ $names = ''; // cart items names
976
+ $categories = ''; // cart items categories
977
+
978
+ foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
979
+
980
+ $product_id = pys_get_woo_cart_item_product_id( $item );
981
+ $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
982
+
983
+ // content_name, category_name for each cart item
984
+ if ( $additional_params_enabled ) {
985
+
986
+ $temp = array();
987
+ pys_get_additional_woo_params( $product_id, $temp );
988
+
989
+ $names .= isset( $temp['content_name'] ) ? $temp['content_name'] . ' ' : null;
990
+ $categories .= isset( $temp['category_name'] ) ? $temp['category_name'] . ' ' : null;
991
+
992
+ }
993
+
994
+ }
995
+
996
+ if ( $additional_params_enabled ) {
997
+ $params['num_items'] = $woocommerce->cart->get_cart_contents_count();
998
+ }
999
+
1000
+ $params['content_ids'] = json_encode( $ids );
1001
+
1002
+ if ( ! empty( $names ) ) {
1003
+ $params['content_name'] = $names;
1004
+ }
1005
+
1006
+ if ( ! empty( $categories ) ) {
1007
+ $params['category_name'] = $categories;
1008
+ }
1009
+
1010
+ return $params;
1011
+
1012
+ }
1013
+
1014
+ }
1015
+
1016
+ if( !function_exists( 'pys_get_default_options' ) ) {
1017
+
1018
+ function pys_get_default_options() {
1019
+
1020
+ $options = array();
1021
+
1022
+ $options['general']['pixel_id'] = '';
1023
+ $options['general']['enabled'] = 0;
1024
+ $options['general']['add_traffic_source'] = 1;
1025
+ $options['general']['enable_advance_matching'] = 1;
1026
+ $options['general']['in_footer'] = 0;
1027
+
1028
+ $options['general']['general_event_enabled'] = 1;
1029
+ $options['general']['general_event_name'] = 'GeneralEvent';
1030
+ $options['general']['general_event_on_posts_enabled'] = 1;
1031
+ $options['general']['general_event_on_pages_enabled'] = 1;
1032
+ $options['general']['general_event_on_tax_enabled'] = 1;
1033
+ $options['general']['general_event_on_woo_enabled'] = 0;
1034
+ $options['general']['general_event_on_edd_enabled'] = 0;
1035
+ $options['general']['general_event_add_tags'] = 0;
1036
+
1037
+ $options['general']['timeonpage_enabled'] = 1;
1038
+
1039
+ $options['general']['search_event_enabled'] = 1;
1040
+
1041
+ $options['std']['enabled'] = 0;
1042
+
1043
+ $options['dyn']['enabled'] = 0;
1044
+ $options['dyn']['enabled_on_content'] = 0;
1045
+ $options['dyn']['enabled_on_widget'] = 0;
1046
+
1047
+ $options['woo']['enabled'] = pys_is_woocommerce_active() ? 1 : 0;
1048
+
1049
+ $options['woo']['content_id'] = 'id';
1050
+ $options['woo']['variation_id'] = 'variation';
1051
+
1052
+ $options['woo']['enable_additional_params'] = 1;
1053
+ $options['woo']['enable_tags'] = 1;
1054
+ $options['woo']['tax'] = 'incl';
1055
+
1056
+ $options['woo']['on_view_content'] = 1;
1057
+ $options['woo']['enable_view_content_value'] = 1;
1058
+ $options['woo']['view_content_value_option'] = 'price';
1059
+ $options['woo']['view_content_percent_value'] = '';
1060
+ $options['woo']['view_content_global_value'] = '';
1061
+
1062
+ $options['woo']['on_add_to_cart_btn'] = 1;
1063
+ $options['woo']['on_add_to_cart_page'] = 0;
1064
+ $options['woo']['on_add_to_cart_checkout'] = 0;
1065
+ $options['woo']['enable_add_to_cart_value'] = 1;
1066
+ $options['woo']['add_to_cart_value_option'] = 'price';
1067
+ $options['woo']['add_to_cart_percent_value'] = '';
1068
+ $options['woo']['add_to_cart_global_value'] = '';
1069
+
1070
+ $options['woo']['on_checkout_page'] = 1;
1071
+ $options['woo']['enable_checkout_value'] = 1;
1072
+ $options['woo']['checkout_value_option'] = 'price';
1073
+ $options['woo']['checkout_percent_value'] = '';
1074
+ $options['woo']['checkout_global_value'] = '';
1075
+
1076
+ $options['woo']['on_thank_you_page'] = 1;
1077
+ $options['woo']['enable_purchase_value'] = 1;
1078
+ $options['woo']['purchase_fire_once'] = 1;
1079
+ $options['woo']['purchase_transport'] = 'included';
1080
+ $options['woo']['purchase_value_option'] = 'total';
1081
+ $options['woo']['purchase_percent_value'] = '';
1082
+ $options['woo']['purchase_global_value'] = '';
1083
+
1084
+ $options['woo']['purchase_add_address'] = 1;
1085
+ $options['woo']['purchase_add_payment_method'] = 1;
1086
+ $options['woo']['purchase_add_shipping_method'] = 1;
1087
+ $options['woo']['purchase_add_coupons'] = 1;
1088
+
1089
+ $options['woo']['enable_aff_event'] = 0;
1090
+ $options['woo']['aff_event'] = 'predefined';
1091
+ $options['woo']['aff_predefined_value'] = 'Lead';
1092
+ $options['woo']['aff_custom_value'] = '';
1093
+ $options['woo']['aff_value_option'] = 'none';
1094
+ $options['woo']['aff_global_value'] = '';
1095
+
1096
+ $options['woo']['enable_paypal_event'] = 0;
1097
+ $options['woo']['pp_event'] = 'predefined';
1098
+ $options['woo']['pp_predefined_value'] = 'InitiatePayment';
1099
+ $options['woo']['pp_custom_value'] = '';
1100
+ $options['woo']['pp_value_option'] = 'none';
1101
+ $options['woo']['pp_global_value'] = '';
1102
+
1103
+ /**
1104
+ * Easy Digital Downloads
1105
+ */
1106
+
1107
+ $options['edd']['enabled'] = pys_is_edd_active() ? 1 : 0;
1108
+
1109
+ $options['edd']['content_id'] = 'id';
1110
+ $options['edd']['enable_additional_params'] = 1;
1111
+ $options['edd']['enable_tags'] = 1;
1112
+ $options['edd']['tax'] = 'incl';
1113
+
1114
+ $options['edd']['on_view_content'] = 1;
1115
+ $options['edd']['on_view_content_delay'] = null;
1116
+ $options['edd']['enable_view_content_value'] = 1;
1117
+ $options['edd']['view_content_value_option'] = 'price';
1118
+ $options['edd']['view_content_percent_value'] = null;
1119
+ $options['edd']['view_content_global_value'] = null;
1120
+
1121
+ $options['edd']['on_add_to_cart_btn'] = 1;
1122
+ $options['edd']['on_add_to_cart_checkout'] = 0;
1123
+ $options['edd']['enable_add_to_cart_value'] = 1;
1124
+ $options['edd']['add_to_cart_value_option'] = 'price';
1125
+ $options['edd']['add_to_cart_percent_value'] = null;
1126
+ $options['edd']['add_to_cart_global_value'] = null;
1127
+
1128
+ $options['edd']['on_checkout_page'] = 1;
1129
+ $options['edd']['enable_checkout_value'] = 1;
1130
+ $options['edd']['checkout_value_option'] = 'price';
1131
+ $options['edd']['checkout_percent_value'] = null;
1132
+ $options['edd']['checkout_global_value'] = null;
1133
+
1134
+ $options['edd']['on_success_page'] = 1;
1135
+ $options['edd']['enable_purchase_value'] = 1;
1136
+ $options['edd']['purchase_fire_once'] = 1;
1137
+ $options['edd']['purchase_value_option'] = 'total';
1138
+ $options['edd']['purchase_percent_value'] = null;
1139
+ $options['edd']['purchase_global_value'] = null;
1140
+
1141
+ $options['edd']['purchase_add_address'] = true;
1142
+ $options['edd']['purchase_add_payment_method'] = true;
1143
+ $options['edd']['purchase_add_coupons'] = true;
1144
+
1145
+ return apply_filters( 'pys_fb_pixel_setting_defaults', $options );
1146
+
1147
+ }
1148
+
1149
+ }
1150
+
1151
+ if( ! function_exists( 'pys_get_custom_params' ) ) {
1152
+
1153
+ /**
1154
+ * Extract non-system params array
1155
+ */
1156
+ function pys_get_custom_params( $event ) {
1157
+
1158
+ if( !is_array( $event ) || empty( $event ) ) {
1159
+ return array();
1160
+ }
1161
+
1162
+ $system_params = array(
1163
+ 'trigger_type',
1164
+ 'url_filter',
1165
+ 'url',
1166
+ 'css',
1167
+ 'pageurl',
1168
+ 'eventtype',
1169
+ 'value',
1170
+ 'currency',
1171
+ 'custom_currency',
1172
+ 'content_name',
1173
+ 'content_ids',
1174
+ 'content_type',
1175
+ 'content_category',
1176
+ 'num_items',
1177
+ 'order_id',
1178
+ 'search_string',
1179
+ 'status',
1180
+ 'code',
1181
+ 'custom_name',
1182
+ 'scroll_pos'
1183
+ );
1184
+
1185
+ $custom_params = array();
1186
+ foreach( $event as $param => $value ) {
1187
+
1188
+ // skip standard params
1189
+ if( in_array( $param, $system_params ) ) {
1190
+ continue;
1191
+ }
1192
+
1193
+ $custom_params[ $param ] = $value;
1194
+
1195
+ }
1196
+
1197
+
1198
+ return $custom_params;
1199
+
1200
+ }
1201
+
1202
+ }
1203
+
1204
+ if( ! function_exists( 'pys_is_standard_event' ) ) {
1205
+
1206
+ function pys_is_standard_event( $eventtype ) {
1207
+
1208
+ $std_events = array(
1209
+ 'PageView',
1210
+ 'ViewContent',
1211
+ 'Search',
1212
+ 'AddToCart',
1213
+ 'AddToWishlist',
1214
+ 'InitiateCheckout',
1215
+ 'AddPaymentInfo',
1216
+ 'Purchase',
1217
+ 'Lead'
1218
+ );
1219
+
1220
+ return in_array( $eventtype, $std_events );
1221
+
1222
+ }
1223
+
1224
+ }
1225
+
1226
+ if( ! function_exists( 'pys_pixel_init_params' ) ) {
1227
+
1228
+ /**
1229
+ * Add extra params to FB init call.
1230
+ */
1231
+ function pys_pixel_init_params() {
1232
+
1233
+ $params = array();
1234
+ $params = apply_filters( 'pys_pixel_init_params', $params );
1235
+
1236
+ $sanitized = array();
1237
+
1238
+ // sanitize params
1239
+ foreach ( $params as $name => $value ) {
1240
+
1241
+ if ( empty( $value ) ) {
1242
+ continue;
1243
+ }
1244
+
1245
+ $key = esc_js( $name );
1246
+ $sanitized[ $key ] = $value;
1247
+
1248
+ }
1249
+
1250
+ return $sanitized;
1251
+
1252
+ }
1253
+
1254
+ }
1255
+
1256
+ if( ! function_exists( 'pys_woocommerce_events' ) ) {
1257
+
1258
+ function pys_woocommerce_events() {
1259
+
1260
+ if ( pys_get_option( 'woo', 'enabled' ) == false || pys_is_woocommerce_active() == false ) {
1261
+ return;
1262
+ }
1263
+
1264
+ pys_get_woo_code();
1265
+
1266
+ // WooCommerce non-ajax AddToCart Event handler
1267
+ if ( pys_get_option( 'woo', 'on_add_to_cart_btn' ) && isset( $_REQUEST['add-to-cart'] ) ) {
1268
+
1269
+ if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $_REQUEST['variation_id'] ) ) {
1270
+ $product_id = $_REQUEST['variation_id'];
1271
+ } else {
1272
+ $product_id = isset( $_REQUEST['add-to-cart'] ) ? $_REQUEST['add-to-cart'] : null;
1273
+ }
1274
+
1275
+ $params = pys_get_woo_ajax_addtocart_params( $product_id );
1276
+
1277
+ pys_add_event( 'AddToCart', $params );
1278
+
1279
+ }
1280
+
1281
+ }
1282
+
1283
+ }
1284
+
1285
+ if( ! function_exists( 'pys_output_woo_ajax_events_code' ) ) {
1286
+
1287
+ function pys_output_woo_ajax_events_code() {
1288
+ global $pys_woo_ajax_events;
1289
+
1290
+ if( empty( $pys_woo_ajax_events ) ) {
1291
+ return;
1292
+ }
1293
+
1294
+ $events = array();
1295
+
1296
+ foreach ( $pys_woo_ajax_events as $id => $event ) {
1297
+
1298
+ $params = pys_clean_system_event_params( $event['params'] );
1299
+
1300
+ // sanitize params
1301
+ $sanitized = array();
1302
+ foreach ( $params as $name => $value ) {
1303
+
1304
+ // skip empty but not zero values
1305
+ if ( empty( $value ) && ! is_numeric( $value ) ) {
1306
+ continue;
1307
+ }
1308
+
1309
+ $key = esc_js( $name );
1310
+ $sanitized[ $key ] = $value;
1311
+
1312
+ }
1313
+
1314
+ $name = $event['name'];
1315
+
1316
+ $events[ $id ] = array(
1317
+ 'type' => pys_is_standard_event( $name ) ? 'track' : 'trackCustom',
1318
+ 'name' => $name,
1319
+ 'params' => $sanitized
1320
+ );
1321
+
1322
+ }
1323
+
1324
+ ?>
1325
+
1326
+ <script type="text/javascript">
1327
+ /* <![CDATA[ */
1328
+ var pys_woo_ajax_events = <?php echo json_encode( $events ); ?>;
1329
+ /* ]]> */
1330
+ </script>
1331
+
1332
+ <?php
1333
+
1334
+ }
1335
+
1336
+ }
1337
+
1338
+ if( ! function_exists( 'pys_output_options' ) ) {
1339
+
1340
+ function pys_output_options() {
1341
+
1342
+ $options = array(
1343
+ 'site_url' => get_site_url(),
1344
+ 'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
1345
+ );
1346
+
1347
+ wp_localize_script( 'pys-public', 'pys_options', $options );
1348
+
1349
+ }
1350
+
1351
+ }
1352
+
1353
+ if( ! function_exists( 'pys_head_comments' ) ) {
1354
+
1355
+ function pys_head_comments() {
1356
+
1357
+ if( defined( 'PYS_PRO_VERSION' ) ) {
1358
+ $version = "PRO v" . PYS_PRO_VERSION;
1359
+ } elseif( defined( 'PYS_FREE_VERSION' ) ) {
1360
+ $version = "FREE v" . PYS_FREE_VERSION;
1361
+ } else {
1362
+ $version = null;
1363
+ }
1364
+
1365
+ ?>
1366
+
1367
+ <!-- Facebook Pixel code is added on this page by PixelYourSite <?php echo esc_attr( $version ); ?> plugin. You can test it with Pixel Helper Chrome Extension. -->
1368
+
1369
+ <?php
1370
+ }
1371
+
1372
+ }
1373
+
1374
+ if( ! function_exists( 'pys_render_event_code' ) ) {
1375
+
1376
+ /**
1377
+ * Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
1378
+ */
1379
+ function pys_render_event_code( $event_name, $params ) {
1380
+
1381
+ $event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
1382
+
1383
+ $params = pys_clean_system_event_params( $params );
1384
+
1385
+ $event_params = '';
1386
+ foreach( $params as $name => $value ) {
1387
+
1388
+ if( empty( $value ) && $value !== "0" ) {
1389
+ continue;
1390
+ }
1391
+
1392
+ $event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
1393
+
1394
+ }
1395
+
1396
+ $event_params = ltrim( $event_params );
1397
+ $event_params = rtrim( $event_params, "," );
1398
+
1399
+ return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
1400
+
1401
+ }
1402
+
1403
+ }
1404
+
1405
+ if( !function_exists( 'pys_add_domain_param' ) ) {
1406
+
1407
+ function pys_add_domain_param( $params, $event ) {
1408
+
1409
+ // get home URL without protocol
1410
+ $params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
1411
+ return $params;
1412
+
1413
+ }
1414
+
1415
+ }
1416
+
1417
+ if ( ! function_exists( 'pys_get_additional_post_params' ) ) {
1418
+
1419
+ function pys_get_additional_post_params( $post, &$params, $taxonomy ) {
1420
+
1421
+ // get WP_Post object
1422
+ if ( is_numeric( $post ) ) {
1423
+ $id = absint( $post );
1424
+ $_post = get_post( $id );
1425
+ } elseif ( $post instanceof WC_Product ) {
1426
+ $_post = $post->post;
1427
+ } elseif ( isset( $post->ID ) ) {
1428
+ $_post = $post;
1429
+ } else {
1430
+ return;
1431
+ }
1432
+
1433
+ $params['content_name'] = $_post->post_title;
1434
+
1435
+ $terms = pys_get_content_taxonomies( $taxonomy, $_post->ID );
1436
+ if ( $terms ) {
1437
+ $params['category_name'] = $terms;
1438
+ }
1439
+
1440
+ }
1441
+
1442
+ }
1443
+
1444
+ if ( ! function_exists( 'pys_get_object_tags' ) ) {
1445
+
1446
+ /**
1447
+ * @param int|WP_Post $post Post ID or object
1448
+ * @param string $taxonomy Taxonomy name
1449
+ *
1450
+ * @return array Array of terms titles on success or empty array
1451
+ */
1452
+ function pys_get_object_tags( $post, $taxonomy ) {
1453
+
1454
+ $tags = array();
1455
+ $terms = get_the_terms( $post, $taxonomy );
1456
+
1457
+ if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
1458
+
1459
+ foreach ( $terms as $term ) {
1460
+ $tags[] = html_entity_decode( $term->name );
1461
+ }
1462
+
1463
+ }
1464
+
1465
+ return $tags;
1466
+
1467
+ }
1468
+
1469
+ }
1470
+
1471
+ if ( ! function_exists( 'pys_delete_events' ) ) {
1472
+
1473
+ function pys_delete_events( $events_ids, $events_type ) {
1474
+
1475
+ if ( $events_type == 'standard' ) {
1476
+ $option_name = 'pixel_your_site_std_events';
1477
+ } else {
1478
+ $option_name = 'pixel_your_site_dyn_events';
1479
+ }
1480
+
1481
+ $events = (array) get_option( $option_name );
1482
+
1483
+ if ( empty( $events ) ) {
1484
+ return;
1485
+ }
1486
+
1487
+ foreach ( $events_ids as $id ) {
1488
+ unset( $events[ $id ] );
1489
+ }
1490
+
1491
+ update_option( $option_name, $events );
1492
+
1493
+ }
1494
+
1495
+ }
1496
+
1497
+ if( ! function_exists( 'pys_is_wc_version_gte' ) ) {
1498
+
1499
+ function pys_is_wc_version_gte( $version ) {
1500
+
1501
+ if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
1502
+ return version_compare( WC_VERSION, $version, '>=' );
1503
+ } else if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
1504
+ return version_compare( WOOCOMMERCE_VERSION, $version, '>=' );
1505
+ } else {
1506
+ return false;
1507
+ }
1508
+
1509
+ }
1510
+
1511
  }
inc/core-edd.php CHANGED
@@ -42,6 +42,32 @@ if ( ! function_exists( 'pys_edd_events' ) ) {
42
  *
43
  * @see pys_edd_purchase_link_args()
44
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  // InitiateCheckout Event
47
  if ( pys_get_option( 'edd', 'on_checkout_page' ) && edd_is_checkout() ) {
42
  *
43
  * @see pys_edd_purchase_link_args()
44
  */
45
+
46
+ // AddToCart on Checkout page
47
+ if ( pys_get_option( 'edd', 'on_add_to_cart_checkout' ) && edd_is_checkout() ) {
48
+
49
+ $ids = array();
50
+
51
+ foreach ( edd_get_cart_contents() as $cart_item ) {
52
+
53
+ $download_id = intval( $cart_item['id'] );
54
+ $ids[] = pys_get_edd_content_id( $download_id );
55
+
56
+ }
57
+
58
+ $params['content_ids'] = "'[" . implode( "','", $ids ) . "']";
59
+
60
+ // currency, value
61
+ if ( pys_get_option( 'edd', 'enable_add_to_cart_value' ) ) {
62
+
63
+ $params['value'] = pys_get_option( 'edd', 'add_to_cart_global_value' );
64
+ $params['currency'] = edd_get_currency();
65
+
66
+ }
67
+
68
+ pys_add_event( 'AddToCart', $params );
69
+
70
+ }
71
 
72
  // InitiateCheckout Event
73
  if ( pys_get_option( 'edd', 'on_checkout_page' ) && edd_is_checkout() ) {
inc/core.php CHANGED
@@ -1,465 +1,557 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly.
5
- }
6
-
7
- if ( ! function_exists( 'pys_get_woo_ajax_addtocart_params' ) ) {
8
-
9
- function pys_get_woo_ajax_addtocart_params( $product_id ) {
10
-
11
- $params = array();
12
- $params['content_type'] = 'product';
13
- $params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
14
-
15
- // currency, value
16
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
17
-
18
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
19
- switch ( $option ) {
20
- case 'global':
21
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
22
- break;
23
-
24
- case 'price':
25
- $value = pys_get_product_price( $product_id );
26
- break;
27
-
28
- default:
29
- $value = null;
30
- }
31
-
32
- $params['value'] = $value;
33
- $params['currency'] = get_woocommerce_currency();
34
-
35
- }
36
-
37
- return $params;
38
-
39
- }
40
-
41
- }
42
-
43
- if ( ! function_exists( 'pys_get_post_tags' ) ) {
44
-
45
- /**
46
- * Return array of product tags.
47
- * PRO only.
48
- */
49
- function pys_get_post_tags( $post_id ) {
50
-
51
- return array(); // PRO feature
52
-
53
- }
54
-
55
- }
56
-
57
- if ( ! function_exists( 'pys_get_woo_code' ) ) {
58
-
59
- /**
60
- * Build WooCommerce related events code.
61
- * Function adds evaluated event params to global array.
62
- */
63
- function pys_get_woo_code() {
64
- global $post, $woocommerce;
65
-
66
- // set defaults params
67
- $params = array();
68
- $params['content_type'] = 'product';
69
-
70
- // ViewContent Event
71
- if ( pys_get_option( 'woo', 'on_view_content' ) && is_product() ) {
72
-
73
- $product = wc_get_product( $post->ID );
74
-
75
- $params['content_ids'] = json_encode( pys_get_product_content_id( $post->ID ) );
76
-
77
- if ( $product->get_type() == 'variable' && pys_get_option( 'woo', 'variation_id' ) != 'main' ) {
78
- $params['content_type'] = 'product_group';
79
- } else {
80
- $params['content_type'] = 'product';
81
- }
82
-
83
- // @since 5.0.6
84
- $params['content_type'] = apply_filters( 'pys_fb_pixel_woo_product_content_type', $params['content_type'],
85
- $product->get_type(), $product, pys_get_option( 'woo', 'content_id_format' ) );
86
-
87
- // currency, value
88
- if ( pys_get_option( 'woo', 'enable_view_content_value' ) ) {
89
-
90
- $option = pys_get_option( 'woo', 'view_content_value_option' );
91
- switch ( $option ) {
92
- case 'global':
93
- $value = pys_get_option( 'woo', 'view_content_global_value' );
94
- break;
95
-
96
- case 'price':
97
- $value = pys_get_product_price( $post );
98
- break;
99
-
100
- default:
101
- $value = null;
102
- }
103
-
104
- $params['value'] = $value;
105
- $params['currency'] = get_woocommerce_currency();
106
-
107
- }
108
-
109
- pys_add_event( 'ViewContent', $params );
110
-
111
- return;
112
-
113
- }
114
-
115
- // AddToCart Cart Page Event
116
- if ( pys_get_option( 'woo', 'on_cart_page' ) && is_cart() ) {
117
-
118
- $ids = array(); // cart items ids or sku
119
-
120
- foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
121
-
122
- $product_id = pys_get_woo_cart_item_product_id( $item );
123
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
124
-
125
- }
126
-
127
- $params['content_ids'] = json_encode( $ids );
128
-
129
- // currency, value
130
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
131
-
132
- $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
133
- switch ( $option ) {
134
- case 'global':
135
- $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
136
- break;
137
-
138
- case 'price':
139
- $value = pys_get_cart_total();
140
- break;
141
-
142
- default:
143
- $value = null;
144
- }
145
-
146
- $params['value'] = $value;
147
- $params['currency'] = get_woocommerce_currency();
148
-
149
- }
150
-
151
- pys_add_event( 'AddToCart', $params );
152
-
153
- return;
154
-
155
- }
156
-
157
- // Checkout Page Event
158
- if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
159
-
160
- $params = pys_get_woo_checkout_params( false );
161
-
162
- // currency, value
163
- if ( pys_get_option( 'woo', 'enable_checkout_value' ) ) {
164
-
165
- $option = pys_get_option( 'woo', 'checkout_value_option' );
166
- switch ( $option ) {
167
- case 'global':
168
- $value = pys_get_option( 'woo', 'checkout_global_value' );
169
- break;
170
-
171
- case 'price':
172
- $value = pys_get_cart_total();
173
- break;
174
-
175
- default:
176
- $value = null;
177
- }
178
-
179
- $params['value'] = $value;
180
- $params['currency'] = get_woocommerce_currency();
181
-
182
- }
183
-
184
- pys_add_event( 'InitiateCheckout', $params );
185
-
186
- return;
187
-
188
- }
189
-
190
- // Purchase Event
191
- if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_wc_endpoint_url( 'order-received' ) ) {
192
-
193
- $order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
194
- $order = new WC_Order( $order_id );
195
- $items = $order->get_items( 'line_item' );
196
-
197
- $ids = array(); // order items ids or sku
198
-
199
- foreach ( $items as $item ) {
200
-
201
- $product_id = pys_get_woo_cart_item_product_id( $item );
202
- $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
203
-
204
- }
205
-
206
- $params['content_ids'] = json_encode( $ids );
207
-
208
- // currency, value
209
- if ( pys_get_option( 'woo', 'enable_purchase_value' ) ) {
210
-
211
- $option = pys_get_option( 'woo', 'purchase_value_option' );
212
- switch ( $option ) {
213
- case 'global':
214
- $value = pys_get_option( 'woo', 'purchase_global_value' );
215
- break;
216
-
217
- case 'total':
218
- $value = pys_get_order_total( $order );
219
- break;
220
-
221
- default:
222
- $value = null;
223
- }
224
-
225
- $params['value'] = $value;
226
- $params['currency'] = get_woocommerce_currency();
227
-
228
- }
229
-
230
- pys_add_event( 'Purchase', $params );
231
-
232
- return;
233
-
234
- }
235
-
236
- }
237
-
238
- }
239
-
240
- if ( ! function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
241
-
242
- /**
243
- * Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
244
- *
245
- * @param string $tag
246
- * @param WC_Product $product
247
- *
248
- * @return string
249
- */
250
- function pys_add_code_to_woo_cart_link( $tag, $product ) {
251
- global $pys_woo_ajax_events;
252
-
253
- // do not add code if AJAX is disabled. event will be processed by another function
254
- if ( 'yes' !== get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
255
- return $tag;
256
- }
257
-
258
- /**
259
- * @since 5.0.1
260
- */
261
- if ( pys_is_wc_version_gte( '2.7' ) ) {
262
- $is_simple_product = $product->is_type( 'simple' );
263
- } else {
264
- $is_simple_product = $product->product_type == 'simple';
265
- }
266
-
267
- if ( false == $is_simple_product ) {
268
- return $tag;
269
- }
270
-
271
- $event_id = uniqid();
272
-
273
- /**
274
- * @since 5.0.1
275
- */
276
- if ( pys_is_wc_version_gte( '2.6' ) ) {
277
- $product_id = $product->get_id();
278
- } else {
279
- $product_id = $product->post->ID;
280
- }
281
-
282
- // common params
283
- $params = array();
284
- $params['content_type'] = 'product';
285
- $params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
286
-
287
- // currency, value
288
- if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
289
-
290
- $option = pys_get_option( 'woo', 'view_content_value_option' );
291
- switch ( $option ) {
292
- case 'global':
293
- $value = pys_get_option( 'woo', 'view_content_global_value' );
294
- break;
295
-
296
- case 'price':
297
- $value = pys_get_product_price( $product_id );
298
- break;
299
-
300
- default:
301
- $value = null;
302
-
303
- }
304
-
305
- $params['value'] = $value;
306
- $params['currency'] = get_woocommerce_currency();
307
-
308
- }
309
-
310
- $tag = pys_insert_attribute( 'data-pys-event-id', $event_id, $tag, true, 'any' );
311
-
312
- $pys_woo_ajax_events[ $event_id ] = array(
313
- 'name' => 'AddToCart',
314
- 'params' => $params
315
- );
316
-
317
- return $tag;
318
-
319
- }
320
-
321
- }
322
-
323
- if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
324
-
325
- /**
326
- * Adds extra params to pixel init code. On Free always returns empty string.
327
- * PRO only.
328
- *
329
- * @see: https://www.facebook.com/help/ipad-app/606443329504150
330
- * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
331
- * @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
332
- *
333
- * @return string
334
- */
335
- function pys_get_additional_matching_code() {
336
-
337
- return ''; // PRO feature
338
-
339
- }
340
-
341
- }
342
-
343
- if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
344
-
345
- /**
346
- * Adds additional post parameters like `content_name` and `category_name`.
347
- * PRO only.
348
- *
349
- * @param $post WP_Post|int
350
- * @param $params array reference to $params array
351
- */
352
- function pys_get_additional_woo_params( $post, &$params ) {
353
-
354
- // PRO only
355
-
356
- }
357
-
358
- }
359
-
360
- if ( ! function_exists( 'pys_general_woo_event' ) ) {
361
-
362
- /**
363
- * Add General event on Woo Product page. PRO only.
364
- *
365
- * @param $post WP_Post|int
366
- * @param $track_tags bool
367
- * @param $delay int
368
- * @param $event_name string
369
- */
370
- function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
371
- // PRO feature
372
- }
373
-
374
- }
375
-
376
- if ( ! function_exists( 'pys_general_edd_event' ) ) {
377
-
378
- /**
379
- * Add General event on EDD Download page. PRO only.
380
- *
381
- * @param $post WP_Post|int
382
- * @param $track_tags bool
383
- * @param $delay int
384
- * @param $event_name string
385
- */
386
- function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
387
- // PRO feature
388
- }
389
-
390
- }
391
-
392
- if ( ! function_exists( 'pys_get_product_price' ) ) {
393
-
394
- /**
395
- * Return product price depends on plugin, product and WooCommerce settings.
396
- *
397
- * @param $product_id
398
- *
399
- * @return null|int Product price
400
- */
401
- function pys_get_product_price( $product_id ) {
402
-
403
- $product = wc_get_product( $product_id );
404
-
405
- /**
406
- * @since 5.0.9
407
- */
408
- if ( false == $product instanceof WC_Product ) {
409
- return 0;
410
- }
411
-
412
- if ( $product->is_taxable() ) {
413
-
414
- /**
415
- * @since 5.0.8
416
- */
417
- if ( pys_is_wc_version_gte( '2.7' ) ) {
418
- $value = wc_get_price_including_tax( $product, $product->get_price() );
419
- } else {
420
- $value = $product->get_price_including_tax( 1, $product->get_price() );
421
- }
422
-
423
- } else {
424
-
425
- /**
426
- * @since 5.0.8
427
- */
428
- if ( pys_is_wc_version_gte( '2.7' ) ) {
429
- $value = wc_get_price_excluding_tax( $product, $product->get_price() );
430
- } else {
431
- $value = $product->get_price_excluding_tax( 1, $product->get_price() );
432
- }
433
-
434
- }
435
-
436
- return $value;
437
-
438
- }
439
-
440
- }
441
-
442
- if ( ! function_exists( 'pys_get_cart_total' ) ) {
443
-
444
- function pys_get_cart_total() {
445
- global $woocommerce;
446
-
447
- return $woocommerce->cart->subtotal;
448
-
449
- }
450
-
451
- }
452
-
453
- if ( ! function_exists( 'pys_get_order_total' ) ) {
454
-
455
- /**
456
- * Calculates order 'value' param depends on WooCommerce and PYS settings
457
- */
458
- function pys_get_order_total( $order ) {
459
-
460
- //wc_get_price_thousand_separator is ignored
461
- return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
462
-
463
- }
464
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  }
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly.
5
+ }
6
+
7
+ if ( ! function_exists( 'pys_get_woo_ajax_addtocart_params' ) ) {
8
+
9
+ function pys_get_woo_ajax_addtocart_params( $product_id ) {
10
+
11
+ $params = array();
12
+ $params['content_type'] = 'product';
13
+ $params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
14
+
15
+ // currency, value
16
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
17
+
18
+ $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
19
+ switch ( $option ) {
20
+ case 'global':
21
+ $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
22
+ break;
23
+
24
+ case 'price':
25
+ $value = pys_get_product_price( $product_id );
26
+ break;
27
+
28
+ default:
29
+ $value = null;
30
+ }
31
+
32
+ $params['value'] = $value;
33
+ $params['currency'] = get_woocommerce_currency();
34
+
35
+ }
36
+
37
+ return $params;
38
+
39
+ }
40
+
41
+ }
42
+
43
+ if ( ! function_exists( 'pys_get_post_tags' ) ) {
44
+
45
+ /**
46
+ * Return array of product tags.
47
+ * PRO only.
48
+ */
49
+ function pys_get_post_tags( $post_id ) {
50
+
51
+ return array(); // PRO feature
52
+
53
+ }
54
+
55
+ }
56
+
57
+ if ( ! function_exists( 'pys_get_woo_code' ) ) {
58
+
59
+ /**
60
+ * Build WooCommerce related events code.
61
+ * Function adds evaluated event params to global array.
62
+ */
63
+ function pys_get_woo_code() {
64
+ global $post, $woocommerce;
65
+
66
+ // set defaults params
67
+ $params = array();
68
+ $params['content_type'] = 'product';
69
+
70
+ // ViewContent Event
71
+ if ( pys_get_option( 'woo', 'on_view_content' ) && is_product() ) {
72
+
73
+ $product = wc_get_product( $post->ID );
74
+
75
+ $params['content_ids'] = json_encode( pys_get_product_content_id( $post->ID ) );
76
+
77
+ if ( $product->get_type() == 'variable' && pys_get_option( 'woo', 'variation_id' ) != 'main' ) {
78
+ $params['content_type'] = 'product_group';
79
+ } else {
80
+ $params['content_type'] = 'product';
81
+ }
82
+
83
+ // @since 5.0.6
84
+ $params['content_type'] = apply_filters( 'pys_fb_pixel_woo_product_content_type', $params['content_type'],
85
+ $product->get_type(), $product, pys_get_option( 'woo', 'content_id_format' ) );
86
+
87
+ // currency, value
88
+ if ( pys_get_option( 'woo', 'enable_view_content_value' ) ) {
89
+
90
+ $option = pys_get_option( 'woo', 'view_content_value_option' );
91
+ switch ( $option ) {
92
+ case 'global':
93
+ $value = pys_get_option( 'woo', 'view_content_global_value' );
94
+ break;
95
+
96
+ case 'price':
97
+ $value = pys_get_product_price( $post );
98
+ break;
99
+
100
+ default:
101
+ $value = null;
102
+ }
103
+
104
+ $params['value'] = $value;
105
+ $params['currency'] = get_woocommerce_currency();
106
+
107
+ }
108
+
109
+ pys_add_event( 'ViewContent', $params );
110
+
111
+ return;
112
+
113
+ }
114
+
115
+ // AddToCart Cart Page Event
116
+ if ( pys_get_option( 'woo', 'on_add_to_cart_page' ) && is_cart() ) {
117
+
118
+ $ids = array(); // cart items ids or sku
119
+
120
+ foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
121
+
122
+ $product_id = pys_get_woo_cart_item_product_id( $item );
123
+ $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
124
+
125
+ }
126
+
127
+ $params['content_ids'] = json_encode( $ids );
128
+
129
+ // currency, value
130
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
131
+
132
+ $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
133
+ switch ( $option ) {
134
+ case 'global':
135
+ $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
136
+ break;
137
+
138
+ case 'price':
139
+ $value = pys_get_cart_total();
140
+ break;
141
+
142
+ default:
143
+ $value = null;
144
+ }
145
+
146
+ $params['value'] = $value;
147
+ $params['currency'] = get_woocommerce_currency();
148
+
149
+ }
150
+
151
+ pys_add_event( 'AddToCart', $params );
152
+
153
+ return;
154
+
155
+ }
156
+
157
+ // AddToCart on Checkout page
158
+ if ( pys_get_option( 'woo', 'on_add_to_cart_checkout' ) && is_checkout() && ! is_wc_endpoint_url() ) {
159
+
160
+ $ids = array(); // cart items ids or sku
161
+
162
+ foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
163
+
164
+ $product_id = pys_get_woo_cart_item_product_id( $item );
165
+ $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
166
+
167
+ }
168
+
169
+ $params['content_ids'] = json_encode( $ids );
170
+
171
+ // currency, value
172
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
173
+
174
+ $option = pys_get_option( 'woo', 'add_to_cart_value_option' );
175
+ switch ( $option ) {
176
+ case 'global':
177
+ $value = pys_get_option( 'woo', 'add_to_cart_global_value' );
178
+ break;
179
+
180
+ case 'price':
181
+ $value = pys_get_cart_total();
182
+ break;
183
+
184
+ default:
185
+ $value = null;
186
+ }
187
+
188
+ $params['value'] = $value;
189
+ $params['currency'] = get_woocommerce_currency();
190
+
191
+ }
192
+
193
+ pys_add_event( 'AddToCart', $params );
194
+
195
+ }
196
+
197
+ // Checkout Page Event
198
+ if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
199
+
200
+ $params = pys_get_woo_checkout_params( false );
201
+
202
+ // currency, value
203
+ if ( pys_get_option( 'woo', 'enable_checkout_value' ) ) {
204
+
205
+ $option = pys_get_option( 'woo', 'checkout_value_option' );
206
+ switch ( $option ) {
207
+ case 'global':
208
+ $value = pys_get_option( 'woo', 'checkout_global_value' );
209
+ break;
210
+
211
+ case 'price':
212
+ $value = pys_get_cart_total();
213
+ break;
214
+
215
+ default:
216
+ $value = null;
217
+ }
218
+
219
+ $params['value'] = $value;
220
+ $params['currency'] = get_woocommerce_currency();
221
+
222
+ }
223
+
224
+ pys_add_event( 'InitiateCheckout', $params );
225
+
226
+ return;
227
+
228
+ }
229
+
230
+ // Purchase Event
231
+ if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_wc_endpoint_url( 'order-received' ) ) {
232
+
233
+ $order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
234
+ $order = new WC_Order( $order_id );
235
+ $items = $order->get_items( 'line_item' );
236
+
237
+ $ids = array(); // order items ids or sku
238
+
239
+ foreach ( $items as $item ) {
240
+
241
+ $product_id = pys_get_woo_cart_item_product_id( $item );
242
+ $ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
243
+
244
+ }
245
+
246
+ $params['content_ids'] = json_encode( $ids );
247
+
248
+ // currency, value
249
+ if ( pys_get_option( 'woo', 'enable_purchase_value' ) ) {
250
+
251
+ $option = pys_get_option( 'woo', 'purchase_value_option' );
252
+ switch ( $option ) {
253
+ case 'global':
254
+ $value = pys_get_option( 'woo', 'purchase_global_value' );
255
+ break;
256
+
257
+ case 'total':
258
+ $value = pys_get_order_total( $order );
259
+ break;
260
+
261
+ default:
262
+ $value = null;
263
+ }
264
+
265
+ $params['value'] = $value;
266
+ $params['currency'] = get_woocommerce_currency();
267
+
268
+ }
269
+
270
+ pys_add_event( 'Purchase', $params );
271
+
272
+ return;
273
+
274
+ }
275
+
276
+ }
277
+
278
+ }
279
+
280
+ if ( ! function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
281
+
282
+ /**
283
+ * Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
284
+ *
285
+ * @param string $tag
286
+ * @param WC_Product $product
287
+ *
288
+ * @return string
289
+ */
290
+ function pys_add_code_to_woo_cart_link( $tag, $product ) {
291
+ global $pys_woo_ajax_events;
292
+
293
+ // do not add code if AJAX is disabled. event will be processed by another function
294
+ if ( 'yes' !== get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
295
+ return $tag;
296
+ }
297
+
298
+ if ( false == pys_woo_product_is_type( $product, 'simple' ) ) {
299
+ return $tag;
300
+ }
301
+
302
+ $event_id = uniqid();
303
+
304
+ /**
305
+ * @since 5.0.1
306
+ */
307
+ if ( pys_is_wc_version_gte( '2.6' ) ) {
308
+ $product_id = $product->get_id();
309
+ } else {
310
+ $product_id = $product->post->ID;
311
+ }
312
+
313
+ // common params
314
+ $params = array();
315
+ $params['content_type'] = 'product';
316
+ $params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
317
+
318
+ // currency, value
319
+ if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
320
+
321
+ $option = pys_get_option( 'woo', 'view_content_value_option' );
322
+ switch ( $option ) {
323
+ case 'global':
324
+ $value = pys_get_option( 'woo', 'view_content_global_value' );
325
+ break;
326
+
327
+ case 'price':
328
+ $value = pys_get_product_price( $product_id );
329
+ break;
330
+
331
+ default:
332
+ $value = null;
333
+
334
+ }
335
+
336
+ $params['value'] = $value;
337
+ $params['currency'] = get_woocommerce_currency();
338
+
339
+ }
340
+
341
+ $tag = pys_insert_attribute( 'data-pys-event-id', $event_id, $tag, true, 'any' );
342
+
343
+ $pys_woo_ajax_events[ $event_id ] = array(
344
+ 'name' => 'AddToCart',
345
+ 'params' => $params
346
+ );
347
+
348
+ return $tag;
349
+
350
+ }
351
+
352
+ }
353
+
354
+ if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
355
+
356
+ /**
357
+ * Adds extra params to pixel init code. On Free always returns empty string.
358
+ * PRO only.
359
+ *
360
+ * @see: https://www.facebook.com/help/ipad-app/606443329504150
361
+ * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
362
+ * @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
363
+ *
364
+ * @return string
365
+ */
366
+ function pys_get_additional_matching_code() {
367
+
368
+ return ''; // PRO feature
369
+
370
+ }
371
+
372
+ }
373
+
374
+ if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
375
+
376
+ /**
377
+ * Adds additional post parameters like `content_name` and `category_name`.
378
+ * PRO only.
379
+ *
380
+ * @param $post WP_Post|int
381
+ * @param $params array reference to $params array
382
+ */
383
+ function pys_get_additional_woo_params( $post, &$params ) {
384
+
385
+ // PRO only
386
+
387
+ }
388
+
389
+ }
390
+
391
+ if ( ! function_exists( 'pys_general_woo_event' ) ) {
392
+
393
+ /**
394
+ * Add General event on Woo Product page. PRO only.
395
+ *
396
+ * @param $post WP_Post|int
397
+ * @param $track_tags bool
398
+ * @param $delay int
399
+ * @param $event_name string
400
+ */
401
+ function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
402
+ // PRO feature
403
+ }
404
+
405
+ }
406
+
407
+ if ( ! function_exists( 'pys_general_edd_event' ) ) {
408
+
409
+ /**
410
+ * Add General event on EDD Download page. PRO only.
411
+ *
412
+ * @param $post WP_Post|int
413
+ * @param $track_tags bool
414
+ * @param $delay int
415
+ * @param $event_name string
416
+ */
417
+ function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
418
+ // PRO feature
419
+ }
420
+
421
+ }
422
+
423
+ if ( ! function_exists( 'pys_get_product_price' ) ) {
424
+
425
+ /**
426
+ * Return product price depends on plugin, product and WooCommerce settings.
427
+ *
428
+ * @param $product_id
429
+ *
430
+ * @return null|int Product price
431
+ */
432
+ function pys_get_product_price( $product_id ) {
433
+
434
+ $product = wc_get_product( $product_id );
435
+
436
+ /**
437
+ * @since 5.0.9
438
+ */
439
+ if ( false == $product instanceof WC_Product ) {
440
+ return 0;
441
+ }
442
+
443
+ if ( $product->is_taxable() ) {
444
+
445
+ /**
446
+ * @since 5.0.8
447
+ */
448
+ if ( pys_is_wc_version_gte( '2.7' ) ) {
449
+ $value = wc_get_price_including_tax( $product, $product->get_price() );
450
+ } else {
451
+ $value = $product->get_price_including_tax( 1, $product->get_price() );
452
+ }
453
+
454
+ } else {
455
+
456
+ /**
457
+ * @since 5.0.8
458
+ */
459
+ if ( pys_is_wc_version_gte( '2.7' ) ) {
460
+ $value = wc_get_price_excluding_tax( $product, $product->get_price() );
461
+ } else {
462
+ $value = $product->get_price_excluding_tax( 1, $product->get_price() );
463
+ }
464
+
465
+ }
466
+
467
+ return $value;
468
+
469
+ }
470
+
471
+ }
472
+
473
+ if ( ! function_exists( 'pys_get_cart_total' ) ) {
474
+
475
+ function pys_get_cart_total() {
476
+ global $woocommerce;
477
+
478
+ return $woocommerce->cart->subtotal;
479
+
480
+ }
481
+
482
+ }
483
+
484
+ if ( ! function_exists( 'pys_get_order_total' ) ) {
485
+
486
+ /**
487
+ * Calculates order 'value' param depends on WooCommerce and PYS settings
488
+ */
489
+ function pys_get_order_total( $order ) {
490
+
491
+ //wc_get_price_thousand_separator is ignored
492
+ return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
493
+
494
+ }
495
+
496
+ }
497
+
498
+ function pys_pixel_options() {
499
+ global $post;
500
+
501
+ $options = array(
502
+ 'woo' => array(),
503
+ );
504
+
505
+ if ( pys_get_option( 'woo', 'enabled' ) && pys_is_woocommerce_active() ) {
506
+
507
+ $options['woo']['is_product'] = is_product();
508
+ $options['woo']['add_to_cart_enabled'] = (bool) pys_get_option( 'woo', 'on_add_to_cart_btn' );
509
+
510
+ if ( is_product() ) {
511
+
512
+ $product = wc_get_product( $post );
513
+
514
+ if ( pys_woo_product_is_type( $product, 'simple' ) ) {
515
+ $options['woo']['single_product']['type'] = 'simple';
516
+ $options['woo']['single_product']['add_to_cart_params'] = pys_get_woo_ajax_addtocart_params(
517
+ $post->ID );
518
+ } elseif ( pys_woo_product_is_type( $product, 'variable' ) ) {
519
+ $options['woo']['single_product']['type'] = 'variable';
520
+ $options['woo']['single_product']['add_to_cart_params'] = pys_woo_product_variations_add_to_cart_params( $product );
521
+ }
522
+
523
+ }
524
+
525
+ }
526
+
527
+ return $options;
528
+
529
+ }
530
+
531
+ function pys_woo_product_variations_add_to_cart_params( $product ) {
532
+
533
+ $params = array();
534
+ $product = wc_get_product( $product );
535
+
536
+ if ( false == $product || false == pys_woo_product_is_type( $product, 'variable' ) ) {
537
+ return array();
538
+ }
539
+
540
+ foreach ( $product->get_available_variations() as $variation ) {
541
+ $params[ $variation['variation_id'] ] = pys_get_woo_ajax_addtocart_params( $variation['variation_id'] );
542
+ }
543
+
544
+
545
+ return $params;
546
+
547
+ }
548
+
549
+ function pys_woo_product_is_type( $product, $type ) {
550
+
551
+ if ( pys_is_wc_version_gte( '2.7' ) ) {
552
+ return $type == $product->is_type( $type );
553
+ } else {
554
+ return $product->product_type == $type;
555
+ }
556
+
557
  }
inc/general.php CHANGED
@@ -132,6 +132,8 @@ if ( ! function_exists( 'pys_public_scripts' ) ) {
132
 
133
  wp_enqueue_script( 'pys-public', plugins_url( 'pixelyoursite/js/public.js' ), array( 'jquery' ), PYS_FREE_VERSION,
134
  $in_footer );
 
 
135
 
136
  }
137
 
132
 
133
  wp_enqueue_script( 'pys-public', plugins_url( 'pixelyoursite/js/public.js' ), array( 'jquery' ), PYS_FREE_VERSION,
134
  $in_footer );
135
+
136
+ wp_localize_script( 'pys-public', 'pys_fb_pixel_options', pys_pixel_options() );
137
 
138
  }
139
 
inc/html-tab-edd.php CHANGED
@@ -150,6 +150,13 @@ if ( ! defined( 'ABSPATH' ) ) {
150
  <strong><?php _e( 'Enable AddToCart on add to cart button', 'pys' ); ?></strong>
151
  </td>
152
  </tr>
 
 
 
 
 
 
 
153
 
154
  <tr>
155
  <td></td>
150
  <strong><?php _e( 'Enable AddToCart on add to cart button', 'pys' ); ?></strong>
151
  </td>
152
  </tr>
153
+
154
+ <tr class="tall">
155
+ <td colspan="2" class="narrow">
156
+ <?php pys_checkbox( 'edd', 'on_add_to_cart_checkout', 'edd-option' ); ?>
157
+ <strong>Enable AddToCart on checkout page</strong>
158
+ </td>
159
+ </tr>
160
 
161
  <tr>
162
  <td></td>
inc/html-tab-woo-general.php CHANGED
@@ -165,27 +165,32 @@ if ( ! defined( 'ABSPATH' ) ) {
165
 
166
  <hr>
167
  <h2 class="section-title">AddToCart Event</h2>
168
- <p>AddToCart event will be added on add to cart button click and on cart page. It is required for Facebook Dynamic Product Ads.</p>
169
  <table class="layout">
170
- <tr>
171
- <td colspan="2" class="narrow">
172
-
173
- <input type="checkbox" name="pys[woo][on_add_to_cart_btn]" value="1" class="woo-option"
174
- <?php pys_checkbox_state( 'woo', 'on_add_to_cart_btn' ); ?> >
175
- <strong>Enable AddToCart on add to cart button</strong>
176
 
177
- </td>
178
- </tr>
179
-
180
- <tr class="tall">
181
- <td colspan="2" class="narrow">
182
-
183
- <input type="checkbox" name="pys[woo][on_cart_page]" value="1" class="woo-option"
184
- <?php pys_checkbox_state( 'woo', 'on_cart_page' ); ?> >
185
- <strong>Enable AddToCart on cart page</strong>
186
-
187
- </td>
188
- </tr>
 
 
 
 
 
 
 
 
 
 
 
189
 
190
  <tr>
191
  <td></td>
165
 
166
  <hr>
167
  <h2 class="section-title">AddToCart Event</h2>
168
+ <p>AddToCart event will be added on add to cart button click and on cart page. It is required for Facebook Dynamic Product Ads.</p>
169
  <table class="layout">
 
 
 
 
 
 
170
 
171
+ <tr>
172
+ <td colspan="2" class="narrow">
173
+ <input type="checkbox" name="pys[woo][on_add_to_cart_btn]" value="1" class="woo-option"
174
+ <?php pys_checkbox_state( 'woo', 'on_add_to_cart_btn' ); ?> >
175
+ <strong>Enable AddToCart on add to cart button</strong>
176
+ </td>
177
+ </tr>
178
+
179
+ <tr>
180
+ <td colspan="2" class="narrow">
181
+ <input type="checkbox" name="pys[woo][on_add_to_cart_page]" value="1" class="woo-option"
182
+ <?php pys_checkbox_state( 'woo', 'on_add_to_cart_page' ); ?> >
183
+ <strong>Enable AddToCart on cart page</strong>
184
+ </td>
185
+ </tr>
186
+
187
+ <tr class="tall">
188
+ <td colspan="2" class="narrow">
189
+ <input type="checkbox" name="pys[woo][on_add_to_cart_checkout]" value="1" class="woo-option"
190
+ <?php pys_checkbox_state( 'woo', 'on_add_to_cart_checkout' ); ?> >
191
+ <strong>Enable AddToCart on checkout page</strong>
192
+ </td>
193
+ </tr>
194
 
195
  <tr>
196
  <td></td>
inc/integrations/facebook-for-woocommerce.php CHANGED
@@ -1,222 +1,225 @@
1
- <?php
2
-
3
- /**
4
- * Manage integration with Facebook for WooCommerce plugin.
5
- *
6
- * When Facebook for WooCommerce is activated this integration completely removes
7
- * default Facebook for WooCommerce pixels and replaces them with PYS's. Also, new "Pixel ID format" option added to
8
- * PYS WooCommerce tab where user can decide what format to use in pixel: PYS default or Facebook for WooCommerce.
9
- */
10
-
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit; // Exit if accessed directly.
13
- }
14
-
15
- if ( class_exists( 'WC_Facebookcommerce' ) && ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
16
-
17
- /**
18
- * Declare fake WC_Facebookcommerce_EventsTracker class to remove all unwanted front-end pixel events.
19
- */
20
-
21
- /** @noinspection PhpUndefinedClassInspection */
22
- class WC_Facebookcommerce_EventsTracker {
23
-
24
- public function __construct( $pixel_id, $user_info ) {
25
- }
26
-
27
- public function inject_base_pixel() {
28
- }
29
-
30
- public function inject_view_category_event() {
31
- }
32
-
33
- public function inject_search_event() {
34
- }
35
-
36
- public function inject_view_content_event() {
37
- }
38
-
39
- public function inject_add_to_cart_event() {
40
- }
41
-
42
- public function inject_initiate_checkout_event() {
43
- }
44
-
45
- public function inject_purchase_event( $order_id ) {
46
- }
47
-
48
- }
49
-
50
- endif;
51
-
52
- if ( class_exists( 'WC_Facebookcommerce' ) ) :
53
-
54
- /**
55
- * Setup PYS hooks and filters for Facebook for WooCommerce related options and pixel ID output format.
56
- */
57
-
58
- add_filter( 'pys_fb_pixel_woo_product_content_id', 'fb_for_woo_pys_fb_pixel_woo_product_content_id', 10, 4 );
59
- function fb_for_woo_pys_fb_pixel_woo_product_content_id( $content_id, $product_id, $content_id_format ) {
60
-
61
- // use value as is
62
- if( $content_id_format !== 'facebook_for_woocommerce' ) {
63
- return $content_id;
64
- }
65
-
66
- $product = wc_get_product($product_id);
67
-
68
- if ( ! $product ) {
69
- return $content_id;
70
- }
71
-
72
- // Call $product->get_id() instead of ->id to account for Variable
73
- // products, which have their own variant_ids.
74
- $retailer_id = $product->get_sku() ? $product->get_sku() . '_' .
75
- $product->get_id() : 'wc_post_id_' . $product->get_id();
76
-
77
- $ids = array(
78
- $product->get_sku(),
79
- 'wc_post_id_' . $product->get_id(),
80
- $retailer_id
81
- );
82
-
83
- return $ids;
84
-
85
- }
86
-
87
- add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
88
- function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
89
-
90
- if( $content_id_format !== 'facebook_for_woocommerce' ) {
91
- return $content_type;
92
- }
93
-
94
- if ( $product_type == 'variable' ) {
95
- return 'product_group';
96
- } else {
97
- return 'product';
98
- }
99
-
100
- }
101
-
102
- add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
103
- function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
104
-
105
- if ( $content_id_format !== 'facebook_for_woocommerce' ) {
106
- return $product_id;
107
- }
108
-
109
- if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
110
- return $cart_item['variation_id'];
111
- } else {
112
- return $cart_item['product_id'];
113
- }
114
-
115
- }
116
-
117
- add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
118
- function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
119
-
120
- $setting_defaults['woo']['content_id_format'] = 'default';
121
-
122
- return $setting_defaults;
123
-
124
- }
125
-
126
- add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
127
- function pys_fb_pixel_admin_woo_content_id_before() {
128
-
129
- ?>
130
-
131
- <tr class="tall">
132
- <td colspan="2" class="narrow">
133
- <p><strong>It looks like you're using both PixelYourSite and Facebook Ads Extension. Good, because they can do a great job together!</strong></p>
134
- <p>Facebook Ads Extension is a useful free tool that lets you import your products to a Facebook shop and adds a very basic Facebook pixel on your site. PixelYourSite is a dedicated plugin that supercharges your Facebook Pixel with extremely useful features.</p>
135
-
136
- <p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
137
-
138
- <p style="margin-top: 0;">
139
- <input type="radio" name="pys[woo][content_id_format]" value="facebook_for_woocommerce" <?php echo pys_radio_state( 'woo', 'content_id_format', 'facebook_for_woocommerce' ); ?>><strong>Use Facebook for WooCommerce extension content_id logic</strong>
140
- </p>
141
-
142
- <p style="margin-top: 0;">
143
- <input type="radio" name="pys[woo][content_id_format]" value="default" <?php echo pys_radio_state( 'woo', 'content_id_format', 'default' ); ?>><strong>PixelYourSite content_id logic</strong>
144
- </p>
145
-
146
- <p><em>* If you plan to use the product catalog created by Facebook for WooCommerce Extension, use the Facebook for WooCommerce Extension ID. If you plan to use older product catalogs, or new ones created with other plugins, it's better to keep the default PixelYourSite settings.</em></p>
147
- </td>
148
- </tr>
149
-
150
-
151
- <script type="text/javascript">
152
- jQuery(document).ready(function ($) {
153
-
154
- $('input[name="pys[woo][content_id_format]"]').change(function (e) {
155
- toggleContentIDFormatControls();
156
- });
157
-
158
- toggleContentIDFormatControls();
159
-
160
- function toggleContentIDFormatControls() {
161
-
162
- var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
163
-
164
- if (format == 'default') {
165
- $('.content_id', '#woo_content_id' ).show();
166
- } else {
167
- $('.content_id', '#woo_content_id').hide();
168
- }
169
-
170
- }
171
-
172
- });
173
- </script>
174
-
175
- <?php
176
- }
177
-
178
- add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
179
- function fb_for_woo_admin_notice_display() {
180
-
181
- $user_id = get_current_user_id();
182
-
183
- if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
184
- return;
185
- }
186
-
187
- ?>
188
-
189
- <div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
190
- <p>You're using both PixelYourSite and Facebook for WooCommerce Extension. Good, because they can do a great job together! <strong><a href="<?php echo admin_url( 'admin.php?page=pixel-your-site&active_tab=woo#woo_content_id' ); ?>">Click here for more details</a></strong>.</p>
191
- </div>
192
-
193
- <script type="text/javascript">
194
- jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
195
-
196
- jQuery.ajax({
197
- url: ajaxurl,
198
- data: {
199
- action: 'fb_for_woo_admin_notice_dismiss',
200
- nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
201
- user_id: '<?php echo $user_id; ?>'
202
- }
203
- })
204
-
205
- })
206
- </script>
207
-
208
- <?php
209
- }
210
-
211
- add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
212
- function fb_for_woo_admin_notice_dismiss_handler() {
213
-
214
- if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
215
- return;
216
- }
217
-
218
- add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
219
-
220
- }
221
-
 
 
 
222
  endif;
1
+ <?php
2
+
3
+ /**
4
+ * Manage integration with Facebook for WooCommerce plugin.
5
+ *
6
+ * When Facebook for WooCommerce is activated this integration completely removes
7
+ * default Facebook for WooCommerce pixels and replaces them with PYS's. Also, new "Pixel ID format" option added to
8
+ * PYS WooCommerce tab where user can decide what format to use in pixel: PYS default or Facebook for WooCommerce.
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit; // Exit if accessed directly.
13
+ }
14
+
15
+ if ( class_exists( 'WC_Facebookcommerce' ) && ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
16
+
17
+ /**
18
+ * Declare fake WC_Facebookcommerce_EventsTracker class to remove all unwanted front-end pixel events.
19
+ */
20
+
21
+ /** @noinspection PhpUndefinedClassInspection */
22
+ class WC_Facebookcommerce_EventsTracker {
23
+
24
+ public function __construct( $pixel_id, $user_info ) {
25
+ }
26
+
27
+ public function inject_base_pixel() {
28
+ }
29
+
30
+ public function inject_view_category_event() {
31
+ }
32
+
33
+ public function inject_search_event() {
34
+ }
35
+
36
+ public function inject_view_content_event() {
37
+ }
38
+
39
+ public function inject_add_to_cart_event() {
40
+ }
41
+
42
+ public function inject_initiate_checkout_event() {
43
+ }
44
+
45
+ public function inject_purchase_event( $order_id ) {
46
+ }
47
+
48
+ public function inject_base_pixel_noscript() {
49
+ }
50
+
51
+ }
52
+
53
+ endif;
54
+
55
+ if ( class_exists( 'WC_Facebookcommerce' ) ) :
56
+
57
+ /**
58
+ * Setup PYS hooks and filters for Facebook for WooCommerce related options and pixel ID output format.
59
+ */
60
+
61
+ add_filter( 'pys_fb_pixel_woo_product_content_id', 'fb_for_woo_pys_fb_pixel_woo_product_content_id', 10, 4 );
62
+ function fb_for_woo_pys_fb_pixel_woo_product_content_id( $content_id, $product_id, $content_id_format ) {
63
+
64
+ // use value as is
65
+ if( $content_id_format !== 'facebook_for_woocommerce' ) {
66
+ return $content_id;
67
+ }
68
+
69
+ $product = wc_get_product($product_id);
70
+
71
+ if ( ! $product ) {
72
+ return $content_id;
73
+ }
74
+
75
+ // Call $product->get_id() instead of ->id to account for Variable
76
+ // products, which have their own variant_ids.
77
+ $retailer_id = $product->get_sku() ? $product->get_sku() . '_' .
78
+ $product->get_id() : 'wc_post_id_' . $product->get_id();
79
+
80
+ $ids = array(
81
+ $product->get_sku(),
82
+ 'wc_post_id_' . $product->get_id(),
83
+ $retailer_id
84
+ );
85
+
86
+ return $ids;
87
+
88
+ }
89
+
90
+ add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
91
+ function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
92
+
93
+ if( $content_id_format !== 'facebook_for_woocommerce' ) {
94
+ return $content_type;
95
+ }
96
+
97
+ if ( $product_type == 'variable' ) {
98
+ return 'product_group';
99
+ } else {
100
+ return 'product';
101
+ }
102
+
103
+ }
104
+
105
+ add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
106
+ function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
107
+
108
+ if ( $content_id_format !== 'facebook_for_woocommerce' ) {
109
+ return $product_id;
110
+ }
111
+
112
+ if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
113
+ return $cart_item['variation_id'];
114
+ } else {
115
+ return $cart_item['product_id'];
116
+ }
117
+
118
+ }
119
+
120
+ add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
121
+ function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
122
+
123
+ $setting_defaults['woo']['content_id_format'] = 'default';
124
+
125
+ return $setting_defaults;
126
+
127
+ }
128
+
129
+ add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
130
+ function pys_fb_pixel_admin_woo_content_id_before() {
131
+
132
+ ?>
133
+
134
+ <tr class="tall">
135
+ <td colspan="2" class="narrow">
136
+ <p><strong>It looks like you're using both PixelYourSite and Facebook Ads Extension. Good, because they can do a great job together!</strong></p>
137
+ <p>Facebook Ads Extension is a useful free tool that lets you import your products to a Facebook shop and adds a very basic Facebook pixel on your site. PixelYourSite is a dedicated plugin that supercharges your Facebook Pixel with extremely useful features.</p>
138
+
139
+ <p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
140
+
141
+ <p style="margin-top: 0;">
142
+ <input type="radio" name="pys[woo][content_id_format]" value="facebook_for_woocommerce" <?php echo pys_radio_state( 'woo', 'content_id_format', 'facebook_for_woocommerce' ); ?>><strong>Use Facebook for WooCommerce extension content_id logic</strong>
143
+ </p>
144
+
145
+ <p style="margin-top: 0;">
146
+ <input type="radio" name="pys[woo][content_id_format]" value="default" <?php echo pys_radio_state( 'woo', 'content_id_format', 'default' ); ?>><strong>PixelYourSite content_id logic</strong>
147
+ </p>
148
+
149
+ <p><em>* If you plan to use the product catalog created by Facebook for WooCommerce Extension, use the Facebook for WooCommerce Extension ID. If you plan to use older product catalogs, or new ones created with other plugins, it's better to keep the default PixelYourSite settings.</em></p>
150
+ </td>
151
+ </tr>
152
+
153
+
154
+ <script type="text/javascript">
155
+ jQuery(document).ready(function ($) {
156
+
157
+ $('input[name="pys[woo][content_id_format]"]').change(function (e) {
158
+ toggleContentIDFormatControls();
159
+ });
160
+
161
+ toggleContentIDFormatControls();
162
+
163
+ function toggleContentIDFormatControls() {
164
+
165
+ var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
166
+
167
+ if (format == 'default') {
168
+ $('.content_id', '#woo_content_id' ).show();
169
+ } else {
170
+ $('.content_id', '#woo_content_id').hide();
171
+ }
172
+
173
+ }
174
+
175
+ });
176
+ </script>
177
+
178
+ <?php
179
+ }
180
+
181
+ add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
182
+ function fb_for_woo_admin_notice_display() {
183
+
184
+ $user_id = get_current_user_id();
185
+
186
+ if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
187
+ return;
188
+ }
189
+
190
+ ?>
191
+
192
+ <div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
193
+ <p>You're using both PixelYourSite and Facebook for WooCommerce Extension. Good, because they can do a great job together! <strong><a href="<?php echo admin_url( 'admin.php?page=pixel-your-site&active_tab=woo#woo_content_id' ); ?>">Click here for more details</a></strong>.</p>
194
+ </div>
195
+
196
+ <script type="text/javascript">
197
+ jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
198
+
199
+ jQuery.ajax({
200
+ url: ajaxurl,
201
+ data: {
202
+ action: 'fb_for_woo_admin_notice_dismiss',
203
+ nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
204
+ user_id: '<?php echo $user_id; ?>'
205
+ }
206
+ })
207
+
208
+ })
209
+ </script>
210
+
211
+ <?php
212
+ }
213
+
214
+ add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
215
+ function fb_for_woo_admin_notice_dismiss_handler() {
216
+
217
+ if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
218
+ return;
219
+ }
220
+
221
+ add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
222
+
223
+ }
224
+
225
  endif;
inc/migrate.php CHANGED
@@ -33,7 +33,6 @@ if( !function_exists( 'pys_migrate_from_22x' ) ) {
33
  $options['woo']['enabled'] = isset( $old_free['woocommerce']['activate'] ) ? $old_free['woocommerce']['activate'] : 0;
34
  $options['woo']['on_view_content'] = isset( $old_free['woocommerce']['events']['ViewContent'] ) ? $old_free['woocommerce']['events']['ViewContent'] : 0;
35
  $options['woo']['on_add_to_cart_btn'] = isset( $old_free['woocommerce']['events']['ProductAddToCart'] ) ? $old_free['woocommerce']['events']['ProductAddToCart'] : 0;
36
- $options['woo']['on_cart_page'] = isset( $old_free['woocommerce']['events']['AddToCart'] ) ? $old_free['woocommerce']['events']['AddToCart'] : 0;
37
  $options['woo']['on_checkout_page'] = isset( $old_free['woocommerce']['events']['InitiateCheckout'] ) ? $old_free['woocommerce']['events']['InitiateCheckout'] : 0;
38
  $options['woo']['on_thank_you_page'] = isset( $old_free['woocommerce']['events']['Purchase'] ) ? $old_free['woocommerce']['events']['Purchase'] : 0;
39
 
33
  $options['woo']['enabled'] = isset( $old_free['woocommerce']['activate'] ) ? $old_free['woocommerce']['activate'] : 0;
34
  $options['woo']['on_view_content'] = isset( $old_free['woocommerce']['events']['ViewContent'] ) ? $old_free['woocommerce']['events']['ViewContent'] : 0;
35
  $options['woo']['on_add_to_cart_btn'] = isset( $old_free['woocommerce']['events']['ProductAddToCart'] ) ? $old_free['woocommerce']['events']['ProductAddToCart'] : 0;
 
36
  $options['woo']['on_checkout_page'] = isset( $old_free['woocommerce']['events']['InitiateCheckout'] ) ? $old_free['woocommerce']['events']['InitiateCheckout'] : 0;
37
  $options['woo']['on_thank_you_page'] = isset( $old_free['woocommerce']['events']['Purchase'] ) ? $old_free['woocommerce']['events']['Purchase'] : 0;
38
 
js/public.js CHANGED
@@ -1,5 +1,11 @@
1
  jQuery(document).ready(function( $ ) {
2
 
 
 
 
 
 
 
3
  // load FB pixel
4
  !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
5
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
@@ -7,6 +13,56 @@ jQuery(document).ready(function( $ ) {
7
  t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
8
  document,'script','https://connect.facebook.net/en_US/fbevents.js');
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  regularEvents();
11
  customCodeEvents();
12
 
@@ -128,4 +184,11 @@ jQuery(document).ready(function( $ ) {
128
 
129
  }
130
 
 
 
 
 
 
 
 
131
  });
1
  jQuery(document).ready(function( $ ) {
2
 
3
+ if (typeof pys_fb_pixel_options === 'undefined') {
4
+ return;
5
+ }
6
+
7
+ var options = pys_fb_pixel_options; // variable shorthand
8
+
9
  // load FB pixel
10
  !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
11
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
13
  t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
14
  document,'script','https://connect.facebook.net/en_US/fbevents.js');
15
 
16
+ /**
17
+ * Setup Events Handlers
18
+ */
19
+ !function setupEventHandlers() {
20
+
21
+ /**
22
+ * WooCommerce Events
23
+ */
24
+ if (options.hasOwnProperty('woo')) {
25
+
26
+ // WooCommerce single product AddToCart handler on AJAX-ed themes
27
+ if (options.woo.is_product && options.woo.add_to_cart_enabled ) {
28
+
29
+ $(document).on('added_to_cart', function () {
30
+
31
+ var params = {};
32
+
33
+ if (options.woo.single_product.type === 'variable') {
34
+
35
+ var $form = $('form.variations_form.cart'),
36
+ variation_id = false,
37
+ qty;
38
+
39
+ if ($form.length === 1) {
40
+ variation_id = $form.find('input[name="variation_id"]').val();
41
+ }
42
+
43
+ if (false === variation_id || false === options.woo.single_product.add_to_cart_params.hasOwnProperty(variation_id)) {
44
+ console.error('PYS PRO: product variation ID not found in available product variants.');
45
+ return;
46
+ }
47
+
48
+ params = clone(options.woo.single_product.add_to_cart_params[variation_id], {});
49
+ qty = parseInt($form.find('input[name="quantity"]').val());
50
+ params.value = params.value * qty;
51
+
52
+ } else {
53
+ params = clone(options.woo.single_product.add_to_cart_params, {});
54
+ }
55
+
56
+ fbq('track', 'AddToCart', params);
57
+
58
+ });
59
+
60
+ }
61
+
62
+ }
63
+
64
+ }();
65
+
66
  regularEvents();
67
  customCodeEvents();
68
 
184
 
185
  }
186
 
187
+ var clone = function (src, dest) {
188
+ for (var key in src) {
189
+ dest[key] = src[key];
190
+ }
191
+ return dest;
192
+ };
193
+
194
  });
readme.txt CHANGED
@@ -2,8 +2,9 @@
2
  Contributors: PixelYourSite, c0d3fev3r, themister
3
  Tags: Facebook Pixel, New Facebook Pixel, Facebook Conversion Pixel, Facebook Pixel Events, Facebook, New Facebook Pixel Events, Dynamic Events, Standard Events, Facebook Events, Facebook Standard Events, Facebook Dynamic Product Ads, WooCommerce, WooCommerce Facebook Pixel, Facebook Custom Events, Facebook Conversion Value, WooCommerce Affiliate Products, Easy Digital Downloads Pixel, Easy Digital Downloads Facebook Pixel
4
  Requires at least: 3.0.1
5
- Tested up to: 4.8
6
- Stable tag: 5.0.7
 
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -18,15 +19,19 @@ The New Facebook Pixel can be a very powerful tool for anyone doing Facebook ads
18
 
19
  [youtube https://www.youtube.com/watch?v=V_IWVxUrzSM]
20
 
21
- >**PixelYourSite will help you insert the Facebook pixel code on every page of your site with just one click** and set up Custom or Standard Events.
22
 
23
- >There is an automatic **WooCommerce and Easy Digital Downloads setup** that will configure all the necessary standard events for you. **You don't have to add any event yourself.**
24
- >
25
- >**Facebook Dynamic Ads (Promote a product catalog) is fully supported for WooCommerce and Easy Digital Downloads**, with ViewContent, AddToCart and Purchase events being added on the corresponding pages (content_ids and content_type are pulled automatically by the plugin).
26
- >
27
- >The plugin is **Custom Audience Super-Friendly**, extracting content_name, post_type, content_ids, content_category on every page of your site. Tags and product tags are tracked by the pro version of the plugin.
 
 
 
 
28
 
29
- You’ll find a **[Learning Section](http://www.pixelyoursite.com/learn)** on our website, with helpful articles that answer to our users common (and sometimes uncommon) questions, together with top notch “how to” pages.
30
 
31
  Find more info [about how to use the FB pixel plugin - Click here](http://www.pixelyoursite.com/facebook-pixel-plugin-help)
32
 
@@ -36,7 +41,25 @@ Not ready to install yet? Read on some of the key features that make PYS a power
36
 
37
  * You can **insert the pixel on every page of your website with just ONE click**. No need to edit any posts or pages
38
 
39
- * **Optimize your site for Facebook Custom Audiences.** We add a special event (GeneralEvent) on every page that will send Facebook key parameters, like content name, content ID, category name and post type. You can use them to create super-powerful Custom Audiences to retarget with your ads, or to expand your reach with Lookalike Audiences (we have a free guide and helpful articles on how to do it)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  * **Search Event** on the search page with the search string pulled as parameter - super useful for creating search based Custom Audiences
42
 
@@ -54,147 +77,104 @@ Retargeting the users that performed a search on your site is a smart strategy b
54
 
55
  * All the events will have a **domain name parameter**, so you can easily create Custom Audiences from events when you have more than one site
56
 
57
- * **Traffic Source and URL tags (UTM)** are added to all the events and you can use them to create Custom Audiences based on where your visitors are coming from. It is possible to track a particular Facebook Ad too. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
58
 
59
- >You can create Custom Audiences based on where the traffic is coming from, like Google, Facebook or a particular referer.
60
- >
61
- >Additionally, if you are using URL parameters they will be tracked and added as parameters for all your events. This is extremely useful because you can create Custom Audiences from people coming from a particular ad or campaign, for example.
62
 
63
- * **Dynamic Events:** optimize your Facebook Campaigns for actions on your website (CLICKS on links, buttons, forms, page scroll or mouse over). Works with **almost all forms or pop-up plugins.** ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
64
-
65
- >Fire a Dynamic Event when the visitor performs a key action on your site and optimize your ads for that event (perfect for affiliate sites, newsletter signups and so on).
66
- >
67
- >Additionally, you can create Custom Audiences based on dynamic events. These are people with a high interest in your products or offers and you can retarget them successfully.
68
- >
69
- >With PixelYourSite PRO you can fire Dynamic Events:
70
- >
71
- >* When a URL is clicked
72
- >* When a CSS element is clicked (any form button, for example)
73
- >* When the mouse is moved over a page element
74
- >* On page scroll (scroll percent).
75
 
 
76
 
77
- * Track **conversion value** for standard and custom events
78
 
79
- * Track tags and use them for Custom Audiences ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
80
 
81
- * Enable **Advanced Matching** - this new FB feature increases the chances to correctly identify users visiting your website without being logged to their Facebook accounts. The plugin will automatically send to Facebook the data you have about the visitors. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
82
 
83
- >**What's the deal with the GeneralEvent**
84
- >
85
- >The plugin will fire a GeneralEvent that can be used in two different ways:
86
- >
87
- >**1. Custom Audiences** - you can create Custom Audiences using Website Trafic > Custom Combination > Event. From here you can select the GeneralEvent and add the desired parameters.
88
- >
89
- >The GeneralEvent will have the following parameters:
90
- >
91
- >* post_id
92
- >* post_type (it will pull the WordPress post type, like post, category and so on)
93
- >* content_category (for posts, it will show the post category)
94
- >* domain (it will pull the domain name - useful if you are using the pixel on more than one sites)
95
- >* tags - pro version
96
- >
97
- >**How to use the GeneralEvent for Custom Audiences**
98
- >
99
- >**Example:** you can create a Custom Audience from people that viewed articles from one specific category in the last 30 days or people that visited articles having one or more tags, a particular page (using the name or the ID), or content that has a particular word in the name.
100
- >
101
- >
102
- >**2. Custom Conversions** - similar to Custom Audiences, you can create Custom Conversions based on the GeneralEvent.
103
- >
104
- >**Example:** You can define a Custom Conversion when someone reads at least 3 articles from a particular category, or when it lands on a specific page, or on any article that has a particular tag.
105
- >
106
- >
107
- >Because this is such a useful feature, we made a special guide that you can download for free: [Click here for the guide](http://www.pixelyoursite.com/general-event)
108
-
109
- <strong>Superb WooCommerce Integration</strong><br>
110
-
111
- Tested with WooCommerce 3
112
-
113
- * You can **insert the Facebook pixel and start tracking events on any WooCommerce** website with just a few clicks (Purchase, ViewContent, AddToCart, InitiateCheckout)
114
 
115
- * Out of the box **Facebook Dynamic Ads** (promote a product catalog) pixel setup for your Woocommerce website (we also have a dedicated feed plugin for Facebook Dynamic Ads Product Catalog)
116
 
117
  * **Dynamic AddToCart** is fully supported (the AddToCart event will fire on add to cart button click)
118
 
119
- * **Track conversion value for WooCommerce**
120
 
121
- * **WooCommerce Conversion Value Optimization:** You can include or exclude TAX for all the WooCommere events and Shipping cost for the Purchase event. You can use the full product price or just a percent of the price for each event Value. You can also set a general value for each event. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
122
-
123
- * You can turn ON/OFF each WooCommerce event.
124
 
125
- * You can turn ON/OFF value for each WooCommerce event.
126
 
127
- * Delay the WooCommerce ViewContent Event, so you don't spend your money on retargeting bouncing visitors ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
128
 
129
- * **Super-Powerful Custom Audiences for WooCommerce:** - we automatically track product name, product category and product tags. You can use them to create highly targeted Custom Audiences for improved retargeting campaigns. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
130
 
131
- * **Improved Purchase Event** - The purchase event will have payment and shipping methods, client city, state and country, plus use of coupons and coupons names tracked as parameters. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
132
 
133
- >With the Improved Purchased Event you can create extremely useful Custom Audiences and retarget them with highly efficient ads.
134
- >Example: Clients that bought products from category X for at least $100 and that never used coupon ABC.
135
  >
136
- >Retargeting this audience with products from the same or similar category and give them the coupon ABC might be a winning strategy.
137
 
138
- * **Advance Matching** is supported for all the events - this is a useful feature from Facebook that increases the chances to correctly identify users visiting your website without being logged to their Facebook accounts. Not sure what "Advanced Matching" does? We have not one, but two articles with more details on our site. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
139
 
140
- >With Advanced Matching ON, the plugin will send to Facebook the data you have about your clients, like their names, address, email or phone, improving conversion attribution and retargeting
141
 
142
- * **WooCommerce Affiliate Products Events:** you can add a dynamic event that will trigger on affiliate button clicks ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
143
 
144
- * **WooCommerce PayPal Standard Events:** you can add a dynamic AddPaymentInfo event that will trigger on WooCommerce PayPal button clicks ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
145
 
146
- * Fully tested with the latest version of WooCommerce
147
 
148
- <strong>Easy Digital Downloads Integration<strong>
149
 
150
- * You can **insert the Facebook pixel and start tracking events on any Easy Digital Downloads** website with just a few clicks (Purchase, ViewContent, AddToCart, InitiateCheckout)
151
 
152
- * Out of the box **Facebook Dynamic Ads** (promote a product catalog) pixel setup for your Easy Digital Downloads website.
 
 
 
153
 
154
- * **Dynamic AddToCart** is fully supported (the AddToCart event will fire on add to cart button click)
155
 
156
- * **Track conversion value for Easy Digital Downloads** ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
157
 
158
- * **Easy Digital Downloads Conversion Value Optimization:** You can include or exclude TAX for all the Easy Digital Downloads events. You can use the full product price or just a percent of the price for each event Value. You can also set a general value for each event. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
159
 
160
- * You can turn ON/OFF each Easy Digital Downloads event.
 
 
161
 
162
- * You can turn ON/OFF value for each Easy Digital Downloads event.
163
 
164
- * Set up a general value for each Easy Digital Downloads event.
165
 
166
- * Delay the Easy Digital Downloads ViewContent Event, so you don't spend your money on retargeting bouncing visitors ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
167
 
168
- * **Super-Powerful Custom Audiences for Easy Digital Downloads:** - we automatically track download name, download category, and download tags. You can use them to create highly targeted Custom Audiences for improved retargeting campaigns. Transaction day, month and year are also tracked as parameters, together with transaction type (free or paid). ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
169
 
170
- * **EDD License Software* integration: license version and license time limit are added as parameters, giving you the possibility to split your custom audiences based on this info.
171
 
172
- * **Improved Purchase Event** - The purchase event will have payment methods, client's city, state and country, plus use of discount codes and the discount codes names tracked as parameters. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
173
 
174
  >With the Improved Purchased Event you can create extremely useful Custom Audiences and retarget them with highly efficient ads.
175
- >Example: Clients that bought download X for and that never used the discount code ABC.
176
  >
177
- >Retargeting this audience with downloads from a similar category and giving them the discount code ABC might be a winning strategy.
 
 
178
 
179
- * **Advance Matching** is supported for all the events - this is a useful feature that increases the chances to correctly identify users visiting your website without being logged to their Facebook accounts. ([Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin))
180
 
181
- >With Advanced Matching ON, the plugin will send to Facebook the data you have about your clients, like their names, address, email or phone, improving conversion attribution and retargeting results.
182
 
 
183
 
184
- **[The Pro Version](http://www.pixelyoursite.com/facebook-pixel-plugin) was seriously improved:
 
 
185
 
186
  * Add multiple pixels IDs - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
187
  * Use dynamic parameters - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
188
  * Remove the pixel from any page - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
189
  * Custom Thank You Page for WooCommerce - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
190
 
191
- **NEW:** insert ANY script with our new Head/Footer option.
192
-
193
-
194
- <strong>What's next<strong>
195
-
196
- We are working on some new handy features for the plugin and we will release them soon.
197
-
198
  <strong>Pixel Helper Errors</strong>
199
 
200
  If you are testing your pixel with Pixel Helper Chrome Extension, it is possible that you will see some errors:
@@ -207,6 +187,8 @@ For more details on how to use Facebook Pixel Helper and how to interpret its re
207
 
208
  **Let’s start now!** Join other thousands of users and install the plugin, because it is easy to use, and will help you with your Facebook campaigns for real
209
 
 
 
210
  == Installation ==
211
  * From the WP admin panel, click \"Plugins\" -> \"Add new\".
212
  * In the browser input box, type \"PixelYourSite\".
@@ -318,6 +300,15 @@ We have an article about how to create Custom Reports:
318
 
319
  == Changelog ==
320
 
 
 
 
 
 
 
 
 
 
321
  = PixelYourSite 5.0.7 =
322
 
323
  * Purchase event 0 value error fixed (there wasn't any value parameter when the order value was zero)
2
  Contributors: PixelYourSite, c0d3fev3r, themister
3
  Tags: Facebook Pixel, New Facebook Pixel, Facebook Conversion Pixel, Facebook Pixel Events, Facebook, New Facebook Pixel Events, Dynamic Events, Standard Events, Facebook Events, Facebook Standard Events, Facebook Dynamic Product Ads, WooCommerce, WooCommerce Facebook Pixel, Facebook Custom Events, Facebook Conversion Value, WooCommerce Affiliate Products, Easy Digital Downloads Pixel, Easy Digital Downloads Facebook Pixel
4
  Requires at least: 3.0.1
5
+ Requires PHP: 5.3
6
+ Tested up to: 4.9
7
+ Stable tag: 5.0.8
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
19
 
20
  [youtube https://www.youtube.com/watch?v=V_IWVxUrzSM]
21
 
22
+ **PixelYourSite will help you insert the Facebook pixel code on every page of your site with just one click** and set up Custom or Standard Events.
23
 
24
+ **E-commerce Ready**
25
+
26
+ There is an automatic **WooCommerce integration** that will configure all the necessary standard events for you. **You don't have to add any event yourself.**
27
+
28
+ **Easy Digital Downloads** is also supported.
29
+
30
+ **Facebook Dynamic Ads (Promote a product catalog) is fully supported for WooCommerce and Easy Digital Downloads**, with ViewContent, AddToCart and Purchase events being added on the corresponding pages (content_ids and content_type are pulled automatically by the plugin).
31
+
32
+ The plugin is **Custom Audience Super-Friendly**, extracting content_name, post_type, content_ids, content_category on every page of your site. Tags and product tags are tracked by the pro version of the plugin.
33
 
34
+ You’ll find a **[Learning Section](http://www.pixelyoursite.com/learn)** on our website, with helpful articles that answer to our users common (and sometimes uncommon) questions, together with top-notch “how to” pages.
35
 
36
  Find more info [about how to use the FB pixel plugin - Click here](http://www.pixelyoursite.com/facebook-pixel-plugin-help)
37
 
41
 
42
  * You can **insert the pixel on every page of your website with just ONE click**. No need to edit any posts or pages
43
 
44
+ * **Optimize your site for Facebook Custom Audiences.** We add a special event (GeneralEvent) on every page that will send key parameters to Facebook, like content name, content ID, category name and post type. You can use it to create super-powerful Custom Audiences to retarget with your ads, or to expand your reach with Lookalike Audiences.
45
+
46
+ >**How to use the GeneralEvent**
47
+ >
48
+ >**1. Custom Audiences**
49
+ >
50
+ >The GeneralEvent will have the following parameters:
51
+ >
52
+ >* post_id
53
+ >* post_type (it will pull the WordPress post type, like post, category and so on)
54
+ >* content_category (for posts, it will show the post category)
55
+ >* domain (it will pull the domain name - useful if you are using the pixel on more than one sites)
56
+ >* tags - pro version
57
+ >
58
+ >**Example:** you can create a Custom Audience from people that viewed articles from one specific category in the last 30 days or people that visited articles having one or more tags, a particular page (using the name or the ID), or content that has a particular word in the name.
59
+ >
60
+ >**2. Custom Conversions**
61
+ >
62
+ >**Example:** You can define a Custom Conversion when someone reads at least 3 articles from a particular category, or when it lands on a specific page, or on any article that has a particular tag.
63
 
64
  * **Search Event** on the search page with the search string pulled as parameter - super useful for creating search based Custom Audiences
65
 
77
 
78
  * All the events will have a **domain name parameter**, so you can easily create Custom Audiences from events when you have more than one site
79
 
80
+ **Superb WooCommerce Integration**
81
 
82
+ Tested with the latest WooCommerce version.
 
 
83
 
84
+ * You can **insert the Facebook pixel and start tracking events on any WooCommerce** website with just a few clicks (Purchase, ViewContent, AddToCart, InitiateCheckout)
 
 
 
 
 
 
 
 
 
 
 
85
 
86
+ * Out of the box **Facebook Dynamic Ads** (promote a product catalog) pixel setup for your Woocommerce website (we also have a dedicated feed plugin for Facebook Dynamic Ads Product Catalog)
87
 
88
+ * Flexible AddToCart Event: the event will fire by default on add to cart button clicks. Ajax buttons are supported. Additionally, the event can be fired on the Cart Page, or on the Checkout Page (useful for some particular web structures).
89
 
90
+ * Track conversion value for WooCommerce - each event can use the product price as value. You can turn it on or off.
91
 
92
+ **Easy Digital Downloads Integration**
93
 
94
+ * You can **insert the Facebook pixel and start tracking events on any Easy Digital Downloads** website with just a few clicks (Purchase, ViewContent, AddToCart, InitiateCheckout)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
+ * Out of the box **Facebook Dynamic Ads** (promote a product catalog) pixel setup for your Easy Digital Downloads website.
97
 
98
  * **Dynamic AddToCart** is fully supported (the AddToCart event will fire on add to cart button click)
99
 
100
+ * **Track conversion value for Easy Digital Downloads**
101
 
102
+ * You can turn ON/OFF each Easy Digital Downloads event.
 
 
103
 
104
+ **Pro Version**
105
 
106
+ If you are serious about your Facebook ads, you'll love our [pro version](http://www.pixelyoursite.com/facebook-pixel-plugin)
107
 
108
+ **Improved Custom Audiences & Custom Conversions**
109
 
110
+ * **Traffic Source and URL tags (UTM)** are added to all the events and you can use them to create Custom Audiences based on where your visitors are coming from. It is possible to track a particular Facebook Ad too.
111
 
112
+ >You can create Custom Audiences based on where the traffic is coming from, like Google, Facebook or a particular referer.
 
113
  >
114
+ >Additionally, if you are using URL parameters they will be tracked and added as parameters for all your events. This is extremely useful because you can create Custom Audiences from people coming from a particular ad or campaign, for example.
115
 
116
+ Find out more on [how the pro version can help you with Custom Conversion and Custom Audiences](http://www.pixelyoursite.com/facebook-pixel-plugin/custom-audiences-conversions)
117
 
118
+ * **NEW: The ClickEvent** - It will fire EVERYTIME a click is made on your site. Use it for Custom Audiences or Custom Conversions. [Find more here](http://www.pixelyoursite.com/clicks-facebook-custom-conversions-audiences)
119
 
120
+ * **NEW: Head/Footer scripts** - Add any script you want with our Head/Footer option. It also works on the WooCommerce thank you page. [Find more here](http://www.pixelyoursite.com/head-footer-scripts)
121
 
122
+ * **NEW: WatchVideo Event** - This event will fire on embedded videos on your site. It can be used to optimize your ads for video views or to retarget your video watchers using Custom Audiences. [Find more here](http://www.pixelyoursite.com/facebook-pixel-plugin/watchvideo-event)
123
 
 
124
 
125
+ **Dynamic Events**
126
 
127
+ Optimize your Facebook Campaigns for actions on your website with dynamic events. You can fire them:
128
 
129
+ * When a URL is clicked
130
+ * When a CSS element is clicked (any form button, for example)
131
+ * When the mouse is moved over a page element
132
+ * On page scroll (scroll percent).
133
 
134
+ Works with **almost all forms or pop-up plugins.**
135
 
136
+ Fire a Dynamic Event when the visitor performs a key action on your site and optimize your ads for that event (perfect for affiliate sites, newsletter signups and so on).
137
 
138
+ Additionally, you can create Custom Audiences based on these dynamic events and retarget them.
139
 
140
+ Find out more about [PixelYourSite Pro events here](http://www.pixelyoursite.com/facebook-pixel-plugin/facebook-pixel-events)
141
+
142
+ **Advanced Matching**
143
 
144
+ This FB feature increases the chances to correctly identify users visiting your website without being logged to their Facebook accounts. The plugin will automatically send to Facebook the data you have about the visitors (email, first name, second name, phone, address info).
145
 
146
+ **Improved WooCommerce & Easy Digital Downloads Integration**
147
 
148
+ * **Customize each event value:** You can include or exclude tax and shipping, you can use the product price, **a percent of the product price**, or a global value. Using the proper event value can improve your ads delivery and ROI.
149
 
150
+ * Delay the WooCommerce & EDD ViewContent Event, so you don't spend your money on retargeting bouncing visitors.
151
 
152
+ * Super-Powerful **Custom Audiences for WooCommerce**: - we automatically track product name, product category, and product tags. You can use them to create highly targeted Custom Audiences for improved retargeting campaigns.
153
 
154
+ * **Improved Purchase Event** - The purchase event will have payment and shipping methods, client city, state, and country, plus use of coupons and coupons names tracked as parameters.
155
 
156
  >With the Improved Purchased Event you can create extremely useful Custom Audiences and retarget them with highly efficient ads.
157
+ >Example: Clients that bought products from category X for at least $100 and that never used coupon ABC.
158
  >
159
+ >Retargeting this audience with products from the same or similar category and give them the coupon ABC might be a winning strategy.
160
+
161
+ * **Advance Matching** is supported for all the events - it will work best for your Purchase event because we will use the client data directly.
162
 
163
+ * **WooCommerce Affiliate Products Events:** you can add a dynamic event that will trigger on affiliate button clicks.
164
 
165
+ * **WooCommerce PayPal Standard Events:** you can add a dynamic AddPaymentInfo event that will trigger on WooCommerce PayPal button clicks.
166
 
167
+ Find more on the [WooCommerce integration here](http://www.pixelyoursite.com/facebook-pixel-plugin/woocommerce-facebook-pixel)
168
 
169
+ Find more on the [EDD integration here](http://www.pixelyoursite.com/facebook-pixel-plugin/easy-digital-downloads-facebook-pixel)
170
+
171
+ **The Super-Pack**
172
 
173
  * Add multiple pixels IDs - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
174
  * Use dynamic parameters - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
175
  * Remove the pixel from any page - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
176
  * Custom Thank You Page for WooCommerce - [with the Super-Pack](http://www.pixelyoursite.com/super-pack)
177
 
 
 
 
 
 
 
 
178
  <strong>Pixel Helper Errors</strong>
179
 
180
  If you are testing your pixel with Pixel Helper Chrome Extension, it is possible that you will see some errors:
187
 
188
  **Let’s start now!** Join other thousands of users and install the plugin, because it is easy to use, and will help you with your Facebook campaigns for real
189
 
190
+
191
+
192
  == Installation ==
193
  * From the WP admin panel, click \"Plugins\" -> \"Add new\".
194
  * In the browser input box, type \"PixelYourSite\".
300
 
301
  == Changelog ==
302
 
303
+ = PixelYourSite 5.0.8 =
304
+
305
+ * AddToCart new option: fire the event on the Checkout Page. It will be helpful for some websites with customized structure.
306
+
307
+ * The AddToCart event was improved to work with AJAX buttons on single product pages. This will help to catch events on a number of themes that use AJAX on the product pages.
308
+
309
+ * We made additional changes to ensure compatibility with Facebook for WooCommerce latest version.
310
+
311
+
312
  = PixelYourSite 5.0.7 =
313
 
314
  * Purchase event 0 value error fixed (there wasn't any value parameter when the order value was zero)