WP Google Analytics Events - Version 1.9

Version Description

Download this release

Release Info

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

Code changes from version 1.8 to 1.9

Files changed (4) hide show
  1. css/style.css +54 -0
  2. ga-scroll-event.php +25 -22
  3. includes/admin.php +294 -256
  4. readme.txt +3 -1
css/style.css CHANGED
@@ -180,3 +180,57 @@ a.btn_close_popup img {
180
  right: 10px;
181
  top: 11px;
182
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  right: 10px;
181
  top: 11px;
182
  }
183
+
184
+ @media only screen and (max-width: 1440px) {
185
+
186
+ /* Force table to not be like tables anymore */
187
+ #ga-events-inputs table,
188
+ #ga-events-inputs thead,
189
+ #ga-events-inputs tbody,
190
+ #ga-events-inputs th,
191
+ #ga-events-inputs td,
192
+ #ga-events-inputs tr {
193
+ display: block;
194
+ }
195
+ /* Hide table headers (but not display: none;, for accessibility) */
196
+ #ga-events-inputs thead tr {
197
+ position: absolute;
198
+ top: -9999px;
199
+ left: -9999px;
200
+ }
201
+
202
+ #ga-events-inputs tr { border: 1px solid #ccc; }
203
+
204
+ #ga-events-inputs td {
205
+ /* Behave like a "row" */
206
+ border: none;
207
+ border-bottom: 1px solid #eee;
208
+ position: relative;
209
+ padding-left: 50%;
210
+ white-space: normal;
211
+ text-align:left;
212
+ }
213
+
214
+ #ga-events-inputs td:before {
215
+ /* Now like a table header */
216
+ position: absolute;
217
+ /* Top/left values mimic padding */
218
+ top: 6px;
219
+ left: 6px;
220
+ width: 45%;
221
+ padding-right: 10px;
222
+ white-space: nowrap;
223
+ text-align:left;
224
+ font-weight: bold;
225
+ }
226
+
227
+ /*
228
+ Label the data
229
+ */
230
+ #ga-events-inputs td:before { content: attr(data-title); }
231
+ }
232
+
233
+ .ga-events-help {
234
+ margin-right: 2px;
235
+ color: #0085ba;
236
+ }
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: 1.8
7
  Author: Yuval Oren
8
  Author URI: http://wpflow.com
9
  License: GPLv2
@@ -45,9 +45,9 @@ function ga_events_install() {
45
  'divs' => array(array(id => '',type =>'', action => '', cat => '', label => '')),
46
  'click' => array(array(id => '',type =>'', action => '', cat => '', label => ''))
47
  );
48
- if (!get_option('ga_events_options')) {
49
- update_option( 'ga_events_options', $ga_events_options );
50
- }
51
 
52
  }
53
 
@@ -88,28 +88,28 @@ function ga_events_header() {
88
 
89
  ga('create','$id', '$domain');
90
  ga('send', 'pageview');
91
- }
92
  </script>";
93
  } else {
94
- echo "<script type='text/javascript'>
95
- if (typeof _gaq === 'undefined') {
96
- var _gaq = _gaq || [];
97
- _gaq.push(['_setAccount', '$id']);
98
- _gaq.push(['_setDomainName', '$domain']);
99
- _gaq.push(['_setAllowLinker', true]);
100
- _gaq.push(['_trackPageview']);
101
-
102
- (function() {
103
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
104
- ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
105
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
106
- })();
107
- }
108
 
109
 
110
  </script>";
111
  }
112
- }
113
  }
114
 
115
  add_action( 'wp_footer', 'ga_events_footer', 100 );
@@ -123,6 +123,7 @@ function ga_events_footer() {
123
  $universal = 0;
124
  }
125
  echo "
 
126
  <script>
127
 
128
  jQuery(document).ready(function() {
@@ -158,7 +159,8 @@ function ga_events_footer() {
158
  });
159
  });
160
 
161
- </script>";
 
162
 
163
 
164
  }
@@ -170,7 +172,8 @@ function ga_events_get_selector($element) {
170
  $selector .= str_replace(' ','',$element[0])."',";
171
  $selector .= "'category':'".$element[2]."',";
172
  $selector .= "'action':'".$element[3]."',";
173
- $selector .= "'label':'".$element[4]."'";
 
174
  $selector .= '}';
175
  return $selector;
176
  }else{
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: 1.9
7
  Author: Yuval Oren
8
  Author URI: http://wpflow.com
9
  License: GPLv2
45
  'divs' => array(array(id => '',type =>'', action => '', cat => '', label => '')),
46
  'click' => array(array(id => '',type =>'', action => '', cat => '', label => ''))
47
  );
48
+ if (!get_option('ga_events_options')) {
49
+ update_option( 'ga_events_options', $ga_events_options );
50
+ }
51
 
52
  }
53
 
88
 
89
  ga('create','$id', '$domain');
90
  ga('send', 'pageview');
91
+ }
92
  </script>";
93
  } else {
94
+ echo "<script type='text/javascript'>
95
+ if (typeof _gaq === 'undefined') {
96
+ var _gaq = _gaq || [];
97
+ _gaq.push(['_setAccount', '$id']);
98
+ _gaq.push(['_setDomainName', '$domain']);
99
+ _gaq.push(['_setAllowLinker', true]);
100
+ _gaq.push(['_trackPageview']);
101
+
102
+ (function() {
103
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
104
+ ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
105
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
106
+ })();
107
+ }
108
 
109
 
110
  </script>";
111
  }
