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

Version Description

Download this release

Release Info

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

Code changes from version 2.0 to 2.1

css/admin.css CHANGED
@@ -1,9 +1,10 @@
1
- #facebook-pixel-panel-2, #facebook-pixel-panel-3{
2
- display: none;
3
  }
4
 
5
 
6
 
 
7
  .facebook-pixel-content {
8
  overflow: hidden;
9
  clear: both;
1
+ #facebook-pixel-panel-2, #facebook-pixel-panel-3, #facebook-pixel-panel-4, #facebook-pixel-panel-5, #facebook-pixel-panel-6{
2
+ display: none;
3
  }
4
 
5
 
6
 
7
+
8
  .facebook-pixel-content {
9
  overflow: hidden;
10
  clear: both;
facebook-pixel-master.php CHANGED
@@ -5,7 +5,7 @@ Description: Add the Facebook Pixel code into your Wordpress site and set up sta
5
  Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
  Author: PixelYourSite
7
  Author URI: http://www.pixelyoursite.com
8
- Version: 2.0
9
  License: GPLv3
10
  */
11
 
@@ -18,7 +18,7 @@ if ( ! defined( 'WPINC' ) ) {
18
  * Constants
19
  */
20
  //Plugin Version
21
- define( 'FBPMP_VERSION', '2.0');
22
 
23
 
24
 
5
  Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
  Author: PixelYourSite
7
  Author URI: http://www.pixelyoursite.com
8
+ Version: 2.1
9
  License: GPLv3
10
  */
11
 
18
  * Constants
19
  */
20
  //Plugin Version
21
+ define( 'FBPMP_VERSION', '2.1');
22
 
23
 
24
 
inc/admin.php CHANGED
@@ -1,9 +1,5 @@
1
  <div class="wrap">
2
- <br>
3
- <h2>PixelYourSite: Manage your Facebook Pixel</h2>
4
- <br>
5
- <p><b>Implement and control Facebook Pixel with just few clicks</b></p>
6
- <br>
7
 
8
  <div class="facebook-pixel-wrap" id="facebook-pixel-wrap">
9
  <div class="facebook-pixel-body">
@@ -11,6 +7,7 @@
11
  <li id="facebook-pixel-menu-1" class="nav-tab nav-tab-active selected">Facebook Pixel</li>
12
  <li id="facebook-pixel-menu-2" class="nav-tab">Standard Events Setup</li>
13
  <li id="facebook-pixel-menu-3" class="nav-tab">Woocommerce Setup</li>
 
14
  </ul>
15
 
16
 
@@ -415,6 +412,69 @@
415
  </div><!-- panel 3 -->
416
 
417
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
  </form>
419
  </div>
420
  </div>
1
  <div class="wrap">
2
+ <h2>PixelYourSite: Manage your Facebook Pixel</h2>
 
 
 
 
3
 
4
  <div class="facebook-pixel-wrap" id="facebook-pixel-wrap">
5
  <div class="facebook-pixel-body">
7
  <li id="facebook-pixel-menu-1" class="nav-tab nav-tab-active selected">Facebook Pixel</li>
8
  <li id="facebook-pixel-menu-2" class="nav-tab">Standard Events Setup</li>
9
  <li id="facebook-pixel-menu-3" class="nav-tab">Woocommerce Setup</li>
10
+ <li id="facebook-pixel-menu-4" class="nav-tab">PayPal Setup</li>
11
  </ul>
12
 
13
 
412
  </div><!-- panel 3 -->
413
 
414
 
415
+ <div id="facebook-pixel-panel-4" class="facebook-pixel-panel">
416
+ <?php if( woofp_is_woocommerce() ){ ?>
417
+ <table class="form-table">
418
+ <tbody>
419
+ <tr>
420
+ <td colspan="2"><?php echo woofp_admin_notices(true); ?></td>
421
+ </tr>
422
+ <tr class="paypal_row">
423
+ <th scope="row">&nbsp;</th>
424
+ <td>
425
+
426
+ <h2 style="font-weight: 400;color:#333;">WooCommerce PayPal Standard Event</h2>
427
+ <p style="font-weight: 400; font-size:12px; color:#333;">It will add a dynamic event on WooCommerce PayPal Standard button</p>
428
+
429
+ <p>
430
+ <label>PayPal button event:</label>
431
+ <select name="woocommerce_paypal[event_name]" class="woofp-input-event" disabled="disabled" >
432
+ <?php echo woofp_event_types('AddPaymentInfo'); ?>
433
+ </select>
434
+ </p>
435
+ <span class="woofpbold woofp-or">OR</span>
436
+ <p>
437
+ <label>Name for custom event:</label>
438
+ <input type="text" value="" name="woocommerce_paypal[event_custom]" disabled="disabled" />
439
+ </p>
440
+ <p>
441
+ <p class="description">*In the PRO version this event will have all the parameters values specific for the selected event.</p>
442
+ <p class="description">*In the PRO version the custom event will have <i>value, currency, content_name, content_type, content_ids</i>.</p>
443
+ </p>
444
+ <br>
445
+ <p>
446
+ <input type="checkbox" value="" name="woocommerce_paypal[event_value]" disabled="disabled" /><span class="woofpbold"> Event value = Product Price</span>
447
+ If left unchecked the event will not pull product price as event value
448
+ </p>
449
+ <p>
450
+ <label>Global value:</label><input type="text" value="" name="woocommerce_paypal[event_global]" disabled="disabled" />
451
+ <p class="description"><span class="woofp-asterik">*</span>Set this if you want a unique global value every time the PayPal Payment button is clicked</p>
452
+ </p>
453
+ <br>
454
+
455
+ <br>
456
+ <p>
457
+ <input type="checkbox" value="1" name="woocommerce_paypal[activate]" disabled="disabled" /><span class="disabled"><span class="woofpbold">Activate WooCommerce PayPal Payment Button.</span></span>
458
+ <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-pro-woo?utm_source=woordpress-tab4-pixel-paypal&utm_medium=tab4-pixel-paypal&utm_campaign=tab4-pixel-paypal" target="_blank"><span class="woofpbold">Update to the Pro Version</span></a>
459
+ </p>
460
+ </td>
461
+ </tr>
462
+
463
+ <tr>
464
+ <th scope="row">&nbsp;</th>
465
+ <td><input type="button" class="button button-primary woofp-savesettings" value="Save PayPal Settings" disabled="disabled" /></td>
466
+ </tr>
467
+ </tbody>
468
+ </table>
469
+
470
+ <?php } else { ?>
471
+ <div>
472
+ <br>
473
+ <p>Please install and activate <b>WooCommerce</b> to enable WooCommerce integration</p>
474
+ </div>
475
+ <?php } ?>
476
+ </div>
477
+
478
  </form>
479
  </div>
480
  </div>
inc/admin_notices.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function woofp_admin_notices($return=false){
3
+
4
+
5
+ $activation_time = get_option('pysf_activation_date', '');
6
+ $version = get_option('pysf_plugin_version', '');
7
+
8
+
9
+ $current_time = time();
10
+
11
+ if( empty($activation_time) || version_compare($version, FBPMP_VERSION, '<') ){
12
+ $activation_time = $current_time;
13
+ update_option( 'pysf_activation_date', $activation_time);
14
+ update_option( 'pysf_plugin_version', FBPMP_VERSION);
15
+ update_option( 'pysf_notice_dismiss', '');
16
+ }
17
+
18
+
19
+ //Expiration time ( 3 days ) = ( number of days * hours * minutes * seconds )
20
+ $expiration_days = 3;
21
+ $expiration_time = $activation_time + ( $expiration_days * 24 * 60 * 60);
22
+
23
+ //calculate number of days passed since activation;
24
+ $days_passed = woofp_days_passed($current_time, $activation_time);
25
+
26
+ //date of expiration
27
+ $expiration_date = date('l jS \of F Y', $expiration_time);
28
+
29
+ $link_1 = 'http://www.pixelyoursite.com/limited-offer?utm_source=wadmin&utm_medium=wordpress&utm_campaign=limited-offer';
30
+ $link_2 = 'http://www.pixelyoursite.com/super-offer?utm_source=wadmin&utm_medium=wordpress&utm_campaign=super-offer';
31
+
32
+
33
+
34
+ //Message for day 1
35
+ $day_1_text = '<span class="pysf_note"><b>Limited Offer, ends on “'.$expiration_date.'”:</b></span> Track Facebook Ads conversion value and enable Facebook Dynamic Ads for WooCommerce: ';
36
+ $day_1_text .= '<a href="'.$link_1.'" target="_blank">Download PixelYourSite PRO for a big discount</a>';
37
+
38
+ //Message for day 2
39
+ $day_2_text = '<span class="pysf_note"><b>Limited Offer, ending in 1 day:</b></span> With PixelYourSite PRO you can track Conversion Value and enable Facebook Dynamic Ads for WooCommerce. ';
40
+ $day_2_text .= '<a href="'.$link_1.'" target="_blank">Download now for a big discount</a>';
41
+
42
+ //Message for day 3
43
+ $day_3_text = '<span class="pysf_note"><b>Limited Offer Ends Today, “'.$expiration_date.'”:</b></span> Last chance to get your big discount for PixelYourSite PRO. ';
44
+ $day_3_text .= 'Don’t lose this opportunity, because you might need the plugin later: <a href="'.$link_1.'" target="_blank">Click here for your big discount</a>';
45
+
46
+ //Message for day 4 to 7;
47
+ $day_4_to_7_text = '';
48
+
49
+ //Message for day 7 to 12
50
+ $day_7_to_12_text = '<span class="pysf_note"><b>Special Offer:</b></span> Update to PixelYourSite PRO to enable Facebook Dynamic Ads for WooCommerce, track conversion value or track WooCommerce Affiliate Products events: <a href="'.$link_2.'">Click here for your discount</a>';
51
+
52
+
53
+ $options = array(
54
+
55
+
56
+ //message for day 1
57
+ array(
58
+
59
+ 'day' => 1,
60
+ 'message' => $day_1_text,
61
+ 'visibility' => 'visible', /* visible OR hidden */
62
+
63
+ ),
64
+
65
+ //message for day 2
66
+ array(
67
+
68
+ 'day' => 2,
69
+ 'message' => $day_2_text,
70
+ 'visibility' => 'visible', /* visible OR hidden */
71
+
72
+
73
+ ),
74
+
75
+ //message for day 3
76
+ array(
77
+
78
+ 'day' => 3,
79
+ 'message' => $day_3_text,
80
+ 'visibility' => 'visible', /* visible OR hidden */
81
+
82
+
83
+ ),
84
+
85
+
86
+ //message for day 4-7
87
+ //This will start on day 4
88
+ //and end on day 7
89
+ array(
90
+
91
+ 'day' => '4-7',
92
+ 'message' => $day_4_to_7_text,
93
+ 'visibility' => 'hidden', /* visible OR hidden */
94
+
95
+
96
+ ),
97
+
98
+ //message for day 7-12
99
+ //This will start on day 7
100
+ //and end on day 12
101
+ array(
102
+
103
+ 'day' => '7-12',
104
+ 'message' => $day_7_to_12_text,
105
+ 'visibility' => 'visible', /* visible OR hidden */
106
+
107
+
108
+ ),
109
+
110
+
111
+ );
112
+
113
+ //we will store the message of each day
114
+ $notice_message = '';
115
+
116
+
117
+ //Get dismissed notices
118
+ $dismiss_option = get_option( 'pysf_notice_dismiss', '');
119
+
120
+ //loop through notice settings
121
+ foreach ($options as $key => $option) {
122
+
123
+ $is_dismissed = isset( $dismiss_option[$option['day']] ) ? true : false;
124
+
125
+ if( is_integer( $option['day']) ){
126
+
127
+ //check if there is a message for a day and that it is on
128
+ if( !$is_dismissed && $option['day'] == $days_passed && $option['visibility'] == 'visible' ){
129
+
130
+ $dismiss_option = $option['day'];
131
+ $notice_message = $option['message'];
132
+ break;
133
+ }
134
+
135
+ } else {
136
+
137
+ //check range of days
138
+
139
+ $pieces = explode('-', $option['day']);
140
+ $start = $pieces[0];
141
+ $end = $pieces[1];
142
+
143
+ //check if there is a message for a day and that it is on
144
+ if( !$is_dismissed && ( $days_passed >= $start && $days_passed <= $end) && $option['visibility'] == 'visible' ){
145
+
146
+ $dismiss_option = $option['day'];
147
+ $notice_message = $option['message'];
148
+ break;
149
+ }
150
+
151
+
152
+ }
153
+ }
154
+
155
+
156
+ if( !empty( $notice_message ) ){
157
+
158
+ $notice = '<style type="text/css">
159
+ .pysf_note{ color: #dd4e4e; }
160
+ #pysf_notice{ padding-top:0; padding-bottom:0; border-left-width:10px;}
161
+ </style>';
162
+
163
+ $html_class = '';
164
+ $html_id = 'pysf_notice_tab';
165
+ $button_html = '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>';
166
+ if( !$return){
167
+ $html_class = 'update-nag notice is-dismissible';
168
+ $html_id = 'pysf_notice';
169
+ $button_html = '';
170
+ }
171
+
172
+ $notice .= '<div id="'.$html_id.'" class="'.$html_class.' pysf_notice pysf_notice_day_'.$dismiss_option.'">';
173
+ $notice .= '<p>'.$notice_message.'</p>';
174
+ $notice .= $button_html;
175
+ $notice .= '</div>';
176
+
177
+ $notice .= "<script type='text/javascript'>
178
+ jQuery(function($){
179
+
180
+ jQuery(document).on( 'click', '.pysf_notice .notice-dismiss', function() {
181
+
182
+ jQuery(this).closest('.notice-dismiss').fadeOut('slow');
183
+
184
+ jQuery.ajax({
185
+ url: ajaxurl,
186
+ data: {
187
+ action: 'pysf_notice_dismiss',
188
+ option: '".$dismiss_option."'
189
+ }
190
+ });
191
+
192
+ });
193
+
194
+ });
195
+ </script>";
196
+ if( !$return)
197
+ echo $notice;
198
+ else
199
+ return $notice;
200
+ }
201
+
202
+ }
203
+
204
+ function woofp_admin_notices_action(){
205
+ woofp_admin_notices();
206
+ }
207
+ if( isset($_GET['page']) && $_GET['page'] == 'woo-facebookpixel' ){
208
+
209
+ } else {
210
+ add_action( 'admin_notices', 'woofp_admin_notices_action' );
211
+ }
212
+
213
+
214
+ //add jquery if not already included;
215
+ function woofp_admin_notices_script(){
216
+
217
+ wp_enqueue_script('jquery');
218
+
219
+ }
220
+ add_action('wp_enqueue_scripts', 'woofp_admin_notices_script');
221
+
222
+
223
+ function ajax_pysf_notice_dismiss(){
224
+
225
+ if( isset($_REQUEST['option'])){
226
+ $dismiss_option = get_option( 'pysf_notice_dismiss', '');
227
+ $dismiss_option[$_REQUEST['option']] = 1;
228
+ update_option( 'pysf_notice_dismiss', $dismiss_option);
229
+ }
230
+ die();
231
+ }
232
+ add_action('wp_ajax_pysf_notice_dismiss', 'ajax_pysf_notice_dismiss');
233
+
234
+ //save activated time on plugin activation
235
+ function pysf_plugin_activated(){
236
+
237
+ $activation_date = get_option('pysf_activation_date', '');
238
+ $version = get_option('pysf_plugin_version', '');
239
+
240
+ if( empty($activation_date) || version_compare($version, FBPMP_VERSION, '<') ){
241
+ update_option( 'pysf_activation_date', time());
242
+ update_option( 'pysf_plugin_version', FBPMP_VERSION);
243
+ update_option( 'pysf_notice_dismiss', '');
244
+ }
245
+ }
246
+ register_activation_hook(__FILE__, 'pysf_plugin_activated');
247
+
248
+
249
+
250
+ //get number of days passed since activation
251
+ function woofp_days_passed($current_time, $activation_time){
252
+
253
+ $timepassed = $current_time-$activation_time;
254
+ $timepassed = ( ( ( $timepassed/24 )/60 )/60 );
255
+ $dayspassed = floor($timepassed);
256
+ $dayspassed = $dayspassed + 1;
257
+
258
+ return $dayspassed;
259
+
260
+ }
inc/helper-functions - Copy.php ADDED
@@ -0,0 +1,901 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Get Admin Settings
4
+ *
5
+ * @return array
6
+ * @author PixelYourSite
7
+ **/
8
+ function woofp_admin_settings($option_name='all'){
9
+
10
+
11
+ $settings = get_option('woofp_admin_settings');
12
+
13
+ if(empty($settings)) {
14
+
15
+ $settings = array();
16
+
17
+ } else {
18
+
19
+ $options = array('facebookpixel', 'standardevent', 'woocommerce');
20
+ foreach ( $options as $key => $name ) {
21
+
22
+ if( !isset( $settings[$name]) || empty( $settings[$name] ) ){
23
+
24
+ $settings[$name] = array();
25
+ }
26
+ }
27
+ }
28
+
29
+
30
+ switch ($option_name) {
31
+ case 'all':
32
+
33
+ return $settings;
34
+
35
+ break;
36
+
37
+ case 'facebookpixel':
38
+
39
+ return ( isset($settings['facebookpixel']) ? $settings['facebookpixel'] : '' );
40
+
41
+ break;
42
+
43
+ case 'standardevent':
44
+
45
+ return ( isset($settings['standardevent']) ? $settings['standardevent'] : '' );
46
+
47
+
48
+ break;
49
+
50
+ case 'woocommerce':
51
+
52
+ return ( isset($settings['woocommerce']) ? $settings['woocommerce'] : '' );
53
+
54
+
55
+ break;
56
+
57
+ default:
58
+
59
+ return $settings;
60
+
61
+ break;
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Get Saved Option Value
67
+ *
68
+ * @return array|string
69
+ * @author PixelYourSite
70
+ **/
71
+ function woofp_get_option($name='', $option=''){
72
+
73
+ if(empty($name) || empty($option))
74
+ return '';
75
+
76
+ $settings = woofp_admin_settings();
77
+
78
+ if( isset( $settings[$name][$option] ) )
79
+ return $settings[$name][$option];
80
+ else
81
+ return '';
82
+ }
83
+
84
+ /**
85
+ * Current Page Full URL
86
+ *
87
+ * @return string
88
+ * @author PixelYourSite
89
+ **/
90
+ function woofp_current_url(){
91
+
92
+ $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
93
+ $current_url = rtrim($current_url, '/');
94
+
95
+ return $current_url;
96
+ }
97
+
98
+ /**
99
+ * Return Javascript Code for facebook standard event
100
+ * ( With fallback for No Javascript )
101
+ *
102
+ * @return array
103
+ * @author PixelYourSite
104
+ **/
105
+ function woofp_page_event(){
106
+
107
+ $facebookpixel = woofp_admin_settings('facebookpixel');
108
+ $standardevent = woofp_admin_settings('standardevent');
109
+ $woocommerce_settings = woofp_admin_settings('woocommerce');
110
+
111
+
112
+ $pixelcode = "";
113
+
114
+ /* whether facebook pixel is activated */
115
+ if( isset($facebookpixel['activate']) && $facebookpixel['activate'] == 1 ){
116
+
117
+ $pixel_id = isset($facebookpixel['ID']) ? $facebookpixel['ID'] : '';
118
+ $current_url = woofp_current_url();
119
+ $event_added = array();
120
+
121
+
122
+ $nojs_pixelcode = "";
123
+
124
+ $pixelcode .= "\n";
125
+ $nojs_pixelcode .= "\n";
126
+
127
+
128
+ $pixelcode .= "// Insert Your Facebook Pixel ID below. \n fbq('init', '".$pixel_id."'); \n\n";
129
+
130
+ $eventtype = 'PageView';
131
+
132
+ $pixelcode .= "//Default Event \n" . woofp_get_event( $eventtype ) . " \n\n";
133
+ $nojs_pixelcode .= "<!-- Default Event --> \n" . woofp_get_event_noscript( $pixel_id, $eventtype ) . " \n\n";
134
+ $event_added[] = array( $current_url, $eventtype );
135
+
136
+
137
+ /* whether standerd events is activated */
138
+ if( isset($standardevent['activate']) && $standardevent['activate'] == 1 ){
139
+
140
+
141
+
142
+
143
+ if( isset($standardevent['pageurl']) && !empty( $standardevent['pageurl'] ) ) {
144
+
145
+ foreach ( $standardevent['pageurl'] as $key => $link) {
146
+
147
+ //if url or event is empty don't go further
148
+ if( empty($standardevent['pageurl'][$key]) || empty($standardevent['eventtype'][$key]) )
149
+ continue;
150
+
151
+ $pageurl = rtrim($standardevent['pageurl'][$key], '/');
152
+ $cartvalue = $standardevent['value'][$key];
153
+ $currency = $standardevent['currency'][$key];
154
+ $eventtype = $standardevent['eventtype'][$key];
155
+
156
+
157
+
158
+
159
+
160
+
161
+ //Add pixel event for added url
162
+ if( !woofp_is_eventadded( $event_added, $eventtype ) && woofp_match_url($current_url, $pageurl, $eventtype) == 'true' ){
163
+ $event_added[] = array($current_url, $eventtype );
164
+
165
+
166
+ $pixelcode .= "//Standard Event\n" . woofp_get_event( $eventtype, $cartvalue, $currency, 'standardevent') . " \n\n";
167
+ $nojs_pixelcode .= "<!-- Standard Event --> \n" . woofp_get_event_noscript( $pixel_id, $eventtype, 'standardevent') . " \n\n";
168
+
169
+ }
170
+
171
+ } /* foreach standardevent['pageurl'] */
172
+
173
+ } /* not empty $standardevent['pageurl'] */
174
+
175
+
176
+ } /* standerd event activated */
177
+
178
+ /* Woocommerce settings */
179
+ if( isset($woocommerce_settings['activate']) && $woocommerce_settings['activate'] == 1 && woofp_is_woocommerce() ){
180
+
181
+ global $woocommerce;
182
+
183
+ $cartvalue = $woocommerce->cart->get_cart_total();
184
+ $currency = get_woocommerce_currency();
185
+
186
+ $symbol = get_woocommerce_currency_symbol();
187
+ $cartvalue = str_replace($symbol, '', $cartvalue);
188
+
189
+
190
+ $cartvalue = strip_tags($cartvalue);
191
+ $cartvalue = preg_replace("/[^0-9\.]/", "", $cartvalue);
192
+
193
+ //Add pixel event for woocommerce pages
194
+ foreach (woofp_woocommerce_events() as $key => $woocommerc_event) {
195
+
196
+ $eventtype = $woocommerc_event['event'];
197
+
198
+ if(
199
+ woofp_is_woocommerce_page($woocommerc_event['page'])
200
+ && !woofp_is_eventadded( $event_added, $woocommerc_event['event'] )
201
+ && woofp_is_woocommerce_event($woocommerc_event['event'], $woocommerce_settings, false)
202
+ )
203
+ {
204
+
205
+
206
+ $event_added[] = array( $current_url, $eventtype );
207
+
208
+ $pixelcode .= "//WooCommerce Event\n" . woofp_get_event( $eventtype, $cartvalue, $currency, 'woocommerce') . " \n\n";
209
+ $nojs_pixelcode .= "<!-- WooCommerce Event --> \n" . woofp_get_event_noscript( $pixel_id, $eventtype, 'woocommerce') . " \n\n";
210
+
211
+ }
212
+
213
+
214
+ } /* foreach woofp_woocommerce_events*/
215
+
216
+ } /* Woocommerce Settings */
217
+
218
+
219
+
220
+ //Search Page
221
+ if( isset($_GET['s']) && $_GET['s'] !='' ){
222
+
223
+ $eventtype = 'Search';
224
+
225
+ if( !woofp_is_eventadded( $event_added, $eventtype ) ) {
226
+ $pixelcode .= "//Default Event \n" . woofp_get_event( $eventtype, 'default') . " \n";
227
+ $nojs_pixelcode .= "<!-- Default Event--> \n" . woofp_get_event_noscript( $pixel_id, $eventtype, 'default') . " \n\n";
228
+ $event_added[] = array( $current_url, $eventtype );
229
+ }
230
+ }
231
+
232
+ //registered page
233
+ if( isset($_GET['checkemail']) && $_GET['checkemail'] =='registered' ){
234
+
235
+ $eventtype = 'CompleteRegistration';
236
+ if( !woofp_is_eventadded( $event_added, $eventtype ) ) {
237
+ $pixelcode .= "//Default Event \n" . woofp_get_event( $eventtype, 'default') . " \n\n";
238
+ $nojs_pixelcode .= "<!-- Default Event--> \n" . woofp_get_event_noscript( $pixel_id, $eventtype, 'default') . " \n\n";
239
+ $event_added[] = array( $current_url, $eventtype );
240
+ }
241
+ }
242
+
243
+
244
+ }/* facebook pixel activated */
245
+
246
+ $pixelcode .= "\n";
247
+ $nojs_pixelcode .= "\n";
248
+
249
+ return array($pixelcode, $nojs_pixelcode);
250
+ }
251
+
252
+
253
+
254
+ /* Todo Prevent Duplicate Event*/
255
+ function woofp_is_eventadded($addedevents, $event){
256
+
257
+ return false;
258
+
259
+ if(!empty($addedevents)){
260
+
261
+ $result = false;
262
+ $current_url = woofp_current_url();
263
+
264
+
265
+ foreach ($addedevents as $key => $addedevent) {
266
+
267
+ if( woofp_match_url($current_url, $addedevent[0]) == 'true' && $event == $addedevent[1] ){
268
+
269
+ $result = true;
270
+ }
271
+ }
272
+
273
+ } else {
274
+
275
+ $result = false;
276
+ }
277
+
278
+ return $result;
279
+ }
280
+
281
+ function woofp_get_event($event='', $value=false, $currency='USD', $type=''){
282
+
283
+ if( 'ProductAddToCart' == $event )
284
+ $event = 'AddToCart';
285
+
286
+ if( 'Purchase' == $event ){
287
+
288
+ if( $type == 'standardevent' && $value != false && is_numeric( $value ) )
289
+ return "fbq('track', '".$event."', {currency:'".$currency."', value:".$value."});";
290
+ else
291
+ return "fbq('track', '".$event."', {currency:'USD', value:0.00});";
292
+
293
+ } else {
294
+
295
+ if( $type == 'standardevent' && $value != false && is_numeric( $value ) )
296
+ return "fbq('track', '".$event."', {currency:'".$currency."', value:".$value."});";
297
+ else
298
+ return "fbq('track', '".$event."');";
299
+
300
+ }
301
+ }
302
+
303
+ function woofp_get_event_noscript($pixel_id, $event, $type=''){
304
+
305
+ return "<noscript><img height='1' width='1' style='display:none'
306
+ src='https://www.facebook.com/tr?id=".$pixel_id."&ev=".$event."&noscript=1'
307
+ /></noscript>";
308
+
309
+ }
310
+
311
+ function woofp_event_types($current=''){
312
+ ?>
313
+
314
+ <option <?php echo selected( 'ViewContent', $current, true ); ?> value="ViewContent">ViewContent</option>
315
+ <option <?php echo selected( 'Search', $current, true ); ?> value="Search">Search</option>
316
+ <option <?php echo selected( 'AddToCart', $current, true ); ?> value="AddToCart">AddToCart</option>
317
+ <option <?php echo selected( 'AddToWishlist', $current, true ); ?> value="AddToWishlist">AddToWishlist</option>
318
+ <option <?php echo selected( 'InitiateCheckout', $current, true ); ?> value="InitiateCheckout">InitiateCheckout</option>
319
+ <option <?php echo selected( 'AddPaymentInfo', $current, true ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
320
+ <option <?php echo selected( 'Purchase', $current, true ); ?> value="Purchase">Purchase</option>
321
+ <option <?php echo selected( 'Lead', $current, true ); ?> value="Lead">Lead</option>
322
+ <option <?php echo selected( 'CompleteRegistration', $current, true ); ?> value="CompleteRegistration">CompleteRegistration</option>
323
+
324
+ <?php
325
+ }
326
+
327
+ function woofp_event_help(){
328
+ ?>
329
+ <ul class="woofp-event-help">
330
+ <li><b>ViewContent:</b> Track key page views (ex: product page, landing page or article)</li>
331
+ <li><b>Search:</b> Track searches on your website (ex. product searches)</li>
332
+ <li><b>AddToCart:</b> Track when items are added to a shopping cart (ex. click/landing page on Add to Cart button)</li>
333
+ <li><b>AddToWishlist:</b> Track when items are added to a wishlist (ex. click/landing page on Add to Wishlist button)</li>
334
+ <li><b>InitiateCheckout:</b> Track when people enter the checkout flow (ex. click/landing page on checkout button)</li>
335
+ <li><b>AddPaymentInfo:</b> Track when payment information is added in the checkout flow (ex. click/landing page on billing info)</li>
336
+ <li><b>Purchase:</b> Track purchases or checkout flow completions (ex. landing on "Thank You" or confirmation page)</li>
337
+ <li><b>Lead:</b> Track when a user expresses interest in your offering (ex. form submission, sign up for trial, landing on pricing page)</li>
338
+ <li><b>CompleteRegistration:</b> Track when a registration form is completed (ex. complete subscription, sign up for a service)</li>
339
+ </ul>
340
+ <?php
341
+ }
342
+
343
+
344
+
345
+ function woofp_currency_options( $current='USD' ){
346
+ ?>
347
+ <option <?php echo selected( 'AUD', $current, true ); ?> value="AUD">Australian Dollar</option>
348
+ <option <?php echo selected( 'BRL', $current, true ); ?> value="BRL">Brazilian Real </option>
349
+ <option <?php echo selected( 'CAD', $current, true ); ?> value="CAD">Canadian Dollar</option>
350
+ <option <?php echo selected( 'CZK', $current, true ); ?> value="CZK">Czech Koruna</option>
351
+ <option <?php echo selected( 'DKK', $current, true ); ?> value="DKK">Danish Krone</option>
352
+ <option <?php echo selected( 'EUR', $current, true ); ?> value="EUR">Euro</option>
353
+ <option <?php echo selected( 'HKD', $current, true ); ?> value="HKD">Hong Kong Dollar</option>
354
+ <option <?php echo selected( 'HUF', $current, true ); ?> value="HUF">Hungarian Forint </option>
355
+ <option <?php echo selected( 'ILS', $current, true ); ?> value="ILS">Israeli New Sheqel</option>
356
+ <option <?php echo selected( 'JPY', $current, true ); ?> value="JPY">Japanese Yen</option>
357
+ <option <?php echo selected( 'MYR', $current, true ); ?> value="MYR">Malaysian Ringgit</option>
358
+ <option <?php echo selected( 'MXN', $current, true ); ?> value="MXN">Mexican Peso</option>
359
+ <option <?php echo selected( 'NOK', $current, true ); ?> value="NOK">Norwegian Krone</option>
360
+ <option <?php echo selected( 'NZD', $current, true ); ?> value="NZD">New Zealand Dollar</option>
361
+ <option <?php echo selected( 'PHP', $current, true ); ?> value="PHP">Philippine Peso</option>
362
+ <option <?php echo selected( 'PLN', $current, true ); ?> value="PLN">Polish Zloty</option>
363
+ <option <?php echo selected( 'GBP', $current, true ); ?> value="GBP">Pound Sterling</option>
364
+ <option <?php echo selected( 'SGD', $current, true ); ?> value="SGD">Singapore Dollar</option>
365
+ <option <?php echo selected( 'SEK', $current, true ); ?> value="SEK">Swedish Krona</option>
366
+ <option <?php echo selected( 'CHF', $current, true ); ?> value="CHF">Swiss Franc</option>
367
+ <option <?php echo selected( 'TWD', $current, true ); ?> value="TWD">Taiwan New Dollar</option>
368
+ <option <?php echo selected( 'THB', $current, true ); ?> value="THB">Thai Baht</option>
369
+ <option <?php echo selected( 'TRY', $current, true ); ?> value="TRY">Turkish Lira</option>
370
+ <option <?php echo selected( 'USD', $current, true ); ?> value="USD">U.S. Dollar</option>
371
+
372
+ <?php
373
+ }
374
+
375
+
376
+ function woofp_pixelcode(){
377
+
378
+ //load facebook pixel on front only
379
+ if( !is_admin() ){
380
+
381
+ $facebookpixel = woofp_admin_settings('facebookpixel');
382
+
383
+ if( isset($facebookpixel['activate']) && $facebookpixel['activate'] == 1 ) {
384
+ ?>
385
+
386
+
387
+ <!-- Facebook Pixel Code -->
388
+ <script>
389
+ var PYS_DOMReady = function(a,b,c){b=document,c='addEventListener';b[c]?b[c]('DOMContentLoaded',a):window.attachEvent('onload',a)}
390
+ !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
391
+ n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
392
+ n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
393
+ t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
394
+ document,'script','//connect.facebook.net/en_US/fbevents.js');
395
+
396
+ /* pixel plugin code */
397
+ PYS_DOMReady(function(){
398
+
399
+ <?php
400
+ $facebookpixel_code = woofp_page_event();
401
+ echo $facebookpixel_code[0];
402
+ ?>
403
+
404
+ });
405
+ /* pixel plugin code */
406
+
407
+ </script>
408
+
409
+ <!-- End Facebook Pixel Code -->
410
+
411
+ <?php
412
+ }
413
+
414
+ } else {
415
+ ?>
416
+ <img src="<?php echo admin_url('admin-ajax.php'); ?>" style="display:none;">
417
+
418
+ <?php
419
+ }
420
+
421
+
422
+
423
+ }
424
+
425
+
426
+ /*
427
+ Woocommerce Related Functions
428
+ Check if woocommerce is install and activated.
429
+ */
430
+
431
+ function woofp_addtocart_urls($woofp_options=''){
432
+
433
+
434
+ $facebookpixel = $woofp_options['facebookpixel'];
435
+ $standardevent = $woofp_options['standardevent'];
436
+ $woocommerce_settings = $woofp_options['woocommerce'];
437
+
438
+
439
+
440
+ /* whether facebook pixel is activated */
441
+ if( woofp_get_option('facebookpixel', 'activate') == 1 ){
442
+
443
+ /* whether standerd events is activated */
444
+ if( woofp_get_option('standardevent', 'activate') == 1 ){
445
+
446
+
447
+
448
+ $results = array();
449
+ if( isset( $standardevent['pageurl'] ) && !empty($standardevent['pageurl']) ){
450
+
451
+ foreach ( $standardevent['pageurl'] as $key => $link) {
452
+
453
+ $pageurl = rtrim($standardevent['pageurl'][$key], '/');
454
+ $cartvalue = $standardevent['value'][$key];
455
+ $currency = $standardevent['currency'][$key];
456
+ $eventtype = $standardevent['eventtype'][$key];
457
+
458
+ if( !in_array($pageurl, $results) && $eventtype == 'AddToCart' )
459
+ $results[] = $pageurl;
460
+
461
+
462
+ }
463
+
464
+ }
465
+
466
+ if( woofp_get_option('woocommerce', 'activate') == 1 ){
467
+
468
+ //Add pixel event for woocommerce pages
469
+ foreach (woofp_woocommerce_events() as $key => $woocommerc_event) {
470
+
471
+ $eventtype = $woocommerc_event['event'];
472
+ if( !in_array( '***', $results) && woofp_is_woocommerce_event($eventtype, $woocommerce_settings, false) && $eventtype == 'AddToCart' )
473
+ $results[] = '***';
474
+ }
475
+
476
+ }
477
+
478
+ }
479
+
480
+ }
481
+
482
+
483
+ return $results;
484
+
485
+ }
486
+
487
+
488
+ function woofp_addtocart_pixel(){
489
+
490
+
491
+ //
492
+
493
+ ?>
494
+
495
+ <!-- noscript facebook pixel -->
496
+
497
+ <?php
498
+ $facebookpixel_code = woofp_page_event();
499
+ echo $facebookpixel_code[1];
500
+ ?>
501
+
502
+ <!-- end noscript facebook pixel -->
503
+
504
+ <?php
505
+ //Run AddToCart Event when product are added using ajax
506
+ //todo: woocommerce_cart_redirect_after_add
507
+
508
+ $woofp_options = get_option('woofp_admin_settings');
509
+ $facebookpixel = $woofp_options['facebookpixel'];
510
+ $standardevent = $woofp_options['standardevent'];
511
+ $woocommerce_settings = $woofp_options['woocommerce'];
512
+
513
+
514
+
515
+ ?>
516
+ <!-- Dynamic AddToCart when Ajax enabled on Woocommerce -->
517
+ <?php
518
+
519
+ if ( get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' && ( is_woocommerce() || is_page() || is_single() ) ) {
520
+
521
+ $php_array = woofp_addtocart_urls($woofp_options);
522
+ $js_array = json_encode($php_array);
523
+ ?>
524
+
525
+
526
+ <script type="text/javascript">
527
+ var fbpmpaddtocart_eventcode = '';
528
+
529
+ jQuery(function($){
530
+
531
+ /*$.ajax({
532
+ url: '<?php echo admin_url("admin-ajax.php"); ?>',
533
+ type: 'POST',
534
+ dataType: 'json',
535
+ data: {action: 'fbpmpaddtocart', nonce:'<?php echo wp_create_nonce("fbpmp_nonce_ajaxaddtocart"); ?>'},
536
+ })
537
+ .done(function(result){
538
+
539
+ if( 1 == result.status ){
540
+ fbpmpaddtocart_eventcode = result.event_code;
541
+ }
542
+ console.log(result);
543
+ console.log(fbpmpaddtocart_eventcode);
544
+
545
+ });*/
546
+
547
+ //Run AddToCart Event when product are added using ajax
548
+ jQuery(document).on( 'click', '.add_to_cart_button', function(e) {
549
+
550
+ e.preventDefault();
551
+
552
+ var current_url = jQuery(this).attr('href') || '';
553
+ var product_id = jQuery(this).attr('data-product_id') || 0;
554
+
555
+ <?php echo "var url_array = ". $js_array . ";\n"; ?>
556
+ <?php echo "var homeurl = '". home_url() . "';\n"; ?>
557
+
558
+ if (current_url.indexOf('http://') < 0 || current_url.indexOf('https://') < 0){
559
+ current_url = homeurl + current_url;
560
+ }
561
+
562
+
563
+
564
+ for (i = 0; i < url_array.length; i++) {
565
+
566
+ if( url_array[i] == '***' ){
567
+
568
+
569
+ fbq('track', 'AddToCart');
570
+
571
+ } else if( current_url.search(url_array[i]) !== -1 ){
572
+
573
+
574
+ fbq('track', 'AddToCart');
575
+
576
+ }
577
+
578
+ }
579
+
580
+
581
+ });
582
+
583
+ });
584
+ </script>
585
+ <?php }
586
+ }
587
+
588
+
589
+
590
+ function woofp_is_woocommerce_page ($page) {
591
+
592
+ switch ($page) {
593
+
594
+ case 'woocommerce_view_content':
595
+
596
+ return is_product();
597
+
598
+ case 'woocommerce_added_to_cart':
599
+
600
+ if ( isset($_REQUEST['add-to-cart']) && is_numeric($_REQUEST['add-to-cart']) )
601
+ return true;
602
+ else
603
+ return false;
604
+
605
+
606
+ break;
607
+
608
+
609
+ case 'woocommerce_cart_page_id':
610
+
611
+ return is_cart();
612
+
613
+ break;
614
+
615
+ case 'woocommerce_checkout_page_id':
616
+
617
+ if( is_checkout() && !is_wc_endpoint_url() )
618
+ return true;
619
+ else
620
+ return false;
621
+
622
+ break;
623
+
624
+ case 'woocommerce_thanks_page_id':
625
+
626
+ if( is_wc_endpoint_url( 'order-received' ) )
627
+ return true;
628
+ else
629
+ return false;
630
+
631
+
632
+ break;
633
+
634
+ case 'woocommerce_search_product':
635
+
636
+ if ( isset($_GET['s']) && ( isset($_GET['post_type']) && $_GET['post_type'] == 'product' ) ) {
637
+
638
+ return true ;
639
+
640
+ } else {
641
+
642
+ return false;
643
+ }
644
+
645
+ break;
646
+
647
+ default:
648
+ return false;
649
+ break;
650
+ }
651
+
652
+ }
653
+
654
+
655
+ /**
656
+ * Return appropriate pixel events for woocommerce pages
657
+ *
658
+ * @return array
659
+ * @author PixelYourSite
660
+ **/
661
+ function woofp_woocommerce_events(){
662
+
663
+ $woocommerce_events = array(
664
+
665
+ array(
666
+ 'event' => 'ViewContent',
667
+ 'page' => 'woocommerce_view_content',
668
+ 'title' => 'Any WooCommerce Page',
669
+ 'label' => 'ViewContent Event'
670
+ ),
671
+
672
+ array(
673
+ 'event' => 'ProductAddToCart',
674
+ 'page' => 'woocommerce_added_to_cart',
675
+ 'title' => 'Product Added to Cart',
676
+ 'label' => 'AddToCart Event'
677
+ ),
678
+
679
+ array(
680
+ 'event' => 'AddToCart',
681
+ 'page' => 'woocommerce_cart_page_id',
682
+ 'title' => 'AddToCart Page',
683
+ 'label' => 'AddToCart Event'
684
+ ),
685
+ array(
686
+ 'event' => 'InitiateCheckout',
687
+ 'page' => 'woocommerce_checkout_page_id',
688
+ 'title' => 'CheckOut Page',
689
+ 'label' => 'InitiateCheckout Event'
690
+ ),
691
+ /*array(
692
+ 'event' => 'AddPaymentInfo',
693
+ 'page' => 'woocommerce_checkout_page_id',
694
+ 'title' => 'Checkout Page',
695
+ 'label' => 'AddPaymentInfo Event'
696
+ ),*/
697
+ array(
698
+ 'event' => 'Purchase',
699
+ 'page' => 'woocommerce_thanks_page_id',
700
+ 'title' => 'Thankyou Page',
701
+ 'label' => 'Purchase Event'
702
+ ),
703
+ /*array(
704
+ 'event' => 'Search',
705
+ 'page' => 'woocommerce_search_product',
706
+ 'title' => 'Product Search',
707
+ 'label' => ' Search Event'
708
+ ),*/
709
+
710
+ );
711
+
712
+ return $woocommerce_events;
713
+ }
714
+
715
+ /**
716
+ * Check if woocommerce event is activated in settings
717
+ * @return string | true/false
718
+ * @author PixelYourSite
719
+ **/
720
+ function woofp_is_woocommerce_event($event, $settings, $echo=true){
721
+
722
+
723
+ if( isset( $settings['events'] ) && !empty($settings['events']) && isset($settings['events'][$event]) && $settings['events'][$event] == 1 ){
724
+ $checked = 'checked="checked"';
725
+ $return = true;
726
+ } else {
727
+
728
+ $checked = '';
729
+ $return = false;
730
+ }
731
+
732
+ if($echo){
733
+ echo $checked;
734
+ } else {
735
+
736
+ return $return;
737
+ }
738
+ }
739
+
740
+ function woofp_startsWith($haystack, $needle) {
741
+ // search backwards starting from haystack length characters from the end
742
+ return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
743
+ }
744
+
745
+ function woofp_endsWith($haystack, $needle) {
746
+ // search forward starting from end minus needle length characters
747
+ return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
748
+ }
749
+
750
+
751
+ function woofp_valid_url($value){
752
+ $pattern = "@^(?:https?://)?(?:[a-z0-9-]+\.)*((?:[a-z0-9-]+\.)[a-z]+)@";
753
+
754
+ if (!preg_match($pattern, $value)){
755
+ return false;
756
+ }
757
+
758
+ return true;
759
+ }
760
+
761
+ /**
762
+ * add http:// to url if missing
763
+ *
764
+ * @return string
765
+ * @author PixelYourSite
766
+ **/
767
+ function woofp_addhttp($url=''){
768
+
769
+ if (preg_match("#https?://#", $url) === 0) {
770
+ $url = 'http://'.$url;
771
+ }
772
+
773
+ return $url;
774
+ }
775
+
776
+
777
+ /**
778
+ * Remove http(s)/www. from url
779
+ *
780
+ * @return string
781
+ * @author PixelYourSite
782
+ **/
783
+ function woofp_remove_protocol($url=''){
784
+
785
+ if(empty($url) && !woofp_valid_url($url))
786
+ return $url;
787
+
788
+ $url = str_replace(array('http://', 'https://', 'http://www.', 'https://www.'), '', $url);
789
+
790
+ $url = trim($url);
791
+ $url = trim($url, '//');
792
+ $url = rtrim($url, '/');
793
+
794
+ return $url;
795
+ }
796
+
797
+
798
+ function woofp_match_url($current_url, $match_url, $eventtype='' ){
799
+
800
+ $current_url = woofp_remove_protocol($current_url);
801
+ $match_url = woofp_remove_protocol($match_url);
802
+
803
+ if(strpos($match_url, '*') !== false && woofp_endsWith($match_url, '*') ){
804
+
805
+ $temp_url = $match_url;
806
+ $temp_url = rtrim($temp_url, '*');
807
+
808
+ $temp_url = trim($temp_url);
809
+ $temp_url = trim($temp_url, '//');
810
+ $temp_url = rtrim($temp_url, '/');
811
+
812
+
813
+
814
+ if ( woofp_valid_url($temp_url) === true) {
815
+
816
+ $current_postid = url_to_postid( woofp_addhttp($current_url) );
817
+ $match_postid = url_to_postid( woofp_addhttp($temp_url) );
818
+ $current_length = strlen($current_url);
819
+ $match_length = strlen($temp_url);
820
+
821
+ $postmatch = false;
822
+
823
+ if( $current_postid && $match_postid && $current_postid == $match_postid ){
824
+ $postmatch = true;
825
+ }
826
+
827
+
828
+ $strcmp1 = strcmp($temp_url, $current_url);
829
+ $strcmp2 = strcmp($current_url, $temp_url);
830
+
831
+ $found1 = ( (strpos($temp_url, $current_url) !== false ) ? 'true' : 'false' );
832
+ $found2 = ( (strpos($current_url, $temp_url) !== false ) ? 'true' : 'false' );
833
+
834
+ if( $match_length > $current_length && $found1 == 'true' ){
835
+
836
+ $ret = ( ( $strcmp1 < 0 || $postmatch ) ? 'true' : 'false' );
837
+
838
+ } else if( $match_length < $current_length && $found2 == 'true' ){
839
+
840
+ $ret = ( ( $strcmp2 > 0 || $postmatch ) ? 'true' : 'false' );
841
+
842
+ } else {
843
+
844
+ $ret = ( ( $strcmp1 == 0 || $postmatch ) ? 'true' : 'false' );
845
+
846
+ }
847
+
848
+
849
+ return $ret;
850
+
851
+ } else {
852
+
853
+
854
+ return 'false';
855
+ }
856
+
857
+ } else {
858
+
859
+
860
+ if ( woofp_valid_url($match_url) === true ) {
861
+
862
+ $current_postid = url_to_postid( woofp_addhttp($current_url) );
863
+ $match_postid = url_to_postid( woofp_addhttp($match_url) );
864
+
865
+ $postmatch = false;
866
+ if( $current_postid && $match_postid && $current_postid == $match_postid ){
867
+ $postmatch = true;
868
+ }
869
+
870
+ $strcmp = strcmp( $current_url, $match_url );
871
+ $ret = ( ( $strcmp == 0 || $postmatch ) ? 'true' : 'false' );
872
+
873
+
874
+ return $ret;
875
+
876
+ } else {
877
+
878
+ $strpos = strpos($current_url, $match_url);
879
+ $ret = ( $strpos !== false ? 'true' : 'false' );
880
+
881
+
882
+ return $ret;
883
+
884
+ }
885
+
886
+ }
887
+ }
888
+
889
+ function woofp_is_woocommerce(){
890
+
891
+ if ( !class_exists( 'WooCommerce' ) ) {
892
+
893
+ return false;
894
+
895
+ } else {
896
+
897
+
898
+ return true;
899
+ }
900
+
901
+ }
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === PixelYourSite: Insert Facebook Pixel and track Standard Events ===
2
  Contributors: PixelYourSite, c0d3fev3r
3
- Tags: Facebook Pixel, Facebook, Facebook Conversion Pixel, Facebook Pixel Events, tracking, standard events, Facebook Events, Facebook Standard Events, New Facebook Pixel, Facebook Dynamic Ads, WooCommerce, Facebook Custom Events, Custom Events, conversion pixel, track conversion, Facebook pixel WooCommerce, Facebook Ads, Facebook Campaign, Facebook Ads Campaign, Facebook Conversion Value, Conversion Value, WooCommerce Affiliate Products, Track Affiliate Products, Affiliate links
4
  Requires at least: 3.0.1
5
  Tested up to: 4.4.1
6
- Stable tag: 2.0
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -34,6 +34,8 @@ As you probably know, Facebook will retire the old Facebook Conversion Pixel in
34
 
35
  * **WooCommerce Affiliate Products Events:** you can add a dynamic event that will trigger on affiliate button clicks (<a href="http://www.pixelyoursite.com" target="_blank">Pro Version</a>)
36
 
 
 
37
  **Important**
38
 
39
  If you are testing your pixel with Pixel Helper Chrome extension you will see some **false** errors:
@@ -46,10 +48,12 @@ You can safely ignore them. It is a normal error trigger by the dynamic AddToCar
46
  **What's next**
47
 
48
 
49
- 1. **PayPal integration**
50
 
51
  2. More control for WooCommerce variable products events - some cool new things comming soon
52
 
 
 
53
 
54
  <p style="text-align: center;">Visit this page for <strong><a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank"><span style="color:#DE4D4D;">more&nbsp;details about how to use the plugin: Click Here</span></a></strong></p>
55
 
@@ -82,8 +86,71 @@ We maintain an up to date FAQ page on our site:
82
 
83
  <strong><a href="http://www.pixelyoursite.com/facebool-pixel-master-faq" target="_blank"><span style="color:#DE4D4D;">Click here for the FAQ page</span></a></strong>
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  == Changelog ==
86
 
 
 
 
 
87
  PixelYourSite 2.0
88
 
89
  - This update adds full control on Standard Events, with the possibility to define all the availeable parameters for each event
@@ -120,4 +187,4 @@ PixelYourSite 1.01
120
 
121
  == Upgrade Notice ==
122
 
123
- New Cool features (more control for Standard Events, WooCommerce Affiliate Products Events + some important fixes). Update Now!
1
  === PixelYourSite: Insert Facebook Pixel and track Standard Events ===
2
  Contributors: PixelYourSite, c0d3fev3r
3
+ Tags: Facebook Pixel, Facebook, Facebook Conversion Pixel, Facebook Pixel Events, Tracking, Standard events, Facebook Events, Facebook Standard Events, New Facebook Pixel, Facebook Dynamic Ads, WooCommerce, Facebook Custom Events, Custom Events, Conversion pixel, track conversion, Facebook pixel WooCommerce, Facebook Ads, Facebook Campaign, Facebook Ads Campaign, Facebook Conversion Value, Conversion Value, WooCommerce Affiliate Products, Track Affiliate Products, Affiliate links, New Facebook Pixel WooCommerce, PayPal, Facebook Pixel PayPal, New Facebook Pixel Events, facebook standard events woocommerce, facebook tracking pixel woocommerce, facebook conversion pixel for woocommerce, new pixel, pixel plugin, tracking pixel
4
  Requires at least: 3.0.1
5
  Tested up to: 4.4.1
6
+ Stable tag: 2.1
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
34
 
35
  * **WooCommerce Affiliate Products Events:** you can add a dynamic event that will trigger on affiliate button clicks (<a href="http://www.pixelyoursite.com" target="_blank">Pro Version</a>)
36
 
37
+ * **WooCommerce PayPal Standard Events:** you can add a dynamic event that will trigger on WooCommerce PayPal button clicks (<a href="http://www.pixelyoursite.com" target="_blank">Pro Version</a>)
38
+
39
  **Important**
40
 
41
  If you are testing your pixel with Pixel Helper Chrome extension you will see some **false** errors:
48
  **What's next**
49
 
50
 
51
+ 1. **Dynamic events on clicks**
52
 
53
  2. More control for WooCommerce variable products events - some cool new things comming soon
54
 
55
+ 3. ... and some secret cool stuf
56
+
57
 
58
  <p style="text-align: center;">Visit this page for <strong><a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank"><span style="color:#DE4D4D;">more&nbsp;details about how to use the plugin: Click Here</span></a></strong></p>
59
 
86
 
87
  <strong><a href="http://www.pixelyoursite.com/facebool-pixel-master-faq" target="_blank"><span style="color:#DE4D4D;">Click here for the FAQ page</span></a></strong>
88
 
89
+ **Do I need to copy/paste the Facebook Pixel code somewhere?**
90
+
91
+ No, you just have to enter your pixel ID in the dedicated filed. The plugin will do the rest for you.
92
+
93
+ **Where can I find the Facebook Pixel ID?**
94
+
95
+ There are multiple ways to do that. One simple method is to:
96
+
97
+ * Go to your Facebook Pixel tab in Ads Manager
98
+ * You will find the Facebook Pixel ID on the right side of the page
99
+
100
+ **What happens when I activate the plugin general settings?**
101
+
102
+ a. The pixel code will be added on every page of your site
103
+
104
+ b. A "Search" standard event will be added on the search page of your site
105
+
106
+ c. A "CompleteRegistration" event will be added on the user complete registration page
107
+
108
+ **What happens when I activate the WooCommerce Setup?**
109
+
110
+ ViewContent is added on the product pages
111
+ AdToCart event is added on the cart page
112
+ AddToCart events is activated on add to cart button click
113
+ InitiateCheckout event is added on the Checkout page
114
+ Purchase event is added on the Thank You page
115
+
116
+ **Can I define new standard events?**
117
+
118
+ Yes, you can! There is a simple menu where you can do that. You'll need to add an URL and select the event type you want to add. If necessary, you can give each event a monetary value and its own currency.
119
+
120
+ **Can I have more then just one event on a page?**
121
+
122
+ Yes, you can! It is up to you.
123
+
124
+ **Can I use your plugin for Facebook Dynamic Ads?**
125
+
126
+ Yes, the PRO version of our plugin is design to help you use Facebook Dynamic Ads for a WooCommerce website.
127
+
128
+ **Are there any known incompatibilities with other themes or plugins?**
129
+
130
+ Any program, service, code or plugin that adds the Pixel Code, since you can't have to similar pixels on a page.
131
+
132
+ * We had a problem with Mamaya, a retargeting service
133
+ * It won't work with LeadPages or any similar system, because that pages are generated outside WordPress
134
+
135
+ If any incompatibilities will arise we will add them here and, of course, will try to fix them as soon is possible.
136
+
137
+ **I have the pixel installed on my website and I am running a Facebook Campaign, but the reports are confusing me. How can I see my campaign results?**
138
+
139
+ We have an article about how to optimize Facebook Ads Reports:
140
+ <strong><a href="http://www.pixelyoursite.com/facebook-ads-reports-optimisation" target="_blank"><span style="color:#DE4D4D;">How to optimize your Facebook Ads Reports for events tracking</span></a></strong>
141
+
142
+ == Screenshots ==
143
+
144
+ 1. Add your Facebook Pixel ID and the plugin will insert the code on every page
145
+ 2. You can define Custom or Standard events on any URL of your website
146
+ 3. Activate Standard events for WooCommerce (ViewContent, AddToCard, InitiateCheckout, Purchase)
147
+
148
  == Changelog ==
149
 
150
+ PixelYourSite 2.1
151
+
152
+ - Introducing new WooCommerce Paypal Standard events (pro)
153
+
154
  PixelYourSite 2.0
155
 
156
  - This update adds full control on Standard Events, with the possibility to define all the availeable parameters for each event
187
 
188
  == Upgrade Notice ==
189
 
190
+ - Introducing WooCommerce PayPal Standard button events (pro)