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

Version Description

Download this release

Release Info

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

Code changes from version 3.1.0 to 4.0.0

css/admin.css CHANGED
@@ -1,130 +1,131 @@
1
  .wrap {
2
- margin-top: 25px;
3
  }
4
 
5
  .disabled {
6
- pointer-events: none;
7
  }
8
 
9
  .pys-btn.disabled,
10
  table.disabled {
11
- opacity: 0.6;
12
  }
13
 
14
  tr.disabled,
 
15
  form.disabled {
16
- opacity: 0.6;
17
- pointer-events: none;
18
  }
19
 
20
  .aligncenter {
21
- display: block !important;
22
- margin: 0 auto;
23
  }
24
 
25
  .pys-logo {
26
- background: url('../img/logo.png') no-repeat;
27
- width: 261px;
28
- height: 58px;
29
  }
30
 
31
  a {
32
- color: #F4524D;
33
  }
34
 
35
  a:hover {
36
- color: #F4524D;
37
  }
38
 
39
  a.big {
40
- font-size: 24px;
41
  }
42
 
43
  h2 {
44
- margin-top: 0;
45
  }
46
 
47
  hr {
48
- margin: 25px 0;
49
  }
50
 
51
  code {
52
- padding: 1px 4px;
53
  }
54
 
55
  .pys-list pre {
56
- margin-top: 0;
57
-
58
- white-space: pre-wrap; /* CSS 3 */
59
- white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
60
- white-space: -pre-wrap; /* Opera 4-6 */
61
- white-space: -o-pre-wrap; /* Opera 7 */
62
- word-wrap: break-word;
63
  }
64
 
65
  .pys-rating {
66
- text-align: center;
67
  }
68
 
69
  .pys-content {
70
- margin: -1px 0 15px;
71
  }
72
 
73
  ul.dashed {
74
- list-style: none;
75
- margin-left: 0;
76
- padding-left: 1.5em;
77
  }
78
 
79
  ul.dashed > li:before {
80
- display: inline-block;
81
- content: "\2014\a0";
82
- width: 1.5em;
83
- margin-left: -1.5em;
84
  }
85
 
86
  /* nav menu */
87
 
88
  .pys-menu {
89
- overflow: hidden;
90
- clear: both;
91
- margin-bottom: 0;
92
  }
93
 
94
  .pys-menu .nav-tab {
95
- border-top-left-radius: 5px;
96
- border-top-right-radius: 5px;
97
- cursor: pointer;
98
- display: block;
99
- margin-bottom: 0;
100
  }
101
 
102
  .pys-menu .nav-tab-active {
103
- background: #fff;
104
- border-bottom: 1px solid #fff;
105
  }
106
 
107
  /* panels */
108
 
109
  .pys-panel {
110
- display: none;
111
  }
112
 
113
  /* boxes */
114
 
115
  .pys-box {
116
- overflow: hidden;
117
- clear: both;
118
- border-radius: 5px;
119
- border: 1px solid #ccc;
120
- padding: 25px 0;
121
- margin-bottom: 15px;
122
- background: #fff;
123
  }
124
 
125
  .pys-box-red {
126
- background: #F4524D;
127
- color: #fff;
128
  }
129
 
130
  .pys-box-red h1,
@@ -137,9 +138,9 @@ ul.dashed > li:before {
137
  }
138
 
139
  .pys-box-middle {
140
- color: #fff;
141
- text-align: center;
142
- background: #516F9F;
143
  }
144
 
145
  .pys-box-middle h2,
@@ -147,55 +148,53 @@ ul.dashed > li:before {
147
  .pys-box-middle p,
148
  .pys-box-middle u,
149
  .pys-box-middle i {
150
- color: #fff;
151
  }
152
 
153
  /* grid */
154
 
155
  .pys-col {
156
- float: left;
157
- width: 100%;
158
- box-sizing: border-box;
159
- padding: 0 25px;
160
  }
161
 
162
  .pys-col-full {
163
- width: 100%;
164
  }
165
 
166
  .pys-col-one-half {
167
- width: 50%;
168
  }
169
 
170
  .pys-col-narrow {
171
- float: none;
172
- width: 70%;
173
- margin: 25px auto;
174
  }
175
 
176
  .pys-col-border-left {
177
- border-left: 1px solid #ccc;
178
  }
179
 
180
  .pys-col-border-right {
181
- border-right: 1px solid #ccc;
182
  }
183
 
184
  /* aligns */
185
 
186
  h3.align-one-third {
187
- margin-left: 30%;
188
- padding: 0 18px;
189
  }
190
 
191
- /* @todo: verify me */
192
-
193
  tr.align-one-third td:first-child {
194
- width: 30%;
195
  }
196
 
197
  tr.align-one-third td:last-child {
198
- width: 70%;
199
  }
200
 
201
  /* buttons */
@@ -204,124 +203,125 @@ tr.align-one-third td:last-child {
204
  .pys-btn:hover,
205
  a.pys-btn,
206
  a.pys-btn:hover {
207
- line-height: normal;
208
- display: inline-block;
209
- color: #fff;
210
- font-weight: bold;
211
- text-decoration: none;
212
- cursor: pointer;
213
- padding: 10px 25px;
214
- border: none;
215
  }
216
 
217
  .pys-btn:hover.pys-btn-big,
218
  a.pys-btn:hover.pys-btn-big {
219
- line-height: normal;
220
- padding: 12px 35px;
221
  }
222
 
223
  .pys-btn-red,
224
  a.pys-btn-red {
225
- background: #F4524D;
226
  }
227
 
228
  .pys-btn-blue,
229
  a.pys-btn-blue {
230
- background: #516F9F;
231
  }
232
 
233
  .pys-btn.pys-btn-big {
234
- font-size: 20px;
235
- padding: 12px 35px;
236
  }
237
 
238
  /* tables */
239
 
240
  table.layout {
241
- width: 100%;
242
- margin: 25px 0;
243
- table-layout: fixed;
244
  }
245
 
246
  table.layout tr {
247
- margin-bottom: 5px;
248
  }
249
 
250
  table.layout tr.tall td {
251
- padding-bottom: 25px;
252
  }
253
 
254
  table.layout td {
255
- padding: 5px 15px;
256
  }
257
 
258
  table.layout td.legend {
259
- vertical-align: top;
260
  }
261
 
262
  table.layout td.narrow {
263
- padding-left: 25%;
264
- padding-right: 25%;
265
  }
266
 
267
  table.pys-list .button {
268
- margin-right: 5px;
269
  }
270
 
271
  table.layout.search {
272
- background-color: transparent; /* default styles bug fix */
273
  }
274
 
275
  /* forms */
276
 
277
  .label {
278
- text-align: right;
279
- margin: 0;
280
- line-height: 27px;
281
- font-weight: bold;
282
  }
283
 
284
  .label.big {
285
- font-size: 16.9px;
286
  }
287
 
288
  .legend > .label {
289
- line-height: inherit;
290
  }
291
 
292
  .help {
293
- display: block;
294
- color: #666;
295
- font-size: 13px;
296
- margin: 5px 0;
297
  }
298
 
299
  input[type="text"] {
300
- width: 300px;
301
- max-width: 100%;
302
  }
303
 
304
- input[type="checkbox"] {
305
- margin-right: 10px;
 
306
  }
307
 
308
  input[type="checkbox"].big {
309
- margin-top: -3px;
310
  }
311
 
312
  /* tickbox */
313
 
314
  #TB_window h2 {
315
- margin: 1em 0;
316
  }
317
 
318
  #TB_window table tr td:last-child {
319
- width: 70%;
320
  }
321
 
322
  #TB_window .actions-row {
323
- text-align: right;
324
- padding: 5px 15px;
325
  }
326
 
327
  /* event fields show/hide classes */
@@ -336,8 +336,8 @@ input[type="checkbox"].big {
336
  .Lead-visible,
337
  .CompleteRegistration-visible,
338
  .CustomCode-visible,
339
- .CustomEvent-visible{
340
- display: none;
341
  }
342
 
343
  .ViewContent .ViewContent-visible,
@@ -351,15 +351,29 @@ input[type="checkbox"].big {
351
  .Search .Search-visible,
352
  .CustomCode .CustomCode-visible,
353
  .CustomEvent .CustomEvent-visible {
354
- display: table-row;
355
  }
356
 
357
- .URL-visible,
358
- .CSS-visible {
359
  display: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  }
361
 
362
  .URL .URL-visible,
363
- .CSS .CSS-visible {
364
- display: table-row;
 
 
365
  }
1
  .wrap {
2
+ margin-top: 25px;
3
  }
4
 
5
  .disabled {
6
+ pointer-events: none;
7
  }
8
 
9
  .pys-btn.disabled,
10
  table.disabled {
11
+ opacity: 0.6;
12
  }
13
 
14
  tr.disabled,
15
+ td.disabled,
16
  form.disabled {
17
+ opacity: 0.6;
18
+ pointer-events: none;
19
  }
20
 
21
  .aligncenter {
22
+ display: block !important;
23
+ margin: 0 auto;
24
  }
25
 
26
  .pys-logo {
27
+ background: url('../img/logo.png') no-repeat;
28
+ width: 261px;
29
+ height: 58px;
30
  }
31
 
32
  a {
33
+ color: #F4524D;
34
  }
35
 
36
  a:hover {
37
+ color: #F4524D;
38
  }
39
 
40
  a.big {
41
+ font-size: 24px;
42
  }
43
 
44
  h2 {
45
+ margin-top: 0;
46
  }
47
 
48
  hr {
49
+ margin: 25px 0;
50
  }
51
 
52
  code {
53
+ padding: 1px 4px;
54
  }
55
 
56
  .pys-list pre {
57
+ margin-top: 0;
58
+
59
+ white-space: pre-wrap; /* CSS 3 */
60
+ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
61
+ white-space: -pre-wrap; /* Opera 4-6 */
62
+ white-space: -o-pre-wrap; /* Opera 7 */
63
+ word-wrap: break-word;
64
  }
65
 
66
  .pys-rating {
67
+ text-align: center;
68
  }
69
 
70
  .pys-content {
71
+ margin: -1px 0 15px;
72
  }
73
 
74
  ul.dashed {
75
+ list-style: none;
76
+ margin-left: 0;
77
+ padding-left: 1.5em;
78
  }
79
 
80
  ul.dashed > li:before {
81
+ display: inline-block;
82
+ content: "\2014\a0";
83
+ width: 1.5em;
84
+ margin-left: -1.5em;
85
  }
86
 
87
  /* nav menu */
88
 
89
  .pys-menu {
90
+ overflow: hidden;
91
+ clear: both;
92
+ margin-bottom: 0;
93
  }
94
 
95
  .pys-menu .nav-tab {
96
+ border-top-left-radius: 5px;
97
+ border-top-right-radius: 5px;
98
+ cursor: pointer;
99
+ display: block;
100
+ margin-bottom: 0;
101
  }
102
 
103
  .pys-menu .nav-tab-active {
104
+ background: #fff;
105
+ border-bottom: 1px solid #fff;
106
  }
107
 
108
  /* panels */
109
 
110
  .pys-panel {
111
+ display: none;
112
  }
113
 
114
  /* boxes */
115
 
116
  .pys-box {
117
+ overflow: hidden;
118
+ clear: both;
119
+ border-radius: 5px;
120
+ border: 1px solid #ccc;
121
+ padding: 25px 0;
122
+ margin-bottom: 15px;
123
+ background: #fff;
124
  }
125
 
126
  .pys-box-red {
127
+ background: #F4524D;
128
+ color: #fff;
129
  }
130
 
131
  .pys-box-red h1,
138
  }
139
 
140
  .pys-box-middle {
141
+ color: #fff;
142
+ text-align: center;
143
+ background: #516F9F;
144
  }
145
 
146
  .pys-box-middle h2,
148
  .pys-box-middle p,
149
  .pys-box-middle u,
150
  .pys-box-middle i {
151
+ color: #fff;
152
  }
153
 
154
  /* grid */
155
 
156
  .pys-col {
157
+ float: left;
158
+ width: 100%;
159
+ box-sizing: border-box;
160
+ padding: 0 25px;
161
  }
162
 
163
  .pys-col-full {
164
+ width: 100%;
165
  }
166
 
167
  .pys-col-one-half {
168
+ width: 50%;
169
  }
170
 
171
  .pys-col-narrow {
172
+ float: none;
173
+ width: 70%;
174
+ margin: 25px auto;
175
  }
176
 
177
  .pys-col-border-left {
178
+ border-left: 1px solid #ccc;
179
  }
180
 
181
  .pys-col-border-right {
182
+ border-right: 1px solid #ccc;
183
  }
184
 
185
  /* aligns */
186
 
187
  h3.align-one-third {
188
+ margin-left: 30%;
189
+ padding: 0 18px;
190
  }
191
 
 
 
192
  tr.align-one-third td:first-child {
193
+ width: 30%;
194
  }
195
 
196
  tr.align-one-third td:last-child {
197
+ width: 70%;
198
  }
199
 
200
  /* buttons */
203
  .pys-btn:hover,
204
  a.pys-btn,
205
  a.pys-btn:hover {
206
+ line-height: normal;
207
+ display: inline-block;
208
+ color: #fff;
209
+ font-weight: bold;
210
+ text-decoration: none;
211
+ cursor: pointer;
212
+ padding: 10px 25px;
213
+ border: none;
214
  }
215
 
216
  .pys-btn:hover.pys-btn-big,
217
  a.pys-btn:hover.pys-btn-big {
218
+ line-height: normal;
219
+ padding: 12px 35px;
220
  }
221
 
222
  .pys-btn-red,
223
  a.pys-btn-red {
224
+ background: #F4524D;
225
  }
226
 
227
  .pys-btn-blue,
228
  a.pys-btn-blue {
229
+ background: #516F9F;
230
  }
231
 
232
  .pys-btn.pys-btn-big {
233
+ font-size: 20px;
234
+ padding: 12px 35px;
235
  }
236
 
237
  /* tables */
238
 
239
  table.layout {
240
+ width: 100%;
241
+ margin: 25px 0;
242
+ table-layout: fixed;
243
  }
244
 
245
  table.layout tr {
246
+ margin-bottom: 5px;
247
  }
248
 
249
  table.layout tr.tall td {
250
+ padding-bottom: 25px;
251
  }
252
 
253
  table.layout td {
254
+ padding: 5px 15px;
255
  }
256
 
257
  table.layout td.legend {
258
+ vertical-align: top;
259
  }
260
 
261
  table.layout td.narrow {
262
+ padding-left: 25%;
263
+ padding-right: 25%;
264
  }
265
 
266
  table.pys-list .button {
267
+ margin-right: 5px;
268
  }
269
 
270
  table.layout.search {
271
+ background-color: transparent; /* default styles bug fix */
272
  }
273
 
274
  /* forms */
275
 
276
  .label {
277
+ text-align: right;
278
+ margin: 0;
279
+ line-height: 27px;
280
+ font-weight: bold;
281
  }
282
 
283
  .label.big {
284
+ font-size: 16.9px;
285
  }
286
 
287
  .legend > .label {
288
+ line-height: inherit;
289
  }
290
 
291
  .help {
292
+ display: block;
293
+ color: #666;
294
+ font-size: 13px;
295
+ margin: 5px 0;
296
  }
297
 
298
  input[type="text"] {
299
+ width: 300px;
300
+ max-width: 100%;
301
  }
302
 
303
+ input[type="checkbox"],
304
+ input[type="radio"] {
305
+ margin-right: 10px;
306
  }
307
 
308
  input[type="checkbox"].big {
309
+ margin-top: -3px;
310
  }
311
 
312
  /* tickbox */
313
 
314
  #TB_window h2 {
315
+ margin: 1em 0;
316
  }
317
 
318
  #TB_window table tr td:last-child {
319
+ width: 70%;
320
  }
321
 
322
  #TB_window .actions-row {
323
+ text-align: right;
324
+ padding: 5px 15px;
325
  }
326
 
327
  /* event fields show/hide classes */
336
  .Lead-visible,
337
  .CompleteRegistration-visible,
338
  .CustomCode-visible,
339
+ .CustomEvent-visible {
340
+ display: none;
341
  }
342
 
343
  .ViewContent .ViewContent-visible,
351
  .Search .Search-visible,
352
  .CustomCode .CustomCode-visible,
353
  .CustomEvent .CustomEvent-visible {
354
+ display: table-row;
355
  }
356
 
357
+ .custom-currency-visible {
 
358
  display: none;
359
+ margin-top: 5px;
360
+ text-transform: uppercase;
361
+ }
362
+
363
+ .custom-currency + .custom-currency-visible {
364
+ display: inline-block;
365
+ }
366
+
367
+ .URL-visible,
368
+ .CSS-visible,
369
+ .scroll-visible,
370
+ .mouse-over-visible {
371
+ display: none;
372
  }
373
 
374
  .URL .URL-visible,
375
+ .CSS .CSS-visible,
376
+ .scroll .scroll-visible,
377
+ .mouse-over .mouse-over-visible {
378
+ display: table-row;
379
  }
facebook-pixel-master.php CHANGED
@@ -5,7 +5,7 @@
5
  Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
  Author: PixelYourSite
7
  Author URI: http://www.pixelyoursite.com
8
- Version: 3.1.0
9
  License: GPLv3
10
  */
11
 
@@ -16,8 +16,8 @@ if( defined( 'WP_DEBUG' ) && WP_DEBUG == true ) {
16
  error_reporting( E_ALL );
17
  }
18
 
19
- define( 'PYS_FREE_VERSION_REAL', '3.1.0');
20
- define( 'PYS_FREE_VERSION', '3.0.2'); // for plugin notices capability
21
 
22
  require_once( 'inc/common.php' );
23
  require_once( 'inc/admin_notices.php' );
@@ -36,14 +36,43 @@ function pys_free_init() {
36
  return;
37
  }
38
 
39
- add_action( 'wp_head', 'pys_pixel_code', 1 ); // display Facebook Pixel Code
40
  add_action( 'wp_enqueue_scripts', 'pys_public_scripts' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- // add addtocart ajax support only if woocommerce installed and events enabled
43
- if ( pys_is_woocommerce_active() && pys_get_option( 'woo', 'enabled' ) && pys_get_option( 'woo', 'on_add_to_cart_btn' ) ) {
44
  add_filter( 'woocommerce_loop_add_to_cart_link', 'pys_add_code_to_woo_cart_link', 10, 2 );
 
45
  }
46
-
 
 
47
  }
48
 
49
  /* Register Admin Page for plugin */