112
+ }
113
  }
114
 
115
  add_action( 'wp_footer', 'ga_events_footer', 100 );
123
  $universal = 0;
124
  }
125
  echo "
126
+ <!-- BEGIN: wpflow ga events array -->
127
  <script>
128
 
129
  jQuery(document).ready(function() {
159
  });
160
  });
161
 
162
+ </script>
163
+ <!-- END: wpflow ga events array -->";
164
 
165
 
166
  }
172
  $selector .= str_replace(' ','',$element[0])."',";
173
  $selector .= "'category':'".$element[2]."',";
174
  $selector .= "'action':'".$element[3]."',";
175
+ $selector .= "'label':'".$element[4]."',";
176
+ $selector .= "'bounce':'".$element[5]."'";
177
  $selector .= '}';
178
  return $selector;
179
  }else{
includes/admin.php CHANGED
@@ -8,122 +8,119 @@
8
  add_action( 'admin_menu', 'ga_events_menu');
9
 
10
  function ga_events_menu() {
11
- add_menu_page('WP Google Analytics Settings','WP GA Events','manage_options', 'wp-google-analytics-events', 'ga_events_settings_page', plugins_url( 'images/icon.png', dirname(__FILE__)));
12
- add_submenu_page('wp-google-analytics-events','General Settings','General Settings', 'manage_options', 'wp-google-analytics-events' , 'ga_events_settings_page' );
13
- add_submenu_page('wp-google-analytics-events','Click Tracking','Click Tracking', 'manage_options', 'wp-google-analytics-events-click' , 'ga_events_settings_page' );
14
- add_submenu_page('wp-google-analytics-events','Scroll Tracking','Scroll Tracking', 'manage_options', 'wp-google-analytics-events-scroll' , 'ga_events_settings_page' );
15
- add_submenu_page('wp-google-analytics-events','Getting Started Guide','Getting Started Guide', 'manage_options', 'wp-google-analytics-events-started' , 'ga_events_settings_page' );
16
- add_submenu_page('wp-google-analytics-events','Upgrade','Upgrade Now', 'manage_options', 'wp-google-analytics-events-upgrade', 'ga_events_settings_page' );
17
  }
18
 
19
  function ga_events_settings_page() {
20
 
21
  ?>
22
- <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
23
- <div id="ga_main" class="wrap">
24
- <?php screen_icon( 'plugins' ); ?>
25
- <h2>GA Scroll Events Plugin</h2>
26
 
27
  <?php
28
- $active_page = isset( $_GET[ 'page' ] ) ? $_GET[ 'page' ] : 'wp-google-analytics-events';
29
- ?>
30
  <h2 class="nav-tab-wrapper">
31
- <a href="?page=wp-google-analytics-events" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events' ? 'nav-tab-active' : ''; ?>">General Settings</a>
32
- <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>
33
- <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>
34
- <a href="?page=wp-google-analytics-events-started" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-started' ? 'nav-tab-active' : ''; ?>">Getting Started Guide</a>
35
- </h2>
36
- <?php
37
- if ($active_page == 'wp-google-analytics-events-started') {
38
- ga_events_setting_started();
39
- } else {
40
- ?>
41
-
42
- <form method="post" action='options.php'>
43
- <?php settings_fields('ga_events_options'); ?>
44
- <?php
45
  $show_sidebar = true;
46
- if ($active_page == 'wp-google-analytics-events-click') {
47
- do_settings_sections('ga_events_click');
48
- $show_sidebar = false;
49
- } else if ($active_page == 'wp-google-analytics-events-scroll') {
50
- do_settings_sections('ga_events_scroll');
51
- }else {
52
- do_settings_sections('ga_events');
53
- }
54
- ?>
55
-
56
- <input class="button-primary" type="submit" name="submit" value="Save Changes" />
57
-
58
- </form>
59
- <div class="settings_content">
60
- <form action="" method="post" enctype="multipart/form-data">
61
- <a href="#" class="btn_close"><img src="<?=plugins_url( 'images/close.png', dirname(__FILE__))?>"></a>
62
- <input type="file" name="settings">
63
- <input type="submit" name="set_settings">
64
- </form>
65
- </div>
66
- </div>
67
  <?php
68
- if ($show_sidebar) {
69
  ?>
70
  <div class="wrap ga_events_sidebar">
71
- <table class="form-table widefat" >
72
- <thead>
73
- <th>Upgrade to Pro</th>
74
- </thead>
75
- <tbody>
76
- <tr class="features">
77
- <td>
78
- <ul>
79
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>One Checkbox Link Tracking</strong></li>
80
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>YouTube Video Tracking</strong></li>
81
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Shortcode support</strong></li>
82
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Set Value for Events</strong></li>
83
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>HTML Tag support</strong></li>
84
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Bounce Rate Control</strong></li>
85
- <li><i class="fa fa-check-square-o fa-lg"></i><strong>Pro Support</strong></li>
86
- </ul>
87
- </td>
88
- </tr>
89
- <tr class="tfoot">
90
- <td>
91
- <div class="wpcta">
92
- <a class="btn btn-subscribe" href="http://wpflow.com/upgrade/">
93
- <span class="btn-title ">
94
- Starting from
95
- <span class="btn-data">
96
- <span class="price">$49</span>
97
- </span>
98
- </span>
99
- </a>
100
- </div>
101
- </td>
102
- </tr>
103
- </tbody>
104
- </table>
105
-
106
- </div>
107
  <?php }} ?>
108
 
109
 
110
  <?php
111
 
112
- echo "<script>
113
- jQuery('.remove').click(function (event) {
114
- event.preventDefault();
115
- jQuery(this).closest('tr').remove();
116
- });
117
- jQuery('.add').click(function (event) {
118
- event.preventDefault();
119
- });
120
- </script>
121
- ";
122
  }
123
 
124
  function load_custom_wp_admin_style() {
125
- wp_register_style( 'custom_wp_admin_css', plugins_url('css/style.css', dirname(__FILE__)));
126
- wp_enqueue_style( 'custom_wp_admin_css' );
127
  wp_enqueue_script( 'admin-init', plugins_url('js/admin.js', dirname(__FILE__)) , array('jquery'), null, true );
128
 
129
  }
@@ -146,154 +143,190 @@ function ga_events_admin_init() {
146
  }
147
 
148
 
149
- register_setting('ga_events_options','ga_events_options','ga_events_validate');
150
- add_settings_section('ga_events_main','WP Google Analytics Events Settings', 'ga_events_section_text','ga_events');
151
- add_settings_section('ga_events_click_section','Click Tracking', 'ga_events_section_text','ga_events_click');
152
- add_settings_section('ga_events_scroll_section','Scroll Tracking', 'ga_events_section_text','ga_events_scroll');
153
- add_settings_section('ga_events_started_section','Getting Started Guide', 'ga_events_section_text','ga_events_started');
154
- add_settings_field('ga_events_id', '','ga_events_setting_input','ga_events','ga_events_main');
155
- add_settings_field('ga_events_exclude_snippet', '','ga_events_setting_snippet_input','ga_events','ga_events_main');
156
- add_settings_field('ga_events_universal', '','ga_events_setting_uni_input','ga_events','ga_events_main');
157
- add_settings_field('ga_events_divs', '','ga_events_setting_divs_input','ga_events_scroll','ga_events_scroll_section');
158
- add_settings_field('ga_events_started', '','ga_events_setting_started','ga_events_started','ga_events_started_section');
159
- add_settings_field('ga_events_click', '','ga_events_setting_click_input','ga_events_click','ga_events_click_section');
160
- add_settings_field('ga_events_sidebar', '','ga_events_setting_sidebar','ga_events','ga_events_main');
161
- add_settings_field('ga_events_download_settings', '','ga_events_settings_download','ga_events','ga_events_main');
162
- add_settings_field('ga_events_upload_settings', '','ga_events_settings_upload','ga_events','ga_events_main');
163
 
164
 
165
  }
