WP Google Analytics Events - Version 2.4.3

Version Description

Download this release

Release Info

Developer yuvalo
Plugin Icon 128x128 WP Google Analytics Events
Version 2.4.3
Comparing to
See all releases

Code changes from version 2.4.2 to 2.4.3

Files changed (6) hide show
  1. ga-scroll-event.php +2 -2
  2. includes/admin.php +173 -175
  3. includes/functions.php +208 -210
  4. js/ajax.js +33 -32
  5. js/ga-scroll-events.js +1 -1
  6. readme.txt +23 -15
ga-scroll-event.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Google Analytics Events
4
  Plugin URI: http://wpflow.com
5
  Description: Adds the Google Analytics code to your website and enables you to send events on scroll or click.
6
- Version: 2.4.2
7
  Author: Yuval Oren
8
  Author URI: http://wpflow.com
9
  License: GPLv2
@@ -83,7 +83,7 @@ add_action('init','ga_events_scripts');
83
 
84
  function ga_events_scripts() {
85
  wp_enqueue_script('jquery');
86
- wp_enqueue_script('scrolldepth',plugins_url( '/js/ga-scroll-events.js', __FILE__) , array('jquery'), '2.4.2', false);
87
  }
88
 
89
  add_action( 'plugins_loaded', 'ga_events_setup');
3
  Plugin Name: WP Google Analytics Events
4
  Plugin URI: http://wpflow.com
5
  Description: Adds the Google Analytics code to your website and enables you to send events on scroll or click.
6
+ Version: 2.4.3
7
  Author: Yuval Oren
8
  Author URI: http://wpflow.com
9
  License: GPLv2
83
 
84
  function ga_events_scripts() {
85
  wp_enqueue_script('jquery');
86
+ wp_enqueue_script('scrolldepth',plugins_url( '/js/ga-scroll-events.js', __FILE__) , array('jquery'), '2.4.3', false);
87
  }
88
 
89
  add_action( 'plugins_loaded', 'ga_events_setup');