@@ -102,7 +131,9 @@ if( !function_exists( 'pys_public_scripts' ) ) {
102
 
103
  function pys_public_scripts() {
104
 
105
- wp_enqueue_script( 'pys', plugins_url( 'js/public.js', __FILE__ ), array( 'jquery' ), PYS_FREE_VERSION );
 
 
106
 
107
  }
108
 
@@ -115,30 +146,25 @@ if( !function_exists( 'pys_free_plugin_activated' ) ) {
115
  function pys_free_plugin_activated() {
116
 
117
  if ( ! function_exists( 'is_plugin_active' ) ) {
118
-
119
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
120
-
121
  }
122
 
123
  if ( is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' ) ) {
124
-
125
  wp_die( 'Please deactivate PixelYourSite Pro version First.', 'Plugin Activation' );
126
-
127
  }
128
 
129
  $options = get_option( 'pixel_your_site' );
130
  if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
131
-
132
  pys_initialize_settings();
133
-
134
  }
135
 
136
  //@todo: refactor options names in future releases
 
137
  // set plugin activation data and remember version (used in admin notices)
138
  $activation_date = get_option('pysf_activation_date', '');
139
  $version = get_option('pysf_plugin_version', '');
140
 
141
- if( empty($activation_date) || version_compare($version, PYS_FREE_VERSION, '<') ) {
142
  update_option( 'pysf_activation_date', time() );
143
  update_option( 'pysf_plugin_version', PYS_FREE_VERSION );
144
  update_option( 'pysf_notice_dismiss', '' );
5
  Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
6
  Author: PixelYourSite
7
  Author URI: http://www.pixelyoursite.com
8
+ Version: 4.0.0
9
  License: GPLv3
10
  */
11
 
16
  error_reporting( E_ALL );
17
  }
18
 
19
+ define( 'PYS_FREE_VERSION_REAL', '4.0.0' );
20
+ define( 'PYS_FREE_VERSION', '4.0.0'); // for plugin notices capability
21
 
22
  require_once( 'inc/common.php' );
23
  require_once( 'inc/admin_notices.php' );
36
  return;
37
  }
38
 
 
39
  add_action( 'wp_enqueue_scripts', 'pys_public_scripts' );
40
+ add_action( 'wp_head', 'pys_head_comments', 10 );
41
+
42
+ /**
43
+ * Hooks call priority:
44
+ * wp_head:
45
+ * 1 - pixel events options - PRO only;
46
+ * 2 - init event;
47
+ * 3 - evaluate events;
48
+ * 4 - output events;
49
+ * 9 (20) - enqueue public scripts (head/footer);
50
+ * wp_footer
51
+ */
52
+
53
+ add_action( 'wp_head', 'pys_pixel_init_event', 2 );
54
+
55
+ add_action( 'wp_head', 'pys_page_view_event', 3 );
56
+ add_action( 'wp_head', 'pys_general_event', 3 );
57
+ add_action( 'wp_head', 'pys_search_event', 3 );
58
+ add_action( 'wp_head', 'pys_standard_events', 3 );
59
+ add_action( 'wp_head', 'pys_woocommerce_events', 3 );
60
+
61
+ add_action( 'wp_head', 'pys_output_js_events_code', 4 );
62
+ add_action( 'wp_head', 'pys_output_custom_events_code', 4 );
63
+
64
+ add_action( 'wp_footer', 'pys_output_noscript_code', 10 );
65
+ add_action( 'wp_footer', 'pys_output_woo_ajax_events_code', 10 );
66
+
67
+ // add add_to_cart ajax support only if woocommerce installed and events enabled
68
+ if ( pys_get_option( 'woo', 'enabled' ) && ( pys_get_option( 'woo', 'on_add_to_cart_btn' ) || pys_get_option( 'woo', 'on_thank_you_page' ) ) ) {
69
 
 
 
70
  add_filter( 'woocommerce_loop_add_to_cart_link', 'pys_add_code_to_woo_cart_link', 10, 2 );
71
+
72
  }
73
+
74
+ add_filter( 'pys_event_params', 'pys_add_domain_param', 10, 2 );
75
+
76
  }
77
 
78
  /* Register Admin Page for plugin */
131
 
132
  function pys_public_scripts() {
133
 
134
+ $in_footer = (bool) pys_get_option( 'general', 'in_footer', false );
135
+
136
+ wp_enqueue_script( 'pys', plugins_url( 'js/public.js', __FILE__ ), array( 'jquery' ), PYS_FREE_VERSION, $in_footer );
137
 
138
  }
139
 
146
  function pys_free_plugin_activated() {
147
 
148
  if ( ! function_exists( 'is_plugin_active' ) ) {
 
149
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
 
150
  }
151
 
152
  if ( is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' ) ) {
 
153
  wp_die( 'Please deactivate PixelYourSite Pro version First.', 'Plugin Activation' );
 
154
  }
155
 
156
  $options = get_option( 'pixel_your_site' );
157
  if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
 
158
  pys_initialize_settings();
 
159
  }
160
 
161
  //@todo: refactor options names in future releases
162
+
163
  // set plugin activation data and remember version (used in admin notices)
164
  $activation_date = get_option('pysf_activation_date', '');
165
  $version = get_option('pysf_plugin_version', '');
166
 