166
 
167
  function ga_events_section_text() {
168
- echo "<a href='http://wpflow.com/documentation'>Plugin Documentation</a>";
169
  }
170
 
171
  function ga_events_setting_started() {
172
- echo '
173
- <h2>Getting Started Guide</h2>
174
- <form action="https://www.getdrip.com/forms/4588171/submissions" method="post" data-drip-embedded-form="4588171">
175
- <div style="background:white; line-height:20px; padding: 5px 15px 15px 15px;
176
  font-size: 15px; max-width:400px;">
177
 
178
- <h3 style="margin-top: 10px;" data-drip-attribute="headline">Want to learn more about event tracking?</h3>
179
- <div data-drip-attribute="description">Now that you installed the plugin, we want to help you get everything up and running.&nbsp;<br />
180
- Join our short email course and get started with event tracking.</div>
181
- <div>
182
- <label style="margin-top:10px;"for="fields[email]">Email Address:</label><br />
183
- <input type="email" name="fields[email]" value="" />
184
- </div>
185
- <div>
186
- <input style="margin-top:15px;" class="button-primary" type="submit" name="submit" value="Get Started" data-drip-attribute="sign-up-button" />
187
- </div>
188
- </div>
189
- </form>';
190
  }
191
 
192
  function ga_events_setting_input() {
193
- $options = get_option('ga_events_options');
194
- $id = $options['id'];
195
- echo "<label>Google Analytics Identifier</label>";
196
- echo "<span class='ga_intable'><input class='inputs' id='id' name='ga_events_options[id]' type='text' value='$id' /></span>";
197
 
198
  }
199
 
200
 
201
  function ga_events_setting_snippet_input() {
202
- $options = get_option('ga_events_options');
203
- $id = $options['exclude_snippet'];
204
- echo "<label>Don't add the GA tracking code</label>";
205
- echo "<span class='ga_intable'><input id='snippet' name='ga_events_options[exclude_snippet]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
206
 
207
  }
208
 
209
  function ga_events_setting_uni_input() {
210
- $options = get_option('ga_events_options');
211
- $id = $options['universal'];
212
- echo "<label>Universal Tracking Code</label>";
213
- echo "<span class='ga_intable'><input id='universal' name='ga_events_options[universal]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
214
  }
215
 
216
  function ga_events_settings_download(){
217
- echo '<a class="button" href="http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] .'&download=1">Export settings</a>';
218
  }
219
 
220
  function ga_events_settings_upload(){
221
- echo '<a href="#" class="button btn_upload">Import settings</a>';
222
  }
223
 
