Version Description
Download this release
Release Info
Developer | yuvalo |
Plugin | WP Google Analytics Events |
Version | 2.2 |
Comparing to | |
See all releases |
Code changes from version 2.1 to 2.2
- ga-scroll-event.php +29 -5
- includes/admin.php +136 -93
- includes/functions.php +32 -0
- includes/notice.php +116 -0
- js/admin.js +9 -0
- js/ga-scroll-events.js +2 -2
- readme.txt +2 -2
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.
|
7 |
Author: Yuval Oren
|
8 |
Author URI: http://wpflow.com
|
9 |
License: GPLv2
|
@@ -16,6 +16,23 @@ You should have received a copy of the GNU General Public License
|
|
16 |
along with this program; if not, write to the Free Software
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
$plugin_path = plugin_dir_path(__FILE__);
|
21 |
|
@@ -41,8 +58,9 @@ function ga_events_install() {
|
|
41 |
$ga_events_options = array(
|
42 |
'id' => '',
|
43 |
'exclude_snippet' => '0',
|
44 |
-
'universal' => '
|
45 |
'anonymizeip' => '0',
|
|
|
46 |
'divs' => array(array(id => '',type =>'', action => '', cat => '', label => '')),
|
47 |
'click' => array(array(id => '',type =>'', action => '', cat => '', label => ''))
|
48 |
);
|
@@ -167,10 +185,16 @@ function ga_events_footer() {
|
|
167 |
}
|
168 |
|
169 |
function ga_events_get_selector($element) {
|
|
|
170 |
if ($element[0]){
|
171 |
-
$selector =
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
174 |
$selector .= "'category':'".$element[2]."',";
|
175 |
$selector .= "'action':'".$element[3]."',";
|
176 |
$selector .= "'label':'".$element[4]."',";
|
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.2
|
7 |
Author: Yuval Oren
|
8 |
Author URI: http://wpflow.com
|
9 |
License: GPLv2
|
16 |
along with this program; if not, write to the Free Software
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
*/
|
19 |
+
error_reporting(E_ERROR | E_PARSE);
|
20 |
+
|
21 |
+
include( dirname( __FILE__ ) . '/includes/notice.php' );
|
22 |
+
if ( function_exists( 'ga_events_set_review_trigger_date' ) ) {
|
23 |
+
register_activation_hook( __FILE__, 'ga_events_set_review_trigger_date' );
|
24 |
+
}
|
25 |
+
/**
|
26 |
+
* Set Trigger Date.
|
27 |
+
*
|
28 |
+
* @since 1.0.0
|
29 |
+
*/
|
30 |
+
function ga_events_set_review_trigger_date() {
|
31 |
+
$triggerreview = mktime(0, 0, 0, date('m') , date('d') + 30 , date('Y'));
|
32 |
+
if ( ! get_option( 'ga_events_activation_date')) {
|
33 |
+
add_option( 'ga_events_activation_date', $triggerreview, '', 'yes' );
|
34 |
+
}
|
35 |
+
}
|
36 |
|
37 |
$plugin_path = plugin_dir_path(__FILE__);
|
38 |
|
58 |
$ga_events_options = array(
|
59 |
'id' => '',
|
60 |
'exclude_snippet' => '0',
|
61 |
+
'universal' => '1',
|
62 |
'anonymizeip' => '0',
|
63 |
+
'advanced' => '0',
|
64 |
'divs' => array(array(id => '',type =>'', action => '', cat => '', label => '')),
|
65 |
'click' => array(array(id => '',type =>'', action => '', cat => '', label => ''))
|
66 |
);
|
185 |
}
|
186 |
|
187 |
function ga_events_get_selector($element) {
|
188 |
+
$options = get_option('ga_events_options');
|
189 |
if ($element[0]){
|
190 |
+
$selector = '{';
|
191 |
+
if($element[1] =='advanced'){
|
192 |
+
$selector .= "'select':'".$element[0]."',";
|
193 |
+
}else{
|
194 |
+
$selector = "{'select':'";
|
195 |
+
$selector .= ($element[1] =='class') ? '.':'#';
|
196 |
+
$selector .= str_replace(' ','',$element[0])."',";
|
197 |
+
}
|
198 |
$selector .= "'category':'".$element[2]."',";
|
199 |
$selector .= "'action':'".$element[3]."',";
|
200 |
$selector .= "'label':'".$element[4]."',";
|
includes/admin.php
CHANGED
@@ -42,7 +42,7 @@ function ga_events_settings_page() {
|
|
42 |
<form id="ga-events-settings-form" method="post" action='options.php'>
|
43 |
<?php settings_fields('ga_events_options'); ?>
|
44 |
<?php
|
45 |
-
|
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') {
|
@@ -55,7 +55,7 @@ function ga_events_settings_page() {
|
|
55 |
<input class="button-primary" type="submit" name="submit" value="Save Changes" />
|
56 |
|
57 |
</form>
|
58 |
-
|
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">
|
@@ -66,41 +66,40 @@ function ga_events_settings_page() {
|
|
66 |
<?php
|
67 |
if ($show_sidebar) {
|
68 |
?>
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
">
|
93 |
-
|
94 |
-
|
95 |
-
</
|
96 |
-
</
|
97 |
-
</
|
98 |
-
</
|
99 |
-
</
|
100 |
-
</
|
101 |
-
</table>
|
102 |
|
103 |
-
|
104 |
<?php }} ?>
|
105 |
|
106 |
|
@@ -130,16 +129,14 @@ add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
|
|
130 |
add_action('admin_init', 'ga_events_admin_init');
|
131 |
|
132 |
function ga_events_admin_init() {
|
133 |
-
|
134 |
-
|
135 |
if(isset($_GET['download']) && isset($_GET['page'])){
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
}
|
140 |
|
141 |
if(isset($_POST['set_settings'])){
|
142 |
-
|
143 |
}
|
144 |
|
145 |
|
@@ -152,6 +149,7 @@ function ga_events_admin_init() {
|
|
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_anonymizeip', '','ga_events_setting_anon_input','ga_events','ga_events_main');
|
|
|
155 |
add_settings_field('ga_events_divs', '','ga_events_setting_divs_input','ga_events_scroll','ga_events_scroll_section');
|
156 |
add_settings_field('ga_events_started', '','ga_events_setting_started','ga_events_started','ga_events_started_section');
|
157 |
add_settings_field('ga_events_click', '','ga_events_setting_click_input','ga_events_click','ga_events_click_section');
|
@@ -163,7 +161,7 @@ function ga_events_admin_init() {
|
|
163 |
}
|
164 |
|
165 |
function ga_events_section_text() {
|
166 |
-
echo "<br><a style='margin-left:8px;' href='http://wpflow.com/documentation'>Plugin Documentation</a>";
|
167 |
}
|
168 |
|
169 |
function ga_events_setting_started() {
|
@@ -218,6 +216,13 @@ function ga_events_setting_anon_input() {
|
|
218 |
echo "<span class='ga_intable'><input id='anonymizeip' name='ga_events_options[anonymizeip]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
|
219 |
}
|
220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
function ga_events_settings_download(){
|
222 |
echo '<a class="button" href="http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] .'&download=1">Export settings</a>';
|
223 |
}
|
@@ -229,12 +234,26 @@ function ga_events_settings_upload(){
|
|
229 |
function ga_events_setting_divs_input() {
|
230 |
$options = get_option('ga_events_options');
|
231 |
$divs= $options['divs'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
$type='divs';
|
|
|
233 |
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>";
|
234 |
if (!($divs[0][0])){
|
|
|
|
|
|
|
235 |
echo "<tr>";
|
236 |
echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][0][0]' type='text' value='".$divs[0][0]."' /></td>";
|
237 |
-
echo "<td data-title='Type'
|
238 |
echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][0][2]' type='text' value='".$divs[0][2]."' /></td>";
|
239 |
echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][0][3]' type='text' value='".$divs[0][3]."' /></td>";
|
240 |
echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][0][4]' type='text' value='".$divs[0][4]."' /></td>";
|
@@ -250,15 +269,12 @@ function ga_events_setting_divs_input() {
|
|
250 |
|
251 |
}else{
|
252 |
for ($i = 0; $i < sizeof($divs)+1; $i++){
|
253 |
-
|
|
|
|
|
254 |
echo "<tr>";
|
255 |
echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][$i][0] type='text' value='".$divs[$i][0]."' /></td>";
|
256 |
-
echo "<td data-title='Type'
|
257 |
-
if ($divs[$i][1] == 'id'){
|
258 |
-
echo "<option selected value='id' >id</option><option value='class'>class</option></select></td>";
|
259 |
-
}else {
|
260 |
-
echo "<option value='id' >id</option><option selected value='class'>class</option></select></td>";
|
261 |
-
}
|
262 |
echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][$i][2]' type='text' value='".$divs[$i][2]."' /></td>";
|
263 |
echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][$i][3]' type='text' value='".$divs[$i][3]."' /></td>";
|
264 |
echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][$i][4]' type='text' value='".$divs[$i][4]."' /></td>";
|
@@ -284,12 +300,27 @@ function ga_events_setting_click_input() {
|
|
284 |
$options = get_option('ga_events_options');
|
285 |
$click = $options['click'];
|
286 |
$divs= $options['click'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
$type='click';
|
|
|
|
|
288 |
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>";
|
289 |
if (!($click[0][0])){
|
|
|
|
|
|
|
290 |
echo "<tr>";
|
291 |
echo "<td data-title='Element Name'><input id='click' name='ga_events_options[click][0][0]' type='text' value='".$click[0][0]."' /></td>";
|
292 |
-
echo "<td data-title='Type'
|
293 |
echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][0][2]' type='text' value='".$click[0][2]."' /></td>";
|
294 |
echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][0][3]' type='text' value='".$click[0][3]."' /></td>";
|
295 |
echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][0][4]' type='text' value='".$click[0][4]."' /></td>";
|
@@ -307,15 +338,13 @@ function ga_events_setting_click_input() {
|
|
307 |
|
308 |
}else{
|
309 |
for ($i = 0; $i < sizeof($click)+1; $i++){
|
310 |
-
|
|
|
|
|
|
|
311 |
echo "<tr>";
|
312 |
echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[click][$i][0] type='text' value='".$click[$i][0]."' /></td>";
|
313 |
-
echo "<td data-title='Type'
|
314 |
-
if ($click[$i][1] == 'id'){
|
315 |
-
echo "<option selected value='id' >id</option><option value='class'>class</option></select></td>";
|
316 |
-
}else {
|
317 |
-
echo "<option value='id' >id</option><option selected value='class'>class</option></select></td>";
|
318 |
-
}
|
319 |
echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][$i][2] type='text' value='".$click[$i][2]."' /></td>";
|
320 |
echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][$i][3] type='text' value='".$click[$i][3]."' /></td>";
|
321 |
echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][$i][4] type='text' value='".$click[$i][4]."' /></td>";
|
@@ -350,20 +379,22 @@ function ga_events_validate($form){
|
|
350 |
if( array_key_exists('divs', $form)) {
|
351 |
|
352 |
$updated['divs'] = array();
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
|
|
357 |
}
|
358 |
}
|
359 |
}
|
360 |
else if(array_key_exists('click', $form)) {
|
361 |
$updated['click'] = array();
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
|
|
367 |
}
|
368 |
}
|
369 |
else {
|
@@ -371,6 +402,7 @@ function ga_events_validate($form){
|
|
371 |
$updated['exclude_snippet'] = $form['exclude_snippet'];
|
372 |
$updated['universal'] = $form['universal'];
|
373 |
$updated['anonymizeip'] = $form['anonymizeip'];
|
|
|
374 |
}
|
375 |
|
376 |
return $updated;
|
@@ -393,44 +425,55 @@ function ga_events_admin_footer() {
|
|
393 |
|
394 |
function ga_events_get_settings(){
|
395 |
$options = get_option('ga_events_options');
|
396 |
-
|
397 |
-
|
398 |
-
return $current;
|
399 |
}
|
400 |
|
401 |
function ga_events_upload_settings($file){
|
402 |
$uploadedfile = $file['settings'];
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
ga_event_get_content($content);
|
410 |
}
|
411 |
|
412 |
function ga_event_get_content($content){
|
413 |
if(!$current = json_decode($content,true)){
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
|
423 |
}
|
424 |
function ga_event_popup(){
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
}
|
429 |
function ga_events_file(){
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
}
|
435 |
|
436 |
?>
|
42 |
<form id="ga-events-settings-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') {
|
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">
|
66 |
<?php
|
67 |
if ($show_sidebar) {
|
68 |
?>
|
69 |
+
<div class="wrap ga_events_sidebar">
|
70 |
+
<table class="form-table widefat" >
|
71 |
+
<thead>
|
72 |
+
<th>Need More Features?</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>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="button-primary button-large" target="_blank" href="https://wpflow.com/upgrade?utm_source=wpadm&utm_medium=banner&utm_content=side&utm_campaign=wpadmin">
|
92 |
+
<span class="btn-title ">
|
93 |
+
Upgrade Now
|
94 |
+
</span>
|
95 |
+
</a>
|
96 |
+
</div>
|
97 |
+
</td>
|
98 |
+
</tr>
|
99 |
+
</tbody>
|
100 |
+
</table>
|
|
|
101 |
|
102 |
+
</div>
|
103 |
<?php }} ?>
|
104 |
|
105 |
|
129 |
add_action('admin_init', 'ga_events_admin_init');
|
130 |
|
131 |
function ga_events_admin_init() {
|
|
|
|
|
132 |
if(isset($_GET['download']) && isset($_GET['page'])){
|
133 |
+
if ($_GET['page'] == 'wp-google-analytics-events') {
|
134 |
+
ga_events_file();
|
135 |
+
}
|
136 |
}
|
137 |
|
138 |
if(isset($_POST['set_settings'])){
|
139 |
+
ga_events_upload_settings($_FILES);
|
140 |
}
|
141 |
|
142 |
|
149 |
add_settings_field('ga_events_exclude_snippet', '','ga_events_setting_snippet_input','ga_events','ga_events_main');
|
150 |
add_settings_field('ga_events_universal', '','ga_events_setting_uni_input','ga_events','ga_events_main');
|
151 |
add_settings_field('ga_events_anonymizeip', '','ga_events_setting_anon_input','ga_events','ga_events_main');
|
152 |
+
add_settings_field('ga_events_advanced', '','ga_events_setting_adv_input','ga_events','ga_events_main');
|
153 |
add_settings_field('ga_events_divs', '','ga_events_setting_divs_input','ga_events_scroll','ga_events_scroll_section');
|
154 |
add_settings_field('ga_events_started', '','ga_events_setting_started','ga_events_started','ga_events_started_section');
|
155 |
add_settings_field('ga_events_click', '','ga_events_setting_click_input','ga_events_click','ga_events_click_section');
|
161 |
}
|
162 |
|
163 |
function ga_events_section_text() {
|
164 |
+
echo "<br><a style='margin-left:8px;' href='http://wpflow.com/documentation' target='_blank'>Plugin Documentation</a>";
|
165 |
}
|
166 |
|
167 |
function ga_events_setting_started() {
|
216 |
echo "<span class='ga_intable'><input id='anonymizeip' name='ga_events_options[anonymizeip]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
|
217 |
}
|
218 |
|
219 |
+
function ga_events_setting_adv_input() {
|
220 |
+
$options = get_option('ga_events_options');
|
221 |
+
$id = $options['advanced'];
|
222 |
+
echo "<label>Advanced Mode</label>";
|
223 |
+
echo "<span class='ga_intable'><input id='advanced' name='ga_events_options[advanced]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></span>";
|
224 |
+
}
|
225 |
+
|
226 |
function ga_events_settings_download(){
|
227 |
echo '<a class="button" href="http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] .'&download=1">Export settings</a>';
|
228 |
}
|
234 |
function ga_events_setting_divs_input() {
|
235 |
$options = get_option('ga_events_options');
|
236 |
$divs= $options['divs'];
|
237 |
+
|
238 |
+
$menu_options = array(
|
239 |
+
'id' => 'id',
|
240 |
+
'class' => 'class',
|
241 |
+
);
|
242 |
+
|
243 |
+
if(is_advanced_mode()){
|
244 |
+
$menu_options['advanced'] = 'advanced'; // if enabled, add 'avanced' on the menu
|
245 |
+
}
|
246 |
+
|
247 |
$type='divs';
|
248 |
+
|
249 |
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>";
|
250 |
if (!($divs[0][0])){
|
251 |
+
$name = "ga_events_options[$type][0][1]";
|
252 |
+
$type_menu = createDropdown($name, $type, $menu_options,'id');
|
253 |
+
|
254 |
echo "<tr>";
|
255 |
echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][0][0]' type='text' value='".$divs[0][0]."' /></td>";
|
256 |
+
echo "<td data-title='Type'>$type_menu</td>";
|
257 |
echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][0][2]' type='text' value='".$divs[0][2]."' /></td>";
|
258 |
echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][0][3]' type='text' value='".$divs[0][3]."' /></td>";
|
259 |
echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][0][4]' type='text' value='".$divs[0][4]."' /></td>";
|
269 |
|
270 |
}else{
|
271 |
for ($i = 0; $i < sizeof($divs)+1; $i++){
|
272 |
+
$name = "ga_events_options[$type][$i][1]";
|
273 |
+
$selected = $divs[$i][1];
|
274 |
+
$type_menu = createDropdown($name, $type, $menu_options, $selected);
|
275 |
echo "<tr>";
|
276 |
echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[divs][$i][0] type='text' value='".$divs[$i][0]."' /></td>";
|
277 |
+
echo "<td data-title='Type'>$type_menu</td>";
|
|
|
|
|
|
|
|
|
|
|
278 |
echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][$i][2]' type='text' value='".$divs[$i][2]."' /></td>";
|
279 |
echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][$i][3]' type='text' value='".$divs[$i][3]."' /></td>";
|
280 |
echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][$i][4]' type='text' value='".$divs[$i][4]."' /></td>";
|
300 |
$options = get_option('ga_events_options');
|
301 |
$click = $options['click'];
|
302 |
$divs= $options['click'];
|
303 |
+
|
304 |
+
$menu_options = array(
|
305 |
+
'id' => 'id',
|
306 |
+
'class' => 'class',
|
307 |
+
);
|
308 |
+
|
309 |
+
if(is_advanced_mode()){
|
310 |
+
$menu_options['advanced'] = 'advanced'; // if enabled, add 'avanced' on the menu
|
311 |
+
}
|
312 |
+
|
313 |
$type='click';
|
314 |
+
|
315 |
+
|
316 |
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>";
|
317 |
if (!($click[0][0])){
|
318 |
+
$name = "ga_events_options[click][0][1]";
|
319 |
+
$type_menu = createDropdown($name, $type, $menu_options,'id');
|
320 |
+
|
321 |
echo "<tr>";
|
322 |
echo "<td data-title='Element Name'><input id='click' name='ga_events_options[click][0][0]' type='text' value='".$click[0][0]."' /></td>";
|
323 |
+
echo "<td data-title='Type'>$type_menu</td>";
|
324 |
echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][0][2]' type='text' value='".$click[0][2]."' /></td>";
|
325 |
echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][0][3]' type='text' value='".$click[0][3]."' /></td>";
|
326 |
echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][0][4]' type='text' value='".$click[0][4]."' /></td>";
|
338 |
|
339 |
}else{
|
340 |
for ($i = 0; $i < sizeof($click)+1; $i++){
|
341 |
+
$name = "ga_events_options[click][$i][1]";
|
342 |
+
$selected = $click[$i][1];
|
343 |
+
$type_menu = createDropdown($name, $type, $menu_options, $selected);
|
344 |
+
|
345 |
echo "<tr>";
|
346 |
echo "<td data-title='Element Name'><input id='divs' name='ga_events_options[click][$i][0] type='text' value='".$click[$i][0]."' /></td>";
|
347 |
+
echo "<td data-title='Type'>$type_menu</td>";
|
|
|
|
|
|
|
|
|
|
|
348 |
echo "<td data-title='Event Category'><input id='click' name='ga_events_options[click][$i][2] type='text' value='".$click[$i][2]."' /></td>";
|
349 |
echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][$i][3] type='text' value='".$click[$i][3]."' /></td>";
|
350 |
echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][$i][4] type='text' value='".$click[$i][4]."' /></td>";
|
379 |
if( array_key_exists('divs', $form)) {
|
380 |
|
381 |
$updated['divs'] = array();
|
382 |
+
$divFields = array_values($form['divs']); //force array index to start with 0
|
383 |
+
for ($i = 0, $j = 0; $i< sizeof($divFields); $i++){
|
384 |
+
if ($divFields[$i][0]){
|
385 |
+
$updated['divs'][$j] = cleanEventFeilds($divFields[$i]);
|
386 |
+
$j++;
|
387 |
}
|
388 |
}
|
389 |
}
|
390 |
else if(array_key_exists('click', $form)) {
|
391 |
$updated['click'] = array();
|
392 |
+
$clickFields = array_values($form['click']); //force array index to start with 0
|
393 |
+
for ($i = 0, $j = 0; $i< sizeof($clickFields); $i++){
|
394 |
+
if ($clickFields[$i][0]){
|
395 |
+
$updated['click'][$j] = cleanEventFeilds($clickFields[$i]);
|
396 |
+
$j++;
|
397 |
+
}
|
398 |
}
|
399 |
}
|
400 |
else {
|
402 |
$updated['exclude_snippet'] = $form['exclude_snippet'];
|
403 |
$updated['universal'] = $form['universal'];
|
404 |
$updated['anonymizeip'] = $form['anonymizeip'];
|
405 |
+
$updated['advanced'] = $form['advanced'];
|
406 |
}
|
407 |
|
408 |
return $updated;
|
425 |
|
426 |
function ga_events_get_settings(){
|
427 |
$options = get_option('ga_events_options');
|
428 |
+
$current = json_encode($options);
|
429 |
+
return $current;
|
|
|
430 |
}
|
431 |
|
432 |
function ga_events_upload_settings($file){
|
433 |
$uploadedfile = $file['settings'];
|
434 |
+
if($uploadedfile['type'] != 'application/octet-stream'){
|
435 |
+
ga_event_popup();
|
436 |
+
return;
|
437 |
+
}
|
438 |
+
$content = file_get_contents($uploadedfile["tmp_name"]);
|
439 |
+
ga_event_get_content($content);
|
|
|
440 |
}
|
441 |
|
442 |
function ga_event_get_content($content){
|
443 |
if(!$current = json_decode($content,true)){
|
444 |
+
ga_event_popup();
|
445 |
+
return;
|
446 |
+
}
|
447 |
+
if (!array_key_exists('id', $current) && !array_key_exists('domain', $current)) {
|
448 |
+
ga_event_popup();
|
449 |
+
return;
|
450 |
+
}
|
451 |
+
update_option( 'ga_events_options', $current );
|
452 |
|
453 |
}
|
454 |
function ga_event_popup(){
|
455 |
+
echo "<dev class='popup'>";
|
456 |
+
echo '<h1>Wrong file format <a href="#" class="btn_close_popup"><img src="'.plugins_url( 'images/close.png', dirname(__FILE__)).'"></a></h1>';
|
457 |
+
echo "</dev>";
|
458 |
}
|
459 |
function ga_events_file(){
|
460 |
+
header("Content-type: text/plain");
|
461 |
+
header("Content-Disposition: attachment; filename='settings.ini'");
|
462 |
+
echo ga_events_get_settings();
|
463 |
+
exit();
|
464 |
+
}
|
465 |
+
|
466 |
+
function cleanEventFeilds($arr) {
|
467 |
+
if('advanced' == $arr[1]){
|
468 |
+
$arr[0] = str_replace("'",'"',$arr[0]);
|
469 |
+
}else{
|
470 |
+
$arr[0] = str_replace("'","",$arr[0]);
|
471 |
+
}
|
472 |
+
|
473 |
+
for ($i = 1; $i < sizeof($arr); $i++) {
|
474 |
+
$arr[$i] = esc_html($arr[$i]);
|
475 |
+
}
|
476 |
+
return $arr;
|
477 |
}
|
478 |
|
479 |
?>
|
includes/functions.php
CHANGED
@@ -33,4 +33,36 @@ function isOptionMigrationRequired(){
|
|
33 |
return false;
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
?>
|
33 |
return false;
|
34 |
}
|
35 |
|
36 |
+
function is_advanced_mode(){
|
37 |
+
$ga_events_options = get_option( 'ga_events_options' );
|
38 |
+
return $ga_events_options['advanced'];
|
39 |
+
}
|
40 |
+
|
41 |
+
function is_advanced_type($type){
|
42 |
+
return 'advanced' == $type;
|
43 |
+
}
|
44 |
+
|
45 |
+
function createDropdown($name, $id, $options = array(), $selected = 'unknown'){
|
46 |
+
$html = '';
|
47 |
+
if(!empty($options)){
|
48 |
+
$html .= "<select id='$id' name='$name'>";
|
49 |
+
|
50 |
+
if(!in_array($selected, $options)){
|
51 |
+
// even advanced mode is off, 'avanced' should still be accepted as valid option
|
52 |
+
if('advanced' == $selected){
|
53 |
+
$options['advanced'] = 'advanced';
|
54 |
+
}else{
|
55 |
+
$selected = reset($options); // set first element's key to be default
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
foreach ($options as $key => $value){
|
60 |
+
$html .= $selected == $key ? "<option selected value='$key' >$value</option>":"<option value='$key' >$value</option>";
|
61 |
+
}
|
62 |
+
|
63 |
+
$html .= "</select>";
|
64 |
+
}
|
65 |
+
return $html;
|
66 |
+
}
|
67 |
+
|
68 |
?>
|
includes/notice.php
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Notice
|
4 |
+
*
|
5 |
+
* Notice related functionality goes in this file.
|
6 |
+
*
|
7 |
+
* @since 1.0.0
|
8 |
+
* @package WP
|
9 |
+
*/
|
10 |
+
// Exit if accessed directly.
|
11 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
+
exit;
|
13 |
+
}
|
14 |
+
if ( ! function_exists( 'ga_events_review_notice' ) ) {
|
15 |
+
// Add an admin notice.
|
16 |
+
add_action( 'admin_notices', 'ga_events_review_notice' );
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Admin Notice to Encourage a Review or Donation.
|
20 |
+
*
|
21 |
+
* @author Matt Cromwell
|
22 |
+
* @version 1.0.0
|
23 |
+
*/
|
24 |
+
function ga_events_review_notice() {
|
25 |
+
// Define your Plugin name, review url, and donation url.
|
26 |
+
$plugin_name = 'WP Google Analytics Events';
|
27 |
+
$review_url = 'https://wordpress.org/support/view/plugin-reviews/wp-google-analytics-events';
|
28 |
+
$donate_url = 'https://wpflow.com/upgrade';
|
29 |
+
// Get current user.
|
30 |
+
global $current_user, $pagenow ;
|
31 |
+
$user_id = $current_user->ID;
|
32 |
+
// Get today's timestamp.
|
33 |
+
$today = mktime( 0, 0, 0, date('m') , date('d'), date('Y') );
|
34 |
+
$actdate = get_option( 'ga_events_activation_date', false );
|
35 |
+
$installed = ( ! empty( $actdate ) ? $actdate : '999999999999999' );
|
36 |
+
if ( $installed <= $today ) {
|
37 |
+
// Make sure we're on the plugins page.
|
38 |
+
// If the user hasn't already dismissed our alert,
|
39 |
+
// Output the activation banner.
|
40 |
+
$nag_admin_dismiss_url = 'plugins.php?ga_events_review_dismiss=0';
|
41 |
+
$user_meta = get_user_meta( $user_id, 'ga_events_review_dismiss' );
|
42 |
+
if ( empty($user_meta) ) {
|
43 |
+
?>
|
44 |
+
<div class="update-nag">
|
45 |
+
|
46 |
+
<style>
|
47 |
+
div.review {
|
48 |
+
position: relative;
|
49 |
+
margin-left: 35px;
|
50 |
+
height: 80px;
|
51 |
+
display:block;
|
52 |
+
}
|
53 |
+
div.review span.ga-events-icon {
|
54 |
+
color: white;
|
55 |
+
position: absolute;
|
56 |
+
left: -30px;
|
57 |
+
/*padding: 9px;*/
|
58 |
+
/*top: -8px;*/
|
59 |
+
}
|
60 |
+
div.review strong {
|
61 |
+
color: #66BB6A;
|
62 |
+
}
|
63 |
+
div.review a.dismiss {
|
64 |
+
float: right;
|
65 |
+
text-decoration: none;
|
66 |
+
color: #000000;
|
67 |
+
}
|
68 |
+
.review a {
|
69 |
+
color:#ED494D;
|
70 |
+
}
|
71 |
+
.ga-events-notice-text {
|
72 |
+
display: inline-block;
|
73 |
+
margin-left: 170px;
|
74 |
+
margin-top: 24px;
|
75 |
+
}
|
76 |
+
|
77 |
+
</style>
|
78 |
+
<?php
|
79 |
+
// For testing purposes
|
80 |
+
//echo '<p>Today = ' . $today . '</p>';
|
81 |
+
//echo '<p>Installed = ' . $installed . '</p>';
|
82 |
+
?>
|
83 |
+
|
84 |
+
<div class="review">
|
85 |
+
<span class="ga-events-icon">
|
86 |
+
<img src="<?php echo plugins_url( 'images/WPGAE_Logo-177x78.png', dirname(__FILE__)) ?>">
|
87 |
+
</span>
|
88 |
+
<span class="ga-events-notice-text">
|
89 |
+
<?php echo wp_kses( sprintf( __( 'Thank you for using <strong>' . $plugin_name . '</strong>? We would love to hear about <a href="https://wpflow.com/contact">your experience</a> with the plugin. Need more features? <a href="https://wpflow.com/upgrade" target="_blank">Upgrade Now</a> to unlock.', 'ga_events_text' ), esc_url( $donate_url ), esc_url( $review_url ) ), array( 'strong' => array(), 'a' => array( 'href' => array(), 'target' => array() ) ) ); ?>
|
90 |
+
</span>
|
91 |
+
<a href="<?php echo admin_url( $nag_admin_dismiss_url ); ?>" class="dismiss"><span class="dashicons dashicons-dismiss"></span></a>
|
92 |
+
</div>
|
93 |
+
|
94 |
+
</div>
|
95 |
+
|
96 |
+
<?php }
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
if ( function_exists( 'ga_events_ignore_review_notice' ) ) {
|
101 |
+
// Function to force the Review Admin Notice to stay dismissed correctly.
|
102 |
+
add_action('admin_init', 'ga_events_ignore_review_notice');
|
103 |
+
/**
|
104 |
+
* Ignore review notice.
|
105 |
+
*
|
106 |
+
* @since 1.0.0
|
107 |
+
*/
|
108 |
+
}
|
109 |
+
function ga_events_ignore_review_notice() {
|
110 |
+
if ( isset( $_GET[ 'ga_events_review_dismiss' ] ) && '0' == $_GET[ 'ga_events_review_dismiss' ] ) {
|
111 |
+
// Get the global user.
|
112 |
+
global $current_user;
|
113 |
+
$user_id = $current_user->ID;
|
114 |
+
add_user_meta( $user_id, 'ga_events_review_dismiss', 'true', true );
|
115 |
+
}
|
116 |
+
}
|
js/admin.js
CHANGED
@@ -26,3 +26,12 @@ jQuery('#snippet').change(function () {
|
|
26 |
jQuery('#anonymizeip').removeAttr("disabled");
|
27 |
}
|
28 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
jQuery('#anonymizeip').removeAttr("disabled");
|
27 |
}
|
28 |
});
|
29 |
+
|
30 |
+
jQuery('#advanced:checkbox').change(function () {
|
31 |
+
var checked = jQuery(this).is(':checked');
|
32 |
+
if(checked) {
|
33 |
+
if(!confirm('Advanced mode allows you to use jQuery selectors for click and scroll events. Enabling this feature and creating advanced events could cause errors on your site if misconfigured. \n\nAre you sure? ')){
|
34 |
+
jQuery(this).removeAttr('checked');
|
35 |
+
}
|
36 |
+
}
|
37 |
+
});
|
js/ga-scroll-events.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
/*!
|
2 |
-
* WP Googel Analytics Events |
|
3 |
* Copyright (c) 2013 Yuval Oren (@yuvalo)
|
4 |
* License: GPLv2
|
5 |
*/
|
@@ -51,7 +51,7 @@ var scroll_events = (function ($) {
|
|
51 |
var hasHref = event.currentTarget.href;
|
52 |
if (hasHref && hasHref !== "") {
|
53 |
event.preventDefault();
|
54 |
-
if (event.currentTarget.target === "_blank") {
|
55 |
var w = window.open('', '_blank');
|
56 |
w.location.href = event.currentTarget.href;
|
57 |
} else {
|
1 |
/*!
|
2 |
+
* WP Googel Analytics Events | v2.2
|
3 |
* Copyright (c) 2013 Yuval Oren (@yuvalo)
|
4 |
* License: GPLv2
|
5 |
*/
|
51 |
var hasHref = event.currentTarget.href;
|
52 |
if (hasHref && hasHref !== "") {
|
53 |
event.preventDefault();
|
54 |
+
if (event.currentTarget.target.trim() === "_blank") {
|
55 |
var w = window.open('', '_blank');
|
56 |
w.location.href = event.currentTarget.href;
|
57 |
} else {
|
readme.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
=== WP Google Analytics Events ===
|
2 |
Contributors: yuvalo
|
3 |
Tags: analytics, google, events, ga, google analytics, tracking
|
4 |
-
Tested up to: 4.
|
5 |
-
Stable tag: 2.
|
6 |
License: GPLv2
|
7 |
Requires at least: 3.0
|
8 |
|
1 |
=== WP Google Analytics Events ===
|
2 |
Contributors: yuvalo
|
3 |
Tags: analytics, google, events, ga, google analytics, tracking
|
4 |
+
Tested up to: 4.6.1
|
5 |
+
Stable tag: 2.2
|
6 |
License: GPLv2
|
7 |
Requires at least: 3.0
|
8 |
|