167
+ if ( empty( $activation_date ) || version_compare( $version, PYS_FREE_VERSION, '<' ) ) {
168
  update_option( 'pysf_activation_date', time() );
169
  update_option( 'pysf_plugin_version', PYS_FREE_VERSION );
170
  update_option( 'pysf_notice_dismiss', '' );
inc/admin_notices.php CHANGED
@@ -33,23 +33,23 @@ $link_2 = 'http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wadmin&
33
 
34
 
35
  //Message for day 1
36
- $day_1_text = '<span class="pysf_note"><b>Update to PixelYourSite Pro </b></span> and optimize your FB ads for clicks on links or buttons with <b>Dynamic Events</b>. Enable <i>time on page</i> parameter, or improve conversion attribution and retargeting reach by using <b>Advanced Matching</b>. Don’t miss this limited discount:<br> ';
37
  $day_1_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to download PixelYourSite Pro for a big discount</b></a>';
38
 
39
  //Message for day 2
40
- $day_2_text = '<span class="pysf_note"><b>Use Dynamic Events </b></span> and optimize your ads for <b>actions on site</b> (clicks on links or buttons). Use Time on Page for key pages Custom Audiences:<br>';
41
  $day_2_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Download PixelYourSite Pro for a limited discount</b></a>';
42
 
43
  //Message for day 3
44
- $day_3_text = '<span class="pysf_note"><b>Last Chance for this discount:</b></span> With PixelYourSite Pro you can use <b>Dynamic Events</b> (optimize campaigns for actions on your site), track <b>Time on Page</b> (create super powerful Custom Audiences for key pages), plus enable <b>Advanced Matching</b> (new FB feature that increases conversion attribution and reach for retargeting campaigns): <br>';
45
  $day_3_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Download Now (offer ending soon)</b></a>';
46
 
47
  //Message for day 4 to 7;
48
- $day_4_to_7_text = '<span class="pysf_note"><b>How to Build Custom Audiences with PixelYourSite:</b></span> The new GeneralEvent option can be used to create powerful Custom Audiences. Since it is a very useful tool, we made this <b>FREE guide</b> about how to use it: <a href="http://www.pixelyoursite.com/general-event?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Click here for your Guide</a>';
49
 
50
 
51
  //Message for day 7 to 12
52
- $day_7_to_12_text = '<span class="pysf_note"><b>Grab Your Free Guide from PixelYourSite Now: </b></span> This is how the new GeneralEvent option can be used to create powerful Custom Audiences that will improve your Facebook Ads profitability:<br><a href="http://www.pixelyoursite.com/general-event?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Click here for your FREE Guide</a>';
53
 
54
  $options = array(
55
 
@@ -116,32 +116,32 @@ $options = array(
116
 
117
  //WooCommerce Message for day 1
118
  $woo_day_1_text = 'WooCommerce Day 1 Message.';
119
- $woo_day_1_text = '<span class="pysf_note"><b>PixelYourSite PRO + Product Catalog Feed Plugin Bundle:</b></span> Track Conversion Value and start with Facebook Dynamic Ads for WooCommerce in minutes. <br>Get <b>PixelYourSite Pro</b> (<i>fine tune Conversion Vaule</i>, optimize WooCommerce events for Cutom Audiences, track tags, product tags and Time on Page, enable Advanced Matching and use <i>Dynamic Events</i>)<br>Get <b>Product Catalog Feed Plugin</b> (create WooCommerce Dynamic Ads Product Catalog XML feeds)<br> ';
120
  $woo_day_1_text .= '<a href="http://www.pixelyoursite.com/bundle-offer?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to DOWNLOAD the bundle now (best deal)</b></a>';
121
 
122
 
123
 
124
  //WooCommerce Message for day 2
125
  $woo_day_2_text = 'WooCommerce Day 2 Message.';
126
- $woo_day_2_text = '<span class="pysf_note"><b>Customize and Track WooCommerce Conversion Value:</b></span> With PixelYourSite Pro you can <b>fine tune WooCommerce Events Values</b> and improve conversion tracking. <b>Time on page</b> is tracked and can be used for Custom Audiences, as well as tags or <b>product tags</b>. With <b>Dynamic Events</b> you can optimize FB ads for actions on your site (clicks on links and buttons) and <b>Advanced Matching</b> will improve conversion attribution and reach of retargeting campaigns.<br> ';
127
  $woo_day_2_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to download PixelYourSite Pro for a serious discount</b></a>';
128
 
129
 
130
  //WooCommerce Message for day 3
131
  $woo_day_3_text = 'WooCommerce Day 3 Message.';
132
- $woo_day_3_text = '<span class="pysf_note"><b>Product Catalog Feed Plugin:</b></span> Create unlimited <b>WooCommerce XML feeds for Facebook Dynamic Ads Product Catalog</b> with just a few clicks. ';
133
- $woo_day_3_text .= '<a href="http://www.pixelyoursite.com/product-catalog-facebook?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to download Product Catalog Feed</b></a>';
134
 
135
 
136
  //WooCommerce Message for day 4 to 7;
137
  $woo_day_4_to_7_text = 'WooCommerce Day 4 to 7 Message.';
138
- $woo_day_4_to_7_text = '<span class="pysf_note"><b>Track Time on Page:</b></span> With PixelYourSite Pro you can track <b>Time on Page</b> and use it to build super powerful Custom Audiences for key pages. <b>Advanced Matching</b> is supported and will improve conversion attribution and retargeting reach. Improving your Facebook Ads is easy: <br> ';
139
  $woo_day_4_to_7_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Click to download PixelYourSite Pro for a serious discount</a>';
140
 
141
 
142
  //WooCommerce Message for day 7 to 12
143
  $woo_day_7_to_12_text = 'WooCommerce Day 7 to 12 Message.';
144
- $woo_day_7_to_12_text = '<span class="pysf_note"><b>How build Custom Audiences - PixelYourSite Free Guide:</b></span> Find out powerful strategies for your WooCommerce website in this <b>FREE guide</b> about the new General Event option (it helps you with Custom Audiences):<br> <a href="http://www.pixelyoursite.com/general-event?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Click here for your own FREE copy</a>';
145
 
146
 
147
 
33
 
34
 
35
  //Message for day 1
36
+ $day_1_text = '<span class="pysf_note"><b>Upgrade to PixelYourSite PRO </b></span> and optimize your FB ads for clicks on links or buttons with <b>Dynamic Events</b>. Enable <i>time on page</i> event, or improve conversion attribution and retargeting reach by using <b>Advanced Matching</b>. Track <b>Traffic Source</b> and UTM for better retargeting with Custom Audiences. Don’t miss this limited discount:<br> ';
37
  $day_1_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to download PixelYourSite Pro for a big discount</b></a>';
38
 
39
  //Message for day 2
40
+ $day_2_text = '<span class="pysf_note"><b>Use Dynamic Events </b></span> and optimize your ads for <b>on-site actions</b> (trigger events on CLICKS, page scroll, mouse over). Use TimeOnPage for key pages Custom Audiences and track the <b>Traffic Source</b> and UTM for all your events:<br>';
41
  $day_2_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Download PixelYourSite Pro for a limited discount</b></a>';
42
 
43
  //Message for day 3
44
+ $day_3_text = '<span class="pysf_note"><b>Last chance to get your DISCOUNT:</b></span> With PixelYourSite Pro you can use <b>Dynamic Events</b> (optimize campaigns for actions on your site, like clicks, page scroll or mouse over), track <b>TimeOnPage</b> (create super powerful Custom Audiences for key pages), plus enable <b>Advanced Matching</b> (new FB feature that increases conversion attribution and reach for retargeting campaigns). <b>Traffic Source</b> and UTM are added to all the events, so you can create <i>highly accurate retargeting campaigns</i>: <br>';
45
  $day_3_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Download Now (offer ending soon)</b></a>';
46
 
47
  //Message for day 4 to 7;
48
+ $day_4_to_7_text = '<span class="pysf_note"><b>Your Facebook Pixel FREE Guide:</b></span> After <i>more than 10 000 users</i> 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? <b>Download it now for free:</b> <a href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Click here for your Guide</a>';
49
 
50
 
51
  //Message for day 7 to 12
52
+ $day_7_to_12_text = '<span class="pysf_note"><b>PixelYourSite FREE Guide:</b></span> 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=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Download it now for free</a>';
53
 
54
  $options = array(
55
 
116
 
117
  //WooCommerce Message for day 1
118
  $woo_day_1_text = 'WooCommerce Day 1 Message.';
119
+ $woo_day_1_text = '<span class="pysf_note"><b>PixelYourSite PRO + Product Catalog Feed Plugin Bundle:</b></span> Track Conversion Value and start with Facebook Dynamic Ads for WooCommerce in minutes. <br>Get <b>PixelYourSite Pro</b> (<i>fine tune Conversion Value</i>, optimize WooCommerce events for Custom Audiences, track tags, product tags and Time on Page, <b>Traffic Source</b> and UTM, enable Advanced Matching and use <i>Dynamic Events</i>)<br>Get <b>Product Catalog Feed Plugin</b> (create WooCommerce Dynamic Ads Product Catalog XML feeds)<br> ';
120
  $woo_day_1_text .= '<a href="http://www.pixelyoursite.com/bundle-offer?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to DOWNLOAD the bundle now (best deal)</b></a>';
121
 
122
 
123
 
124
  //WooCommerce Message for day 2
125
  $woo_day_2_text = 'WooCommerce Day 2 Message.';
126
+ $woo_day_2_text = '<span class="pysf_note"><b>Customize WooCommerce Conversion Value:</b></span> With PixelYourSite Pro you can <b>fine tune WooCommerce Events Values</b> and improve conversion tracking. Include/Exclude Tax or Shipping, plus define the value for each WooCommerce event as the full product price, price percent or a global value. Turn ON/OFF value tracking for each event according to your needs.<br>';
127
  $woo_day_2_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to download PixelYourSite Pro for a serious discount</b></a>';
128
 
129
 
130
  //WooCommerce Message for day 3
131
  $woo_day_3_text = 'WooCommerce Day 3 Message.';
132
+ $woo_day_3_text = '<span class="pysf_note"><b>WooCommerce Custom Audiences Optimization:</b></span> Build super-powerful Custom Audiences with PixelYourSite PRO. Track product name, category or product tags, plus shipping and payment methods, client city or country, coupon used and coupons names. All the events will have <b>Traffic Source and UTM</B> as parameters and there is a TimeOnPage event. Use them to <b>create highly relevant retargeting campaigns.</b></br>';
133
+ $woo_day_3_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank"><b>Click to download PixelYourSite Pro for a serious discount</b></a>';
134
 
135
 
136
  //WooCommerce Message for day 4 to 7;
137
  $woo_day_4_to_7_text = 'WooCommerce Day 4 to 7 Message.';
138
+ $woo_day_4_to_7_text = '<span class="pysf_note"><b>Track Traffic Source:</b></span> With PixelYourSite Pro you can track <b>Traffic Source</b> and use it to build super-powerful Custom Audiences for your retargeting campaigns. Create Custom Audiences based on <b>where the users are coming from (Google, FB, any other site or URL), including a particular Facebook Ad</b><br> ';
139
  $woo_day_4_to_7_text .= '<a href="http://www.pixelyoursite.com/facebook-pixel-plugin?utm_source=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Click to download PixelYourSite Pro for a serious discount</a>';
140
 
141
 
142
  //WooCommerce Message for day 7 to 12
143
  $woo_day_7_to_12_text = 'WooCommerce Day 7 to 12 Message.';
144
+ $woo_day_7_to_12_text = '<span class="pysf_note"><b>Your Facebook Pixel FREE Guide:</b></span> After <i>more than 10 000 users</i> 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=wpadmin-update&utm_medium=update&utm_campaign=update" target="_blank">Click here for your own FREE copy</a>';
145
 
146
 
147
 
inc/ajax-standard.php CHANGED
@@ -8,11 +8,44 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
8
  add_action( 'wp_ajax_pys_edit_std_event', 'pys_edit_std_event' );
9
  function pys_edit_std_event() {
10
 
11
- $id = isset( $_REQUEST['id'] ) == true ? $_REQUEST['id'] : uniqid();
 
12
 
13
- // get event data
14
- $events = (array) get_option( 'pixel_your_site_std_events' );
15
- $std_event = $events[ $id ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  ?>
18
 
@@ -20,11 +53,11 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
20
  <input type="hidden" name="action" value="add_std_event">
21
  <input type="hidden" name="std_event[id]" value="<?php echo $id; ?>">
22
 
23
- <table class="layout <?php echo $std_event['eventtype']; ?>">
24
  <tr>
25
  <td class="legend"><p class="label">URL:</p></td>
26
  <td>
27
- <input type="text" name="std_event[pageurl]" value="<?php echo $std_event['pageurl']; ?>" id="std-url">
28
  <span class="help">Event will trigger when this URL is visited.<br>If you add * at the end of the URL string, it will match all URLs starting with the this string.</span>
29
  </td>
30
  </tr>
@@ -33,7 +66,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
33
  <td class="legend"><p class="label">Event type:</p></td>
34
  <td>
35
  <select name="std_event[eventtype]" autocomplete="off" id="std-event-type">
36
- <?php echo pys_event_types_select_options( $std_event['eventtype'] ); ?>
37
  </select>
38
  </td>
39
  </tr>
@@ -41,7 +74,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
41
  <tr class="ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible">
42
  <td class="legend"><p class="label">Value:</p></td>
43
  <td>
44
- <input type="text" name="std_event[value]" value="<?php echo $std_event['value']; ?>">
45
  <span class="help">Mandatory for purchase event only.</span>
46
  </td>
47
  </tr>
@@ -49,10 +82,13 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
49
  <tr class="ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible">
50
  <td class="legend"><p class="label">Currency:</p></td>
51
  <td>
52
- <select name="std_event[currency]">
53
- <option value="">Select Currency</option>
54
- <?php echo pys_currency_options( $std_event['currency'] ); ?>
 
 
55
  </select>
 
56
  <span class="help">Mandatory for purchase event only.</span>
57
  </td>
58
  </tr>
@@ -61,7 +97,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
61
  <td class="legend"><p class="label">content_name:</p></td>
62
  <td>
63
  <input type="text" name="std_event[content_name]"
64
- value="<?php echo $std_event['content_name']; ?>">
65
  <span class="help">Name of the page/product i.e 'Really Fast Running Shoes'.</span>
66
  </td>
67
  </tr>
@@ -70,7 +106,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
70
  <td class="legend"><p class="label">content_ids:</p></td>
71
  <td>
72
  <input type="text" name="std_event[content_ids]"
73
- value="<?php echo $std_event['content_ids']; ?>">
74
  <span class="help">Product ids/SKUs associated with the event.</span>
75
  </td>
76
  </tr>
@@ -79,7 +115,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
79
  <td class="legend"><p class="label">content_type:</p></td>
80
  <td>
81
  <input type="text" name="std_event[content_type]"
82
- value="<?php echo $std_event['content_type']; ?>">
83
  <span class="help">The type of content. i.e product or product_group.</span>
84
  </td>
85
  </tr>
@@ -88,7 +124,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
88
  <td class="legend"><p class="label">content_category:</p></td>
89
  <td>
90
  <input type="text" name="std_event[content_category]"
91
- value="<?php echo $std_event['content_category']; ?>">
92
  <span class="help">Category of the page/product.</span>
93
  </td>
94
  </tr>
@@ -96,7 +132,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
96
  <tr class="InitiateCheckout-visible Purchase-visible">
97
  <td class="legend"><p class="label">num_items:</p></td>
98
  <td>
99
- <input type="text" name="std_event[num_items]" value="<?php echo $std_event['num_items']; ?>">
100
  <span class="help">The number of items in the cart. i.e '3'.</span>
101
  </td>
102
  </tr>
@@ -104,7 +140,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
104
  <tr class="Purchase-visible">
105
  <td class="legend"><p class="label">order_id:</p></td>
106
  <td>
107
- <input type="text" name="std_event[order_id]" value="<?php echo $std_event['order_id']; ?>">
108
  <span class="help">The unique order id of the successful purchase. i.e 19.</span>
109
  </td>
110
  </tr>
@@ -113,7 +149,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
113
  <td class="legend"><p class="label">search_string:</p></td>
114
  <td>
115
  <input type="text" name="std_event[search_string]"
116
- value="<?php echo $std_event['search_string']; ?>">
117
  <span class="help">The string entered by the user for the search. i.e 'Shoes'.</span>
118
  </td>
119
  </tr>
@@ -121,7 +157,7 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
121
  <tr class="CompleteRegistration-visible">
122
  <td class="legend"><p class="label">status:</p></td>
123
  <td>
124
- <input type="text" name="std_event[status]" value="<?php echo $std_event['status']; ?>">
125
  <span class="help">The status of the registration. i.e completed.</span>
126
  </td>
127
  </tr>
@@ -131,13 +167,43 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
131
  only):</p></td>
132
  <td>
133
  <textarea name="std_event[code]" rows="5"
134
- style="width:100%;"><?php echo stripslashes( $std_event['code'] ); ?></textarea>
135
  <span class="help">The code inserted in the field MUST be complete, including <code>fbq('track',
136
  'AddToCart', { … });</code></span>
137
  </td>
138
  </tr>
139
 
140
- <tr class="CustomEvent-visible">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  <td class="legend"></td>
142
  <td>
143
  <a href="#" class="button button-add-row button-primary action">Add Param</a>
@@ -156,6 +222,16 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
156
  <script>
157
  jQuery(function ($) {
158
 
 
 
 
 
 
 
 
 
 
 
159
  validate();
160
 
161
  /* Standard event fields show/hide on event type change. */
@@ -170,6 +246,17 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
170
 
171
  });
172
 
 
 
 
 
 
 
 
 
 
 
 
173
  /* Close modal window */
174
  $('.button-close').on('click', function (e) {
175
  e.preventDefault();
@@ -206,6 +293,42 @@ if( !function_exists( 'pys_edit_std_event' ) ) {
206
 
207
  });
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  // Form validation
210
  $('form').submit(function(e) {
211
 
@@ -257,17 +380,48 @@ if( !function_exists( 'pys_update_std_event' ) ) {
257
  add_action( 'wp_ajax_pys_update_std_event', 'pys_update_std_event' );
258
  function pys_update_std_event() {
259
 
 
 
260
  $events = (array) get_option( 'pixel_your_site_std_events' );
261
- $std_event = $_REQUEST['std_event'];
262
 
263
- $id = $std_event['id'];
264
- unset( $std_event['action'] );
265
- unset( $std_event['id'] );
266
 
267
- unset( $std_event['custom_names'] );
268
- unset( $std_event['custom_values'] );
269
 
270
- $events[ $id ] = $std_event;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  update_option( 'pixel_your_site_std_events', $events );
272
 
273
  echo json_encode( 'success' );
@@ -285,6 +439,8 @@ if( !function_exists( 'pys_delete_std_event' ) ) {
285
  add_action( 'wp_ajax_pys_delete_std_event', 'pys_delete_std_event' );
286
  function pys_delete_std_event() {
287
 
 
 
288
  $events = (array) get_option( 'pixel_your_site_std_events' );
289
  $ids = $_REQUEST['ids'];
290
 
8
  add_action( 'wp_ajax_pys_edit_std_event', 'pys_edit_std_event' );
9
  function pys_edit_std_event() {
10
 
11
+ $id = isset( $_REQUEST['id'] ) == true ? $_REQUEST['id'] : uniqid();
12
+ $events = (array) get_option( 'pixel_your_site_std_events' );
13
 
14
+ if ( array_key_exists( $id, $events ) ) {
15
+
16
+ $event = $events[ $id ];
17
+
18
+ } else {
19
+
20
+ $event = array(
21
+ 'eventtype' => null,
22
+ 'pageurl' => null,
23
+ 'value' => null,
24
+ 'currency' => null,
25
+ 'content_name' => null,
26
+ 'content_ids' => null,
27
+ 'content_type' => null,
28
+ 'content_category' => null,
29
+ 'num_items' => null,
30
+ 'search_string' => null,
31
+ 'status' => null,
32
+ 'code' => null,
33
+ 'custom_name' => null
34
+ );
35
+
36
+ }
37
+
38
+ // change `eventtype`
39
+ if ( ! empty( $event['custom_name'] ) ) {
40
+ $event['eventtype'] = 'CustomEvent';
41
+ }
42
+
43
+ // collect custom params
44
+ $custom_params = pys_get_custom_params( $event );
45
+
46
+ $table_class = $event['eventtype'];
47
+
48
+ $is_custom_currency = isset( $event['custom_currency'] ) ? $event['custom_currency'] : false;
49
 
50
  ?>
51
 
53
  <input type="hidden" name="action" value="add_std_event">
54
  <input type="hidden" name="std_event[id]" value="<?php echo $id; ?>">
55
 
56
+ <table class="layout <?php echo $table_class; ?>">
57
  <tr>
58
  <td class="legend"><p class="label">URL:</p></td>
59
  <td>
60
+ <input type="text" name="std_event[pageurl]" value="<?php echo $event['pageurl']; ?>" id="std-url">
61
  <span class="help">Event will trigger when this URL is visited.<br>If you add * at the end of the URL string, it will match all URLs starting with the this string.</span>
62
  </td>
63
  </tr>
66
  <td class="legend"><p class="label">Event type:</p></td>
67
  <td>
68
  <select name="std_event[eventtype]" autocomplete="off" id="std-event-type">
69
+ <?php pys_event_types_select_options( $event['eventtype'] ); ?>
70
  </select>
71
  </td>
72
  </tr>
74
  <tr class="ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible">
75
  <td class="legend"><p class="label">Value:</p></td>
76
  <td>
77
+ <input type="text" name="std_event[value]" value="<?php echo $event['value']; ?>">
78
  <span class="help">Mandatory for purchase event only.</span>
79
  </td>
80
  </tr>
82
  <tr class="ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible">
83
  <td class="legend"><p class="label">Currency:</p></td>
84
  <td>
85
+ <select name="std_event[currency]" id="currency" class="<?php echo $is_custom_currency ? 'custom-currency' : null; ?>" >
86
+ <option disabled <?php selected( false, $is_custom_currency && $event['currency'] ); ?> >Select Currency</option>
87
+ <?php pys_currency_options( $event['currency'] ); ?>
88
+ <option disabled></option>
89
+ <option value="pys_custom_currency" <?php selected( true, $is_custom_currency ); ?> >Custom Currency</option>
90
  </select>
91
+ <input type="text" name="std_event[custom_currency]" value="<?php echo $is_custom_currency ? $event['currency'] : null; ?>" placeholder="Enter custom currency code" class="custom-currency-visible">
92
  <span class="help">Mandatory for purchase event only.</span>
93
  </td>
94
  </tr>
97
  <td class="legend"><p class="label">content_name:</p></td>
98
  <td>
99
  <input type="text" name="std_event[content_name]"
100
+ value="<?php echo $event['content_name']; ?>">
101
  <span class="help">Name of the page/product i.e 'Really Fast Running Shoes'.</span>
102
  </td>
103
  </tr>
106
  <td class="legend"><p class="label">content_ids:</p></td>
107
  <td>
108
  <input type="text" name="std_event[content_ids]"
109
+ value="<?php echo $event['content_ids']; ?>">
110
  <span class="help">Product ids/SKUs associated with the event.</span>
111
  </td>
112
  </tr>
115
  <td class="legend"><p class="label">content_type:</p></td>
116
  <td>
117
  <input type="text" name="std_event[content_type]"
118
+ value="<?php echo $event['content_type']; ?>">
119
  <span class="help">The type of content. i.e product or product_group.</span>
120
  </td>
121
  </tr>
124
  <td class="legend"><p class="label">content_category:</p></td>
125
  <td>
126
  <input type="text" name="std_event[content_category]"
127
+ value="<?php echo $event['content_category']; ?>">
128
  <span class="help">Category of the page/product.</span>
129
  </td>
130
  </tr>
132
  <tr class="InitiateCheckout-visible Purchase-visible">
133
  <td class="legend"><p class="label">num_items:</p></td>
134
  <td>
135
+ <input type="text" name="std_event[num_items]" value="<?php echo $event['num_items']; ?>">
136
  <span class="help">The number of items in the cart. i.e '3'.</span>
137
  </td>
138
  </tr>
140
  <tr class="Purchase-visible">
141
  <td class="legend"><p class="label">order_id:</p></td>
142
  <td>
143
+ <input type="text" name="std_event[order_id]" value="<?php echo $event['order_id']; ?>">
144
  <span class="help">The unique order id of the successful purchase. i.e 19.</span>
145
  </td>
146
  </tr>
149
  <td class="legend"><p class="label">search_string:</p></td>
150
  <td>
151
  <input type="text" name="std_event[search_string]"
152
+ value="<?php echo $event['search_string']; ?>">
153
  <span class="help">The string entered by the user for the search. i.e 'Shoes'.</span>
154
  </td>
155
  </tr>
157
  <tr class="CompleteRegistration-visible">
158
  <td class="legend"><p class="label">status:</p></td>
159
  <td>
160
+ <input type="text" name="std_event[status]" value="<?php echo $event['status']; ?>">
161
  <span class="help">The status of the registration. i.e completed.</span>
162
  </td>
163
  </tr>
167
  only):</p></td>
168
  <td>
169
  <textarea name="std_event[code]" rows="5"
170
+ style="width:100%;"><?php echo stripslashes( $event['code'] ); ?></textarea>
171
  <span class="help">The code inserted in the field MUST be complete, including <code>fbq('track',
172
  'AddToCart', { … });</code></span>
173
  </td>
174
  </tr>
175
 
176
+ <tr class="CustomEvent-visible tall">
177
+ <td class="legend"><p class="label">Event name:</p></td>
178
+ <td>
179
+ <input type="text" name="std_event[custom_name]" value="<?php echo $event['custom_name']; ?>">
180
+ </td>
181
+ </tr>
182
+
183
+ <?php foreach( $custom_params as $param => $value ) : ?>
184
+
185
+ <?php $param_id = uniqid() . $param; ?>
186
+
187
+ <tr class="class-<?php echo $param_id; ?> ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible CustomEvent-visible">
188
+ <td class="legend"><p class="label">Param name:</p></td>
189
+ <td><input type="text" name="std_event[custom_names][<?php echo $param; ?>]" value="<?php echo $param; ?>"></td>
190
+ </tr>
191
+
192
+ <tr class="class-<?php echo $param_id; ?> ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible CustomEvent-visible">
193
+ <td class="legend"><p class="label">Param value:</p></td>
194
+ <td><input type="text" name="std_event[custom_values][<?php echo $param; ?>]" value="<?php echo $value; ?>"></td>
195
+ </tr>
196
+
197
+ <tr class="class-<?php echo $param_id; ?> tall ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible CustomEvent-visible">
198
+ <td></td>
199
+ <td><a href="#" class="remove-param" data-id="<?php echo $param_id; ?>">Remove param</a></td>
200
+ </tr>
201
+
202
+ <?php endforeach; ?>
203
+
204
+ <tr id="marker"></tr>
205
+
206
+ <tr class="ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible CustomEvent-visible">
207
  <td class="legend"></td>
208
  <td>
209
  <a href="#" class="button button-add-row button-primary action">Add Param</a>
222
  <script>
223
  jQuery(function ($) {
224
 
225
+ function makeid() {
226
+ var id = "";
227
+ var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
228
+
229
+ for (var i = 0; i < 10; i++)
230
+ id += possible.charAt(Math.floor(Math.random() * possible.length));
231
+
232
+ return id;
233
+ }
234
+
235
  validate();
236
 
237
  /* Standard event fields show/hide on event type change. */
246
 
247
  });
248
 
249
+ // Show/hide custom currency field
250
+ $('select#currency').on('change', function(){
251
+
252
+ if( $(this).val() == 'pys_custom_currency' ) {
253
+ $(this).addClass('custom-currency');
254
+ } else {
255
+ $(this).removeClass('custom-currency');
256
+ }
257
+
258
+ });
259
+
260
  /* Close modal window */
261
  $('.button-close').on('click', function (e) {
262
  e.preventDefault();
293
 
294
  });
295
 
296
+ /* Add new param/value group */
297
+ var marker = $('#marker');
298
+ $('.button-add-row').on('click', function(e) {
299
+ e.preventDefault();
300
+
301
+ var id = makeid();
302
+
303
+ var html = '<tr class="class-'+id+' ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible CustomEvent-visible">';
304
+ html += '<td class="legend"><p class="label">Param name:</p></td>';
305
+ html += '<td><input type="text" name="std_event[custom_names]['+id+']" value=""></td>';
306
+ html += '</tr>';
307
+
308
+ html += '<tr class="class-'+id+' ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible CustomEvent-visible">';
309
+ html += '<td class="legend"><p class="label">Param value:</p></td>';
310
+ html += '<td><input type="text" name="std_event[custom_values]['+id+']" value=""></td>';
311
+ html += '</tr>';
312
+
313
+ html += '<tr class="class-'+id+' tall ViewContent-visible Search-visible AddToCart-visible AddToWishlist-visible InitiateCheckout-visible AddPaymentInfo-visible Purchase-visible Lead-visible CompleteRegistration-visible CustomEvent-visible">';
314
+ html += '<td></td>';
315
+ html += '<td><a href="#" class="remove-param" data-id="'+id+'">Remove param</a></td>';
316
+ html += '</tr>';
317
+
318
+
319
+ $(html).insertBefore(marker);
320
+
321
+ });
322
+
323
+ // Remove custom params row
324
+ $(document).on('click', '.remove-param', function(e){
325
+ e.preventDefault();
326
+
327
+ var id = $(this).data('id');
328
+ $('tr.class-'+id).remove();
329
+
330
+ });
331
+
332
  // Form validation
333
  $('form').submit(function(e) {
334
 
380
  add_action( 'wp_ajax_pys_update_std_event', 'pys_update_std_event' );
381
  function pys_update_std_event() {
382
 
383
+ //@todo: merge with dynamic events function and move to common code
384
+
385
  $events = (array) get_option( 'pixel_your_site_std_events' );
386
+ $event = $_REQUEST['std_event'];
387
 
388
+ $id = $event['id'];
389
+ unset( $event['action'] );
390
+ unset( $event['id'] );
391
 
392
+ if( isset( $event['custom_currency'] ) && ! empty( $event['custom_currency'] ) ) {
 
393
 
394
+ $event['currency'] = strtoupper( $event['custom_currency'] );
395
+ $event['custom_currency'] = true;
396
+
397
+ }
398
+
399
+ if( $event['eventtype'] == 'CustomEvent' ) {
400
+
401
+ $custom_name = $event['custom_name'];
402
+ $custom_name = preg_replace( '/[^A-Za-z0-9\_]/u', '', $custom_name );
403
+
404
+ $event['eventtype'] = trim( $custom_name );
405
+
406
+ }
407
+
408
+ if( isset( $event['custom_names'] ) && is_array( $event['custom_names'] ) ) {
409
+
410
+ foreach ( $event['custom_names'] as $key => $value ) {
411
+
412
+ $key_name = $value;
413
+ $key_name = preg_replace( '/[^A-Za-z0-9\_]/u', '', $key_name );
414
+
415
+ $event[ $key_name ] = $event['custom_values'][ $key ];
416
+
417
+ }
418
+
419
+ }
420
+
421
+ unset( $event['custom_names'] );
422
+ unset( $event['custom_values'] );
423
+
424
+ $events[ $id ] = $event;
425
  update_option( 'pixel_your_site_std_events', $events );
426
 
427
  echo json_encode( 'success' );
439
  add_action( 'wp_ajax_pys_delete_std_event', 'pys_delete_std_event' );
440
  function pys_delete_std_event() {
441
 
442
+ //@todo: merge with dynamic events function and move to common code
443
+
444
  $events = (array) get_option( 'pixel_your_site_std_events' );
445
  $ids = $_REQUEST['ids'];
446
 
inc/common.php CHANGED
@@ -86,10 +86,16 @@ if( !function_exists( 'pys_radio_state' ) ) {
86
  $options = get_option( 'pixel_your_site' );
87
 
88
  if ( isset( $options[ $section ][ $option ] ) ) {
 
89
  return $options[ $section ][ $option ] == $value ? 'checked' : '';
 
 
 
 
 
 
90
  }
91
 
92
- return null;
93
  }
94
 
95
  }
@@ -106,7 +112,9 @@ if( !function_exists( 'pys_event_types_select_options' ) ) {
106
  <option <?php echo selected( 'ViewContent', $current, true ); ?> value="ViewContent">ViewContent</option>
107
 
108
  <?php if ( $full ) : ?>
109
- <option <?php echo selected( 'Search', $current, true ); ?> value="Search">Search</option>
 
 
110
  <?php endif; ?>
111
 
112
  <option <?php echo selected( 'AddToCart', $current, true ); ?> value="AddToCart">AddToCart</option>
@@ -115,15 +123,13 @@ if( !function_exists( 'pys_event_types_select_options' ) ) {
115
  <option <?php echo selected( 'AddPaymentInfo', $current, true ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
116
  <option <?php echo selected( 'Purchase', $current, true ); ?> value="Purchase">Purchase</option>
117
  <option <?php echo selected( 'Lead', $current, true ); ?> value="Lead">Lead</option>
118
- <option <?php echo selected( 'CompleteRegistration', $current, true ); ?> value="CompleteRegistration">
119
- CompleteRegistration
120
- </option>
121
 
122
  <?php if ( $full ) : ?>
123
 
124
- <option disabled></option>
125
- <option <?php echo selected( 'CustomEvent', $current, true ); ?> value="CustomEvent">Custom event</option>
126
- <option <?php echo selected( 'CustomCode', $current, true ); ?> value="CustomCode">Custom event code</option>
127
 
128
  <?php endif; ?>
129
 
@@ -227,294 +233,6 @@ if( !function_exists( 'pys_endsWith' ) ) {
227
 
228
  }
229
 
230
- /**
231
- * Clean string to be UTF-8
232
- */
233
- if( !function_exists( 'pys_clean_param_value' ) ) {
234
-
235
- function pys_clean_param_value( $value ) {
236
-
237
- //@todo: remove deprecated function
238
-
239
- $replace = array(
240
- '&lt;' => '',
241
- '&gt;' => '',
242
- '&#039;' => '',
243
- '&amp;' => '',
244
- '&quot;' => '',
245
- 'À' => 'A',
246
- 'Á' => 'A',
247
- 'Â' => 'A',
248
- 'Ã' => 'A',
249
- 'Ä' => 'Ae',
250
- '&Auml;' => 'A',
251
- 'Å' => 'A',
252
- 'Ā' => 'A',
253
- 'Ą' => 'A',
254
- 'Ă' => 'A',
255
- 'Æ' => 'Ae',
256
- 'Ç' => 'C',
257
- 'Ć' => 'C',
258
- 'Č' => 'C',
259
- 'Ĉ' => 'C',
260
- 'Ċ' => 'C',
261
- 'Ď' => 'D',
262
- 'Đ' => 'D',
263
- 'Ð' => 'D',
264
- 'È' => 'E',
265
- 'É' => 'E',
266
- 'Ê' => 'E',
267
- 'Ë' => 'E',
268
- 'Ē' => 'E',
269
- 'Ę' => 'E',
270
- 'Ě' => 'E',
271
- 'Ĕ' => 'E',
272
- 'Ė' => 'E',
273
- 'Ĝ' => 'G',
274
- 'Ğ' => 'G',
275
- 'Ġ' => 'G',
276
- 'Ģ' => 'G',
277
- 'Ĥ' => 'H',
278
- 'Ħ' => 'H',
279
- 'Ì' => 'I',
280
- 'Í' => 'I',
281
- 'Î' => 'I',
282
- 'Ï' => 'I',
283
- 'Ī' => 'I',
284
- 'Ĩ' => 'I',
285
- 'Ĭ' => 'I',
286
- 'Į' => 'I',
287
- 'İ' => 'I',
288
- 'IJ' => 'IJ',
289
- 'Ĵ' => 'J',
290
- 'Ķ' => 'K',
291
- 'Ł' => 'K',
292
- 'Ľ' => 'K',
293
- 'Ĺ' => 'K',
294
- 'Ļ' => 'K',
295
- 'Ŀ' => 'K',
296
- 'Ñ' => 'N',
297
- 'Ń' => 'N',
298
- 'Ň' => 'N',
299
- 'Ņ' => 'N',
300
- 'Ŋ' => 'N',
301
- 'Ò' => 'O',
302
- 'Ó' => 'O',
303
- 'Ô' => 'O',
304
- 'Õ' => 'O',
305
- 'Ö' => 'Oe',
306
- '&Ouml;' => 'Oe',
307
- 'Ø' => 'O',
308
- 'Ō' => 'O',
309
- 'Ő' => 'O',
310
- 'Ŏ' => 'O',
311
- 'Œ' => 'OE',
312
- 'Ŕ' => 'R',
313
- 'Ř' => 'R',
314
- 'Ŗ' => 'R',
315
- 'Ś' => 'S',
316
- 'Š' => 'S',
317
- 'Ş' => 'S',
318
- 'Ŝ' => 'S',
319
- 'Ș' => 'S',
320
- 'Ť' => 'T',
321
- 'Ţ' => 'T',
322
- 'Ŧ' => 'T',
323
- 'Ț' => 'T',
324
- 'Ù' => 'U',
325
- 'Ú' => 'U',
326
- 'Û' => 'U',
327
- 'Ü' => 'Ue',
328
- 'Ū' => 'U',
329
- '&Uuml;' => 'Ue',
330
- 'Ů' => 'U',
331
- 'Ű' => 'U',
332
- 'Ŭ' => 'U',
333
- 'Ũ' => 'U',
334
- 'Ų' => 'U',
335
- 'Ŵ' => 'W',
336
- 'Ý' => 'Y',
337
- 'Ŷ' => 'Y',
338
- 'Ÿ' => 'Y',
339
- 'Ź' => 'Z',
340
- 'Ž' => 'Z',
341
- 'Ż' => 'Z',
342
- 'Þ' => 'T',
343
- 'à' => 'a',
344
- 'á' => 'a',
345
- 'â' => 'a',
346
- 'ã' => 'a',
347
- 'ä' => 'ae',
348
- '&auml;' => 'ae',
349
- 'å' => 'a',
350
- 'ā' => 'a',
351
- 'ą' => 'a',
352
- 'ă' => 'a',
353
- 'æ' => 'ae',
354
- 'ç' => 'c',
355
- 'ć' => 'c',
356
- 'č' => 'c',
357
- 'ĉ' => 'c',
358
- 'ċ' => 'c',
359
- 'ď' => 'd',
360
- 'đ' => 'd',
361
- 'ð' => 'd',
362
- 'è' => 'e',
363
- 'é' => 'e',
364
- 'ê' => 'e',
365
- 'ë' => 'e',
366
- 'ē' => 'e',
367
- 'ę' => 'e',
368
- 'ě' => 'e',
369
- 'ĕ' => 'e',
370
- 'ė' => 'e',
371
- 'ƒ' => 'f',
372
- 'ĝ' => 'g',
373
- 'ğ' => 'g',
374
- 'ġ' => 'g',
375
- 'ģ' => 'g',
376
- 'ĥ' => 'h',
377
- 'ħ' => 'h',
378
- 'ì' => 'i',
379
- 'í' => 'i',
380
- 'î' => 'i',
381
- 'ï' => 'i',
382
- 'ī' => 'i',
383
- 'ĩ' => 'i',
384
- 'ĭ' => 'i',
385
- 'į' => 'i',
386
- 'ı' => 'i',
387
- 'ij' => 'ij',
388
- 'ĵ' => 'j',
389
- 'ķ' => 'k',
390
- 'ĸ' => 'k',
391
- 'ł' => 'l',
392
- 'ľ' => 'l',
393
- 'ĺ' => 'l',
394
- 'ļ' => 'l',
395
- 'ŀ' => 'l',
396
- 'ñ' => 'n',
397
- 'ń' => 'n',
398
- 'ň' => 'n',
399
- 'ņ' => 'n',
400
- 'ʼn' => 'n',
401
- 'ŋ' => 'n',
402
- 'ò' => 'o',
403
- 'ó' => 'o',
404
- 'ô' => 'o',
405
- 'õ' => 'o',
406
- 'ö' => 'oe',
407
- '&ouml;' => 'oe',
408
- 'ø' => 'o',
409
- 'ō' => 'o',
410
- 'ő' => 'o',
411
- 'ŏ' => 'o',
412
- 'œ' => 'oe',
413
- 'ŕ' => 'r',
414
- 'ř' => 'r',
415
- 'ŗ' => 'r',
416
- 'š' => 's',
417
- 'ù' => 'u',
418
- 'ú' => 'u',
419
- 'û' => 'u',
420
- 'ü' => 'ue',
421
- 'ū' => 'u',
422
- '&uuml;' => 'ue',
423
- 'ů' => 'u',
424
- 'ű' => 'u',
425
- 'ŭ' => 'u',
426
- 'ũ' => 'u',
427
- 'ų' => 'u',
428
- 'ŵ' => 'w',
429
- 'ý' => 'y',
430
- 'ÿ' => 'y',
431
- 'ŷ' => 'y',
432
- 'ž' => 'z',
433
- 'ż' => 'z',
434
- 'ź' => 'z',
435
- 'þ' => 't',
436
- 'ß' => 'ss',
437
- 'ſ' => 'ss',
438
- 'ый' => 'iy',
439
- 'А' => 'A',
440
- 'Б' => 'B',
441
- 'В' => 'V',
442
- 'Г' => 'G',
443
- 'Д' => 'D',
444
- 'Е' => 'E',
445
- 'Ё' => 'YO',
446
- 'Ж' => 'ZH',
447
- 'З' => 'Z',
448
- 'И' => 'I',
449
- 'Й' => 'Y',
450
- 'К' => 'K',
451
- 'Л' => 'L',
452
- 'М' => 'M',
453
- 'Н' => 'N',
454
- 'О' => 'O',
455
- 'П' => 'P',
456
- 'Р' => 'R',
457
- 'С' => 'S',
458
- 'Т' => 'T',
459
- 'У' => 'U',
460
- 'Ф' => 'F',
461
- 'Х' => 'H',
462
- 'Ц' => 'C',
463
- 'Ч' => 'CH',
464
- 'Ш' => 'SH',
465
- 'Щ' => 'SCH',
466
- 'Ъ' => '',
467
- 'Ы' => 'Y',
468
- 'Ь' => '',
469
- 'Э' => 'E',
470
- 'Ю' => 'YU',
471
- 'Я' => 'YA',
472
- 'а' => 'a',
473
- 'б' => 'b',
474
- 'в' => 'v',
475
- 'г' => 'g',
476
- 'д' => 'd',
477
- 'е' => 'e',
478
- 'ё' => 'yo',
479
- 'ж' => 'zh',
480
- 'з' => 'z',
481
- 'и' => 'i',
482
- 'й' => 'y',
483
- 'к' => 'k',
484
- 'л' => 'l',
485
- 'м' => 'm',
486
- 'н' => 'n',
487
- 'о' => 'o',
488
- 'п' => 'p',
489
- 'р' => 'r',
490
- 'с' => 's',
491
- 'т' => 't',
492
- 'у' => 'u',
493
- 'ф' => 'f',
494
- 'х' => 'h',
495
- 'ц' => 'c',
496
- 'ч' => 'ch',
497
- 'ш' => 'sh',
498
- 'щ' => 'sch',
499
- 'ъ' => '',
500
- 'ы' => 'y',
501
- 'ь' => '',
502
- 'э' => 'e',
503
- 'ю' => 'yu',
504
- 'я' => 'ya'
505
- );
506
-
507
- $value = str_replace( array_keys( $replace ), $replace, $value );
508
- //$value = preg_replace('/[^A-Za-z0-9\\x{0590}-\\x{05FF}\p{Arabic}]/u',' ', strip_tags($value));
509
- $value = preg_replace( '/[^A-Za-z0-9\p{Hebrew}\p{Arabic}]/u', ' ', strip_tags( $value ) );
510
- $value = preg_replace( '/ {2,}/', ' ', $value );
511
-
512
- return trim( $value );
513
-
514
- }
515
-
516
- }
517
-
518
  if( !function_exists( 'pys_currency_options' ) ) {
519
 
520
  function pys_currency_options( $current = 'USD' ) {
@@ -559,164 +277,63 @@ if( !function_exists( 'pys_currency_options' ) ) {
559
  }
560
 
561
  /**
562
- * Build taxonomies list for current post.
563
- * Examples:
564
- * Cat1, Cat2;
565
- * Cat1, Cat2 > Cat3; Movie1; Tax1 > Tax2
566
  */
567
  if( !function_exists( 'pys_get_content_taxonomies' ) ) {
568
 
569
- function pys_get_content_taxonomies( $taxonomy = 'category', $id = null ) {
570
 
571
- $post_id = isset( $id ) ? $id : get_the_ID();
572
- $tax = get_the_terms( $post_id, $taxonomy );
573
 
574
- if ( is_wp_error( $tax ) || empty ( $tax ) ) {
575
  return false;
576
  }
577
 
578
- $tree = pys_build_taxonomy_tree( $tax );
579
-
580
- return pys_explode_taxonomies( $tree );
581
-
582
- }
583
-
584
- }
585
-
586
- /**
587
- * Build hierarchy tree array from array of WP_Terms.
588
- */
589
- if( !function_exists( 'pys_build_taxonomy_tree' ) ) {
590
-
591
- function pys_build_taxonomy_tree( array $wp_terms ) {
592
-
593
- // convert WP_Term objects to array
594
- $terms = array();
595
- foreach ( $wp_terms as $id => $term ) {
596
- $terms[ $id ] = array(
597
- 'id' => $term->term_id,
598
- 'parent' => $term->parent,
599
- 'name' => $term->name
600
- );
601
- }
602
-
603
- // build tree
604
- $tree = array();
605
- $references = array();
606
- foreach ( $terms as $id => &$node ) {
607
-
608
- $references[ $node['id'] ] = &$node;
609
-
610
- if ( $node['parent'] == 0 ) {
611
-
612
- // it is root node. add direct to tree root
613
- $tree[ $node['id'] ] = &$node;
614
-
615
- } else {
616
-
617
- // it is child node. add to parent 'children'
618
- $references[ $node['parent'] ]['children'][ $node['id'] ] = &$node;
619
-
620
- }
621
-
622
- }
623
-
624
- return $tree;
625
- }
626
-
627
- }
628
-
629
- /**
630
- * Format taxonomies tree to string.
631
- */
632
- if( !function_exists( 'pys_explode_taxonomies' ) ) {
633
-
634
- function pys_explode_taxonomies( $tree ) {
635
-
636
- $str = '';
637
- foreach ( $tree as $node ) {
638
-
639
- if ( isset( $node['children'] ) ) {
640
-
641
- $str .= $node['name'] . ', ';
642
- $str .= pys_explode_taxonomies( $node['children'] );
643
-
644
- } else {
645
-
646
- $str .= $node['name'] . '; ';
647
-
648
- }
649
- }
650
-
651
- return $str;
652
-
653
- }
654
-
655
- }
656
-
657
- if( !function_exists( 'pys_get_noscript_code' ) ) {
658
-
659
- function pys_get_noscript_code( $type, $params ) {
660
-
661
- // skip, because event is works only if js supported
662
- if( $type == 'TimeOnPage' ) {
663
- return null;
664
- }
665
-
666
- $args = array();
667
-
668
- $args['id'] = pys_get_option( 'general', 'pixel_id' );
669
- $args['ev'] = $type;
670
- $args['noscript'] = 1;
671
 
672
- foreach ( $params as $param => $value ) {
673
- @$args[ 'cd[' . $param . ']' ] = urlencode( $value );
674
  }
675
 
676
- $src = add_query_arg( $args, 'https://www.facebook.com/tr' );
677
-
678
- return "<noscript><img height='1' width='1' style='display:none' src='" . $src . "'></noscript>\n";
679
 
680
  }
681
 
682
  }
683
 
684
- if( !function_exists( 'pys_build_event_pixel_code' ) ) {
685
 
686
- function pys_build_event_pixel_code( $params, $event ) {
 
 
 
 
 
 
 
687
 
688
  $params = apply_filters( 'pys_event_params', $params, $event );
689
 
690
- $js = null;
691
- $nojs = array();
692
 
693
- // explode params to formatted string
694
  foreach ( $params as $name => $value ) {
695
 
696
- if( empty( $value ) ) {
697
  continue;
698
  }
699
-
700
- // skip cleanup
701
- //@todo: remove after tests
702
- // if ( ! in_array( $name, array( 'content_ids', 'value', 'time' ) ) ) {
703
- // $value = pys_clean_param_value( $value );
704
- // }
705
-
706
- // sanitize prams
707
- $key = esc_js( $name );
708
- $value = esc_js( $value );
709
-
710
- $js .= "{$key}: '{$value}', ";
711
- $nojs[ $name ] = esc_attr( $value );
712
 
713
  }
714
 
715
- $track = pys_is_standard_event( $event ) ? 'track' : 'trackCustom';
716
-
717
- return array(
718
- 'js' => "fbq('{$track}', '{$event}', {{$js}} );\n",
719
- 'nojs' => pys_get_noscript_code( $event, $nojs )
720
  );
721
 
722
  }
@@ -821,7 +438,7 @@ if( !function_exists( 'pys_insert_attribute' ) ) {
821
  }
822
 
823
  // append value to exist attribute
824
- if( $overwrite ) {
825
 
826
  $value = $attribute . ' ' . $attr_value;
827
  $node->setAttribute( $attr_name, $value );
@@ -835,46 +452,6 @@ if( !function_exists( 'pys_insert_attribute' ) ) {
835
 
836
  }
837
 
838
- if( !function_exists( 'pys_convert_quotes' ) ) {
839
-
840
- function pys_convert_quotes( $str ) {
841
-
842
- $chr_map = array(
843
- // Windows codepage 1252
844
- "\xC2\x82" => "'", // U+0082⇒U+201A single low-9 quotation mark
845
- "\xC2\x84" => '"', // U+0084⇒U+201E double low-9 quotation mark
846
- "\xC2\x8B" => "'", // U+008B⇒U+2039 single left-pointing angle quotation mark
847
- "\xC2\x91" => "'", // U+0091⇒U+2018 left single quotation mark
848
- "\xC2\x92" => "'", // U+0092⇒U+2019 right single quotation mark
849
- "\xC2\x93" => '"', // U+0093⇒U+201C left double quotation mark
850
- "\xC2\x94" => '"', // U+0094⇒U+201D right double quotation mark
851
- "\xC2\x9B" => "'", // U+009B⇒U+203A single right-pointing angle quotation mark
852
-
853
- // Regular Unicode // U+0022 quotation mark (")
854
- // U+0027 apostrophe (')
855
- "\xC2\xAB" => '"', // U+00AB left-pointing double angle quotation mark
856
- "\xC2\xBB" => '"', // U+00BB right-pointing double angle quotation mark
857
- "\xE2\x80\x98" => "'", // U+2018 left single quotation mark
858
- "\xE2\x80\x99" => "'", // U+2019 right single quotation mark
859
- "\xE2\x80\x9A" => "'", // U+201A single low-9 quotation mark
860
- "\xE2\x80\x9B" => "'", // U+201B single high-reversed-9 quotation mark
861
- "\xE2\x80\x9C" => '"', // U+201C left double quotation mark
862
- "\xE2\x80\x9D" => '"', // U+201D right double quotation mark
863
- "\xE2\x80\x9E" => '"', // U+201E double low-9 quotation mark
864
- "\xE2\x80\x9F" => '"', // U+201F double high-reversed-9 quotation mark
865
- "\xE2\x80\xB9" => "'", // U+2039 single left-pointing angle quotation mark
866
- "\xE2\x80\xBA" => "'", // U+203A single right-pointing angle quotation mark
867
- );
868
-
869
- $chr = array_keys( $chr_map ); // but: for efficiency you should
870
- $rpl = array_values( $chr_map ); // pre-calculate these two arrays
871
- $str = str_replace( $chr, $rpl, html_entity_decode( $str, ENT_QUOTES, "UTF-8" ) );
872
-
873
- return $str;
874
- }
875
-
876
- }
877
-
878
  if( !function_exists( 'pys_is_disabled_for_role' ) ) {
879
 
880
  function pys_is_disabled_for_role() {
@@ -886,13 +463,19 @@ if( !function_exists( 'pys_is_disabled_for_role' ) ) {
886
  foreach ( (array) $user->roles as $role ) {
887
 
888
  if ( array_key_exists( "disable_for_$role", $disabled_roles ) ) {
 
 
889
  return true;
 
890
  }
891
 
892
  }
893
 
894
  if( empty( $user->roles ) && isset( $disabled_roles['disable_for_guest'] ) ) {
 
 
895
  return true;
 
896
  }
897
 
898
  return false;
@@ -902,227 +485,93 @@ if( !function_exists( 'pys_is_disabled_for_role' ) ) {
902
  }
903
 
904
  /**
905
- * Output pixel code.
906
  */
907
- if( !function_exists( 'pys_pixel_code' ) ) {
908
-
909
- function pys_pixel_code() {
910
-
911
- $pixel_id = pys_get_option( 'general', 'pixel_id' );
912
-
913
- // build pixel code...
914
- $pixelcode = "\n";
915
- $nojscode = "\n";
916
-
917
- // pixel id
918
- $pixelcode .= "fbq('init', '{$pixel_id}', {" . pys_pixel_init_params() . "});\n";
919
-
920
- // default event
921
- $default_event = pys_build_event_pixel_code( array(), 'PageView' );
922
- $pixelcode .= $default_event['js'];
923
- $nojscode .= $default_event['nojs'];
924
-
925
- // general event
926
- if ( pys_get_option( 'general', 'general_event_enabled' ) ) {
927
-
928
- $code = pys_get_general_event_code();
929
 
930
- $pixelcode .= $code['js'];
931
- $nojscode .= $code['nojs'];
932
-
933
- }
934
-
935
- // search event
936
- if ( pys_get_option( 'general', 'search_event_enabled' ) && is_search() && isset( $_REQUEST['s'] ) ) {
937
-
938
- $search_event = pys_build_event_pixel_code( array(
939
- 'search_string' => $_REQUEST['s']
940
- ), 'Search' );
941
-
942
- $pixelcode .= $search_event['js'];
943
- $nojscode .= $search_event['nojs'];
944
-
945
- }
946
-
947
- // add standard events
948
- $std_events = get_option( 'pixel_your_site_std_events', array() );
949
- if ( pys_get_option( 'std', 'enabled' ) && count( $std_events ) > 0 ) {
950
-
951
- foreach ( $std_events as $std_event_params ) {
952
-
953
- // skip wrong events
954
- if( ! isset( $std_event_params['pageurl'] ) || ! isset( $std_event_params['eventtype'] ) ) {
955
- continue;
956
- }
957
-
958
- // add event on url's match
959
- if ( pys_match_url( $std_event_params['pageurl'] ) ) {
960
-
961
- if ( $std_event_params['eventtype'] == 'CustomCode' ) {
962
-
963
- $custom_code = $std_event_params['code'];
964
- $custom_code = stripcslashes( $custom_code );
965
- $custom_code = trim( $custom_code );
966
-
967
- $pixelcode .= "{$custom_code}\n";
968
-
969
- } else {
970
-
971
- $std_event_type = $std_event_params['eventtype'];
972
- $std_event_params = pys_clean_system_event_params( $std_event_params );
973
-
974
- $std_event_code = pys_build_event_pixel_code( $std_event_params, $std_event_type );
975
-
976
- $pixelcode .= $std_event_code['js'];
977
- $nojscode .= $std_event_code['nojs'];
978
-
979
- }
980
-
981
- }
982
-
983
- }
984
-
985
- }
986
-
987
- // add woocommerce events
988
- if ( pys_get_option( 'woo', 'enabled' ) && pys_is_woocommerce_active() ) {
989
-
990
- $woo_event_code = pys_get_woo_code();
991
-
992
- $pixelcode .= $woo_event_code['js'];
993
- $nojscode .= $woo_event_code['nojs'];
994
-
995
- }
996
-
997
- // WooCommerce non-ajax AddToCart Event handler
998
- if ( pys_get_option( 'woo', 'enabled' ) && pys_is_woocommerce_active() && isset( $_REQUEST['add-to-cart'] ) ) {
999
-
1000
- $product_id = isset( $_REQUEST['add-to-cart'] ) ? $_REQUEST['add-to-cart'] : null;
1001
-
1002
- if ( pys_get_option( 'woo', 'variation_id' ) == 'variation' && isset( $_REQUEST['variation_id'] ) ) {
1003
- $product_id = $_REQUEST['variation_id'];
1004
- }
1005
 
1006
- $params = pys_get_woo_ajax_addtocart_params( $product_id );
1007
- $event_code = pys_build_event_pixel_code( $params, 'AddToCart' );
1008
 
1009
- $pixelcode .= $event_code['js'];
1010
- $nojscode .= $event_code['nojs'];
1011
 
1012
- }
1013
 
1014
- // version data
1015
  if( defined('PYS_PRO_VERSION') ) {
1016
- $version = "PRO v".PYS_PRO_VERSION;
1017
  } elseif( defined('PYS_FREE_VERSION') ) {
1018
- $version = "FREE v".PYS_FREE_VERSION_REAL;
1019
  } else {
1020
  $version = null;
1021
  }
1022
 
1023
- ?>
1024
-
1025
- <!-- Facebook Pixel Code ( <?php echo esc_attr( $version ); ?> ) -->
1026
- <script>
1027
- var PYS_DOMReady = function (a, b, c) {
1028
- b = document, c = 'addEventListener';
1029
- b[c] ? b[c]('DOMContentLoaded', a) : window.attachEvent('onload', a)
1030
- };
1031
- !function (f, b, e, v, n, t, s) {
1032
- if (f.fbq)return;
1033
- n = f.fbq = function () {
1034
- n.callMethod ?
1035
- n.callMethod.apply(n, arguments) : n.queue.push(arguments)
1036
- };
1037
- if (!f._fbq)f._fbq = n;
1038
- n.push = n;
1039
- n.loaded = !0;
1040
- n.version = '2.0';
1041
- n.queue = [];
1042
- t = b.createElement(e);
1043
- t.async = !0;
1044
- t.src = v;
1045
- s = b.getElementsByTagName(e)[0];
1046
- s.parentNode.insertBefore(t, s)
1047
- }(window,
1048
- document, 'script', '//connect.facebook.net/en_US/fbevents.js');
1049
-
1050
- /* pixel plugin code */
1051
- PYS_DOMReady(function () {
1052
- <?php echo $pixelcode; ?>
1053
- });
1054
- /* pixel plugin code */
1055
-
1056
- </script>
1057
- <!-- End Facebook Pixel Code -->
1058
-
1059
- <?php
1060
 
1061
- // noscript fallback
1062
- echo $nojscode;
1063
  }
1064
 
1065
  }
1066
 
1067
- if( !function_exists( 'pys_clean_system_event_params' ) ) {
1068
-
1069
- function pys_clean_system_event_params( $params ) {
1070
-
1071
- // remove unused params
1072
- unset( $params['pageurl'] );
1073
- unset( $params['eventtype'] );
1074
- unset( $params['code'] );
1075
- unset( $params['trigger_type'] ); // pro
1076
- unset( $params['url'] ); // pro
1077
- unset( $params['css'] ); // pro
1078
- unset( $params['custom_name'] ); // custom events
1079
-
1080
- return $params;
1081
 
 
 
 
 
 
1082
  }
1083
 
1084
  }
1085
 
1086
- /**
1087
- * Build General Event code.
1088
- */
1089
- if( !function_exists( 'pys_get_general_event_code' ) ) {
1090
 
1091
- function pys_get_general_event_code() {
1092
  global $post;
1093
 
 
 
 
 
1094
  $params = array();
1095
- $pys = get_option( 'pixel_your_site' );
1096
- $event_name = $pys['general']['general_event_name'];
1097
  $post_type = get_post_type();
 
 
 
 
 
 
 
 
1098
 
1099
  // Posts
1100
- if ( pys_get_option( 'general', 'general_event_on_posts_enabled' ) && is_singular( 'post' ) ) {
1101
 
1102
  $params['post_type'] = 'post';
1103
  $params['content_name'] = $post->post_title;
1104
  $params['post_id'] = $post->ID;
1105
 
1106
- $terms = pys_get_content_taxonomies();
1107
- if ( $terms ) {
1108
  $params['content_category'] = $terms;
1109
  }
1110
 
1111
- // track post tags
1112
- if ( pys_get_option( 'general', 'general_event_add_tags', 0 ) && $tags = pys_get_post_tags( $post->ID ) ) {
1113
  $params['tags'] = implode( ', ', $tags );
1114
  }
1115
 
1116
- return pys_build_event_pixel_code( $params, $event_name );
 
 
1117
 
1118
  }
1119
 
1120
  // Pages or Front Page
1121
- if ( pys_get_option( 'general', 'general_event_on_pages_enabled' ) && ( is_singular( 'page' ) || is_home() ) ) {
1122
 
1123
  // exclude WooCommerce Cart page
1124
  if ( pys_is_woocommerce_active() && is_cart() ) {
1125
- return false;
1126
  }
1127
 
1128
  $params['post_type'] = 'page';
@@ -1130,12 +579,14 @@ if( !function_exists( 'pys_get_general_event_code' ) ) {
1130
 
1131
  is_home() != true ? $params['post_id'] = $post->ID : null;
1132
 
1133
- return pys_build_event_pixel_code( $params, $event_name );
 
 
1134
 
1135
  }
1136
 
1137
  // WooCommerce Shop page
1138
- if ( pys_get_option( 'general', 'general_event_on_pages_enabled' ) && pys_is_woocommerce_active() && is_shop() ) {
1139
 
1140
  $page_id = wc_get_page_id( 'shop' );
1141
 
@@ -1143,12 +594,14 @@ if( !function_exists( 'pys_get_general_event_code' ) ) {
1143
  $params['post_id'] = $page_id;
1144
  $params['content_name'] = get_the_title( $page_id );;
1145
 
1146
- return pys_build_event_pixel_code( $params, $event_name );
 
 
1147
 
1148
  }
1149
 
1150
  // Taxonomies (built-in and custom)
1151
- if ( pys_get_option( 'general', 'general_event_on_tax_enabled' ) && ( is_category() || is_tax() || is_tag() ) ) {
1152
 
1153
  $term = null;
1154
  $type = null;
@@ -1181,18 +634,18 @@ if( !function_exists( 'pys_get_general_event_code' ) ) {
1181
 
1182
  }
1183
 
1184
- return pys_build_event_pixel_code( $params, $event_name );
 
 
1185
 
1186
  }
1187
 
1188
  // Custom Post Type
1189
- if ( pys_get_option( 'general', 'general_event_on_' . $post_type . '_enabled' )
1190
- && $post_type != 'post' && $post_type != 'page'
1191
- ) {
1192
 
1193
  // skip products and downloads is plugins are activated
1194
  if ( ( pys_is_woocommerce_active() && $post_type == 'product' ) || ( pys_is_edd_active() && $post_type == 'download' ) ) {
1195
- return false;
1196
  }
1197
 
1198
  $params['post_type'] = $post_type;
@@ -1205,17 +658,18 @@ if( !function_exists( 'pys_get_general_event_code' ) ) {
1205
  $params['content_category'] = $terms;
1206
  }
1207
 
1208
- // track custom post type tags
1209
- if ( pys_get_option( 'general', 'general_event_add_tags', 0 ) && $tags = pys_get_post_tags( $post->ID ) ) {
1210
  $params['tags'] = implode( ', ', $tags );
1211
  }
1212
 
1213
- return pys_build_event_pixel_code( $params, $event_name );
 
 
1214
 
1215
  }
1216
 
1217
  // Easy Digital Downloads
1218
- if ( pys_get_option( 'general', 'general_event_on_edd_enabled' ) && pys_is_edd_active() && $post_type == 'download' ) {
1219
 
1220
  $download = new EDD_Download( $post->ID );
1221
 
@@ -1225,15 +679,180 @@ if( !function_exists( 'pys_get_general_event_code' ) ) {
1225
  $params['value'] = $download->get_price();
1226
  $params['currency'] = edd_get_currency();
1227
 
1228
- $terms = pys_get_content_taxonomies( 'download_category' );
1229
- if ( $terms ) {
1230
  $params['content_category'] = $terms;
1231
  }
1232
 
1233
- return pys_build_event_pixel_code( $params, $event_name );
 
 
 
1234
  }
1235
 
1236
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1237
  }
1238
 
1239
  }
@@ -1298,7 +917,9 @@ if( !function_exists( 'pys_get_default_options' ) ) {
1298
 
1299
  $options['general']['pixel_id'] = '';
1300
  $options['general']['enabled'] = 0;
 
1301
  $options['general']['enable_advance_matching'] = 1;
 
1302
 
1303
  $options['general']['general_event_enabled'] = 1;
1304
  $options['general']['general_event_name'] = 'GeneralEvent';
@@ -1378,11 +999,10 @@ if( !function_exists( 'pys_get_default_options' ) ) {
1378
 
1379
  }
1380
 
1381
- if( !function_exists( 'pys_get_custom_params' ) ) {
1382
 
1383
  /**
1384
- * Get custom event (std or dynamic) params => values
1385
- * @param array $event
1386
  */
1387
  function pys_get_custom_params( $event ) {
1388
 
@@ -1390,14 +1010,16 @@ if( !function_exists( 'pys_get_custom_params' ) ) {
1390
  return array();
1391
  }
1392
 
1393
- $std_params = array(
1394
  'trigger_type',
 
1395
  'url',
1396
  'css',
1397
  'pageurl',
1398
  'eventtype',
1399
  'value',
1400
  'currency',
 
1401
  'content_name',
1402
  'content_ids',
1403
  'content_type',
@@ -1407,14 +1029,15 @@ if( !function_exists( 'pys_get_custom_params' ) ) {
1407
  'search_string',
1408
  'status',
1409
  'code',
1410
- 'custom_name'
 
1411
  );
1412
 
1413
  $custom_params = array();
1414
  foreach( $event as $param => $value ) {
1415
 
1416
  // skip standard params
1417
- if( in_array( $param, $std_params ) ) {
1418
  continue;
1419
  }
1420
 
@@ -1429,7 +1052,7 @@ if( !function_exists( 'pys_get_custom_params' ) ) {
1429
 
1430
  }
1431
 
1432
- if( !function_exists( 'pys_is_standard_event' ) ) {
1433
 
1434
  function pys_is_standard_event( $eventtype ) {
1435
 
@@ -1451,33 +1074,191 @@ if( !function_exists( 'pys_is_standard_event' ) ) {
1451
 
1452
  }
1453
 
1454
- /**
1455
- * Add extra params to FB init call.
1456
- */
1457
- if( !function_exists( 'pys_pixel_init_params' ) ) {
1458
 
 
 
 
1459
  function pys_pixel_init_params() {
1460
 
1461
  $params = array();
1462
  $params = apply_filters( 'pys_pixel_init_params', $params );
1463
 
1464
- $code = null;
1465
- foreach ( $params as $key => $value ) {
 
 
1466
 
1467
- // remove empty params
1468
  if ( empty( $value ) ) {
1469
- unset( $params[ $key ] );
1470
  }
1471
 
1472
- // sanitize prams
1473
- $key = esc_js( $key );
1474
- $value = esc_js( $value );
 
 
 
1475
 
1476
- $code .= "{$key}: '{$value}', ";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1477
 
1478
  }
1479
 
1480
- return $code;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1481
 
1482
  }
1483
 
86
  $options = get_option( 'pixel_your_site' );
87
 
88
  if ( isset( $options[ $section ][ $option ] ) ) {
89
+
90
  return $options[ $section ][ $option ] == $value ? 'checked' : '';
91
+
92
+ } else {
93
+
94
+ $defaults = pys_get_default_options();
95
+ return $defaults[ $section ][ $option ] == $value ? 'checked' : '';
96
+
97
  }
98
 
 
99
  }
100
 
101
  }
112
  <option <?php echo selected( 'ViewContent', $current, true ); ?> value="ViewContent">ViewContent</option>
113
 
114
  <?php if ( $full ) : ?>
115
+
116
+ <option <?php echo selected( 'Search', $current, true ); ?> value="Search">Search</option>
117
+
118
  <?php endif; ?>
119
 
120
  <option <?php echo selected( 'AddToCart', $current, true ); ?> value="AddToCart">AddToCart</option>
123
  <option <?php echo selected( 'AddPaymentInfo', $current, true ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
124
  <option <?php echo selected( 'Purchase', $current, true ); ?> value="Purchase">Purchase</option>
125
  <option <?php echo selected( 'Lead', $current, true ); ?> value="Lead">Lead</option>
126
+ <option <?php echo selected( 'CompleteRegistration', $current, true ); ?> value="CompleteRegistration">CompleteRegistration</option>
 
 
127
 
128
  <?php if ( $full ) : ?>
129
 
130
+ <option disabled></option>
131
+ <option <?php echo selected( 'CustomEvent', $current, true ); ?> value="CustomEvent">Custom event</option>
132
+ <option <?php echo selected( 'CustomCode', $current, true ); ?> value="CustomCode">Custom event code</option>
133
 
134
  <?php endif; ?>
135
 
233
 
234
  }
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  if( !function_exists( 'pys_currency_options' ) ) {
237
 
238
  function pys_currency_options( $current = 'USD' ) {
277
  }
278
 
279
  /**
280
+ * Extract Object taxonomies list.
 
 
 
281
  */
282
  if( !function_exists( 'pys_get_content_taxonomies' ) ) {
283
 
284
+ function pys_get_content_taxonomies( $taxonomy = 'category', $post_id = null ) {
285
 
286
+ $post_id = isset( $post_id ) ? $post_id : get_the_ID();
287
+ $terms = get_the_terms( $post_id, $taxonomy );
288
 
289
+ if ( is_wp_error( $terms ) || empty ( $terms ) ) {
290
  return false;
291
  }
292
 
293
+ $list = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
+ foreach( $terms as $term ) {
296
+ $list[ $term->term_id ] = $term->name;
297
  }
298
 
299
+ return implode( ', ', $list );
 
 
300
 
301
  }
302
 
303
  }
304
 
305
+ if( !function_exists( 'pys_add_event' ) ) {
306
 
307
+ /**
308
+ * Add event with params to global events array *$pys_events*.
309
+ * @param string $event Event name, eg. PageView
310
+ * @param array $params Optional. Associated array of event parameters in 'param_name' => 'param_value' format.
311
+ * @param int $delay Optional. If set, event will be fired with desired delay in seconds.
312
+ */
313
+ function pys_add_event( $event, $params = array(), $delay = 0 ) {
314
+ global $pys_events;
315
 
316
  $params = apply_filters( 'pys_event_params', $params, $event );
317
 
318
+ $sanitized = array();
 
319
 
320
+ // sanitize params
321
  foreach ( $params as $name => $value ) {
322
 
323
+ if ( empty( $value ) ) {
324
  continue;
325
  }
326
+
327
+ $key = esc_js( $name );
328
+ $sanitized[ $key ] = $value;
 
 
 
 
 
 
 
 
 
 
329
 
330
  }
331
 
332
+ $pys_events[] = array(
333
+ 'type' => pys_is_standard_event( $event ) ? 'track' : 'trackCustom',
334
+ 'name' => $event,
335
+ 'params' => $sanitized,
336
+ 'delay' => $delay
337
  );
338
 
339
  }
438
  }
439
 
440
  // append value to exist attribute
441
+ if( $overwrite == false ) {
442
 
443
  $value = $attribute . ' ' . $attr_value;
444
  $node->setAttribute( $attr_name, $value );
452
 
453
  }
454
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
  if( !function_exists( 'pys_is_disabled_for_role' ) ) {
456
 
457
  function pys_is_disabled_for_role() {
463
  foreach ( (array) $user->roles as $role ) {
464
 
465
  if ( array_key_exists( "disable_for_$role", $disabled_roles ) ) {
466
+
467
+ add_action( 'wp_head', 'pys_head_message', 1 );
468
  return true;
469
+
470
  }
471
 
472
  }
473
 
474
  if( empty( $user->roles ) && isset( $disabled_roles['disable_for_guest'] ) ) {
475
+
476
+ add_action( 'wp_head', 'pys_head_message', 1 );
477
  return true;
478
+
479
  }
480
 
481
  return false;
485
  }
486
 
487
  /**
488
+ * Output "disabled for role" and version number message to document head.
489
  */
490
+ if( ! function_exists( 'pys_head_message' ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
 
492
+ function pys_head_message() {
493
+ echo "<!-- Facebook Pixel Code disabled for current role ( " . pys_get_version() . " ) -->\r\n";
494
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
495
 
496
+ }
 
497
 
498
+ if( ! function_exists( 'pys_get_version' ) ) {
 
499
 
500
+ function pys_get_version() {
501
 
 
502
  if( defined('PYS_PRO_VERSION') ) {
503
+ $version = "PixelYourSite PRO v".PYS_PRO_VERSION;
504
  } elseif( defined('PYS_FREE_VERSION') ) {
505
+ $version = "PixelYourSite FREE v".PYS_FREE_VERSION_REAL;
506
  } else {
507
  $version = null;
508
  }
509
 
510
+ return $version;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
 
 
512
  }
513
 
514
  }
515
 
516
+ if( ! function_exists( 'pys_page_view_event' ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
517
 
518
+ /*
519
+ * PageView event. Present on each page if pixel setup is enabled.
520
+ */
521
+ function pys_page_view_event() {
522
+ pys_add_event( 'PageView' );
523
  }
524
 
525
  }
526
 
527
+ if( ! function_exists( 'pys_general_event' ) ) {
 
 
 
528
 
529
+ function pys_general_event() {
530
  global $post;
531
 
532
+ if ( pys_get_option( 'general', 'general_event_enabled' ) == false ) {
533
+ return;
534
+ }
535
+
536
  $params = array();
537
+ $event_name = pys_get_option( 'general', 'general_event_name' );
 
538
  $post_type = get_post_type();
539
+ $delay = floatval( pys_get_option( 'general', 'general_event_delay', 0 ) );
540
+
541
+ $on_posts_enabled = pys_get_option( 'general', 'general_event_on_posts_enabled' );
542
+ $on_pages_enables = pys_get_option( 'general', 'general_event_on_pages_enabled' );
543
+ $on_taxonomies_enabled = pys_get_option( 'general', 'general_event_on_tax_enabled' );
544
+ $on_cpt_enabled = pys_get_option( 'general', 'general_event_on_' . $post_type . '_enabled' );
545
+ $on_edd_enabled = pys_get_option( 'general', 'general_event_on_edd_enabled' );
546
+ $track_tags_enabled = pys_get_option( 'general', 'general_event_add_tags', false );
547
 
548
  // Posts
549
+ if ( $on_posts_enabled && is_singular( 'post' ) ) {
550
 
551
  $params['post_type'] = 'post';
552
  $params['content_name'] = $post->post_title;
553
  $params['post_id'] = $post->ID;
554
 
555
+ if ( $terms = pys_get_content_taxonomies() ) {
 
556
  $params['content_category'] = $terms;
557
  }
558
 
559
+ if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
 
560
  $params['tags'] = implode( ', ', $tags );
561
  }
562
 
563
+ pys_add_event( $event_name, $params, $delay );
564
+
565
+ return;
566
 
567
  }
568
 
569
  // Pages or Front Page
570
+ if ( $on_pages_enables && ( is_singular( 'page' ) || is_home() ) ) {
571
 
572
  // exclude WooCommerce Cart page
573
  if ( pys_is_woocommerce_active() && is_cart() ) {
574
+ return;
575
  }
576
 
577
  $params['post_type'] = 'page';
579
 
580
  is_home() != true ? $params['post_id'] = $post->ID : null;
581
 
582
+ pys_add_event( $event_name, $params, $delay );
583
+
584
+ return;
585
 
586
  }
587
 
588
  // WooCommerce Shop page
589
+ if ( $on_pages_enables && pys_is_woocommerce_active() && is_shop() ) {
590
 
591
  $page_id = wc_get_page_id( 'shop' );
592
 
594
  $params['post_id'] = $page_id;
595
  $params['content_name'] = get_the_title( $page_id );;
596
 
597
+ pys_add_event( $event_name, $params, $delay );
598
+
599
+ return;
600
 
601
  }
602
 
603
  // Taxonomies (built-in and custom)
604
+ if ( $on_taxonomies_enabled && ( is_category() || is_tax() || is_tag() ) ) {
605
 
606
  $term = null;
607
  $type = null;
634
 
635
  }
636
 
637
+ pys_add_event( $event_name, $params, $delay );
638
+
639
+ return;
640
 
641
  }
642
 
643
  // Custom Post Type
644
+ if ( $on_cpt_enabled && $post_type != 'post' && $post_type != 'page' ) {
 
 
645
 
646
  // skip products and downloads is plugins are activated
647
  if ( ( pys_is_woocommerce_active() && $post_type == 'product' ) || ( pys_is_edd_active() && $post_type == 'download' ) ) {
648
+ return;
649
  }
650
 
651
  $params['post_type'] = $post_type;
658
  $params['content_category'] = $terms;
659
  }
660
 
661
+ if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
 
662
  $params['tags'] = implode( ', ', $tags );
663
  }
664
 
665
+ pys_add_event( $event_name, $params, $delay );
666
+
667
+ return;
668
 
669
  }
670
 
671
  // Easy Digital Downloads
672
+ if ( $on_edd_enabled && pys_is_edd_active() && $post_type == 'download' ) {
673
 
674
  $download = new EDD_Download( $post->ID );
675
 
679
  $params['value'] = $download->get_price();
680
  $params['currency'] = edd_get_currency();
681
 
682
+ if ( $terms = pys_get_content_taxonomies( 'download_category' ) ) {
 
683
  $params['content_category'] = $terms;
684
  }
685
 
686
+ pys_add_event( $event_name, $params, $delay );
687
+
688
+ return;
689
+
690
  }
691
 
692
+ }
693
+
694
+ }
695
+
696
+ if( ! function_exists( 'pys_search_event' ) ) {
697
+
698
+ function pys_search_event() {
699
+
700
+ if ( pys_get_option( 'general', 'search_event_enabled' ) == false || is_search() == false || ! isset( $_REQUEST['s'] ) ) {
701
+ return;
702
+ }
703
+
704
+ pys_add_event( 'Search', array(
705
+ 'search_string' => $_REQUEST['s']
706
+ ) );
707
+
708
+ }
709
+
710
+ }
711
+
712
+ if( ! function_exists( 'pys_standard_events' ) ) {
713
+
714
+ function pys_standard_events() {
715
+ global $pys_custom_events;
716
+
717
+ $std_events = get_option( 'pixel_your_site_std_events', array() );
718
+
719
+ if ( pys_get_option( 'std', 'enabled' ) == false || empty( $std_events ) ) {
720
+ return;
721
+ }
722
+
723
+ foreach ( $std_events as $event ) {
724
+
725
+ // skip wrong events
726
+ if( ! isset( $event['pageurl'] ) || ! isset( $event['eventtype'] ) ) {
727
+ continue;
728
+ }
729
+
730
+ // skip if current page does not match URL filter
731
+ if ( pys_match_url( $event['pageurl'] ) == false ) {
732
+ continue;
733
+ }
734
+
735
+ if ( $event['eventtype'] == 'CustomCode' ) {
736
+
737
+ $custom_code = $event['code'];
738
+ $custom_code = stripcslashes( $custom_code );
739
+ $custom_code = trim( $custom_code );
740
+
741
+ // add custom code to global custom events array
742
+ $pys_custom_events[] = $custom_code;
743
+
744
+ } else {
745
+
746
+ $type = $event['eventtype'];
747
+ $params = pys_clean_system_event_params( $event );
748
+
749
+ pys_add_event( $type, $params );
750
+
751
+ }
752
+
753
+ }
754
+
755
+ }
756
+
757
+ }
758
+
759
+ if( !function_exists( 'pys_pixel_init_event' ) ) {
760
+
761
+ function pys_pixel_init_event() {
762
+ global $pys_events;
763
+
764
+ $pys_events[] = array(
765
+ 'type' => 'init',
766
+ 'name' => pys_get_option( 'general', 'pixel_id' ),
767
+ 'params' => pys_pixel_init_params()
768
+ );
769
+
770
+ }
771
+
772
+ }
773
+
774
+ if( ! function_exists( 'pys_output_noscript_code' ) ) {
775
+
776
+ function pys_output_noscript_code() {
777
+ global $pys_events;
778
+
779
+ if( empty( $pys_events ) ) {
780
+ return;
781
+ }
782
+
783
+ foreach( $pys_events as $event ) {
784
+
785
+ $args = array();
786
+
787
+ $args['id'] = pys_get_option( 'general', 'pixel_id' );
788
+ $args['ev'] = $event['name'];
789
+ $args['noscript'] = 1;
790
+
791
+ foreach ( $event['params'] as $param => $value ) {
792
+ @$args[ 'cd[' . $param . ']' ] = urlencode( $value );
793
+ }
794
+
795
+ $src_attr = add_query_arg( $args, 'https://www.facebook.com/tr' );
796
+
797
+ echo "<noscript><img height='1' width='1' style='display:none' src='" . $src_attr . "'></noscript>\n\r";
798
+
799
+ }
800
+
801
+ }
802
+
803
+ }
804
+
805
+ if( ! function_exists( 'pys_output_js_events_code' ) ) {
806
+
807
+ function pys_output_js_events_code() {
808
+ global $pys_events;
809
+
810
+ // allow external plugins modify events
811
+ $pys_events = apply_filters( 'pys_prepared_events', $pys_events );
812
+
813
+ if( empty( $pys_events ) ) {
814
+ return;
815
+ }
816
+
817
+ wp_localize_script( 'pys', 'pys_events', $pys_events );
818
+
819
+ }
820
+
821
+ }
822
+
823
+ if( ! function_exists( 'pys_output_custom_events_code' ) ) {
824
+
825
+ function pys_output_custom_events_code() {
826
+ global $pys_custom_events;
827
+
828
+ if( empty( $pys_custom_events ) ) {
829
+ return;
830
+ }
831
+
832
+ wp_localize_script( 'pys', 'pys_customEvents', $pys_custom_events );
833
+
834
+ }
835
+
836
+ }
837
+
838
+ if( !function_exists( 'pys_clean_system_event_params' ) ) {
839
+
840
+ function pys_clean_system_event_params( $params ) {
841
+
842
+ // remove unused params
843
+ unset( $params['pageurl'] );
844
+ unset( $params['eventtype'] );
845
+ unset( $params['code'] );
846
+ unset( $params['trigger_type'] ); // pro
847
+ unset( $params['custom_currency'] ); // pro
848
+ unset( $params['url'] ); // pro
849
+ unset( $params['css'] ); // pro
850
+ unset( $params['custom_name'] ); // custom events
851
+ unset( $params['scroll_pos'] ); // pro
852
+ unset( $params['url_filter'] ); // pro - dynamic events
853
+
854
+ return $params;
855
+
856
  }
857
 
858
  }
917
 
918
  $options['general']['pixel_id'] = '';
919
  $options['general']['enabled'] = 0;
920
+ $options['general']['add_traffic_source'] = 1;
921
  $options['general']['enable_advance_matching'] = 1;
922
+ $options['general']['in_footer'] = 0;
923
 
924
  $options['general']['general_event_enabled'] = 1;
925
  $options['general']['general_event_name'] = 'GeneralEvent';
999
 
1000
  }
1001
 
1002
+ if( ! function_exists( 'pys_get_custom_params' ) ) {
1003
 
1004
  /**
1005
+ * Extract non-system params array
 
1006
  */
1007
  function pys_get_custom_params( $event ) {
1008
 
1010
  return array();
1011
  }
1012
 
1013
+ $system_params = array(
1014
  'trigger_type',
1015
+ 'url_filter',
1016
  'url',
1017
  'css',
1018
  'pageurl',
1019
  'eventtype',
1020
  'value',
1021
  'currency',
1022
+ 'custom_currency',
1023
  'content_name',
1024
  'content_ids',
1025
  'content_type',
1029
  'search_string',
1030
  'status',
1031
  'code',
1032
+ 'custom_name',
1033
+ 'scroll_pos'
1034
  );
1035
 
1036
  $custom_params = array();
1037
  foreach( $event as $param => $value ) {
1038
 
1039
  // skip standard params
1040
+ if( in_array( $param, $system_params ) ) {
1041
  continue;
1042
  }
1043
 
1052
 
1053
  }
1054
 
1055
+ if( ! function_exists( 'pys_is_standard_event' ) ) {
1056
 
1057
  function pys_is_standard_event( $eventtype ) {
1058
 
1074
 
1075
  }
1076
 
1077
+ if( ! function_exists( 'pys_pixel_init_params' ) ) {
 
 
 
1078
 
1079
+ /**
1080
+ * Add extra params to FB init call.
1081
+ */
1082
  function pys_pixel_init_params() {
1083
 
1084
  $params = array();
1085
  $params = apply_filters( 'pys_pixel_init_params', $params );
1086
 
1087
+ $sanitized = array();
1088
+
1089
+ // sanitize params
1090
+ foreach ( $params as $name => $value ) {
1091
 
 
1092
  if ( empty( $value ) ) {
1093
+ continue;
1094
  }
1095
 
1096
+ $key = esc_js( $name );
1097
+ $sanitized[ $key ] = $value;
1098
+
1099
+ }
1100
+
1101
+ return $sanitized;
1102
 
1103
+ }
1104
+
1105
+ }
1106
+
1107
+ if( ! function_exists( 'pys_woocommerce_events' ) ) {
1108
+
1109
+ function pys_woocommerce_events() {
1110
+
1111
+ if ( pys_get_option( 'woo', 'enabled' ) == false || pys_is_woocommerce_active() == false ) {
1112
+ return;
1113
+ }
1114
+
1115
+ pys_get_woo_code();
1116
+
1117
+ // WooCommerce non-ajax AddToCart Event handler
1118
+ if ( isset( $_REQUEST['add-to-cart'] ) ) {
1119
+
1120
+ $product_id = isset( $_REQUEST['add-to-cart'] ) ? $_REQUEST['add-to-cart'] : null;
1121
+
1122
+ if ( pys_get_option( 'woo', 'variation_id' ) == 'variation' && isset( $_REQUEST['variation_id'] ) ) {
1123
+ $product_id = $_REQUEST['variation_id'];
1124
+ }
1125
+
1126
+ $params = pys_get_woo_ajax_addtocart_params( $product_id );
1127
+
1128
+ pys_add_event( 'AddToCart', $params );
1129
+
1130
+ }
1131
+
1132
+ }
1133
+
1134
+ }
1135
+
1136
+ if( ! function_exists( 'pys_output_woo_ajax_events_code' ) ) {
1137
+
1138
+ function pys_output_woo_ajax_events_code() {
1139
+ global $pys_woo_ajax_events;
1140
+
1141
+ if( empty( $pys_woo_ajax_events ) ) {
1142
+ return;
1143
+ }
1144
+
1145
+ $events = array();
1146
+
1147
+ foreach ( $pys_woo_ajax_events as $id => $event ) {
1148
+
1149
+ $params = pys_clean_system_event_params( $event['params'] );
1150
+
1151
+ // sanitize params
1152
+ $sanitized = array();
1153
+ foreach ( $params as $name => $value ) {
1154
+
1155
+ if ( empty( $value ) ) {
1156
+ continue;
1157
+ }
1158
+
1159
+ $key = esc_js( $name );
1160
+ $sanitized[ $key ] = $value;
1161
+
1162
+ }
1163
+
1164
+ $name = $event['name'];
1165
+
1166
+ $events[ $id ] = array(
1167
+ 'type' => pys_is_standard_event( $name ) ? 'track' : 'trackCustom',
1168
+ 'name' => $name,
1169
+ 'params' => $sanitized
1170
+ );
1171
 
1172
  }
1173
 
1174
+ ?>
1175
+
1176
+ <script type="text/javascript">
1177
+ /* <![CDATA[ */
1178
+ var pys_woo_ajax_events = <?php echo json_encode( $events ); ?>;
1179
+ /* ]]> */
1180
+ </script>
1181
+
1182
+ <?php
1183
+
1184
+ }
1185
+
1186
+ }
1187
+
1188
+ if( ! function_exists( 'pys_output_options' ) ) {
1189
+
1190
+ function pys_output_options() {
1191
+
1192
+ $options = array(
1193
+ 'site_url' => get_site_url(),
1194
+ 'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
1195
+ );
1196
+
1197
+ wp_localize_script( 'pys', 'pys_options', $options );
1198
+
1199
+ }
1200
+
1201
+ }
1202
+
1203
+ if( ! function_exists( 'pys_head_comments' ) ) {
1204
+
1205
+ function pys_head_comments() {
1206
+
1207
+ if( defined( 'PYS_PRO_VERSION' ) ) {
1208
+ $version = "PRO v" . PYS_PRO_VERSION;
1209
+ } elseif( defined( 'PYS_FREE_VERSION' ) ) {
1210
+ $version = "FREE v" . PYS_FREE_VERSION_REAL;
1211
+ } else {
1212
+ $version = null;
1213
+ }
1214
+
1215
+ ?>
1216
+
1217
+ <!-- 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. -->
1218
+
1219
+ <?php
1220
+ }
1221
+
1222
+ }
1223
+
1224
+ if( ! function_exists( 'pys_render_event_code' ) ) {
1225
+
1226
+ /**
1227
+ * Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
1228
+ */
1229
+ function pys_render_event_code( $event_name, $params ) {
1230
+
1231
+ $event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
1232
+
1233
+ $params = pys_clean_system_event_params( $params );
1234
+
1235
+ $event_params = '';
1236
+ foreach( $params as $name => $value ) {
1237
+
1238
+ if( empty( $value ) ) {
1239
+ continue;
1240
+ }
1241
+
1242
+ $event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
1243
+
1244
+ }
1245
+
1246
+ $event_params = ltrim( $event_params );
1247
+ $event_params = rtrim( $event_params, "," );
1248
+
1249
+ return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
1250
+
1251
+ }
1252
+
1253
+ }
1254
+
1255
+ if( !function_exists( 'pys_add_domain_param' ) ) {
1256
+
1257
+ function pys_add_domain_param( $params, $event ) {
1258
+
1259
+ // get home URL without protocol
1260
+ $params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
1261
+ return $params;
1262
 
1263
  }
1264
 
inc/core.php CHANGED
@@ -17,22 +17,26 @@ if( !function_exists( 'pys_get_woo_ajax_addtocart_params' ) ) {
17
 
18
  }
19
 
20
- /**
21
- * Return array of product tags.
22
- */
23
  if( !function_exists( 'pys_get_post_tags' ) ) {
24
 
 
 
 
 
25
  function pys_get_post_tags( $post_id ) {
 
26
  return array(); // PRO feature
 
27
  }
28
 
29
  }
30
 
31
- /**
32
- * Build WooCommerce related events code.
33
- */
34
  if( !function_exists( 'pys_get_woo_code' ) ) {
35
 
 
 
 
 
36
  function pys_get_woo_code() {
37
  global $post, $woocommerce;
38
 
@@ -45,40 +49,46 @@ if( !function_exists( 'pys_get_woo_code' ) ) {
45
 
46
  $params['content_ids'] = '[' . pys_get_product_content_id( $post->ID ) . ']';
47
 
48
- return pys_build_event_pixel_code( $params, 'ViewContent' );
 
 
49
 
50
  }
51
 
52
  // AddToCart Cart Page Event
53
- if( pys_get_option( 'woo', 'on_cart_page' ) && is_cart() ) {
54
 
55
- $ids = array(); // cart items ids or sku
56
 
57
  foreach( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
58
 
59
  $product_id = pys_get_product_id( $item );
60
- $value= pys_get_product_content_id( $product_id );
61
- $ids[] = $value;
62
 
63
  }
64
 
65
  $params['content_ids'] = '[' . implode( ',', $ids ) . ']';
66
 
67
- return pys_build_event_pixel_code( $params, 'AddToCart' );
 
 
68
 
69
  }
70
 
71
  // Checkout Page Event
72
- if( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && !is_wc_endpoint_url() ) {
73
 
74
  $params = pys_get_woo_checkout_params( false );
75
 
76
- return pys_build_event_pixel_code( $params, 'InitiateCheckout' );
 
 
77
 
78
  }
79
 
80
  // Purchase Event
81
- if( pys_get_option( 'woo', 'on_thank_you_page' ) && is_wc_endpoint_url( 'order-received' ) ) {
82
 
83
  $order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
84
  $order = new WC_Order( $order_id );
@@ -89,34 +99,37 @@ if( !function_exists( 'pys_get_woo_code' ) ) {
89
  foreach( $items as $item ) {
90
 
91
  $product_id = pys_get_product_id( $item );
92
- $value= pys_get_product_content_id( $product_id );
93
- $ids[] = $value;
94
 
95
  }
96
 
97
  $params['content_ids'] = '[' . implode( ',', $ids ) . ']';
98
 
99
- return pys_build_event_pixel_code( $params, 'Purchase' );
100
 
101
- }
102
 
103
- return false;
104
 
105
  }
106
 
107
  }
108
 
109
- /**
110
- * Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
111
- */
112
  if( !function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
113
 
 
 
 
114
  function pys_add_code_to_woo_cart_link( $tag, $product ) {
 
115
 
116
  if ( $product->product_type == 'variable' || $product->product_type == 'grouped' ) {
117
  return $tag;
118
  }
119
 
 
 
120
  // common params
121
  $params = array();
122
  $params['content_type'] = 'product';
@@ -124,15 +137,18 @@ if( !function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
124
 
125
  if ( $product->product_type == 'simple' && pys_get_option( 'woo', 'on_add_to_cart_btn' ) ) {
126
 
127
- // do not add code it AJAX is disabled
128
  $is_ajax = get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' ? true : false;
129
  if ( ! $is_ajax ) {
130
  return $tag;
131
  }
132
 
133
- $code = pys_build_event_pixel_code( $params, 'AddToCart' );
134
 
135
- return pys_insert_attribute( 'data-pixelcode', $code['js'], $tag, true );
 
 
 
136
 
137
  }
138
 
@@ -146,6 +162,7 @@ if( !function_exists( 'pys_get_additional_matching_code' ) ) {
146
 
147
  /**
148
  * Adds extra params to pixel init code. On Free always returns empty string.
 
149
  *
150
  * @see: https://www.facebook.com/help/ipad-app/606443329504150
151
  * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
@@ -154,7 +171,26 @@ if( !function_exists( 'pys_get_additional_matching_code' ) ) {
154
  * @return string
155
  */
156
  function pys_get_additional_matching_code() {
 
157
  return ''; // PRO feature
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
 
160
  }
17
 
18
  }
19
 
 
 
 
20
  if( !function_exists( 'pys_get_post_tags' ) ) {
21
 
22
+ /**
23
+ * Return array of product tags.
24
+ * PRO only.
25
+ */
26
  function pys_get_post_tags( $post_id ) {
27
+
28
  return array(); // PRO feature
29
+
30
  }
31
 
32
  }
33
 
 
 
 
34
  if( !function_exists( 'pys_get_woo_code' ) ) {
35
 
36
+ /**
37
+ * Build WooCommerce related events code.
38
+ * Function adds evaluated event params to global array.
39
+ */
40
  function pys_get_woo_code() {
41
  global $post, $woocommerce;
42
 
49
 
50
  $params['content_ids'] = '[' . pys_get_product_content_id( $post->ID ) . ']';
51
 
52
+ pys_add_event( 'ViewContent', $params );
53
+
54
+ return;
55
 
56
  }
57
 
58
  // AddToCart Cart Page Event
59
+ if ( pys_get_option( 'woo', 'on_cart_page' ) && is_cart() ) {
60
 
61
+ $ids = array(); // cart items ids or sku
62
 
63
  foreach( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
64
 
65
  $product_id = pys_get_product_id( $item );
66
+ $value = pys_get_product_content_id( $product_id );
67
+ $ids[] = $value;
68
 
69
  }
70
 
71
  $params['content_ids'] = '[' . implode( ',', $ids ) . ']';
72
 
73
+ pys_add_event( 'AddToCart', $params );
74
+
75
+ return;
76
 
77
  }
78
 
79
  // Checkout Page Event
80
+ if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
81
 
82
  $params = pys_get_woo_checkout_params( false );
83
 
84
+ pys_add_event( 'InitiateCheckout', $params );
85
+
86
+ return;
87
 
88
  }
89
 
90
  // Purchase Event
91
+ if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_wc_endpoint_url( 'order-received' ) ) {
92
 
93
  $order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
94
  $order = new WC_Order( $order_id );
99
  foreach( $items as $item ) {
100
 
101
  $product_id = pys_get_product_id( $item );
102
+ $value = pys_get_product_content_id( $product_id );
103
+ $ids[] = $value;
104
 
105
  }
106
 
107
  $params['content_ids'] = '[' . implode( ',', $ids ) . ']';
108
 
109
+ pys_add_event( 'Purchase', $params );
110
 
111
+ return;
112
 
113
+ }
114
 
115
  }
116
 
117
  }
118
 
 
 
 
119
  if( !function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
120
 
121
+ /**
122
+ * Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
123
+ */
124
  function pys_add_code_to_woo_cart_link( $tag, $product ) {
125
+ global $pys_woo_ajax_events;
126
 
127
  if ( $product->product_type == 'variable' || $product->product_type == 'grouped' ) {
128
  return $tag;
129
  }
130
 
131
+ $event_id = uniqid();
132
+
133
  // common params
134
  $params = array();
135
  $params['content_type'] = 'product';
137
 
138
  if ( $product->product_type == 'simple' && pys_get_option( 'woo', 'on_add_to_cart_btn' ) ) {
139
 
140
+ // do not add code if AJAX is disabled. event will be processed by another function
141
  $is_ajax = get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' ? true : false;
142
  if ( ! $is_ajax ) {
143
  return $tag;
144
  }
145
 
146
+ $tag = pys_insert_attribute( 'data-pys-event-id', $event_id, $tag, true );
147
 
148
+ $pys_woo_ajax_events[ $event_id ] = array(
149
+ 'name' => 'AddToCart',
150
+ 'params' => $params
151
+ );
152
 
153
  }
154
 
162
 
163
  /**
164
  * Adds extra params to pixel init code. On Free always returns empty string.
165
+ * PRO only.
166
  *
167
  * @see: https://www.facebook.com/help/ipad-app/606443329504150
168
  * @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
171
  * @return string
172
  */
173
  function pys_get_additional_matching_code() {
174
+
175
  return ''; // PRO feature
176
+
177
+ }
178
+
179
+ }
180
+
181
+ if( !function_exists( 'pys_get_additional_woo_params' ) ) {
182
+
183
+ /**
184
+ * Adds additional post parameters like `content_name` and `category_name`.
185
+ * PRO only.
186
+ *
187
+ * @param $post WP_Post|int
188
+ * @param $params array reference to $params array
189
+ */
190
+ function pys_get_additional_woo_params( $post, &$params ) {
191
+
192
+ // PRO only
193
+
194
  }
195
 
196
  }
inc/html-box-top-dynamic.php CHANGED
@@ -1,10 +1,15 @@
1
  <div class="pys-box pys-box-top">
2
  <div class="pys-col pys-col-one-half">
3
  <ul>
4
- <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this before starting</a></h2></li>
5
  </ul>
6
  <ul>
7
  <li><h2>Click for help: <a href="http://www.pixelyoursite.com/facebook-pixel-dynamic-events" target="_blank">How to use Dynamic Events - Step by Step Guide</a></h2></li>
 
 
 
 
 
8
  </ul>
9
  </div>
10
  <div class="pys-col pys-col-one-half pys-col-border-left">
1
  <div class="pys-box pys-box-top">
2
  <div class="pys-col pys-col-one-half">
3
  <ul>
4
+ <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this Help Page before starting</a></h2></li>
5
  </ul>
6
  <ul>
7
  <li><h2>Click for help: <a href="http://www.pixelyoursite.com/facebook-pixel-dynamic-events" target="_blank">How to use Dynamic Events - Step by Step Guide</a></h2></li>
8
+ <li>
9
+ <p><br></p>
10
+ <p>What you <strong>must</strong> know about the NEW Facebook Pixel. Download your FREE GUIDE now:</p>
11
+ <p><a class="pys-btn pys-btn-blue" href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide" target="_blank">DOWNLOAD YOUR FREE GUIDE</a></p>
12
+ </li>
13
  </ul>
14
  </div>
15
  <div class="pys-col pys-col-one-half pys-col-border-left">
inc/html-box-top-general.php CHANGED
@@ -1,10 +1,15 @@
1
  <div class="pys-box pys-box-top">
2
- <div class="pys-col pys-col-one-half">
3
- <ul>
4
- <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this before starting</a></h2></li>
5
- </ul>
6
- </div>
7
- <div class="pys-col pys-col-one-half pys-col-border-left">
8
- <?php include "html-offer-content.php"; ?>
9
- </div>
 
 
 
 
 
10
  </div>
1
  <div class="pys-box pys-box-top">
2
+ <div class="pys-col pys-col-one-half">
3
+ <ul>
4
+ <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this Help Page before starting</a></h2></li>
5
+ <li>
6
+ <p><br></p>
7
+ <p>What you <strong>must</strong> know about the NEW Facebook Pixel. Download your FREE GUIDE now:</p>
8
+ <p><a class="pys-btn pys-btn-blue" href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide" target="_blank">DOWNLOAD YOUR FREE GUIDE</a></p>
9
+ </li>
10
+ </ul>
11
+ </div>
12
+ <div class="pys-col pys-col-one-half pys-col-border-left">
13
+ <?php include "html-offer-content.php"; ?>
14
+ </div>
15
  </div>
inc/html-box-top-post-event.php CHANGED
@@ -1,10 +1,15 @@
1
  <div class="pys-box pys-box-top">
2
  <div class="pys-col pys-col-one-half">
3
  <ul>
4
- <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this before starting</a></h2></li>
5
  </ul>
6
  <ul>
7
  <li><h2>Click for help: <a href="http://www.pixelyoursite.com/how-to-add-facebook-pixel-events" target="_blank">How to use Events - Step by Step Guide</a></h2></li>
 
 
 
 
 
8
  </ul>
9
  </div>
10
  <div class="pys-col pys-col-one-half pys-col-border-left">
1
  <div class="pys-box pys-box-top">
2
  <div class="pys-col pys-col-one-half">
3
  <ul>
4
+ <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this Help Page before starting</a></h2></li>
5
  </ul>
6
  <ul>
7
  <li><h2>Click for help: <a href="http://www.pixelyoursite.com/how-to-add-facebook-pixel-events" target="_blank">How to use Events - Step by Step Guide</a></h2></li>
8
+ <li>
9
+ <p><br></p>
10
+ <p>What you <strong>must</strong> know about the NEW Facebook Pixel. Download your FREE GUIDE now:</p>
11
+ <p><a class="pys-btn pys-btn-blue" href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide" target="_blank">DOWNLOAD YOUR FREE GUIDE</a></p>
12
+ </li>
13
  </ul>
14
  </div>
15
  <div class="pys-col pys-col-one-half pys-col-border-left">
inc/html-box-top-woo.php CHANGED
@@ -1,10 +1,15 @@
1
  <div class="pys-box pys-box-top">
2
  <div class="pys-col pys-col-one-half">
3
  <ul>
4
- <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this before starting</a></h2></li>
5
  </ul>
6
  <ul>
7
  <li><h2>Click for help: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-woocommerce" target="_blank">How to configure Facebook Pixel on WooCommerce - Must Read</a></h2></li>
 
 
 
 
 
8
  </ul>
9
  </div>
10
  <div class="pys-col pys-col-one-half pys-col-border-left">
1
  <div class="pys-box pys-box-top">
2
  <div class="pys-col pys-col-one-half">
3
  <ul>
4
+ <li><h2>First time here? <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-help" target="_blank">Read this Help Page before starting</a></h2></li>
5
  </ul>
6
  <ul>
7
  <li><h2>Click for help: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin-woocommerce" target="_blank">How to configure Facebook Pixel on WooCommerce - Must Read</a></h2></li>
8
+ <li>
9
+ <p><br></p>
10
+ <p>What you <strong>must</strong> know about the NEW Facebook Pixel. Download your FREE GUIDE now:</p>
11
+ <p><a class="pys-btn pys-btn-blue" href="http://www.pixelyoursite.com/facebook-pixel-pdf-guide" target="_blank">DOWNLOAD YOUR FREE GUIDE</a></p>
12
+ </li>
13
  </ul>
14
  </div>
15
  <div class="pys-col pys-col-one-half pys-col-border-left">
inc/html-offer-content.php CHANGED
@@ -1,22 +1,26 @@
1
- <?php if( pys_is_woocommerce_active() ) : ?>
2
 
3
- <h2>Special Offer:</h2>
4
- <p>Get the PRO version for <strong>a big discount</strong> and improve your ads return:</p>
5
- <ul class="dashed">
6
- <li>Woocommerce <strong>Conversion Value fine-tuned tracking</strong>, so you can really measure your Ads ROI</li>
7
- <li>Superior <strong>Woocommerce Integration</strong> with key events parameters, like product name or category name, so you can create highly targeted Custom Audiences</li>
8
- <li>Use <strong>Dynamic Events</strong> like a pro marketer and optimize your FB Ads for impoortant clicks on your site (like newsletter sign up or links in pop-ups)
9
-
10
- </ul>
 
11
 
12
  <?php else: ?>
13
 
14
- <h2>Super Offer:</h2>
15
- <p>Get the PRO version for <strong>a big discount</strong> and improve your ads return:</p>
16
- <ul class="dashed">
17
- <li>Use <strong>Dynamic Events</strong> like a pro marketer (add events on links and buttons clicks - perfect for affiliates and lead generation)</li>
18
- </ul>
 
 
19
 
20
  <?php endif; ?>
21
 
22
- <a class="pys-btn pys-btn-red" href="http://www.pixelyoursite.com/facebook-pixel-plugin" target="_blank">CLICK TO UPGRADE NOW</a>
 
1
+ <?php if ( pys_is_woocommerce_active() ) : ?>
2
 
3
+ <h2>Special Offer:</h2>
4
+ <p>Get the PRO version for <strong>a big discount</strong> and improve your ads return:</p>
5
+ <ul class="dashed">
6
+ <li><strong>Woocommerce Conversion Value Fine-Tuned Tracking</strong>, so you can really measure your Ads ROI.</li>
7
+ <li><strong>WooCommerce Custom Audiences</strong>: track important things like product names, product category, product tags, payment and shipping methods or coupons. Use them to create powerful Custom Audiences for better retargeting and Lookalike expansion.</li>
8
+ <li><strong>Track Traffic Source</strong> and <strong>URL tags (UTM)</strong> for all your events and segment your Custom Audiences with them.</li>
9
+ <li>Enable the <strong>TimeOnPage Event</strong> and use it for Custom Audiences</li>
10
+ <li>Use <strong>Dynamic Events</strong> like a pro marketer and optimize your FB Ads for important actions on your site (like clicks on key links, page scroll or mouse over).</li>
11
+ </ul>
12
 
13
  <?php else: ?>
14
 
15
+ <h2>Special Offer:</h2>
16
+ <p>Get the PRO version for <strong>a big discount</strong> and improve your ads return:</p>
17
+ <ul class="dashed">
18
+ <li>Use <strong>Dynamic Events</strong> like a pro marketer to trigger events when the visitors performs a key action on your site, like clicks on important links or buttons, page scroll or mouse over. Optimize your ads for them for an improved ROI.</li>
19
+ <li>Track <strong>Traffic Source</strong> and <strong>URL tags (UTM)</strong> to segment your Custom Audiences based on them for superior retargeting strategies. </li>
20
+ <li>Enable <strong>TimeOnPage Event</strong> to make Custom Audiences for key pages where only people spending a minimum amount of time are important for your business.</li>
21
+ </ul>
22
 
23
  <?php endif; ?>
24
 
25
+ <a class="pys-btn pys-btn-red" href="http://www.pixelyoursite.com/facebook-pixel-plugin" target="_blank">CLICK TO
26
+ UPGRADE NOW</a>
inc/html-tab-dynamic-events-general.php CHANGED
@@ -1,44 +1,64 @@
1
  <div class="pys-box">
2
- <div class="pys-col pys-col-full">
3
- <h2 class="section-title">Dynamic Events</h2>
4
- <p>Add standard or custom events that will trigger when a visitor clicks a link or a button on your website.</p>
5
-
6
- <div class="pys-col-narrow">
7
- <h2>Start using Dynamic Events with the PRO version of the plugin</h2>
8
- <p>With Dynamic Events you can optimize your ads for actions on your website, like filing up forms (Contact Form 7 supported), newsletter sign ups, or any other click on links and buttons. Better ad optimization, better custom audience targeting, better conversion tracking.</p>
9
- <p><strong>If you are not using Facebook Dynamic Events you are literally leaving money on the table.</strong></p>
10
-
11
- <p><strong>Super Offer Ending Soon: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin" target="_blank">Update now and start to benefit from Dynamic Events</a></strong></p>
12
-
13
- <p>Or Learn more about <a href="http://www.pixelyoursite.com/facebook-pixel-dynamic-events" target="_blank">How to use Dynamic Events - Complete guide</a></p>
14
- </div>
15
-
16
- <div style="text-align: center; margin-top: 40px; margin-bottom: 40px;">
17
- <a href="#" class="pys-btn pys-btn-big pys-btn-blue disabled">Add New Dynamic Event</a>
18
- </div>
19
-
20
-
21
- <hr>
22
-
23
- <table class="layout">
24
- <tr>
25
- <td class="alignright"><p class="label big">Activate Dynamic Events</p></td>
26
- <td><input type="checkbox" disabled="disabled"></input></td>
27
- </tr>
28
-
29
- <tr>
30
- <td class="alignright"><p class="label">Process links</p></td>
31
- <td>
32
- <input type="checkbox" disabled="disabled">Process links in Post Content</input>
33
- <span class="help">The <code>the_content()</code> hook.</span>
34
-
35
- <input type="checkbox" disabled="disabled">Process links in Widgets Text</input>
36
- <span class="help">The <code>widget_text()</code> hook.</span>
37
- </td>
38
- </tr>
39
- </table>
40
-
41
- <button class="pys-btn pys-btn-blue pys-btn-big aligncenter disabled">Save Settings</button>
42
-
43
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  </div>
1
  <div class="pys-box">
2
+ <div class="pys-col pys-col-full">
3
+ <h2 class="section-title">Dynamic Events (Pro Option)</h2>
4
+
5
+ <p>Add standard or custom events that will fire when a visitor performs an important action on your site.</p>
6
+
7
+ <div class="pys-col-narrow">
8
+ <h2>Start using Dynamic Events with the PRO version of the plugin</h2>
9
+
10
+ <p>Dynamic Events will not fire when a page is loaded, but when the user does a desired action on that page
11
+ (clicks on something, scrolls the page or moves the mouse over some key element).</p>
12
+
13
+ <p>This way you can <strong>optimize your ads for actions on your website</strong>, like filling up forms
14
+ (contact forms and popup plugins are supported), newsletter signups, clicks on links and buttons (useful
15
+ for affiliate sites).</p>
16
+
17
+ <p>Incorporating Dynamic Events in your strategy is a proven way to increase your ads ROI and the overall
18
+ profitability of your Facebook campaigns.</p>
19
+
20
+ <h2>Trigger Dynamic Events:</h2>
21
+
22
+ <ul style="list-style: initial; padding-left: 20px;">
23
+ <li><strong>On Clicks</strong>: When the users <strong>clicks on links or buttons</strong> (html links or CSS Selector)</li>
24
+ <li>On <strong>Page Scroll</strong>: when the user scrolls the page up to a defined percent</li>
25
+ <li>On <strong>MouseOver</strong>: when the user moves the mouse on a page element</li>
26
+ </ul>
27
+
28
+ <p><strong>If you are not using Facebook Dynamic Events you are literally leaving money on the table.</strong></p>
29
+
30
+ <p><strong>Super Offer Ending Soon: <a href="http://www.pixelyoursite.com/facebook-pixel-plugin"
31
+ target="_blank">Update now and start to benefit from Dynamic Events</a></strong></p>
32
+
33
+ <p>Or Learn more about <a href="http://www.pixelyoursite.com/facebook-pixel-dynamic-events" target="_blank">How to use Dynamic Events - Complete guide</a></p>
34
+ </div>
35
+
36
+ <div style="text-align: center; margin-top: 40px; margin-bottom: 40px;">
37
+ <a href="#" class="pys-btn pys-btn-big pys-btn-blue disabled">Add New Dynamic Event</a>
38
+ </div>
39
+
40
+
41
+ <hr>
42
+
43
+ <table class="layout">
44
+ <tr>
45
+ <td class="alignright"><p class="label big">Activate Dynamic Events</p></td>
46
+ <td><input type="checkbox" disabled="disabled"></input></td>
47
+ </tr>
48
+
49
+ <tr>
50
+ <td class="alignright"><p class="label">Process links</p></td>
51
+ <td>
52
+ <input type="checkbox" disabled="disabled">Process links in Post Content</input>
53
+ <span class="help">The <code>the_content()</code> hook.</span>
54
+
55
+ <input type="checkbox" disabled="disabled">Process links in Widgets Text</input>
56
+ <span class="help">The <code>widget_text()</code> hook.</span>
57
+ </td>
58
+ </tr>
59
+ </table>
60
+
61
+ <button class="pys-btn pys-btn-blue pys-btn-big aligncenter disabled">Save Settings</button>
62
+
63
+ </div>
64
  </div>
inc/html-tab-dynamic-events-list.php CHANGED
@@ -10,12 +10,12 @@
10
  <table class="widefat fixed pys-list disabled">
11
  <thead>
12
  <tr>
13
- <td class="check-column"><input type="checkbox"></td>
14
- <th scope="col" class="column-type">Type</th>
15
- <th scope="col" class="column-name">Custom name</th>
16
- <th scope="col" class="column-url">URL</th>
17
- <th scope="col" class="column-code">Code</th>
18
- <th scope="col" class="column-actions">Actions</th>
19
  </tr>
20
  </thead>
21
  <tbody>
10
  <table class="widefat fixed pys-list disabled">
11
  <thead>
12
  <tr>
13
+ <td class="check-column"><input type="checkbox"></td>
14
+ <th scope="col" class="column-type">Trigger On</th>
15
+ <th scope="col" class="column-url">URL / CSS / Position</th>
16
+ <th scope="col" class="column-type">Type</th>
17
+ <th scope="col" class="column-code">Code</th>
18
+ <th scope="col" class="column-actions">Actions</th>
19
  </tr>
20
  </thead>
21
  <tbody>
inc/html-tab-pixel-general.php CHANGED
@@ -27,6 +27,14 @@
27
  value="<?php echo pys_get_option( 'general', 'general_event_name' ); ?>">
28
  </td>
29
  </tr>
 
 
 
 
 
 
 
 
30
 
31
  <tr>
32
  <td></td>
@@ -101,7 +109,7 @@
101
  <hr>
102
 
103
  <h2>TimeOnPage Event</h2>
104
- <p>TimeOnPage event will pull the time spent on each page in seconds, the page name as <code>content_name</code>, and the page ID as <code>content_ids</code> - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></p>
105
 
106
  <table class="layout disabled">
107
 
27
  value="<?php echo pys_get_option( 'general', 'general_event_name' ); ?>">
28
  </td>
29
  </tr>
30
+
31
+ <tr>
32
+ <td class="alignright"><p class="label">Delay</p></td>
33
+ <td>
34
+ <input type="number" name="pys[general][general_event_delay]" value="<?php echo pys_get_option( 'general', 'general_event_delay' ); ?>" min="0" step="0.1"> seconds
35
+ <span class="help">Avoid retargeting bouncing users (It is better to add a lower time that the desired one because the pixel code will not load instantaneously). People that spent less time on the page will not be part of your Custom Audiences. You will not spend money retargeting them and your Lookalike Audiences will be more accurate.</span>
36
+ </td>
37
+ </tr>
38
 
39
  <tr>
40
  <td></td>
109
  <hr>
110
 
111
  <h2>TimeOnPage Event</h2>
112
+ <p>TimeOnPage event will pull the time spent on each page in seconds, the page name as <code>content_name</code>, and the page ID as <code>content_ids</code>. Use it to create CustomAudiences for key pages <strong>where only people that spend a minimum amount of time matter for your business</strong>. This will improve your retargeting as well as Lookalike Audiences. - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></p>
113
 
114
  <table class="layout disabled">
115
 
inc/html-tab-pixel-id.php CHANGED
@@ -13,6 +13,14 @@
13
  </td>
14
  </tr>
15
 
 
 
 
 
 
 
 
 
16
  <tr>
17
  <td></td>
18
  <td>
@@ -21,6 +29,14 @@
21
  </td>
22
  </tr>
23
 
 
 
 
 
 
 
 
 
24
  </table>
25
  </div>
26
  </div>
13
  </td>
14
  </tr>
15
 
16
+ <tr>
17
+ <td></td>
18
+ <td>
19
+ <input type="checkbox" name="" value="1" class="disabled">Track Traffic Source and UTM (URL Tags) - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
20
+ <span class="help">Add traffic source as <code>traffic_source</code> param on all your events. URL tags (UTM) will be also tracked for each event. Use this to segment your Custom Audiences and improve your retargeting (retarget people based on when they come from, like Google, Facebook or a particular ad, for example).</span>
21
+ </td>
22
+ </tr>
23
+
24
  <tr>
25
  <td></td>
26
  <td>
29
  </td>
30
  </tr>
31
 
32
+ <tr>
33
+ <td class="legend"><p class="label">Output Pixel Code to:</p></td>
34
+ <td>
35
+ <p style="margin-top: 0;"><input type="radio" name="pys[general][in_footer]" value="0" <?php echo pys_radio_state( 'general', 'in_footer', 0 ); ?> >Head</p>
36
+ <p style="margin-top: 0;"><input type="radio" name="pys[general][in_footer]" value="1" <?php echo pys_radio_state( 'general', 'in_footer', 1 ); ?>>Footer</p>
37
+ </td>
38
+ </tr>
39
+
40
  </table>
41
  </div>
42
  </div>
inc/html-tab-std-event-list.php CHANGED
@@ -40,27 +40,26 @@
40
  <td><?php echo $params['eventtype']; ?></td>
41
  <td><pre><?php echo $params['pageurl']; ?></pre></td>
42
  <td>
43
- <?php
44
-
45
- $code = '';
46
- if( $params['eventtype'] == 'CustomCode' ) {
47
-
48
- $code = $params['code'];
49
-
50
- } else {
51
 
52
- $event_type = $params['eventtype'];
53
- $params = pys_clean_system_event_params( $params );
54
- $code = pys_build_event_pixel_code( $params, $event_type );
55
- $code = $code['js'];
56
-
57
- }
58
-
59
- $code = stripcslashes( $code );
60
- $code = trim( $code );
61
- echo '<pre>' . $code . '</pre>';
62
-
63
- ?>
 
 
 
 
 
 
 
64
  </td>
65
  <td>
66
  <a href="<?php echo admin_url('admin-ajax.php'); ?>?action=pys_edit_std_event&id=<?php echo $key; ?>" class="button action thickbox">Edit</a>
40
  <td><?php echo $params['eventtype']; ?></td>
41
  <td><pre><?php echo $params['pageurl']; ?></pre></td>
42
  <td>
 
 
 
 
 
 
 
 
43
 
44
+ <?php
45
+
46
+ $code = '';
47
+ if ( $params['eventtype'] == 'CustomCode' ) {
48
+
49
+ $code = $params['code'];
50
+
51
+ } else {
52
+
53
+ $code = pys_render_event_code( $params['eventtype'], $params );
54
+
55
+ }
56
+
57
+ $code = stripcslashes( $code );
58
+ $code = trim( $code );
59
+ echo '<pre>' . $code . '</pre>';
60
+
61
+ ?>
62
+
63
  </td>
64
  <td>
65
  <a href="<?php echo admin_url('admin-ajax.php'); ?>?action=pys_edit_std_event&id=<?php echo $key; ?>" class="button action thickbox">Edit</a>
inc/html-tab-woo-general.php CHANGED
@@ -51,7 +51,7 @@
51
 
52
  <h2>Custom Audiences Optimization</h2>
53
 
54
- <input type="checkbox">Enable Additional Parameters</input>
55
  <span class="help">Product name will be pulled as <code>content_name</code>, and Product Category as <code>category_name</code> for all WooCommerce events.</span>
56
  <span class="help" style="margin-bottom: 20px;">The number of items is <code>num_items</code> for InitiateCheckout and Purchase events.</span>
57
 
@@ -99,12 +99,20 @@
99
  <strong>Enable ViewContent on Product Pages</strong></input>
100
  </td>
101
  </tr>
 
 
 
 
 
 
 
 
102
 
103
  <tr>
104
  <td></td>
105
  <td>
106
  <input type="checkbox" disabled>Enable Value - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></input>
107
- <span class="help">add value and currency - Important for ROI measurement</span>
108
  </td>
109
  </tr>
110
 
51
 
52
  <h2>Custom Audiences Optimization</h2>
53
 
54
+ <input type="checkbox" disabled>Enable Additional Parameters</input>
55
  <span class="help">Product name will be pulled as <code>content_name</code>, and Product Category as <code>category_name</code> for all WooCommerce events.</span>
56
  <span class="help" style="margin-bottom: 20px;">The number of items is <code>num_items</code> for InitiateCheckout and Purchase events.</span>
57
 
99
  <strong>Enable ViewContent on Product Pages</strong></input>
100
  </td>
101
  </tr>
102
+
103
+ <tr>
104
+ <td class="alignright disabled"><p class="label">Delay</p></td>
105
+ <td>
106
+ <input type="number" name="pys[woo][on_view_content_delay]" value="" disabled> seconds - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a>
107
+ <span class="help">Avoid retargeting bouncing users (It is better to add a lower time that the desired one because the pixel code will not load instantaneously). People that spent less time on the page will not be part of your Custom Audiences. You will not spend money retargeting them and your Lookalike Audiences will be more accurate.</span>
108
+ </td>
109
+ </tr>
110
 
111
  <tr>
112
  <td></td>
113
  <td>
114
  <input type="checkbox" disabled>Enable Value - <strong>This is a PRO feature</strong> - <a href="http://www.pixelyoursite.com/facebook-pixel-plugin">Update NOW</a></input>
115
+ <span class="help">Add value and currency - Important for ROI measurement</span>
116
  </td>
117
  </tr>
118
 
js/public.js CHANGED
@@ -1,15 +1,100 @@
1
  jQuery(document).ready(function( $ ) {
2
 
 
 
 
 
 
 
 
 
 
 
3
  // AddToCart button
4
  $(".ajax_add_to_cart").click(function(e){
5
 
6
- var code = jQuery(this).attr('data-pixelcode') || false;
7
 
8
- if( code != false && code != '' ) {
9
- console.log( code );
10
- eval( code );
11
  }
12
 
 
 
13
  });
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  });
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;
6
+ n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
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
+
13
  // AddToCart button
14
  $(".ajax_add_to_cart").click(function(e){
15
 
16
+ var attr = $(this).attr('data-pys-event-id');
17
 
18
+ if( typeof attr == 'undefined' || typeof pys_woo_ajax_events == 'undefined' ) {
19
+ return;
 
20
  }
21
 
22
+ evaluateEventByID( attr.toString(), pys_woo_ajax_events );
23
+
24
  });
25
 
26
+ /**
27
+ * Process Init, General, Search, Standard (except custom code), WooCommerce (except AJAX AddToCart, Affiliate and
28
+ * PayPal events. In case if delay param is present - event will be fired after desired timeout.
29
+ */
30
+ function regularEvents() {
31
+
32
+ if( typeof pys_events == 'undefined' ) {
33
+ return;
34
+ }
35
+
36
+ for( var i = 0; i < pys_events.length; i++ ) {
37
+
38
+ var eventData = pys_events[i];
39
+
40
+ if( eventData.hasOwnProperty('delay') == false || eventData.delay == 0 ) {
41
+
42
+ fbq( eventData.type, eventData.name, eventData.params );
43
+
44
+ } else {
45
+
46
+ setTimeout( function( type, name, params ) {
47
+ fbq( type, name, params );
48
+ }, eventData.delay * 1000, eventData.type, eventData.name, eventData.params );
49
+
50
+ }
51
+
52
+ }
53
+
54
+ }
55
+
56
+ /**
57
+ * Process only custom code Standard events.
58
+ */
59
+ function customCodeEvents() {
60
+
61
+ if( typeof pys_customEvents == 'undefined' ) {
62
+ return;
63
+ }
64
+
65
+ $.each( pys_customEvents, function( index, code ) {
66
+ eval( code );
67
+ } );
68
+
69
+ }
70
+
71
+ /**
72
+ * Fire event with {eventID} from =events= events list. In case of event data have =custom= property, code will be
73
+ * evaluated without regular Facebook pixel call.
74
+ */
75
+ function evaluateEventByID( eventID, events ) {
76
+
77
+ if( typeof events == 'undefined' || events.length == 0 ) {
78
+ return;
79
+ }
80
+
81
+ // try to find required event
82
+ if( events.hasOwnProperty( eventID ) == false ) {
83
+ return;
84
+ }
85
+
86
+ var eventData = events[ eventID ];
87
+
88
+ if( eventData.hasOwnProperty( 'custom' ) ) {
89
+
90
+ eval( eventData.custom );
91
+
92
+ } else {
93
+
94
+ fbq( eventData.type, eventData.name, eventData.params );
95
+
96
+ }
97
+
98
+ }
99
+
100
  });
readme.txt CHANGED
@@ -2,8 +2,8 @@
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, Facebook Pixel PayPal
4
  Requires at least: 3.0.1
5
- Tested up to: 4.6
6
- Stable tag: 3.1.0
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -38,7 +38,13 @@ Not ready to install yet? Read on some of the key features that make PYS a power
38
 
39
  * You can **set up and track Standard or Custom Events** and add parameters for each of them
40
 
41
- * **Dynamic Events:** optimize your Facebook Campaigns for actions on your website (CLICKS on links, buttons, forms). Works with **Contact Form 7 and any other form or pop-up plugins.** ([Pro Version](http://www.pixelyoursite.com))
 
 
 
 
 
 
42
 
43
  * Track **conversion value** for standard and custom events
44
 
@@ -70,6 +76,8 @@ Not ready to install yet? Read on some of the key features that make PYS a power
70
 
71
  * You can turn ON/OFF value for each WooCommerce event.
72
 
 
 
73
  * **Super-Powerful Custom Audiences for WooCommerce:** we automatically track product name and product category (you can create audiences based on them), together with customer's city, state, and country. Additionally, we track payment and shipping methods. Use of coupons and coupon names are also automatically extracted. With this data, you can unleash some fantastic retargeting campaigns based on highly granulated audiences. ([Pro Version](http://www.pixelyoursite.com))
74
 
75
  * **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))
@@ -195,6 +203,19 @@ We have an article about how to optimize Facebook Ads Reports:
195
 
196
  == Changelog ==
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  = PixelYourSite 3.1.0 =
199
 
200
  * Changing GeneralEvent parameters names to avoid Pixel Helper warning (post_id and post_type are now being used)
@@ -308,6 +329,6 @@ This is a major release, with new design and new features:
308
 
309
  == Upgrade Notice ==
310
 
311
- = 3.0 =
312
 
313
- 3.0 is a complete rewrite, with a new design and improve functionality. You have a new GeneralEvent that can be used to create Custom Audiences (plus a FREE guide on how to do it!) and Facebook Dynamic Ads are fully supported for WooCommerce. Update, then open the plugin menu for details
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, Facebook Pixel PayPal
4
  Requires at least: 3.0.1
5
+ Tested up to: 4.6.1
6
+ Stable tag: 4.0.0
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
38
 
39
  * You can **set up and track Standard or Custom Events** and add parameters for each of them
40
 
41
+ * **Delay Events**, so you don't spend your money on retargeting bouncing visitors
42
+
43
+ * 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
44
+
45
+ * **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))
46
+
47
+ * **Dynamic Events:** optimize your Facebook Campaigns for actions on your website (CLICKS on links, buttons, forms, page scroll or mouse over). Works with **Contact Form 7 and any other form or pop-up plugins.** ([Pro Version](http://www.pixelyoursite.com))
48
 
49
  * Track **conversion value** for standard and custom events
50
 
76
 
77
  * You can turn ON/OFF value for each WooCommerce event.
78
 
79
+ * Delay the WooCommerce ViewContent Event, so you don't spend your money on retargeting bouncing visitors ([Pro Version](http://www.pixelyoursite.com))
80
+
81
  * **Super-Powerful Custom Audiences for WooCommerce:** we automatically track product name and product category (you can create audiences based on them), together with customer's city, state, and country. Additionally, we track payment and shipping methods. Use of coupons and coupon names are also automatically extracted. With this data, you can unleash some fantastic retargeting campaigns based on highly granulated audiences. ([Pro Version](http://www.pixelyoursite.com))
82
 
83
  * **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))
203
 
204
  == Changelog ==
205
 
206
+ = PixelYourSite 4.0.0 =
207
+
208
+ * From version 4.0 the plugin uses JS to trigger the code. This allows us to add new useful features.
209
+
210
+ * Delay Event option added for the GeneralEvent
211
+
212
+ * Head/Footer option - you can decide where the pixel JS will be called. The default setting is in head.
213
+
214
+ * Various text changes to reflect the new pro features
215
+
216
+ * WooCommerce SKU id possible error fix
217
+
218
+
219
  = PixelYourSite 3.1.0 =
220
 
221
  * Changing GeneralEvent parameters names to avoid Pixel Helper warning (post_id and post_type are now being used)
329
 
330
  == Upgrade Notice ==
331
 
332
+ = 4.0 =
333
 
334
+ It is recommended that you DELETE THE CACHE after this update, so that the new JS is loaded. PYS 4.0 comes with an improved way to fire the code. We now use JS, so we can add new features to our plugin, like Delay Events.