224
  function ga_events_setting_divs_input() {
225
- $options = get_option('ga_events_options');
226
- $divs= $options['divs'];
227
- echo "<label>Scroll Events</label><br />";
228
- echo "<table class='widefat inputs inner_table'><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th></th></thead><tbody>";
229
- if (!($divs[0][0])){
230
- echo "<tr>";
231
- echo "<td><input id='divs' name='ga_events_options[divs][0][0]' type='text' value='".$divs[0][0]."' /></td>";
232
- echo "<td><select id='divs' name='ga_events_options[divs][0][1]'><option selected value='id' >id</option><option value='class'>class</option></select></td>";
233
- echo "<td><input id='divs' name='ga_events_options[divs][0][2]' type='text' value='".$divs[0][2]."' /></td>";
234
- echo "<td><input id='divs' name='ga_events_options[divs][0][3]' type='text' value='".$divs[0][3]."' /></td>";
235
- echo "<td><input id='divs' name='ga_events_options[divs][0][4]' type='text' value='".$divs[0][4]."' /></td>";
236
- echo "</tr>";
237
-
238
- }else{
239
- for ($i = 0; $i < sizeof($divs)+1; $i++){
240
-
241
- echo "<tr>";
242
- echo "<td><input id='divs' name='ga_events_options[divs][$i][0] type='text' value='".$divs[$i][0]."' /></td>";
243
- echo "<td><select id='divs' name='ga_events_options[divs][$i][1]'>";
244
- if ($divs[$i][1] == 'id'){
245
- echo "<option selected value='id' >id</option><option value='class'>class</option></select></td>";
246
- }else {
247
- echo "<option value='id' >id</option><option selected value='class'>class</option></select></td>";
248
- }
249
- echo "<td><input id='divs' name='ga_events_options[divs][$i][2]' type='text' value='".$divs[$i][2]."' /></td>";
250
- echo "<td><input id='divs' name='ga_events_options[divs][$i][3]' type='text' value='".$divs[$i][3]."' /></td>";
251
- echo "<td><input id='divs' name='ga_events_options[divs][$i][4]' type='text' value='".$divs[$i][4]."' /></td>";
252
- echo "<td><a class='remove' href=''>Remove</a></td>";
253
- echo "</tr>";
254
-
255
- }
256
-
257
- }
258
- echo "</tbody></table>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  }
260
 
261
 
262
  function ga_events_setting_click_input() {
263
- $options = get_option('ga_events_options');
264
- $click = $options['click'];
265
- echo "<label>Click Events</label><br />";
266
- echo "<table class='widefat inputs inner_table'><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th></th></thead><tbody>";
267
- if (!($click[0][0])){
268
- echo "<tr>";
269
- echo "<td><input id='click' name='ga_events_options[click][0][0]' type='text' value='".$click[0][0]."' /></td>";
270
- echo "<td><select id='click' name='ga_events_options[click][0][1]'><option selected value='id'>id</option><option value='class'>class</option></select></td>";
271
- echo "<td><input id='click' name='ga_events_options[click][0][2]' type='text' value='".$click[0][2]."' /></td>";
272
- echo "<td><input id='click' name='ga_events_options[click][0][3]' type='text' value='".$click[0][3]."' /></td>";
273
- echo "<td><input id='click' name='ga_events_options[click][0][4]' type='text' value='".$click[0][4]."' /></td>";
274
- echo "</tr>";
275
-
276
- }else{
277
- for ($i = 0; $i < sizeof($click)+1; $i++){
278
-
279
- echo "<tr>";
280
- echo "<td><input id='divs' name='ga_events_options[click][$i][0] type='text' value='".$click[$i][0]."' /></td>";
281
- echo "<td><select id='click' name='ga_events_options[click][$i][1]'>";
282
- if ($click[$i][1] == 'id'){
283
- echo "<option selected value='id' >id</option><option value='class'>class</option></select></td>";
284
- }else {
285
- echo "<option value='id' >id</option><option selected value='class'>class</option></select></td>";
286
- }
287
- echo "<td><input id='click' name='ga_events_options[click][$i][2] type='text' value='".$click[$i][2]."' /></td>";
288
- echo "<td><input id='click' name='ga_events_options[click][$i][3] type='text' value='".$click[$i][3]."' /></td>";
289
- echo "<td><input id='click' name='ga_events_options[click][$i][4] type='text' value='".$click[$i][4]."' /></td>";
290
- echo "<td><a class='remove' href=''>Remove</a></td>";
291
- echo "</tr>";
292
-
293
- }
294
-
295
- }
296
- echo "</tbody></table>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
 
299
  }
@@ -302,31 +335,36 @@ function ga_events_setting_sidebar(){
302
  }
303
 
304
  function ga_events_validate($form){
305
- $options = get_option('ga_events_options');
306
- $updated = $options;
307
- if (array_key_exists('divs', $form)) {
308
- $updated['divs'] = array();
309
- for ($i = 0, $j = 0; $i< sizeof($form['divs']); $i++){
310
- if ($form['divs'][$i][0]){
311
- $updated['divs'][$j] = $form['divs'][$i];
312
- $j++;
313
- }
314
- }
315
- } else if(array_key_exists('click', $form)) {
316
- $updated['click'] = array();
317
- for ($i = 0, $j = 0; $i< sizeof($form['click']); $i++){
318
- if ($form['click'][$i][0]){
319
- $updated['click'][$j] = $form['click'][$i];
320
- $j++;
321
- }
322
  }
323
- } else {
324
- $updated['id'] = $form['id'];
325
- $updated['exclude_snippet'] = $form['exclude_snippet'];
326
- $updated['universal'] = $form['universal'];
327
  }
328
-
329
- return $updated;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  }
331
 
332
 
@@ -337,7 +375,7 @@ function ga_events_admin_footer() {
337
  <script>
338
  jQuery('body').on('click','a[href="admin.php?page=wp-google-analytics-events-upgrade"]', function (e) {
339
  e.preventDefault();
340
- window.open('http://wpflow.com/upgrade', '_blank');
341
  });
342
  </script>
343
  <?php
@@ -345,45 +383,45 @@ function ga_events_admin_footer() {
345
 
346
 
347
  function ga_events_get_settings(){
348
- $options = get_option('ga_events_options');
349
- $current = json_encode($options);
350
 
351
- return $current;
352
  }
353
 
354
  function ga_events_upload_settings($file){
355
- $uploadedfile = $file['settings'];
356
- if($uploadedfile['type'] != 'application/octet-stream'){
357
- ga_event_popup();
358
- return;
359
- }
360
- $content = file_get_contents($uploadedfile["tmp_name"]);
361
-
362
- ga_event_get_content($content);
363
  }
364
 
365
  function ga_event_get_content($content){
366
- if(!$current = json_decode($content,true)){
367
- ga_event_popup();
368
- return;
369
- }
370
- if (!array_key_exists('id', $current) && !array_key_exists('domain', $current)) {
371
- ga_event_popup();
372
- return;
373
- }
374
- update_option( 'ga_events_options', $current );
375
 
376
  }
377
  function ga_event_popup(){
378
- echo "<dev class='popup'>";
379
  echo '<h1>Wrong file format <a href="#" class="btn_close_popup"><img src="'.plugins_url( 'images/close.png', dirname(__FILE__)).'"></a></h1>';
380
  echo "</dev>";
381
  }
382
  function ga_events_file(){
383
- header("Content-type: text/plain");
384
  header("Content-Disposition: attachment; filename='settings.ini'");
385
  echo ga_events_get_settings();
386
- exit();
387
  }
388
 
389
  ?>
8
  add_action( 'admin_menu', 'ga_events_menu');
9
 
10
  function ga_events_menu() {
11
+ add_menu_page('WP Google Analytics Settings','WP GA Events','manage_options', 'wp-google-analytics-events', 'ga_events_settings_page', plugins_url( 'images/icon.png', dirname(__FILE__)));
12
+ add_submenu_page('wp-google-analytics-events','General Settings','General Settings', 'manage_options', 'wp-google-analytics-events' , 'ga_events_settings_page' );
13
+ add_submenu_page('wp-google-analytics-events','Click Tracking','Click Tracking', 'manage_options', 'wp-google-analytics-events-click' , 'ga_events_settings_page' );
14
+ add_submenu_page('wp-google-analytics-events','Scroll Tracking','Scroll Tracking', 'manage_options', 'wp-google-analytics-events-scroll' , 'ga_events_settings_page' );
15
+ add_submenu_page('wp-google-analytics-events','Getting Started Guide','Getting Started Guide', 'manage_options', 'wp-google-analytics-events-started' , 'ga_events_settings_page' );
16
+ add_submenu_page('wp-google-analytics-events','Upgrade','Upgrade Now', 'manage_options', 'wp-google-analytics-events-upgrade', 'ga_events_settings_page' );
17
  }
18
 
19
  function ga_events_settings_page() {
20
 
21
  ?>
22
+ <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
23
+ <div id="ga_main" class="wrap">
24
+ <?php screen_icon( 'plugins' ); ?>
25
+ <h2>GA Scroll Events Plugin</h2>
26
 
27
  <?php
28
+ $active_page = isset( $_GET[ 'page' ] ) ? $_GET[ 'page' ] : 'wp-google-analytics-events';
29
+ ?>
30
  <h2 class="nav-tab-wrapper">
31
+ <a href="?page=wp-google-analytics-events" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events' ? 'nav-tab-active' : ''; ?>">General Settings</a>
32
+ <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>
33
+ <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>
34
+ <a href="?page=wp-google-analytics-events-started" class="nav-tab <?php echo $active_page == 'wp-google-analytics-events-started' ? 'nav-tab-active' : ''; ?>"><i class="fa fa-question-circle ga-events-help"></i> Getting Started Guide</a>
35
+ </h2>
36
+ <?php
37
+ if ($active_page == 'wp-google-analytics-events-started') {
38
+ ga_events_setting_started();
39
+ } else {
40
+ ?>
41
+
42
+ <form method="post" action='options.php'>
43
+ <?php settings_fields('ga_events_options'); ?>
44
+ <?php
45
  $show_sidebar = true;
46
+ if ($active_page == 'wp-google-analytics-events-click') {
47
+ do_settings_sections('ga_events_click');
48
+ } else if ($active_page == 'wp-google-analytics-events-scroll') {
49
+ do_settings_sections('ga_events_scroll');
50
+ }else {
51
+ do_settings_sections('ga_events');
52
+ }
53
+ ?>
54
+
55
+ <input class="button-primary" type="submit" name="submit" value="Save Changes" />
56
+
57
+ </form>
58
+ <div class="settings_content">
59
+ <form action="" method="post" enctype="multipart/form-data">
60
+ <a href="#" class="btn_close"><img src="<?=plugins_url( 'images/close.png', dirname(__FILE__))?>"></a>
61
+ <input type="file" name="settings">
62
+ <input type="submit" name="set_settings">
63
+ </form>
64
+ </div>
65
+ </div>
 
66
  <?php
67
+ if ($show_sidebar) {
68
  ?>
69
  <div class="wrap ga_events_sidebar">
70
+ <table class="form-table widefat" >
71
+ <thead>
72
+ <th>Upgrade to Pro</th>
73
+ </thead>
74
+ <tbody>
75
+ <tr class="features">
76
+ <td>
77
+ <ul>
78
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>One Checkbox Link Tracking</strong></li>
79
+ <li title="Dynamic Event Data"><i class="fa fa-check-square-o fa-lg"></i><strong>Placeholders</strong></li>
80
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>YouTube Video Tracking</strong></li>
81
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>Shortcode support</strong></li>
82
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>Set Value for Events</strong></li>
83
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>HTML Tag support</strong></li>
84
+ <li><i class="fa fa-check-square-o fa-lg"></i><strong>Pro Support</strong></li>
85
+ </ul>
86
+ </td>
87
+ </tr>
88
+ <tr class="tfoot">
89
+ <td>
90
+ <div class="wpcta">
91
+ <a class="btn btn-subscribe" target="_blank" href="https://wpflow.com/upgrade?utm_source=wpadm&utm_medium=banner&utm_content=side&utm_campaign=wpadmin
92
+ ">
93
+ <span class="btn-title ">
94
+ Upgrade Now
95
+ </span>
96
+ </a>
97
+ </div>
98
+ </td>
99
+ </tr>
100
+ </tbody>
101
+ </table>
102
+
103
+ </div>
 
 
104
  <?php }} ?>
105
 
106
 
107
  <?php
108
 
109
+ echo "<script>
110
+ jQuery('.remove').click(function (event) {
111
+ event.preventDefault();
112
+ jQuery(this).closest('tr').remove();
113
+ });
114
+ jQuery('.add').click(function (event) {
115
+ event.preventDefault();
116
+ });
117
+ </script>
118
+ ";
119
  }
120
 
121
  function load_custom_wp_admin_style() {
122
+ wp_register_style( 'custom_wp_admin_css', plugins_url('css/style.css', dirname(__FILE__)));
123
+ wp_enqueue_style( 'custom_wp_admin_css' );
124
  wp_enqueue_script( 'admin-init', plugins_url('js/admin.js', dirname(__FILE__)) , array('jquery'), null, true );
125
 
126
  }
143
  }
144
 
145
 
146
+ register_setting('ga_events_options','ga_events_options','ga_events_validate');
147
+ add_settings_section('ga_events_main','WP Google Analytics Events Settings', 'ga_events_section_text','ga_events');
148
+ add_settings_section('ga_events_click_section','', 'ga_events_section_text','ga_events_click');
149
+ add_settings_section('ga_events_scroll_section','', 'ga_events_section_text','ga_events_scroll');
150
+ add_settings_section('ga_events_started_section','Getting Started Guide', 'ga_events_section_text','ga_events_started');
151
+ add_settings_field('ga_events_id', '','ga_events_setting_input','ga_events','ga_events_main');
152
+ add_settings_field('ga_events_exclude_snippet', '','ga_events_setting_snippet_input','ga_events','ga_events_main');
153
+ add_settings_field('ga_events_universal', '','ga_events_setting_uni_input','ga_events','ga_events_main');
154
+ add_settings_field('ga_events_divs', '','ga_events_setting_divs_input','ga_events_scroll','ga_events_scroll_section');
155
+ add_settings_field('ga_events_started', '','ga_events_setting_started','ga_events_started','ga_events_started_section');
156
+ add_settings_field('ga_events_click', '','ga_events_setting_click_input','ga_events_click','ga_events_click_section');
157
+ add_settings_field('ga_events_sidebar', '','ga_events_setting_sidebar','ga_events','ga_events_main');
158
+ add_settings_field('ga_events_download_settings', '','ga_events_settings_download','ga_events','ga_events_main');
159
+ add_settings_field('ga_events_upload_settings', '','ga_events_settings_upload','ga_events','ga_events_main');
160
 
161
 
162
  }
163
 
164
  function ga_events_section_text() {
165
+ echo "<br><a style='margin-left:8px;' href='http://wpflow.com/documentation'>Plugin Documentation</a>";
166
  }
167
 
168
  function ga_events_setting_started() {
169
+ echo '
170
+ <h2>Getting Started Guide</h2>
171
+ <form action="https://www.getdrip.com/forms/4588171/submissions" method="post" data-drip-embedded-form="4588171">
172
+ <div style="background:white; line-height:20px; padding: 5px 15px 15px 15px;
173
  font-size: 15px; max-width:400px;">
174
 
175
+ <h3 style="margin-top: 10px;" data-drip-attribute="headline">Want to learn more about event tracking?</h3>
176
+ <div data-drip-attribute="description">Now that you installed the plugin, we want to help you get everything up and running.&nbsp;<br />
177
+ Join our short email course and get started with event tracking.</div>
178
+ <div>
179
+ <label style="margin-top:10px;"for="fields[email]">Email Address:</label><br />
180
+ <input type="email" name="fields[email]" value="" />
181
+ </div>
182
+ <div>
183
+ <input style="margin-top:15px;" class="button-primary" type="submit" name="submit" value="Get Started" data-drip-attribute="sign-up-button" />
184
+ </div>
185
+ </div>
186
+ </form>';
187
  }
188
 
189
  function ga_events_setting_input() {
190
+ $options = get_option('ga_events_options');
191
+ $id = $options['id'];
192
+ echo "<label>Google Analytics Identifier</label>";
193
+ echo "<span class='ga_intable'><input class='inputs' id='id' name='ga_events_options[id]' type='text' value='$id' /></span>";
194
 
195
  }
196
 
197
 
198
  function ga_events_setting_snippet_input() {
199
+ $options = get_option('ga_events_options');
200
+ $id = $options['exclude_snippet'];
201
+ echo "<label>Don't add the GA tracking code</label>";
202
+ echo "<span class='ga_intable'><input id='snippet' name='ga_events_options[exclude_snippet]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
203
 
204
  }
205
 
206
  function ga_events_setting_uni_input() {
207
+ $options = get_option('ga_events_options');
208
+ $id = $options['universal'];
209
+ echo "<label>Universal Tracking Code</label>";
210
+ echo "<span class='ga_intable'><input id='universal' name='ga_events_options[universal]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
211
  }
212
 
213
  function ga_events_settings_download(){
214
+ echo '<a class="button" href="http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] .'&download=1">Export settings</a>';
215
  }
216
 
217
  function ga_events_settings_upload(){
218
+ echo '<a href="#" class="button btn_upload">Import settings</a>';
219
  }
220
 
221
  function ga_events_setting_divs_input() {
222
+ $options = get_option('ga_events_options');
223
+ $divs= $options['divs'];
224
+ $type='divs';
225
+ echo "<table id='ga-events-inputs' class='widefat inputs inner_table'><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th>Non-Interaction</th><th></th></thead><tbody>";
226
+ if (!($divs[0][0])){
227
+ echo "<tr>";
228
+ echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][0][0]' type='text' value='".$divs[0][0]."' /></td>";
229
+ echo "<td data-title='Type'><select id='divs' name='ga_events_options[divs][0][1]'><option selected value='id' >id</option><option value='class'>class</option></select></td>";
230
+ echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][0][2]' type='text' value='".$divs[0][2]."' /></td>";
231
+ echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][0][3]' type='text' value='".$divs[0][3]."' /></td>";
232
+ echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][0][4]' type='text' value='".$divs[0][4]."' /></td>";
233
+
234
+ echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
235
+ if ($divs[$i][5] == 'true') {
236
+ echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
237
+ } else {
238
+ echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
239
+ }
240
+
241
+ echo "</tr>";
242
+
243
+ }else{
244
+ for ($i = 0; $i < sizeof($divs)+1; $i++){
245
+
246
+ echo "<tr>";
247
+ echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][$i][0] type='text' value='".$divs[$i][0]."' /></td>";
248
+ echo "<td data-title='Type'><select id='divs' name='ga_events_options[divs][$i][1]'>";
249
+ if ($divs[$i][1] == 'id'){
250
+ echo "<option selected value='id' >id</option><option value='class'>class</option></select></td>";
251
+ }else {
252
+ echo "<option value='id' >id</option><option selected value='class'>class</option></select></td>";
253
+ }
254
+ echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][$i][2]' type='text' value='".$divs[$i][2]."' /></td>";
255
+ echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][$i][3]' type='text' value='".$divs[$i][3]."' /></td>";
256
+ echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][$i][4]' type='text' value='".$divs[$i][4]."' /></td>";
257
+
258
+ echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
259
+ if ($divs[$i][5] == 'true') {
260
+ echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
261
+ } else {
262
+ echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
263
+ }
264
+
265
+ echo "<td><a class='remove' href=''>Remove</a></td>";
266
+ echo "</tr>";
267
+
268
+ }
269
+
270
+ }
271
+ echo "</tbody></table>";
272
  }