includes/admin.php CHANGED
@@ -19,17 +19,17 @@ function ga_events_menu() {
19
 
20
  function ga_events_settings_page() {
21
 
22
- ?>
23
- <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
24
- <div id="ga_mainwrap">
25
  <div id="ga_main" class="wrap">
26
  <?php screen_icon( 'plugins' ); ?>
27
- <h2>GA Scroll Events Plugin</h2>
28
 
29
- <?php
30
- $active_page = isset( $_GET[ 'page' ] ) ? $_GET[ 'page' ] : 'wp-google-analytics-events';
31
- ?>
32
- <h2 class="nav-tab-wrapper">
33
  <a href="?page=wp-google-analytics-events" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events' ? 'nav-tab-active' : ''; ?>">General Settings</a>
34
  <a href="?page=wp-google-analytics-events-click" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-click' ? 'nav-tab-active' : ''; ?>">Click Tracking</a>
35
  <a href="?page=wp-google-analytics-events-scroll" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-scroll' ? 'nav-tab-active' : ''; ?>">Scroll Tracking</a>
@@ -37,33 +37,33 @@ function ga_events_settings_page() {
37
  <a href="?page=wp-google-analytics-events-whatsnew&wpgae_whatsnew_notify=1" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-whatsnew' ? 'nav-tab-active' : ''; ?>"><i class="fa fa-question-circle ga-events-help"></i> What's New</a>
38
  </h2>
39
  <?php
40
- if ($active_page == 'wp-google-analytics-events-started') {
41
  do_settings_sections('ga_events_started');
42
 
43
- }
44
- else if ($active_page == 'wp-google-analytics-events-whatsnew') {
45
- do_settings_sections('ga_events_whatsnew');
46
- }
47
- else {
48
  ?>
49
 
50
  <form id="ga-events-settings-form" method="post" action='options.php'>
51
  <?php settings_fields('ga_events_options'); ?>
52
  <?php
53
- $show_sidebar = true;
54
- if ($active_page == 'wp-google-analytics-events-click') {
55
- do_settings_sections('ga_events_click');
56
- } else if ($active_page == 'wp-google-analytics-events-scroll') {
57
- do_settings_sections('ga_events_scroll');
58
- }else {
59
- do_settings_sections('ga_events');
60
- }
61
  ?>
62
 
63
  <?php
64
  if ($active_page == 'wp-google-analytics-events') {
65
- ?>
66
- <input class="button-primary" type="submit" name="submit" value="Save Changes" />
67
  <?php
68
  }
69
  ?>
@@ -76,53 +76,53 @@ function ga_events_settings_page() {
76
  </form>
77
  </div>
78
  </div>
79
- <?php
80
- if ($show_sidebar) {
81
  ?>
82
- <div class="wrap ga_events_sidebar">
83
  <table class="form-table widefat" >
84
  <thead>
85
- <th>Need More Features?</th>
86
  </thead>
87
  <tbody>
88
- <tr class="features">
89
- <td>
90
- <ul>
91
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Link Tracking</strong></li>
92
- <li title="Dynamic Event Data"><i class="fa fa-check-square-o fa-lg"></i><strong>Placeholders</strong></li>
93
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>YouTube Video Tracking</strong></li>
94
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Vimeo Video support</strong></li>
95
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Set Value for Events</strong></li>
96
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>HTML Tag support</strong></li>
97
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Pro Support</strong></li>
98
- </ul>
99
- </td>
100
- </tr>
101
- <tr class="tfoot">
102
- <td>
103
- <div class="wpcta">
104
- <a class="button-primary button-large" target="_blank" href="https://wpflow.com/upgrade?utm_source=wpadm&utm_medium=banner&utm_content=side&utm_campaign=wpadmin">
105
  <span class="btn-title ">
106
  Upgrade Now
107
  </span>
108
- </a>
109
- </div>
110
- </td>
111
- </tr>
112
  </tbody>
113
  </table>
114
 
115
  </div>
116
- <?php }
117
- ?>
118
- </div> <!-- END #ga_mainwrap ->
119
  <?php
120
- } ?>
121
 
122
 
123
  <?php
124
 
125
- echo "<script>
126
  jQuery('.remove').click(function (event) {
127
  event.preventDefault();
128
  jQuery(this).closest('tr').remove();
@@ -140,10 +140,10 @@ function load_custom_wp_admin_style() {
140
  wp_enqueue_style( 'custom_wp_admin_css' );
141
 
142
  $params = array(
143
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
144
- 'advaced' => $advanced,
145
- 'ajaxnonce' => wp_create_nonce('wpgae_nonce_CRX0XDPfqe5dd3P')
146
- );
147
  wp_register_script( 'wpgae-ajax', plugins_url('js/ajax.js', dirname(__FILE__)) , array('jquery') );
148
  wp_localize_script( 'wpgae-ajax', 'wpgae_ajax', $params);
149
 
@@ -155,15 +155,15 @@ add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
155
  add_action('admin_init', 'ga_events_admin_init');
156
 
157
  function ga_events_admin_init() {
158
- if(isset($_GET['download']) && isset($_GET['page'])){
159
- if ($_GET['page'] == 'wp-google-analytics-events') {
160
- ga_events_file();
161
- }
162
  }
 
163
 
164
- if(isset($_POST['set_settings'])){
165
- ga_events_upload_settings($_FILES);
166
- }
167
 
168
 
169
  register_setting('ga_events_options','ga_events_options','ga_events_validate');
@@ -193,7 +193,7 @@ function ga_events_section_text() {
193
  }
194
 
195
  function ga_events_whatsnew_section_content() {
196
- ob_start(); ?>
197
  <div class="wpgae-container wpgae-container__warning">
198
  <h3><span class="dashicons dashicons-flag"></span> What's New (3)</h3>
199
  <div id="wpgae-warnings">
@@ -213,7 +213,7 @@ function ga_events_whatsnew_section_content() {
213
  <div class="wpgae-alert">
214
  <p>We added support for the <strong>Google Tag Manager</strong>.
215
  <br>This feature requires some preparation on the Google Tag Manager side so make sure to <a target="_blank" href="https://wpflow.com/knowledgebase/google-tag-manager-support/">check out the video guide</a>.</p>
216
- </div>
217
  </div>
218
  </div>
219
  <div class="container" id="wpgae-warnings-dismissed">
@@ -221,8 +221,8 @@ function ga_events_whatsnew_section_content() {
221
  </div>
222
  </div>
223
  <?php
224
- $content = ob_get_clean();
225
- echo $content;
226
  }
227
 
228
  function ga_events_setting_started() {
@@ -299,36 +299,36 @@ function ga_events_setting_adv_input() {
299
  $id = $options['advanced'];
300
  echo "<label>Advanced Mode ".ga_tooltip('Enable Advanced Selectors')."</label>";
301
  echo "<span class='ga_intable'><input id='advanced' name='ga_events_options[advanced]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
302
- }
303
 
304
  function ga_events_settings_download(){
305
- echo '<a class="button" href="http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] .'&download=1">Export settings</a>';
306
  }
307
 
308
  function ga_events_settings_upload(){
309
- echo '<a href="#" class="button btn_upload">Import settings</a>';
310
  }
311
 
312
  function ga_events_setting_divs_input() {
313
  $options = get_option('ga_events_options');
314
  $divs= $options['divs'];
315
-
316
  $menu_options = array(
317
- 'id' => 'id',
318
- 'class' => 'class',
319
- );
320
-
321
  if(is_advanced_mode()){
322
  $menu_options['advanced'] = 'advanced'; // if enabled, add 'avanced' on the menu
323
  }
324
-
325
  $type='divs';
326
-
327
  echo "<table id='ga-events-inputs' class='widefat inputs inner_table divs_table' data-name='divs'><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th>Event Value</th><th>Non-Interaction</th><th></th></thead><tbody>";
328
- if (!($divs[0][0])){
329
- $name = "ga_events_options[$type][0][1]";
330
  $type_menu = createDropdown($name, $type, $menu_options,'id');
331
-
332
  echo "<tr>";
333
  echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][0][0]' type='text' value='".$divs[0][0]."' /></td>";
334
  echo "<td data-title='Type'>$type_menu</td>";
@@ -349,31 +349,31 @@ function ga_events_setting_divs_input() {
349
 
350
  }else{
351
  for ($i = 0; $i < sizeof($divs)+1; $i++){
352
- $name = "ga_events_options[$type][$i][1]";
353
- $selected = $divs[$i][1];
354
- $type_menu = createDropdown($name, $type, $menu_options, $selected);
355
- echo "<tr>";
356
- echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][$i][0] type='text' value='".$divs[$i][0]."' /></td>";
357
- echo "<td data-title='Type'>$type_menu</td>";
358
- echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][$i][2]' type='text' value='".$divs[$i][2]."' /></td>";
359
- echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][$i][3]' type='text' value='".$divs[$i][3]."' /></td>";
360
- echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][$i][4]' type='text' value='".$divs[$i][4]."' /></td>";
361
- echo "<td data-title='Event Value'><input id='click' name='ga_events_options[divs][$i][6]' type='number' value='".$divs[$i][6]."' /></td>";
362
- echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
363
- if ($divs[$i][5] == 'true') {
364
- echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
365
- } else {
366
- echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
367
- }
368
-
369
- if($divs[$i][0]){
370
- echo "<td><a class='btn-update' href=''><i class='fa fa-floppy-o' title='Update' aria-hidden='true'></i></a></td>";
371
- echo "<td><a class='btn-remove' href=''><i class='fa fa-times' title='Remove' aria-hidden='true'></i></a></td>";
372
- }else{
373
- echo "<td><a class='btn-add' href='#'>Add</a></td>";
374
- }
375
-
376
- echo "</tr>";
377
 
378
  }
379
 
@@ -388,22 +388,22 @@ function ga_events_setting_click_input() {
388
  $divs= $options['click'];
389
 
390
  $menu_options = array(
391
- 'id' => 'id',
392
- 'class' => 'class',
393
- );
394
-
395
  if(is_advanced_mode()){
396
  $menu_options['advanced'] = 'advanced'; // if enabled, add 'avanced' on the menu
397
- }
398
 
399
  $type='click';
400
-
401
-
402
  echo "<table id='ga-events-inputs' class='widefat inputs inner_table click_table' data-name='click'><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th>Event Value</th><th>Non-Interaction</th><th></th></thead><tbody>";
403
- if (!($click[0][0])){
404
- $name = "ga_events_options[click][0][1]";
405
  $type_menu = createDropdown($name, $type, $menu_options,'id');
406
-
407
  echo "<tr>";
408
  echo "<td data-title='Element Name'><input id='click' name='ga_events_options[click][0][0]' type='text' value='".$click[0][0]."' /></td>";
409
  echo "<td data-title='Type'>$type_menu</td>";
@@ -426,36 +426,36 @@ function ga_events_setting_click_input() {
426
 
427
  }else{
428
  for ($i = 0; $i < sizeof($click)+1; $i++){
429
- $name = "ga_events_options[click][$i][1]";
430
- $selected = $click[$i][1];
431
- $type_menu = createDropdown($name, $type, $menu_options, $selected);
432
-
433
- echo "<tr>";
434
- echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[click][$i][0] type='text' value='".$click[$i][0]."' /></td>";
435
- echo "<td data-title='Type'>$type_menu</td>";
436
- echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][$i][2] type='text' value='".$click[$i][2]."' /></td>";
437
- echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][$i][3] type='text' value='".$click[$i][3]."' /></td>";
438
- echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][$i][4] type='text' value='".$click[$i][4]."' /></td>";
439
-
440
- echo "<td data-title='Event Value'><input id='click' name='ga_events_options[click][$i][6]' type='number' value='".$click[$i][6]."' /></td>";
441
-
442
- echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
443
- if ($divs[$i][5] == 'true') {
444
- echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
445
- }
446
- else {
447
- echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
448
- }
449
-
450
-
451
- if($click[$i][0]){
452
- echo "<td><a class='btn-update' href=''><i class='fa fa-floppy-o' title='Update' aria-hidden='true'></i></a></td>";
453
- echo "<td><a class='btn-remove' href=''><i class='fa fa-times' title='Remove' aria-hidden='true'></i></a></td>";
454
- }else{
455
- echo "<td><a class='btn-add' href='#'>Add</a></td>";
456
- }
457
-
458
- echo "</tr>";
459
 
460
  }
461
 
@@ -469,7 +469,7 @@ function ga_events_setting_sidebar(){
469
  }
470
 
471
  function ga_events_validate($form){
472
-
473
  $options = get_option('ga_events_options');
474
  $updated = $options;
475
 
@@ -483,11 +483,11 @@ function ga_events_validate($form){
483
  $j++;
484
  }
485
  }
486
- }
487
  else if(array_key_exists('click', $form)) {
488
  $updated['click'] = array();
489
  $clickFields = array_values($form['click']); //force array index to start with 0
490
- for ($i = 0, $j = 0; $i< sizeof($clickFields); $i++){
491
  if ($clickFields[$i][0]){
492
  $updated['click'][$j] = cleanEventFeilds($clickFields[$i]);
493
  $j++;
@@ -510,7 +510,7 @@ function ga_events_validate($form){
510
  add_action('admin_footer', 'ga_events_admin_footer');
511
 
512
  function ga_events_admin_footer() {
513
- ?>
514
  <script>
515
  jQuery('body').on('click','a[href="admin.php?page=wp-google-analytics-events-upgrade"]', function (e) {
516
  e.preventDefault();
@@ -522,31 +522,31 @@ function ga_events_admin_footer() {
522
 
523
 
524
  function ga_events_get_settings(){
525
- $options = get_option('ga_events_options');
526
- $current = json_encode($options);
527
- return $current;
528
  }
529
 
530
  function ga_events_upload_settings($file){
531
- $uploadedfile = $file['settings'];
532
- if($uploadedfile['type'] != 'application/octet-stream'){
533
- ga_event_popup();
534
- return;
535
- }
536
- $content = file_get_contents($uploadedfile["tmp_name"]);
537
- ga_event_get_content($content);
538
  }
539
 
540
  function ga_event_get_content($content){
541
- if(!$current = json_decode($content,true)){
542
- ga_event_popup();
543
- return;
544
- }
545
- if (!array_key_exists('id', $current) && !array_key_exists('domain', $current)) {
546
- ga_event_popup();
547
- return;
548
- }
549
- update_option( 'ga_events_options', $current );
550
 
551
  }
552
  function ga_event_popup(){
@@ -567,7 +567,7 @@ function cleanEventFeilds($arr) {
567
  }else{
568
  $arr[0] = str_replace("'","",$arr[0]);
569
  }
570
-
571
  for ($i = 1; $i < sizeof($arr); $i++) {
572
  $arr[$i] = esc_html($arr[$i]);
573
  }
@@ -575,15 +575,13 @@ function cleanEventFeilds($arr) {
575
  }
576
 
577
  function cleanAjaxFeilds($data) {
578
- //doLog( print_r( $data, true) );
579
  $newData = array();
580
 
581
  foreach( $data as $key => $value ) {
582
 
583
- $newData[$key] = htmlspecialchars( stripslashes($value) ,ENT_QUOTES, 'UTF-8');
584
- }
585
 
586
- doLog( print_r( $newData, true) );
587
  return $newData;
588
  }
589
 
19
 
20
  function ga_events_settings_page() {
21
 
22
+ ?>
23
+ <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
24
+ <div id="ga_mainwrap">
25
  <div id="ga_main" class="wrap">
26
  <?php screen_icon( 'plugins' ); ?>
27
+ <h2>GA Scroll Events Plugin</h2>
28
 
29
+ <?php
30
+ $active_page = isset( $_GET[ 'page' ] ) ? $_GET[ 'page' ] : 'wp-google-analytics-events';
31
+ ?>
32
+ <h2 class="nav-tab-wrapper">
33
  <a href="?page=wp-google-analytics-events" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events' ? 'nav-tab-active' : ''; ?>">General Settings</a>
34
  <a href="?page=wp-google-analytics-events-click" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-click' ? 'nav-tab-active' : ''; ?>">Click Tracking</a>
35
  <a href="?page=wp-google-analytics-events-scroll" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-scroll' ? 'nav-tab-active' : ''; ?>">Scroll Tracking</a>
37
  <a href="?page=wp-google-analytics-events-whatsnew&wpgae_whatsnew_notify=1" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-whatsnew' ? 'nav-tab-active' : ''; ?>"><i class="fa fa-question-circle ga-events-help"></i> What's New</a>
38
  </h2>
39
  <?php
40
+ if ($active_page == 'wp-google-analytics-events-started') {
41
  do_settings_sections('ga_events_started');
42
 
43
+ }
44
+ else if ($active_page == 'wp-google-analytics-events-whatsnew') {
45
+ do_settings_sections('ga_events_whatsnew');
46
+ }
47
+ else {
48
  ?>
49
 
50
  <form id="ga-events-settings-form" method="post" action='options.php'>
51
  <?php settings_fields('ga_events_options'); ?>
52
  <?php
53
+ $show_sidebar = true;
54
+ if ($active_page == 'wp-google-analytics-events-click') {
55
+ do_settings_sections('ga_events_click');
56
+ } else if ($active_page == 'wp-google-analytics-events-scroll') {
57
+ do_settings_sections('ga_events_scroll');
58
+ }else {
59
+ do_settings_sections('ga_events');
60
+ }
61
  ?>
62
 
63
  <?php
64
  if ($active_page == 'wp-google-analytics-events') {
65
+ ?>
66
+ <input class="button-primary" type="submit" name="submit" value="Save Changes" />
67
  <?php
68
  }
69
  ?>
76
  </form>
77
  </div>
78
  </div>
79
+ <?php
80
+ if ($show_sidebar) {
81
  ?>
82
+ <div class="wrap ga_events_sidebar">
83
  <table class="form-table widefat" >
84
  <thead>
85
+ <th>Need More Features?</th>
86
  </thead>
87
  <tbody>
88
+ <tr class="features">
89
+ <td>
90
+ <ul>
91
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>Link Tracking</strong></li>
92
+ <li title="Dynamic Event Data"><i class="fa fa-check-square-o fa-lg"></i><strong>Placeholders</strong></li>
93
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>YouTube Video Tracking</strong></li>
94
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>Vimeo Video support</strong></li>
95
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>Set Value for Events</strong></li>
96
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>HTML Tag support</strong></li>
97
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>Pro Support</strong></li>
98
+ </ul>
99
+ </td>
100
+ </tr>
101
+ <tr class="tfoot">
102
+ <td>
103
+ <div class="wpcta">
104
+ <a class="button-primary button-large" target="_blank" href="https://wpflow.com/upgrade?utm_source=wpadm&utm_medium=banner&utm_content=side&utm_campaign=wpadmin">
105
  <span class="btn-title ">
106
  Upgrade Now
107
  </span>
108
+ </a>
109
+ </div>
110
+ </td>
111
+ </tr>
112
  </tbody>
113
  </table>
114
 
115
  </div>
116
+ <?php }
117
+ ?>
118
+ </div> <!-- END #ga_mainwrap ->
119
  <?php
120
+ } ?>
121
 
122
 
123
  <?php
124
 
125
+ echo "<script>
126
  jQuery('.remove').click(function (event) {
127
  event.preventDefault();
128
  jQuery(this).closest('tr').remove();
140
  wp_enqueue_style( 'custom_wp_admin_css' );
141
 
142
  $params = array(
143
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
144
+ 'advaced' => $advanced,
145
+ 'ajaxnonce' => wp_create_nonce('wpgae_nonce_CRX0XDPfqe5dd3P')
146
+ );
147
  wp_register_script( 'wpgae-ajax', plugins_url('js/ajax.js', dirname(__FILE__)) , array('jquery') );
148
  wp_localize_script( 'wpgae-ajax', 'wpgae_ajax', $params);
149
 
155
  add_action('admin_init', 'ga_events_admin_init');
156
 
157
  function ga_events_admin_init() {
158
+ if(isset($_GET['download']) && isset($_GET['page'])){
159
+ if ($_GET['page'] == 'wp-google-analytics-events') {
160
+ ga_events_file();
 
161
  }
162
+ }
163
 
164
+ if(isset($_POST['set_settings'])){
165
+ ga_events_upload_settings($_FILES);
166
+ }
167
 
168
 
169
  register_setting('ga_events_options','ga_events_options','ga_events_validate');
193
  }
194
 
195
  function ga_events_whatsnew_section_content() {
196
+ ob_start(); ?>
197
  <div class="wpgae-container wpgae-container__warning">
198
  <h3><span class="dashicons dashicons-flag"></span> What's New (3)</h3>
199
  <div id="wpgae-warnings">
213
  <div class="wpgae-alert">
214
  <p>We added support for the <strong>Google Tag Manager</strong>.
215
  <br>This feature requires some preparation on the Google Tag Manager side so make sure to <a target="_blank" href="https://wpflow.com/knowledgebase/google-tag-manager-support/">check out the video guide</a>.</p>
216
+ </div>
217
  </div>
218
  </div>
219
  <div class="container" id="wpgae-warnings-dismissed">
221
  </div>
222
  </div>
223
  <?php
224
+ $content = ob_get_clean();
225
+ echo $content;
226
  }
227
 
228
  function ga_events_setting_started() {
299
  $id = $options['advanced'];
300
  echo "<label>Advanced Mode ".ga_tooltip('Enable Advanced Selectors')."</label>";
301
  echo "<span class='ga_intable'><input id='advanced' name='ga_events_options[advanced]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
302
+ }
303
 
304
  function ga_events_settings_download(){
305
+ echo '<a class="button" href="http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] .'&download=1">Export settings</a>';
306
  }
307
 
308
  function ga_events_settings_upload(){
309
+ echo '<a href="#" class="button btn_upload">Import settings</a>';
310
  }
311
 
312
  function ga_events_setting_divs_input() {
313
  $options = get_option('ga_events_options');
314
  $divs= $options['divs'];
315
+
316
  $menu_options = array(
317
+ 'id' => 'id',
318
+ 'class' => 'class',
319
+ );
320
+
321
  if(is_advanced_mode()){
322
  $menu_options['advanced'] = 'advanced'; // if enabled, add 'avanced' on the menu
323
  }
324
+
325
  $type='divs';
326
+
327
  echo "<table id='ga-events-inputs' class='widefat inputs inner_table divs_table' data-name='divs'><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th>Event Value</th><th>Non-Interaction</th><th></th></thead><tbody>";
328
+ if (!($divs[0][0]) && !($divs[0][1])){
329
+ $name = "ga_events_options[$type][0][1]";
330
  $type_menu = createDropdown($name, $type, $menu_options,'id');
331
+
332
  echo "<tr>";
333
  echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][0][0]' type='text' value='".$divs[0][0]."' /></td>";
334
  echo "<td data-title='Type'>$type_menu</td>";
349
 
350
  }else{
351
  for ($i = 0; $i < sizeof($divs)+1; $i++){
352
+ $name = "ga_events_options[$type][$i][1]";
353
+ $selected = $divs[$i][1];
354
+ $type_menu = createDropdown($name, $type, $menu_options, $selected);
355
+ echo "<tr>";
356
+ echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][$i][0] type='text' value='".$divs[$i][0]."' /></td>";
357
+ echo "<td data-title='Type'>$type_menu</td>";
358
+ echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][$i][2]' type='text' value='".$divs[$i][2]."' /></td>";
359
+ echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][$i][3]' type='text' value='".$divs[$i][3]."' /></td>";
360
+ echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][$i][4]' type='text' value='".$divs[$i][4]."' /></td>";
361
+ echo "<td data-title='Event Value'><input id='click' name='ga_events_options[divs][$i][6]' type='number' value='".$divs[$i][6]."' /></td>";
362
+ echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
363
+ if ($divs[$i][5] == 'true') {
364
+ echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
365
+ } else {
366
+ echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
367
+ }
368
+
369
+ if($divs[$i][0] || $divs[$i][1]){
370
+ echo "<td><a class='btn-update' href=''><i class='fa fa-floppy-o' title='Update' aria-hidden='true'></i></a></td>";
371
+ echo "<td><a class='btn-remove' href=''><i class='fa fa-times' title='Remove' aria-hidden='true'></i></a></td>";
372
+ }else{
373
+ echo "<td><a class='btn-add' href='#'>Add</a></td>";
374
+ }
375
+
376
+ echo "</tr>";
377
 
378
  }
379
 
388
  $divs= $options['click'];
389
 
390
  $menu_options = array(
391
+ 'id' => 'id',
392
+ 'class' => 'class',
393
+ );
394
+
395
  if(is_advanced_mode()){
396
  $menu_options['advanced'] = 'advanced'; // if enabled, add 'avanced' on the menu
397
+ }
398
 
399
  $type='click';
400
+
401
+
402
  echo "<table id='ga-events-inputs' class='widefat inputs inner_table click_table' data-name='click'><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th>Event Value</th><th>Non-Interaction</th><th></th></thead><tbody>";
403
+ if (!($click[0][0]) && !($click[0][1])){
404
+ $name = "ga_events_options[click][0][1]";
405
  $type_menu = createDropdown($name, $type, $menu_options,'id');
406
+
407
  echo "<tr>";
408
  echo "<td data-title='Element Name'><input id='click' name='ga_events_options[click][0][0]' type='text' value='".$click[0][0]."' /></td>";
409
  echo "<td data-title='Type'>$type_menu</td>";
426
 
427
  }else{
428
  for ($i = 0; $i < sizeof($click)+1; $i++){
429
+ $name = "ga_events_options[click][$i][1]";
430
+ $selected = $click[$i][1];
431
+ $type_menu = createDropdown($name, $type, $menu_options, $selected);
432
+
433
+ echo "<tr>";
434
+ echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[click][$i][0] type='text' value='".$click[$i][0]."' /></td>";
435
+ echo "<td data-title='Type'>$type_menu</td>";
436
+ echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][$i][2] type='text' value='".$click[$i][2]."' /></td>";
437
+ echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][$i][3] type='text' value='".$click[$i][3]."' /></td>";
438
+ echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][$i][4] type='text' value='".$click[$i][4]."' /></td>";
439
+
440
+ echo "<td data-title='Event Value'><input id='click' name='ga_events_options[click][$i][6]' type='number' value='".$click[$i][6]."' /></td>";
441
+
442
+ echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
443
+ if ($divs[$i][5] == 'true') {
444
+ echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
445
+ }
446
+ else {
447
+ echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
448
+ }
449
+
450
+
451
+ if($click[$i][0] || $click[$i][1]){
452
+ echo "<td><a class='btn-update' href=''><i class='fa fa-floppy-o' title='Update' aria-hidden='true'></i></a></td>";
453
+ echo "<td><a class='btn-remove' href=''><i class='fa fa-times' title='Remove' aria-hidden='true'></i></a></td>";
454
+ }else{
455
+ echo "<td><a class='btn-add' href='#'>Add</a></td>";
456
+ }
457
+
458
+ echo "</tr>";
459
 
460
  }
461
 
469
  }
470
 
471
  function ga_events_validate($form){
472
+
473
  $options = get_option('ga_events_options');
474
  $updated = $options;
475
 
483
  $j++;
484
  }
485
  }
486
+ }
487
  else if(array_key_exists('click', $form)) {
488
  $updated['click'] = array();
489
  $clickFields = array_values($form['click']); //force array index to start with 0
490
+ for ($i = 0, $j = 0; $i< sizeof($clickFields); $i++){
491
  if ($clickFields[$i][0]){
492
  $updated['click'][$j] = cleanEventFeilds($clickFields[$i]);
493
  $j++;
510
  add_action('admin_footer', 'ga_events_admin_footer');
511
 
512
  function ga_events_admin_footer() {
513
+ ?>
514
  <script>
515
  jQuery('body').on('click','a[href="admin.php?page=wp-google-analytics-events-upgrade"]', function (e) {
516
  e.preventDefault();
522
 
523
 
524
  function ga_events_get_settings(){
525
+ $options = get_option('ga_events_options');
526
+ $current = json_encode($options);
527
+ return $current;
528
  }
529
 
530
  function ga_events_upload_settings($file){
531
+ $uploadedfile = $file['settings'];
532
+ if($uploadedfile['type'] != 'application/octet-stream'){
533
+ ga_event_popup();
534
+ return;
535
+ }
536
+ $content = file_get_contents($uploadedfile["tmp_name"]);
537
+ ga_event_get_content($content);
538
  }
539
 
540
  function ga_event_get_content($content){
541
+ if(!$current = json_decode($content,true)){
542
+ ga_event_popup();
543
+ return;
544
+ }
545
+ if (!array_key_exists('id', $current) && !array_key_exists('domain', $current)) {
546
+ ga_event_popup();
547
+ return;
548
+ }
549
+ update_option( 'ga_events_options', $current );
550
 
551
  }
552
  function ga_event_popup(){
567
  }else{
568
  $arr[0] = str_replace("'","",$arr[0]);
569
  }
570
+
571
  for ($i = 1; $i < sizeof($arr); $i++) {
572
  $arr[$i] = esc_html($arr[$i]);
573
  }
575
  }
576
 
577
  function cleanAjaxFeilds($data) {
 
578
  $newData = array();
579
 
580
  foreach( $data as $key => $value ) {
581
 
582
+ $newData[$key] = htmlspecialchars( stripslashes($value) ,ENT_QUOTES, 'UTF-8');
583
+ }
584
 
 
585
  return $newData;
586
  }
587
 
includes/functions.php CHANGED
@@ -3,24 +3,24 @@
3
  add_action("wp_ajax_add_wpgae_event", "add_wpgae_event_action");
4
 
5
  function add_wpgae_event_action() {
6
-
7
- check_ajax_referer( 'wpgae_nonce_CRX0XDPfqe5dd3P', 'security' );
8
-
9
- $response = array();
10
- $response['success'] = false;
11
-
12
- $event = strtolower ( sanitize_text_field( $_POST['event'] ) );
13
-
14
- $input = stripslashes($_POST['input']);
15
- $decoded = json_decode($input);
16
-
17
- if( isValidEvent($event) ) {
18
- $response = ajax_add($event, $decoded);
19
- }
20
-
21
-
22
- echo json_encode($response);
23
- die();
24
  }
25
 
26
  /*
@@ -34,181 +34,179 @@ function add_wpgae_event_action() {
34
  array
35
  */
36
  function ajax_add($event, $data){
37
-
38
- $options = get_option('ga_events_options');
39
- doLog(print_r($options, true));
40
- $response = array();
41
-
42
- $cleanData = cleanAjaxFeilds($data);
43
- $newEntry = extractEventData($event, $cleanData);
44
-
45
- if (!isset($options[$event])) {
46
- $options[$event] = array();
47
- }
48
-
49
- array_push($options[$event], $newEntry);
50
-
51
- doLog("After: ".print_r($options, true));
52
-
53
-
54
- //Remove sanitizing for adding
55
- remove_filter( "sanitize_option_ga_events_options", "ga_events_validate" );
56
-
57
- $response['success'] = update_option( 'ga_events_options', $options );
58
- //doLog (print_r($options,true));
59
- return $response;
60
  }
61
 
62
 
63
  add_action("wp_ajax_update_wpgae_event", "update_wpgae_event_action");
64
 
65
  function update_wpgae_event_action() {
66
-
67
- check_ajax_referer( 'wpgae_nonce_CRX0XDPfqe5dd3P', 'security' );
68
-
69
- $response = array();
70
- $response['success'] = false;
71
-
72
- $event = strtolower ( sanitize_text_field( $_POST['event'] ) );
73
-
74
- $index = intval( $_POST['index'] );
75
-
76
- //index should not be null or empty and non-negative, 0 should be treated as int and not boolean false
77
- if ( ( !$index && $index != 0 ) || $index < 0 ) {
78
- $event = 'INVALID';
79
- }
80
-
81
- $input = stripslashes($_POST['input']);
82
- $decoded = json_decode($input);
83
-
84
- if( isValidEvent($event) ) {
85
- $response = ajax_update($event, $index, $decoded);
86
- }
87
-
88
- echo json_encode($response);
89
- die();
90
  }
91
 
92
  function ajax_update($event, $index, $data){
93
 
94
- $options = get_option('ga_events_options');
95
- $response = array();
96
- $cleanData = cleanAjaxFeilds($data);
97
- $newEvent = extractEventData($event, $cleanData);
98
 
99
- $options[$event][$index] = $newEvent;
100
 
101
- //Remove sanitizing for updating
102
- remove_filter( "sanitize_option_ga_events_options", "ga_events_validate" );
103
 
104
- $response['success'] = update_option( 'ga_events_options', $options );
105
- return $response;
106
  }
107
 
108
  add_action("wp_ajax_remove_wpgae_event", "remove_wpgae_event_action");
109
  function remove_wpgae_event_action() {
110
-
111
- check_ajax_referer( 'wpgae_nonce_CRX0XDPfqe5dd3P', 'security' );
112
-
113
- $response = array();
114
- $response['success'] = false;
115
- $event = strtolower ( sanitize_text_field( $_POST['event'] ) );
116
- $index = intval( $_POST['index'] );
117
-
118
- //index should not be null and non-negative, 0 should be treated as int and not boolean false
119
- if ( ( !$index && $index != 0 ) || $index < 0 ) {
120
- $event = 'INVALID';
121
- }
122
-
123
- doLog($index);
124
-
125
- if( isValidEvent($event) ) {
126
- $response = ajax_remove($event,$index);
127
- }
128
-
129
- echo json_encode($response);
130
- die();
131
  }
132
 
133
  function ajax_remove($event, $index){
134
- $options = get_option('ga_events_options');
135
- $response = array();
136
 
137
 
138
- unset($options[$event][$index]);
139
- $options[$event] = array_values(array_filter($options[$event])); //re-index array
140
 
141
- //Remove sanitizing for adding
142
- remove_filter( "sanitize_option_ga_events_options", "ga_events_validate" );
143
 
144
- $response['success'] = update_option( 'ga_events_options', $options );
145
- return $response;
146
  }
147
 
148
  function isValidEvent($input){
149
-
150
- $valid = array('click','divs','youtube','vimeo');
151
-
152
- return in_array($input, $valid);
153
  }
154
 
155
  function extractEventData($event, $data){
156
-
157
- $extracted = array();
158
- switch ($event) {
159
- case 'click':
160
- $extracted = [
161
- $data['name'],
162
- $data['type'],
163
- $data['category'],
164
- $data['action'],
165
- $data['label'],
166
- $data['interaction'],
167
- $data['value']
168
- ];
169
- break;
170
- case 'divs':
171
- $extracted = [
172
- $data['name'],
173
- $data['type'],
174
- $data['category'],
175
- $data['action'],
176
- $data['label'],
177
- $data['interaction'],
178
- $data['value'],
179
- // $data['tracktime'],
180
- //$data['time']
181
-
182
- ];
183
- break;
184
- case 'youtube':
185
- $extracted = [
186
- 'title' => $data['title'],
187
- 'id' => $data['id'],
188
- 'id_type' => $data['type'],
189
- 'play' => $data['play'],
190
- 'pause' => $data['pause'],
191
- 'end' => $data['end'],
192
- 'quality' => $data['quality']
193
- ];
194
- break;
195
- case 'vimeo':
196
- $extracted = [
197
- 'title' => $data['title'],
198
- 'id' => $data['id'],
199
- 'id_type' => $data['type'],
200
- 'play' => $data['play'],
201
- 'pause' => $data['pause'],
202
- 'end' => $data['end'],
203
- 'skip' => $data['skip']
204
- ];
205
- break;
206
-
207
- default:
208
- // do nothing
209
- break;
210
- }
211
- return $extracted;
212
  }
213
 
214
  function doLog($text){
@@ -221,67 +219,67 @@ function doLog($text){
221
 
222
 
223
  function migrateOptions() {
224
- $current_options = get_option('ga_events_options');
225
- $new_options = array();
226
- $new_options['id'] = $current_options['id'];
227
- $new_options['exclude_snippet'] = $current_options['exclude_snippet'];
228
- $new_options['universal'] = $current_options['universal'];
229
- $new_options['events'] = array();
230
- for ($i=0; $i < sizeof($current_options['divs']); $i++) {
231
- $current_option = $current_options['divs'][$i];
232
- $event = new Event('scroll', $current_option[0], $current_option[1], $current_option[2], $current_option[3], $current_option[4]);
233
- array_push($new_options['events'], $event->getEventArray() );
234
- }
235
-
236
- for ($i=0; $i < sizeof($current_options['click']); $i++) {
237
- $current_option = $current_options['click'][$i];
238
- $event = new Event('click', $current_option[0], $current_option[1], $current_option[2], $current_option[3], $current_option[4]);
239
- array_push($new_options['events'], $event->getEventArray() );
240
- }
241
-
242
- update_option('ga_events_options', $new_options);
243
  // print(var_dump($new_options));
244
  }
245
 
246
 
247
  function isOptionMigrationRequired(){
248
- $current_options = get_option('ga_events_options');
249
- if (array_key_exists('divs', $current_options) || array_key_exists('clicks', $current_options)) {
250
- return true;
251
- }
252
- return false;
253
  }
254
 
255
  function is_advanced_mode(){
256
- $ga_events_options = get_option( 'ga_events_options' );
257
- return $ga_events_options['advanced'];
258
  }
259
 
260
  function is_advanced_type($type){
261
- return 'advanced' == $type;
262
  }
263
 
264
  function createDropdown($name, $id, $options = array(), $selected = 'unknown'){
265
- $html = '';
266
- if(!empty($options)){
267
- $html .= "<select id='$id' name='$name'>";
268
-
269
- if(!in_array($selected, $options)){
270
- // even advanced mode is off, 'avanced' should still be accepted as valid option
271
- if('advanced' == $selected){
272
- $options['advanced'] = 'advanced';
273
- }else{
274
- $selected = reset($options); // set first element's key to be default
275
- }
276
- }
277
-
278
- foreach ($options as $key => $value){
279
- $html .= $selected == $key ? "<option selected value='$key' >$value</option>":"<option value='$key' >$value</option>";
280
- }
281
-
282
- $html .= "</select>";
283
- }
284
- return $html;
285
  }
286
 
287
  ?>
3
  add_action("wp_ajax_add_wpgae_event", "add_wpgae_event_action");
4
 
5
  function add_wpgae_event_action() {
6
+
7
+ check_ajax_referer( 'wpgae_nonce_CRX0XDPfqe5dd3P', 'security' );
8
+
9
+ $response = array();
10
+ $response['success'] = false;
11
+
12
+ $event = strtolower ( sanitize_text_field( $_POST['event'] ) );
13
+
14
+ $input = stripslashes($_POST['input']);
15
+ $decoded = json_decode($input);
16
+
17
+ if( isValidEvent($event) ) {
18
+ $response = ajax_add($event, $decoded);
19
+ }
20
+
21
+
22
+ echo json_encode($response);
23
+ die();
24
  }
25
 
26
  /*
34
  array
35
  */
36
  function ajax_add($event, $data){
37
+
38
+ $options = get_option('ga_events_options');
39
+ $response = array();
40
+
41
+ $cleanData = cleanAjaxFeilds($data);
42
+ $newEntry = extractEventData($event, $cleanData);
43
+
44
+ if (!isset($options[$event])) {
45
+ $options[$event] = array();
46
+ }
47
+
48
+ array_push($options[$event], $newEntry);
49
+ if (sizeof($options[$event][0][0]) == 0 && sizeof($options[$event][0][1]) == 0) {
50
+ array_shift($options[$event]);
51
+ }
52
+
53
+
54
+ //Remove sanitizing for adding
55
+ remove_filter( "sanitize_option_ga_events_options", "ga_events_validate" );
56
+
57
+ $response['success'] = update_option( 'ga_events_options', $options );
58
+
59
+ return $response;
60
  }
61
 
62
 
63
  add_action("wp_ajax_update_wpgae_event", "update_wpgae_event_action");
64
 
65
  function update_wpgae_event_action() {
66
+
67
+ check_ajax_referer( 'wpgae_nonce_CRX0XDPfqe5dd3P', 'security' );
68
+
69
+ $response = array();
70
+ $response['success'] = false;
71
+
72
+ $event = strtolower ( sanitize_text_field( $_POST['event'] ) );
73
+
74
+ $index = intval( $_POST['index'] );
75
+
76
+ //index should not be null or empty and non-negative, 0 should be treated as int and not boolean false
77
+ if ( ( !$index && $index != 0 ) || $index < 0 ) {
78
+ $event = 'INVALID';
79
+ }
80
+
81
+ $input = stripslashes($_POST['input']);
82
+ $decoded = json_decode($input);
83
+
84
+ if( isValidEvent($event) ) {
85
+ $response = ajax_update($event, $index, $decoded);
86
+ }
87
+
88
+ echo json_encode($response);
89
+ die();
90
  }
91
 
92
  function ajax_update($event, $index, $data){
93
 
94
+ $options = get_option('ga_events_options');
95
+ $response = array();
96
+ $cleanData = cleanAjaxFeilds($data);
97
+ $newEvent = extractEventData($event, $cleanData);
98
 
99
+ $options[$event][$index] = $newEvent;
100
 
101
+ //Remove sanitizing for updating
102
+ remove_filter( "sanitize_option_ga_events_options", "ga_events_validate" );
103
 
104
+ $response['success'] = update_option( 'ga_events_options', $options );
105
+ return $response;
106
  }
107
 
108
  add_action("wp_ajax_remove_wpgae_event", "remove_wpgae_event_action");
109
  function remove_wpgae_event_action() {
110
+
111
+ check_ajax_referer( 'wpgae_nonce_CRX0XDPfqe5dd3P', 'security' );
112
+
113
+ $response = array();
114
+ $response['success'] = false;
115
+ $event = strtolower ( sanitize_text_field( $_POST['event'] ) );
116
+ $index = intval( $_POST['index'] );
117
+
118
+ //index should not be null and non-negative, 0 should be treated as int and not boolean false
119
+ if ( ( !$index && $index != 0 ) || $index < 0 ) {
120
+ $event = 'INVALID';
121
+ }
122
+
123
+ if( isValidEvent($event) ) {
124
+ $response = ajax_remove($event,$index);
125
+ }
126
+
127
+ echo json_encode($response);
128
+ die();
 
 
129
  }
130
 
131
  function ajax_remove($event, $index){
132
+ $options = get_option('ga_events_options');
133
+ $response = array();
134
 
135
 
136
+ unset($options[$event][$index]);
137
+ $options[$event] = array_values(array_filter($options[$event])); //re-index array
138
 
139
+ //Remove sanitizing for adding
140
+ remove_filter( "sanitize_option_ga_events_options", "ga_events_validate" );
141
 
142
+ $response['success'] = update_option( 'ga_events_options', $options );
143
+ return $response;
144
  }
145
 
146
  function isValidEvent($input){
147
+
148
+ $valid = array('click','divs','youtube','vimeo');
149
+
150
+ return in_array($input, $valid);
151
  }
152
 
153
  function extractEventData($event, $data){
154
+
155
+ $extracted = array();
156
+ switch ($event) {
157
+ case 'click':
158
+ $extracted = [
159
+ $data['name'],
160
+ $data['type'],
161
+ $data['category'],
162
+ $data['action'],
163
+ $data['label'],
164
+ $data['interaction'],
165
+ $data['value']
166
+ ];
167
+ break;
168
+ case 'divs':
169
+ $extracted = [
170
+ $data['name'],
171
+ $data['type'],
172
+ $data['category'],
173
+ $data['action'],
174
+ $data['label'],
175
+ $data['interaction'],
176
+ $data['value'],
177
+ // $data['tracktime'],
178
+ //$data['time']
179
+
180
+ ];
181
+ break;
182
+ case 'youtube':
183
+ $extracted = [
184
+ 'title' => $data['title'],
185
+ 'id' => $data['id'],
186
+ 'id_type' => $data['type'],
187
+ 'play' => $data['play'],
188
+ 'pause' => $data['pause'],
189
+ 'end' => $data['end'],
190
+ 'quality' => $data['quality']
191
+ ];
192
+ break;
193
+ case 'vimeo':
194
+ $extracted = [
195
+ 'title' => $data['title'],
196
+ 'id' => $data['id'],
197
+ 'id_type' => $data['type'],
198
+ 'play' => $data['play'],
199
+ 'pause' => $data['pause'],
200
+ 'end' => $data['end'],
201
+ 'skip' => $data['skip']
202
+ ];
203
+ break;
204
+
205
+ default:
206
+ // do nothing
207
+ break;
208
+ }
209
+ return $extracted;
210
  }
211
 
212
  function doLog($text){
219
 
220
 
221
  function migrateOptions() {
222
+ $current_options = get_option('ga_events_options');
223
+ $new_options = array();
224
+ $new_options['id'] = $current_options['id'];
225
+ $new_options['exclude_snippet'] = $current_options['exclude_snippet'];
226
+ $new_options['universal'] = $current_options['universal'];
227
+ $new_options['events'] = array();
228
+ for ($i=0; $i < sizeof($current_options['divs']); $i++) {
229
+ $current_option = $current_options['divs'][$i];
230
+ $event = new Event('scroll', $current_option[0], $current_option[1], $current_option[2], $current_option[3], $current_option[4]);
231
+ array_push($new_options['events'], $event->getEventArray() );
232
+ }
233
+
234
+ for ($i=0; $i < sizeof($current_options['click']); $i++) {
235
+ $current_option = $current_options['click'][$i];
236
+ $event = new Event('click', $current_option[0], $current_option[1], $current_option[2], $current_option[3], $current_option[4]);
237
+ array_push($new_options['events'], $event->getEventArray() );
238
+ }
239
+
240
+ update_option('ga_events_options', $new_options);
241
  // print(var_dump($new_options));
242
  }
243
 
244
 
245
  function isOptionMigrationRequired(){
246
+ $current_options = get_option('ga_events_options');
247
+ if (array_key_exists('divs', $current_options) || array_key_exists('clicks', $current_options)) {
248
+ return true;
249
+ }
250
+ return false;
251
  }
252
 
253
  function is_advanced_mode(){
254
+ $ga_events_options = get_option( 'ga_events_options' );
255
+ return $ga_events_options['advanced'];
256
  }
257
 
258
  function is_advanced_type($type){
259
+ return 'advanced' == $type;
260
  }
261
 
262
  function createDropdown($name, $id, $options = array(), $selected = 'unknown'){
263
+ $html = '';
264
+ if(!empty($options)){
265
+ $html .= "<select id='$id' name='$name'>";
266
+
267
+ if(!in_array($selected, $options)){
268
+ // even advanced mode is off, 'avanced' should still be accepted as valid option
269
+ if('advanced' == $selected){
270
+ $options['advanced'] = 'advanced';
271
+ }else{
272
+ $selected = reset($options); // set first element's key to be default
273
+ }
274
+ }
275
+
276
+ foreach ($options as $key => $value){
277
+ $html .= $selected == $key ? "<option selected value='$key' >$value</option>":"<option value='$key' >$value</option>";
278
+ }
279
+
280
+ $html .= "</select>";
281
+ }
282
+ return $html;
283
  }
284
 
285
  ?>
js/ajax.js CHANGED
@@ -1,28 +1,30 @@
1
  jQuery(document).ready( function() {
2
 
3
- function getInputValue(trObj, tdIndex, fieldType, fieldIndex = 0) {
4
-
5
  var fieldObj = trObj.find('td').eq(tdIndex).find(fieldType)[fieldIndex];
6
  if(fieldType === 'input[type="checkbox"]'){
7
-
8
  return fieldObj.checked ? 1:0;
9
-
10
  }
11
  return fieldObj.value;
12
  }
13
 
14
- function getNewRow(event, index, advanced = false) {
 
 
15
  var html = "<tr>"; //start row
16
  switch (event) {
17
  case "click":
18
  html+="<td><input type='text' value=''/></td>";
19
  html+="<td><select>\n\
20
  <option selected value='id'>id</option>\n\
21
- <option value='class'>class</option>";
22
- if(advanced){
23
- html+="<option value='advanced'>advanced</option>";
24
- }
25
- html+="</select></td>";
26
  html+="<td><input type='text' value=''/></td>\n\
27
  <td><input type='text' value=''/></td>\n\
28
  <td><input type='text' value=''/></td>\n\
@@ -30,18 +32,18 @@ jQuery(document).ready( function() {
30
  <td><select id='click'>\n\
31
  <option selected value='true'>true</option>\n\
32
  <option value='false'>false</option>\n\
33
- </select></td>";
34
  break;
35
  case "divs":
36
  html+="<td><input type='text' value=''/></td>";
37
  html+="<td><select>\n\
38
  <option selected value='id'>id</option>\n\
39
- <option value='class'>class</option>";
40
- if(advanced){
41
- html+="<option value='advanced'>advanced</option>";
42
- }
43
- html+="</select></td>";
44
-
45
  html+="<td><input type='text' value=''/></td>\n\
46
  <td><input type='text' value=''/></td>\n\
47
  <td><input type='text' value=''/></td>\n\
@@ -49,16 +51,16 @@ jQuery(document).ready( function() {
49
  <td><select id='divs'>\n\
50
  <option selected value='true'>true</option>\n\
51
  <option value='false'>false</option>\n\
52
- </select></td>";
53
- break;
54
-
55
  default:
56
  break;
57
- }
58
-
59
-
60
- html+="<td><a class='btn-add' href='#'>Add</a></td></tr>"; //end row
61
-
62
  return html;
63
  }
64
 
@@ -94,7 +96,7 @@ jQuery(document).ready( function() {
94
  }
95
 
96
 
97
- jQuery(document).on('click', '.btn-remove', function (event) {
98
  event.preventDefault();
99
  var button = jQuery(this);
100
  var tr = button.closest('tr');
@@ -103,11 +105,10 @@ jQuery(document).ready( function() {
103
  var tblName = table.data('name');
104
 
105
  var index = tr.index();
106
-
107
  var input = getEventData(tr, tblName);
108
-
109
- console.log('Input: ', input);
110
-
111
  jQuery.ajax({
112
  type: "post",
113
  dataType: "json",
@@ -147,7 +148,7 @@ jQuery(document).ready( function() {
147
  data: {
148
  action: 'add_wpgae_event',
149
  security: wpgae_ajax.ajaxnonce,
150
- event: tblName,
151
  input: input
152
  },
153
  success: function (response) {
@@ -161,7 +162,7 @@ jQuery(document).ready( function() {
161
  });
162
  });
163
 
164
- jQuery(document).on('click', '.btn-update', function (event) {
165
  event.preventDefault();
166
  var button = jQuery(this);
167
  var tr = button.closest('tr');
1
  jQuery(document).ready( function() {
2
 
3
+ function getInputValue(trObj, tdIndex, fieldType, fieldIndex) {
4
+ fieldIndex = typeof fieldIndex !== 'undefined' ? fieldIndex : 0;
5
  var fieldObj = trObj.find('td').eq(tdIndex).find(fieldType)[fieldIndex];
6
  if(fieldType === 'input[type="checkbox"]'){
7
+
8
  return fieldObj.checked ? 1:0;
9
+
10
  }
11
  return fieldObj.value;
12
  }
13
 
14
+ function getNewRow(event, index, advanced) {
15
+ advanced = typeof advanced !== 'undefined' ? advanced : 0;
16
+
17
  var html = "<tr>"; //start row
18
  switch (event) {
19
  case "click":
20
  html+="<td><input type='text' value=''/></td>";
21
  html+="<td><select>\n\
22
  <option selected value='id'>id</option>\n\
23
+ <option value='class'>class</option>";
24
+ if(advanced){
25
+ html+="<option value='advanced'>advanced</option>";
26
+ }
27
+ html+="</select></td>";
28
  html+="<td><input type='text' value=''/></td>\n\
29
  <td><input type='text' value=''/></td>\n\
30
  <td><input type='text' value=''/></td>\n\
32
  <td><select id='click'>\n\
33
  <option selected value='true'>true</option>\n\
34
  <option value='false'>false</option>\n\
35
+ </select></td>";
36
  break;
37
  case "divs":
38
  html+="<td><input type='text' value=''/></td>";
39
  html+="<td><select>\n\
40
  <option selected value='id'>id</option>\n\
41
+ <option value='class'>class</option>";
42
+ if(advanced){
43
+ html+="<option value='advanced'>advanced</option>";
44
+ }
45
+ html+="</select></td>";
46
+
47
  html+="<td><input type='text' value=''/></td>\n\
48
  <td><input type='text' value=''/></td>\n\
49
  <td><input type='text' value=''/></td>\n\
51
  <td><select id='divs'>\n\
52
  <option selected value='true'>true</option>\n\
53
  <option value='false'>false</option>\n\
54
+ </select></td>";
55
+ break;
56
+
57
  default:
58
  break;
59
+ }
60
+
61
+
62
+ html+="<td><a class='btn-add' href='#'>Add</a></td></tr>"; //end row
63
+
64
  return html;
65
  }
66
 
96
  }
97
 
98
 
99
+ jQuery(document).on('click', '.btn-remove', function (event) {
100
  event.preventDefault();
101
  var button = jQuery(this);
102
  var tr = button.closest('tr');
105
  var tblName = table.data('name');
106
 
107
  var index = tr.index();
108
+
109
  var input = getEventData(tr, tblName);
110
+
111
+
 
112
  jQuery.ajax({
113
  type: "post",
114
  dataType: "json",
148
  data: {
149
  action: 'add_wpgae_event',
150
  security: wpgae_ajax.ajaxnonce,
151
+ event: tblName,
152
  input: input
153
  },
154
  success: function (response) {
162
  });
163
  });
164
 
165
+ jQuery(document).on('click', '.btn-update', function (event) {
166
  event.preventDefault();
167
  var button = jQuery(this);
168
  var tr = button.closest('tr');
js/ga-scroll-events.js CHANGED
@@ -1,5 +1,5 @@
1
  /*!
2
- * WP Googel Analytics Events | v2.4.2
3
  * Copyright (c) 2013 Yuval Oren (@yuvalo)
4
  * License: GPLv2
5
  */
1
  /*!
2
+ * WP Googel Analytics Events | v2.4.3
3
  * Copyright (c) 2013 Yuval Oren (@yuvalo)
4
  * License: GPLv2
5
  */
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: yuvalo, claconsay
3
  Tags: analytics, google, events, ga, google analytics, tracking
4
  Tested up to: 4.7.5
5
- Stable tag: 2.4.2
6
  License: GPLv2
7
  Requires at least: 3.0
8
 
@@ -41,20 +41,30 @@ If you want to learn more about Event Tracking or how to use this plugin, visit
41
  [Plugin Documentation](http://wpflow.com/documentation/ "Documentation")
42
 
43
 
 
 
 
 
 
 
 
 
 
44
  == Frequently Asked Questions ==
45
 
46
- ## What Is Google Analytics Event Tracking?
47
  Glad you asked, here is our [Complete Introduction to Event Tracking in Google Analytics](https://wpflow.com/what-is-google-analytics-event-tracking/).
48
- ## Where can I see the events in Google Analytics?
 
49
  There are two places that show events in GA -
50
 
51
  1. The real-time dashboard under "events" - An event should show up here in (almost) real-time.
52
  2. The full report can be found under "Behavior" -> "Events". Note that it can take up to 24 hours to show up in this section.
53
 
54
- ## Do I have to write any code to use this plugin?
55
  Don't be silly. This is why we made this plugin. But on a serious note, this could get a little technical so take a look at our [Plugin Documentation](http://wpflow.com/documentation/ "Documentation") page.
56
 
57
- ## What are some examples of using events?
58
  There are many benefits of using events, and you can get very creative:
59
 
60
  1. Setting event-driven goals in Google Analytics
@@ -64,23 +74,15 @@ There are many benefits of using events, and you can get very creative:
64
  5. Tracking contact form submissions
65
  6. Track Links
66
 
67
- ## Can the plugin work along the Google Tag Manager?
68
  Yes, our plugin can work with GTM by using the Data Layer.
69
  Read more about how to set it up in our [Google Tag Manager implementation guide](https://wpflow.com/knowledgebase/google-tag-manager-support/).
70
 
71
- ## I'm stuck and need support
72
  You can always use the support tab to open a ticket.
73
  Please note that while we do our best to answer your questions, we don't check this forum every day.
74
  If you are looking for more in-depth support, we encourage you to check out [WP Google Analytics Events Pro](http://wpflow.com/upgrade/ "Upgrade to WP Google Analytics Events Pro").
75
 
76
- == Installation ==
77
- Add the plugin by uploading the zip file or by installing it from the Wordpress Plugin directory.
78
- Activate the plugin and go to the WP Google Analytics Settings page.
79
- Fill in your Google Analytics account identifier, add scroll and start creating scroll and click events.
80
-
81
- http://www.youtube.com/watch?v=UP8mfuV9huI
82
-
83
- [For more Documentation](http://wpflow.com/documentation/ "Documentation")
84
 
85
  == Screenshots ==
86
  1. Plugin General Settings screenshot-3.png
@@ -88,6 +90,12 @@ http://www.youtube.com/watch?v=UP8mfuV9huI
88
  3. Plugin Scroll Settings screenshot-5.png
89
  2. Google Analytics real time events screenshot-2.png
90
  == Changelog ==
 
 
 
 
 
 
91
  = Version 2.4 =
92
  1. Fix for a permissions problem when clicking the settings button
93
  = Version 2.4 =
2
  Contributors: yuvalo, claconsay
3
  Tags: analytics, google, events, ga, google analytics, tracking
4
  Tested up to: 4.7.5
5
+ Stable tag: 2.4.3
6
  License: GPLv2
7
  Requires at least: 3.0
8
 
41
  [Plugin Documentation](http://wpflow.com/documentation/ "Documentation")
42
 
43
 
44
+ == Installation ==
45
+ Add the plugin by uploading the zip file or by installing it from the Wordpress Plugin directory.
46
+ Activate the plugin and go to the WP Google Analytics Settings page.
47
+ Fill in your Google Analytics account identifier, add scroll and start creating scroll and click events.
48
+
49
+ http://www.youtube.com/watch?v=UP8mfuV9huI
50
+
51
+ [For more Documentation](http://wpflow.com/documentation/ "Documentation")
52
+
53
  == Frequently Asked Questions ==
54
 
55
+ = What Is Google Analytics Event Tracking? =
56
  Glad you asked, here is our [Complete Introduction to Event Tracking in Google Analytics](https://wpflow.com/what-is-google-analytics-event-tracking/).
57
+
58
+ = Where can I see the events in Google Analytics? =
59
  There are two places that show events in GA -
60
 
61
  1. The real-time dashboard under "events" - An event should show up here in (almost) real-time.
62
  2. The full report can be found under "Behavior" -> "Events". Note that it can take up to 24 hours to show up in this section.
63
 
64
+ = Do I have to write any code to use this plugin? =
65
  Don't be silly. This is why we made this plugin. But on a serious note, this could get a little technical so take a look at our [Plugin Documentation](http://wpflow.com/documentation/ "Documentation") page.
66
 
67
+ = What are some examples of using events? =
68
  There are many benefits of using events, and you can get very creative:
69
 
70
  1. Setting event-driven goals in Google Analytics
74
  5. Tracking contact form submissions
75
  6. Track Links
76
 
77
+ = Can the plugin work along the Google Tag Manager? =
78
  Yes, our plugin can work with GTM by using the Data Layer.
79
  Read more about how to set it up in our [Google Tag Manager implementation guide](https://wpflow.com/knowledgebase/google-tag-manager-support/).
80
 
81
+ = I'm stuck and need support =
82
  You can always use the support tab to open a ticket.
83
  Please note that while we do our best to answer your questions, we don't check this forum every day.
84
  If you are looking for more in-depth support, we encourage you to check out [WP Google Analytics Events Pro](http://wpflow.com/upgrade/ "Upgrade to WP Google Analytics Events Pro").
85
 
 
 
 
 
 
 
 
 
86
 
87
  == Screenshots ==
88
  1. Plugin General Settings screenshot-3.png
90
  3. Plugin Scroll Settings screenshot-5.png
91
  2. Google Analytics real time events screenshot-2.png
92
  == Changelog ==
93
+
94
+ = Version 2.4.3 =
95
+ 1. Google Tag Manager Support
96
+ 2. Updated User Interface
97
+ 3. Added the Value field to click and scroll events (used to be a Pro feature)
98
+
99
  = Version 2.4 =
100
  1. Fix for a permissions problem when clicking the settings button
101
  = Version 2.4 =