273
 
274
 
275
  function ga_events_setting_click_input() {
276
+ $options = get_option('ga_events_options');
277
+ $click = $options['click'];
278
+ $divs= $options['click'];
279
+ $type='click';
280
+ echo "<table id='ga-events-inputs' class='widefat inputs inner_table '><thead><th>Element Name</th><th>Type</th><th>Event Category</th><th>Event Action</th><th>Event Label</th><th>Non-Interaction</th><th></th></thead><tbody>";
281
+ if (!($click[0][0])){
282
+ echo "<tr>";
283
+ echo "<td data-title='Element Name'><input id='click' name='ga_events_options[click][0][0]' type='text' value='".$click[0][0]."' /></td>";
284
+ echo "<td data-title='Type'><select id='click' name='ga_events_options[click][0][1]'><option selected value='id'>id</option><option value='class'>class</option></select></td>";
285
+ echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][0][2]' type='text' value='".$click[0][2]."' /></td>";
286
+ echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][0][3]' type='text' value='".$click[0][3]."' /></td>";
287
+ echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][0][4]' type='text' value='".$click[0][4]."' /></td>";
288
+
289
+ echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
290
+ if ($divs[$i][5] == 'true') {
291
+ echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
292
+ } else {
293
+ echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
294
+ }
295
+
296
+
297
+
298
+ echo "</tr>";
299
+
300
+ }else{
301
+ for ($i = 0; $i < sizeof($click)+1; $i++){
302
+
303
+ echo "<tr>";
304
+ echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[click][$i][0] type='text' value='".$click[$i][0]."' /></td>";
305
+ echo "<td data-title='Type'><select id='click' name='ga_events_options[click][$i][1]'>";
306
+ if ($click[$i][1] == 'id'){
307
+ echo "<option selected value='id' >id</option><option value='class'>class</option></select></td>";
308
+ }else {
309
+ echo "<option value='id' >id</option><option selected value='class'>class</option></select></td>";
310
+ }
311
+ echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][$i][2] type='text' value='".$click[$i][2]."' /></td>";
312
+ echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][$i][3] type='text' value='".$click[$i][3]."' /></td>";
313
+ echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][$i][4] type='text' value='".$click[$i][4]."' /></td>";
314
+
315
+ echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
316
+ if ($divs[$i][5] == 'true') {
317
+ echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
318
+ }
319
+ else {
320
+ echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
321
+ }
322
+
323
+ echo "<td><a class='remove' href=''>Remove</a></td>";
324
+ echo "</tr>";
325
+
326
+ }
327
+
328
+ }
329
+ echo "</tbody></table>";
330
 
331
 
332
  }
335
  }
336
 
337
  function ga_events_validate($form){
338
+
339
+ $options = get_option('ga_events_options');
340
+ $updated = $options;
341
+
342
+ if( array_key_exists('divs', $form)) {
343
+
344
+ $updated['divs'] = array();
345
+ for ($i = 0, $j = 0; $i< sizeof($form['divs']); $i++){
346
+ if ($form['divs'][$i][0]){
347
+ $updated['divs'][$j] = $form['divs'][$i];
348
+ $j++;
 
 
 
 
 
 
349
  }
 
 
 
 
350
  }
351
+ }
352
+ else if(array_key_exists('click', $form)) {
353
+ $updated['click'] = array();
354
+ for ($i = 0, $j = 0; $i< sizeof($form['click']); $i++){
355
+ if ($form['click'][$i][0]){
356
+ $updated['click'][$j] = $form['click'][$i];
357
+ $j++;
358
+ }
359
+ }
360
+ }
361
+ else {
362
+ $updated['id'] = $form['id'];
363
+ $updated['exclude_snippet'] = $form['exclude_snippet'];
364
+ $updated['universal'] = $form['universal'];
365
+ }
366
+
367
+ return $updated;
368
  }
369
 
370
 
375
  <script>
376
  jQuery('body').on('click','a[href="admin.php?page=wp-google-analytics-events-upgrade"]', function (e) {
377
  e.preventDefault();
378
+ window.open('https://wpflow.com/upgrade?utm_source=wpadm&utm_medium=banner&utm_content=menu&utm_campaign=wpadmin', '_blank');
379
  });
380
  </script>
381
  <?php
383
 
384
 
385
  function ga_events_get_settings(){
386
+ $options = get_option('ga_events_options');
387
+ $current = json_encode($options);
388
 
389
+ return $current;
390
  }
391
 
392
  function ga_events_upload_settings($file){
393
+ $uploadedfile = $file['settings'];
394
+ if($uploadedfile['type'] != 'application/octet-stream'){
395
+ ga_event_popup();
396
+ return;
397
+ }
398
+ $content = file_get_contents($uploadedfile["tmp_name"]);
399
+
400
+ ga_event_get_content($content);
401
  }
402
 
403
  function ga_event_get_content($content){
404
+ if(!$current = json_decode($content,true)){
405
+ ga_event_popup();
406
+ return;
407
+ }
408
+ if (!array_key_exists('id', $current) && !array_key_exists('domain', $current)) {
409
+ ga_event_popup();
410
+ return;
411
+ }
412
+ update_option( 'ga_events_options', $current );
413
 
414
  }
415
  function ga_event_popup(){
416
+ echo "<dev class='popup'>";
417
  echo '<h1>Wrong file format <a href="#" class="btn_close_popup"><img src="'.plugins_url( 'images/close.png', dirname(__FILE__)).'"></a></h1>';
418
  echo "</dev>";
419
  }
420
  function ga_events_file(){
421
+ header("Content-type: text/plain");
422
  header("Content-Disposition: attachment; filename='settings.ini'");
423
  echo ga_events_get_settings();
424
+ exit();
425
  }
426
 
427
  ?>
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: yuvalo
3
  Tags: analytics, google, events, ga
4
  Tested up to: 4.4
5
- Stable tag: 1.8
6
  License: GPLv2
7
  Requires at least: 3.0
8
 
@@ -38,6 +38,8 @@ http://www.youtube.com/watch?v=UP8mfuV9huI
38
  3. Plugin Scroll Settings screenshot-5.png
39
  2. Google Analytics real time events screenshot-2.png
40
  == Changelog ==
 
 
41
  = Version 1.7 =
42
  1. Import / Export ferature added
43
  = Version 1.6 =
2
  Contributors: yuvalo
3
  Tags: analytics, google, events, ga
4
  Tested up to: 4.4
5
+ Stable tag: 1.9
6
  License: GPLv2
7
  Requires at least: 3.0
8
 
38
  3. Plugin Scroll Settings screenshot-5.png
39
  2. Google Analytics real time events screenshot-2.png
40
  == Changelog ==
41
+ = Version 1.9 =
42
+ 1. Added the Non-Interaction Field
43
  = Version 1.7 =
44
  1. Import / Export ferature added
45
  = Version 1.6 =