Version Description
Download this release
Release Info
Developer | yuvalo |
Plugin | WP Google Analytics Events |
Version | 2.4.2 |
Comparing to | |
See all releases |
Code changes from version 2.4.1 to 2.4.2
- css/style.css +43 -0
- ga-scroll-event.php +17 -7
- includes/admin.php +119 -13
- includes/functions.php +219 -0
- includes/notice.php +48 -0
- js/admin.js +65 -39
- js/ajax.js +193 -0
- js/ga-scroll-events.js +68 -12
- readme.txt +11 -3
css/style.css
CHANGED
@@ -46,6 +46,10 @@
|
|
46 |
display: inline-block;
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
49 |
.btn-subscribe {
|
50 |
|
51 |
z-index: 10000;
|
@@ -301,3 +305,42 @@ a.btn_close_popup img {
|
|
301 |
bottom: -20px;
|
302 |
top: auto;
|
303 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
display: inline-block;
|
47 |
}
|
48 |
|
49 |
+
#ga_main .inner_table .fa{
|
50 |
+
font-size: 20px;
|
51 |
+
}
|
52 |
+
|
53 |
.btn-subscribe {
|
54 |
|
55 |
z-index: 10000;
|
305 |
bottom: -20px;
|
306 |
top: auto;
|
307 |
}
|
308 |
+
|
309 |
+
.wpgae-container__warning{
|
310 |
+
padding: 10px 20px;
|
311 |
+
background-color: #fff;
|
312 |
+
}
|
313 |
+
|
314 |
+
.wpgae-alert-holder{
|
315 |
+
display: flex;
|
316 |
+
margin-bottom: .8em;
|
317 |
+
}
|
318 |
+
|
319 |
+
.wpgae-alert{
|
320 |
+
width: 100%;
|
321 |
+
padding: 0 12px;
|
322 |
+
border-left: 4px solid #4b8813;
|
323 |
+
background: #fff;
|
324 |
+
box-shadow: 0 1px 2px rgba(0,0,0,.2);
|
325 |
+
}
|
326 |
+
|
327 |
+
@media screen and (min-width: 1024px){
|
328 |
+
|
329 |
+
#ga_main{
|
330 |
+
width: 70%;
|
331 |
+
}
|
332 |
+
|
333 |
+
#ga_main td{
|
334 |
+
max-width: 100px;
|
335 |
+
}
|
336 |
+
#ga_main .click_table input,
|
337 |
+
#ga_main .click_table select,
|
338 |
+
#ga_main .divs_table input,
|
339 |
+
#ga_main .divs_table select{
|
340 |
+
width: 100%;
|
341 |
+
}
|
342 |
+
|
343 |
+
#ga_main input[type="submit"]{
|
344 |
+
width: auto;
|
345 |
+
}
|
346 |
+
}
|
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.
|
7 |
Author: Yuval Oren
|
8 |
Author URI: http://wpflow.com
|
9 |
License: GPLv2
|
@@ -61,13 +61,15 @@ function ga_events_install() {
|
|
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 |
);
|
67 |
if (!get_option('ga_events_options')) {
|
68 |
update_option( 'ga_events_options', $ga_events_options );
|
69 |
}
|
70 |
|
|
|
|
|
71 |
}
|
72 |
|
73 |
function ga_events_deactivate() {
|
@@ -81,10 +83,9 @@ add_action('init','ga_events_scripts');
|
|
81 |
|
82 |
function ga_events_scripts() {
|
83 |
wp_enqueue_script('jquery');
|
84 |
-
wp_enqueue_script('scrolldepth',plugins_url( '/js/ga-scroll-events.js', __FILE__) , array('jquery'), '2.4.
|
85 |
}
|
86 |
|
87 |
-
|
88 |
add_action( 'plugins_loaded', 'ga_events_setup');
|
89 |
|
90 |
function ga_events_setup() {
|
@@ -138,9 +139,15 @@ function ga_events_footer() {
|
|
138 |
$divs = $options['divs'];
|
139 |
$click = $options['click'];
|
140 |
$universal = $options['universal'];
|
141 |
-
|
|
|
|
|
142 |
$universal = 0;
|
143 |
}
|
|
|
|
|
|
|
|
|
144 |
echo "
|
145 |
<!-- BEGIN: wpflow ga events array -->
|
146 |
<script>
|
@@ -148,6 +155,8 @@ function ga_events_footer() {
|
|
148 |
jQuery(document).ready(function() {
|
149 |
scroll_events.bind_events( {
|
150 |
universal: ".$universal.",
|
|
|
|
|
151 |
scroll_elements: [";
|
152 |
$i = 0;
|
153 |
if (is_array($divs)){
|
@@ -214,7 +223,8 @@ function ga_events_get_selector($element) {
|
|
214 |
$selector .= "'category':'".$element[2]."',";
|
215 |
$selector .= "'action':'".$element[3]."',";
|
216 |
$selector .= "'label':'".$element[4]."',";
|
217 |
-
$selector .= "'bounce':'".$element[5]."'";
|
|
|
218 |
$selector .= '}';
|
219 |
return $selector;
|
220 |
}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: 2.4.2
|
7 |
Author: Yuval Oren
|
8 |
Author URI: http://wpflow.com
|
9 |
License: GPLv2
|
61 |
'universal' => '1',
|
62 |
'anonymizeip' => '0',
|
63 |
'advanced' => '0',
|
64 |
+
'divs' => array(array(id => '',type =>'', action => '', cat => '', label => '', interaction => 0, value => '')),
|
65 |
+
'click' => array(array(id => '',type =>'', action => '', cat => '', label => '', interaction => 0, value => ''))
|
66 |
);
|
67 |
if (!get_option('ga_events_options')) {
|
68 |
update_option( 'ga_events_options', $ga_events_options );
|
69 |
}
|
70 |
|
71 |
+
wpgae_reactivate_notice();
|
72 |
+
|
73 |
}
|
74 |
|
75 |
function ga_events_deactivate() {
|
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');
|
90 |
|
91 |
function ga_events_setup() {
|
139 |
$divs = $options['divs'];
|
140 |
$click = $options['click'];
|
141 |
$universal = $options['universal'];
|
142 |
+
$gtm = $options['gtm'];
|
143 |
+
|
144 |
+
if ($universal == ""){
|
145 |
$universal = 0;
|
146 |
}
|
147 |
+
|
148 |
+
if ($gtm == ""){
|
149 |
+
$gtm = 0;
|
150 |
+
}
|
151 |
echo "
|
152 |
<!-- BEGIN: wpflow ga events array -->
|
153 |
<script>
|
155 |
jQuery(document).ready(function() {
|
156 |
scroll_events.bind_events( {
|
157 |
universal: ".$universal.",
|
158 |
+
gtm:".$gtm.",
|
159 |
+
|
160 |
scroll_elements: [";
|
161 |
$i = 0;
|
162 |
if (is_array($divs)){
|
223 |
$selector .= "'category':'".$element[2]."',";
|
224 |
$selector .= "'action':'".$element[3]."',";
|
225 |
$selector .= "'label':'".$element[4]."',";
|
226 |
+
$selector .= "'bounce':'".$element[5]."',";
|
227 |
+
$selector .= "'evalue':'".$element[6]."'";
|
228 |
$selector .= '}';
|
229 |
return $selector;
|
230 |
}else{
|
includes/admin.php
CHANGED
@@ -13,6 +13,7 @@ function ga_events_menu() {
|
|
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 |
|
@@ -33,11 +34,17 @@ function ga_events_settings_page() {
|
|
33 |
<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>
|
34 |
<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>
|
35 |
<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>
|
|
|
36 |
</h2>
|
37 |
<?php
|
38 |
if ($active_page == 'wp-google-analytics-events-started') {
|
39 |
do_settings_sections('ga_events_started');
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
?>
|
42 |
|
43 |
<form id="ga-events-settings-form" method="post" action='options.php'>
|
@@ -53,8 +60,13 @@ function ga_events_settings_page() {
|
|
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">
|
@@ -123,10 +135,19 @@ function ga_events_settings_page() {
|
|
123 |
}
|
124 |
|
125 |
function load_custom_wp_admin_style() {
|
126 |
-
wp_register_style( '
|
|
|
127 |
wp_enqueue_style( 'custom_wp_admin_css' );
|
128 |
-
wp_enqueue_script( 'admin-init', plugins_url('js/admin.js', dirname(__FILE__)) , array('jquery','jquery-ui-tooltip'), null, true );
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
}
|
131 |
|
132 |
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
|
@@ -150,8 +171,10 @@ function ga_events_admin_init() {
|
|
150 |
add_settings_section('ga_events_click_section','', 'ga_events_section_text','ga_events_click');
|
151 |
add_settings_section('ga_events_scroll_section','', 'ga_events_section_text','ga_events_scroll');
|
152 |
add_settings_section('ga_events_started_section','Getting Started Guide', 'ga_events_section_text','ga_events_started');
|
|
|
153 |
add_settings_field('ga_events_id', '','ga_events_setting_input','ga_events','ga_events_main');
|
154 |
add_settings_field('ga_events_exclude_snippet', '','ga_events_setting_snippet_input','ga_events','ga_events_main');
|
|
|
155 |
add_settings_field('ga_events_universal', '','ga_events_setting_uni_input','ga_events','ga_events_main');
|
156 |
add_settings_field('ga_events_anonymizeip', '','ga_events_setting_anon_input','ga_events','ga_events_main');
|
157 |
add_settings_field('ga_events_advanced', '','ga_events_setting_adv_input','ga_events','ga_events_main');
|
@@ -169,16 +192,53 @@ function ga_events_section_text() {
|
|
169 |
echo "<br><a style='margin-left:8px;' href='http://wpflow.com/documentation' target='_blank'>Plugin Documentation</a>";
|
170 |
}
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
function ga_events_setting_started() {
|
173 |
echo '
|
174 |
<h2>Getting Started Guide</h2>
|
175 |
<form action="https://www.getdrip.com/forms/4588171/submissions" method="post" data-drip-embedded-form="4588171">
|
176 |
<div style="background:white; line-height:20px; padding: 5px 15px 15px 15px;
|
177 |
-
font-size: 15px; max-width:
|
178 |
|
179 |
<h3 style="margin-top: 10px;" data-drip-attribute="headline">Want to learn more about event tracking?</h3>
|
180 |
<div data-drip-attribute="description">Now that you installed the plugin, we want to help you get everything up and running. <br />
|
181 |
-
Join our short email course and get started with event tracking.</div>
|
|
|
|
|
|
|
|
|
182 |
<div>
|
183 |
<label style="margin-top:10px;"for="fields[email]">Email Address:</label><br />
|
184 |
<input type="email" name="fields[email]" value="" />
|
@@ -207,6 +267,19 @@ function ga_events_setting_snippet_input() {
|
|
207 |
|
208 |
}
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
function ga_events_setting_uni_input() {
|
211 |
$options = get_option('ga_events_options');
|
212 |
$id = $options['universal'];
|
@@ -251,7 +324,7 @@ function ga_events_setting_divs_input() {
|
|
251 |
|
252 |
$type='divs';
|
253 |
|
254 |
-
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>";
|
255 |
if (!($divs[0][0])){
|
256 |
$name = "ga_events_options[$type][0][1]";
|
257 |
$type_menu = createDropdown($name, $type, $menu_options,'id');
|
@@ -263,13 +336,15 @@ function ga_events_setting_divs_input() {
|
|
263 |
echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][0][3]' type='text' value='".$divs[0][3]."' /></td>";
|
264 |
echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][0][4]' type='text' value='".$divs[0][4]."' /></td>";
|
265 |
|
|
|
|
|
266 |
echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
|
267 |
if ($divs[$i][5] == 'true') {
|
268 |
echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
|
269 |
} else {
|
270 |
echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
|
271 |
}
|
272 |
-
|
273 |
echo "</tr>";
|
274 |
|
275 |
}else{
|
@@ -283,7 +358,7 @@ function ga_events_setting_divs_input() {
|
|
283 |
echo "<td data-title='Event Category'><input id='divs' name='ga_events_options[divs][$i][2]' type='text' value='".$divs[$i][2]."' /></td>";
|
284 |
echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][$i][3]' type='text' value='".$divs[$i][3]."' /></td>";
|
285 |
echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][$i][4]' type='text' value='".$divs[$i][4]."' /></td>";
|
286 |
-
|
287 |
echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
|
288 |
if ($divs[$i][5] == 'true') {
|
289 |
echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
|
@@ -291,7 +366,13 @@ function ga_events_setting_divs_input() {
|
|
291 |
echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
|
292 |
}
|
293 |
|
294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
echo "</tr>";
|
296 |
|
297 |
}
|
@@ -318,7 +399,7 @@ function ga_events_setting_click_input() {
|
|
318 |
$type='click';
|
319 |
|
320 |
|
321 |
-
echo "<table id='ga-events-inputs' class='widefat inputs inner_table
|
322 |
if (!($click[0][0])){
|
323 |
$name = "ga_events_options[click][0][1]";
|
324 |
$type_menu = createDropdown($name, $type, $menu_options,'id');
|
@@ -330,6 +411,8 @@ function ga_events_setting_click_input() {
|
|
330 |
echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][0][3]' type='text' value='".$click[0][3]."' /></td>";
|
331 |
echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][0][4]' type='text' value='".$click[0][4]."' /></td>";
|
332 |
|
|
|
|
|
333 |
echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
|
334 |
if ($divs[$i][5] == 'true') {
|
335 |
echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
|
@@ -338,7 +421,7 @@ function ga_events_setting_click_input() {
|
|
338 |
}
|
339 |
|
340 |
|
341 |
-
|
342 |
echo "</tr>";
|
343 |
|
344 |
}else{
|
@@ -354,6 +437,8 @@ function ga_events_setting_click_input() {
|
|
354 |
echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][$i][3] type='text' value='".$click[$i][3]."' /></td>";
|
355 |
echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][$i][4] type='text' value='".$click[$i][4]."' /></td>";
|
356 |
|
|
|
|
|
357 |
echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
|
358 |
if ($divs[$i][5] == 'true') {
|
359 |
echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
|
@@ -362,7 +447,14 @@ function ga_events_setting_click_input() {
|
|
362 |
echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
|
363 |
}
|
364 |
|
365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
echo "</tr>";
|
367 |
|
368 |
}
|
@@ -408,6 +500,7 @@ function ga_events_validate($form){
|
|
408 |
$updated['universal'] = $form['universal'];
|
409 |
$updated['anonymizeip'] = $form['anonymizeip'];
|
410 |
$updated['advanced'] = $form['advanced'];
|
|
|
411 |
}
|
412 |
|
413 |
return $updated;
|
@@ -481,6 +574,19 @@ function cleanEventFeilds($arr) {
|
|
481 |
return $arr;
|
482 |
}
|
483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
function ga_tooltip($content = '') {
|
485 |
$html = '<span class="ga-tooltip" title="'.$content.'"></span>';
|
486 |
return $html;
|
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',"What's New","What's New", 'manage_options', 'wp-google-analytics-events-whatsnew' , 'ga_events_settings_page' );
|
17 |
add_submenu_page('wp-google-analytics-events','Upgrade','Upgrade Now', 'manage_options', 'wp-google-analytics-events-upgrade', 'ga_events_settings_page' );
|
18 |
}
|
19 |
|
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>
|
36 |
<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>
|
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'>
|
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 |
+
?>
|
70 |
</form>
|
71 |
<div class="settings_content">
|
72 |
<form action="" method="post" enctype="multipart/form-data">
|
135 |
}
|
136 |
|
137 |
function load_custom_wp_admin_style() {
|
138 |
+
wp_register_style( 'wpgae-font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css' );
|
139 |
+
wp_register_style( 'custom_wp_admin_css', plugins_url('css/style.css', dirname(__FILE__)), array('wpgae-font-awesome'));
|
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 |
+
|
150 |
+
wp_enqueue_script( 'admin-init', plugins_url('js/admin.js', dirname(__FILE__)) , array('jquery','jquery-ui-tooltip','wpgae-ajax'), null, true );
|
151 |
}
|
152 |
|
153 |
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
|
171 |
add_settings_section('ga_events_click_section','', 'ga_events_section_text','ga_events_click');
|
172 |
add_settings_section('ga_events_scroll_section','', 'ga_events_section_text','ga_events_scroll');
|
173 |
add_settings_section('ga_events_started_section','Getting Started Guide', 'ga_events_section_text','ga_events_started');
|
174 |
+
add_settings_section('ga_events_whatsnew_section','', 'ga_events_whatsnew_section_content','ga_events_whatsnew');
|
175 |
add_settings_field('ga_events_id', '','ga_events_setting_input','ga_events','ga_events_main');
|
176 |
add_settings_field('ga_events_exclude_snippet', '','ga_events_setting_snippet_input','ga_events','ga_events_main');
|
177 |
+
add_settings_field('ga_events_gtm', '', 'ga_events_setting_gtm_input', 'ga_events', 'ga_events_main');
|
178 |
add_settings_field('ga_events_universal', '','ga_events_setting_uni_input','ga_events','ga_events_main');
|
179 |
add_settings_field('ga_events_anonymizeip', '','ga_events_setting_anon_input','ga_events','ga_events_main');
|
180 |
add_settings_field('ga_events_advanced', '','ga_events_setting_adv_input','ga_events','ga_events_main');
|
192 |
echo "<br><a style='margin-left:8px;' href='http://wpflow.com/documentation' target='_blank'>Plugin Documentation</a>";
|
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">
|
200 |
+
<p></p>
|
201 |
+
<div class="container" id="wpgae-warnings-active">
|
202 |
+
<div class="wpgae-alert-holder">
|
203 |
+
<div class="wpgae-alert">
|
204 |
+
<p>The admin UI got a little update - We started working with ajax forms. These changes solve a problem that some of the users had with adding a long list of events.</p>
|
205 |
+
</div>
|
206 |
+
</div>
|
207 |
+
<div class="wpgae-alert-holder">
|
208 |
+
<div class="wpgae-alert">
|
209 |
+
<p>We added the value field to click and scroll events. This used to be a Pro version feature and now it is part of this plugin as well.</p>
|
210 |
+
</div>
|
211 |
+
</div>
|
212 |
+
<div class="wpgae-alert-holder">
|
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">
|
220 |
+
</div>
|
221 |
+
</div>
|
222 |
+
</div>
|
223 |
+
<?php
|
224 |
+
$content = ob_get_clean();
|
225 |
+
echo $content;
|
226 |
+
}
|
227 |
+
|
228 |
function ga_events_setting_started() {
|
229 |
echo '
|
230 |
<h2>Getting Started Guide</h2>
|
231 |
<form action="https://www.getdrip.com/forms/4588171/submissions" method="post" data-drip-embedded-form="4588171">
|
232 |
<div style="background:white; line-height:20px; padding: 5px 15px 15px 15px;
|
233 |
+
font-size: 15px; max-width:600px;">
|
234 |
|
235 |
<h3 style="margin-top: 10px;" data-drip-attribute="headline">Want to learn more about event tracking?</h3>
|
236 |
<div data-drip-attribute="description">Now that you installed the plugin, we want to help you get everything up and running. <br />
|
237 |
+
<br>Join our short email course and get started with event tracking.</div>
|
238 |
+
<div style="margin-top:10px;">
|
239 |
+
<label for="fields[first_name]">First Name</label><br />
|
240 |
+
<input type="text" name="fields[first_name]" value="" />
|
241 |
+
</div>
|
242 |
<div>
|
243 |
<label style="margin-top:10px;"for="fields[email]">Email Address:</label><br />
|
244 |
<input type="email" name="fields[email]" value="" />
|
267 |
|
268 |
}
|
269 |
|
270 |
+
function ga_events_setting_gtm_input() {
|
271 |
+
$options = get_option('ga_events_options');
|
272 |
+
if (isset($options['gtm'])) {
|
273 |
+
$id = $options['gtm'];
|
274 |
+
} else {
|
275 |
+
$id = 0;
|
276 |
+
}
|
277 |
+
echo "<label >I'm using the Google Tag Manager " . ga_tooltip('Make sure to configure on the GTM side as well') . " </label>";
|
278 |
+
|
279 |
+
echo "<input style='margin-left: 5px;' id='gtm' name='ga_events_options[gtm]' type='checkbox' value='1' " . checked($id, 1, false) . " />";
|
280 |
+
echo "<a style='margin-left: 5px;' href='https://wpflow.com/knowledgebase/google-tag-manager-support/' target='_blank'>Read More...</a>";
|
281 |
+
}
|
282 |
+
|
283 |
function ga_events_setting_uni_input() {
|
284 |
$options = get_option('ga_events_options');
|
285 |
$id = $options['universal'];
|
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');
|
336 |
echo "<td data-title='Event Action'><input id='divs' name='ga_events_options[divs][0][3]' type='text' value='".$divs[0][3]."' /></td>";
|
337 |
echo "<td data-title='Event Label'><input id='divs' name='ga_events_options[divs][0][4]' type='text' value='".$divs[0][4]."' /></td>";
|
338 |
|
339 |
+
echo "<td data-title='Event Value'><input id='click' name='ga_events_options[divs][0][6]' type='number' value='".$divs[0][6]."' /></td>";
|
340 |
+
|
341 |
echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
|
342 |
if ($divs[$i][5] == 'true') {
|
343 |
echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
|
344 |
} else {
|
345 |
echo "<option value='true' >true</option><option selected value='false'>false</option></select></td>";
|
346 |
}
|
347 |
+
echo "<td><a class='btn-add' href='#'>Add</a></td>";
|
348 |
echo "</tr>";
|
349 |
|
350 |
}else{
|
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>";
|
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 |
}
|
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');
|
411 |
echo "<td data-title='Event Action'><input id='click' name='ga_events_options[click][0][3]' type='text' value='".$click[0][3]."' /></td>";
|
412 |
echo "<td data-title='Event Label'><input id='click' name='ga_events_options[click][0][4]' type='text' value='".$click[0][4]."' /></td>";
|
413 |
|
414 |
+
echo "<td data-title='Event Value'><input id='click' name='ga_events_options[click][0][6]' type='number' value='".$click[0][6]."' /></td>";
|
415 |
+
|
416 |
echo "<td data-title='Non-Interaction'><select id='".$type."' name='ga_events_options[".$type."][$i][5]'>";
|
417 |
if ($divs[$i][5] == 'true') {
|
418 |
echo "<option selected value='true' >true</option><option value='false'>false</option></select></td>";
|
421 |
}
|
422 |
|
423 |
|
424 |
+
echo "<td><a class='btn-add' href='#'>Add</a></td>";
|
425 |
echo "</tr>";
|
426 |
|
427 |
}else{
|
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>";
|
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 |
}
|
500 |
$updated['universal'] = $form['universal'];
|
501 |
$updated['anonymizeip'] = $form['anonymizeip'];
|
502 |
$updated['advanced'] = $form['advanced'];
|
503 |
+
$updated['gtm'] = $form['gtm'];
|
504 |
}
|
505 |
|
506 |
return $updated;
|
574 |
return $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 |
+
|
590 |
function ga_tooltip($content = '') {
|
591 |
$html = '<span class="ga-tooltip" title="'.$content.'"></span>';
|
592 |
return $html;
|
includes/functions.php
CHANGED
@@ -1,5 +1,224 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
function migrateOptions() {
|
5 |
$current_options = get_option('ga_events_options');
|
1 |
<?php
|
2 |
|
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 |
+
/*
|
27 |
+
description:
|
28 |
+
function to add new tracking on both click and scroll event
|
29 |
+
TODO: create separate function for each event when inputs needed will no
|
30 |
+
longer the same
|
31 |
+
param:
|
32 |
+
$data array
|
33 |
+
return:
|
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){
|
215 |
+
// open log file
|
216 |
+
$filename = "event.log";
|
217 |
+
$fh = fopen($filename, "a") or die("Could not open log file.");
|
218 |
+
fwrite($fh, date("d-m-Y, H:i")." - $text\n") or die("Could not write file!");
|
219 |
+
fclose($fh);
|
220 |
+
}
|
221 |
+
|
222 |
|
223 |
function migrateOptions() {
|
224 |
$current_options = get_option('ga_events_options');
|
includes/notice.php
CHANGED
@@ -11,6 +11,54 @@
|
|
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' );
|
11 |
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
exit;
|
13 |
}
|
14 |
+
|
15 |
+
function whatsnew_admin_notice__success() {
|
16 |
+
|
17 |
+
global $current_user;
|
18 |
+
$user_id = $current_user->ID;
|
19 |
+
$was_ignored = get_user_meta($user_id, 'wpgae_whatsnew_ignore_notice', true);
|
20 |
+
/* Check that the user hasn't already clicked to ignore the message */
|
21 |
+
if (! $was_ignored ) {
|
22 |
+
echo '<div class="notice notice-success"><p>';
|
23 |
+
printf(__('Learn about what\'s new in <strong><a href="%s">WP Google Analytics Events</a></strong>'), 'admin.php?page=wp-google-analytics-events-whatsnew&wpgae_whatsnew_notify=1');
|
24 |
+
|
25 |
+
$active_page = isset( $_GET[ 'page' ] ) ? '&page='.esc_html( $_GET[ 'page' ] ): '';
|
26 |
+
printf(__('<a href="%s" style="float:right;">Close</a>'), '?wpgae_whatsnew_notify=1'.$active_page);
|
27 |
+
|
28 |
+
|
29 |
+
echo "</p></div>";
|
30 |
+
}
|
31 |
+
}
|
32 |
+
add_action( 'admin_notices', 'whatsnew_admin_notice__success' );
|
33 |
+
|
34 |
+
function wpgae_whatsnew_notify() {
|
35 |
+
global $current_user;
|
36 |
+
$user_id = $current_user->ID;
|
37 |
+
/* If user clicks to ignore the notice, add that to their user meta */
|
38 |
+
if ( isset($_GET['wpgae_whatsnew_notify']) && '1' == $_GET['wpgae_whatsnew_notify'] ) {
|
39 |
+
update_user_meta($user_id, 'wpgae_whatsnew_ignore_notice', true);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
add_action('admin_init', 'wpgae_whatsnew_notify');
|
43 |
+
|
44 |
+
|
45 |
+
/*
|
46 |
+
Upon plugin activation, reset 'wpgae_whatsnew_ignore_notice' for all admin users.
|
47 |
+
* This functions was called inside ga_events_install funtion.
|
48 |
+
*/
|
49 |
+
function wpgae_reactivate_notice(){
|
50 |
+
|
51 |
+
$args = array(
|
52 |
+
'role' => 'administrator'
|
53 |
+
);
|
54 |
+
|
55 |
+
$admins = get_users($args);
|
56 |
+
|
57 |
+
foreach ($admins as $user) {
|
58 |
+
update_user_meta($user->ID, 'wpgae_whatsnew_ignore_notice', false);
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
if ( ! function_exists( 'ga_events_review_notice' ) ) {
|
63 |
// Add an admin notice.
|
64 |
add_action( 'admin_notices', 'ga_events_review_notice' );
|
js/admin.js
CHANGED
@@ -1,46 +1,72 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
jQuery(
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
}
|
9 |
-
|
10 |
-
|
11 |
-
jQuery('.
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
jQuery('.
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
jQuery('.
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
jQuery('
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
-
jQuery('#snippet').
|
31 |
-
if (this.checked) {
|
32 |
jQuery('#anonymizeip')[0].checked = false;
|
33 |
jQuery('#anonymizeip').attr("disabled", true);
|
34 |
-
} else {
|
35 |
-
jQuery('#anonymizeip').removeAttr("disabled");
|
36 |
}
|
37 |
-
});
|
38 |
|
39 |
-
jQuery('#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
if (document.location.href.indexOf("wp-google-analytics-events") > -1) {
|
2 |
+
|
3 |
+
jQuery.widget.bridge('gaetooltip', jQuery.ui.tooltip);
|
4 |
+
|
5 |
+
jQuery('.ga-tooltip').gaetooltip({
|
6 |
+
position: {
|
7 |
+
my: "left bottom-10", at: "right top", collision: "none"
|
8 |
+
}
|
9 |
+
});
|
10 |
+
|
11 |
+
jQuery('.remove').click(function (event) {
|
12 |
+
event.preventDefault();
|
13 |
+
jQuery(this).closest('tr').remove();
|
14 |
+
});
|
15 |
+
|
16 |
+
jQuery('.btn_upload').on('click', function (e) {
|
17 |
+
jQuery('.settings_content').slideDown();
|
18 |
+
e.preventDefault();
|
19 |
+
});
|
20 |
+
|
21 |
+
jQuery('.btn_close').on('click', function (e) {
|
22 |
+
jQuery('.settings_content').slideUp();
|
23 |
+
e.preventDefault();
|
24 |
+
});
|
25 |
+
|
26 |
+
jQuery('.popup').on('click', function (e) {
|
27 |
+
jQuery('.popup').slideUp();
|
28 |
+
e.preventDefault();
|
29 |
+
});
|
30 |
|
31 |
+
if (jQuery('#snippet').is(":checked")) {
|
|
|
32 |
jQuery('#anonymizeip')[0].checked = false;
|
33 |
jQuery('#anonymizeip').attr("disabled", true);
|
|
|
|
|
34 |
}
|
|
|
35 |
|
36 |
+
jQuery('#snippet').change(function () {
|
37 |
+
if (this.checked) {
|
38 |
+
jQuery('#anonymizeip')[0].checked = false;
|
39 |
+
jQuery('#anonymizeip').attr("disabled", true);
|
40 |
+
} else {
|
41 |
+
jQuery('#anonymizeip').removeAttr("disabled");
|
42 |
}
|
43 |
+
});
|
44 |
+
|
45 |
+
jQuery('#advanced:checkbox').change(function () {
|
46 |
+
var checked = jQuery(this).is(':checked');
|
47 |
+
if (checked) {
|
48 |
+
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? ')) {
|
49 |
+
jQuery(this).removeAttr('checked');
|
50 |
+
}
|
51 |
+
}
|
52 |
+
});
|
53 |
+
|
54 |
+
if (jQuery('#gtm').is(":checked")) {
|
55 |
+
jQuery('#anonymizeip')[0].checked = false;
|
56 |
+
jQuery('#anonymizeip').attr("disabled", true);
|
57 |
+
jQuery('#snippet')[0].checked = true;
|
58 |
+
jQuery('#snippet').attr("disabled", true);
|
59 |
}
|
60 |
+
|
61 |
+
jQuery('#gtm').change(function () {
|
62 |
+
if (this.checked) {
|
63 |
+
jQuery('#anonymizeip')[0].checked = false;
|
64 |
+
jQuery('#anonymizeip').attr("disabled", true);
|
65 |
+
jQuery('#snippet')[0].checked = true;
|
66 |
+
jQuery('#snippet').attr("disabled", true);
|
67 |
+
} else {
|
68 |
+
jQuery('#anonymizeip').removeAttr("disabled");
|
69 |
+
jQuery('#snippet').removeAttr("disabled");
|
70 |
+
}
|
71 |
+
});
|
72 |
+
}
|
js/ajax.js
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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\
|
29 |
+
<td><input type='number' value=''/></td>\n\
|
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\
|
48 |
+
<td><input type='number' value=''/></td>\n\
|
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 |
+
|
65 |
+
|
66 |
+
function getEventData(tr, event) {
|
67 |
+
|
68 |
+
var data = {};
|
69 |
+
|
70 |
+
switch (event) {
|
71 |
+
case "click":
|
72 |
+
data['name'] = getInputValue(tr, 0, 'input');
|
73 |
+
data['type'] = getInputValue(tr, 1, 'select');
|
74 |
+
data['category'] = getInputValue(tr, 2, 'input');
|
75 |
+
data['action'] = getInputValue(tr, 3, 'input');
|
76 |
+
data['label'] = getInputValue(tr, 4, 'input');
|
77 |
+
data['value'] = getInputValue(tr, 5, 'input');
|
78 |
+
data['interaction'] = getInputValue(tr, 6, 'select');
|
79 |
+
break;
|
80 |
+
|
81 |
+
case "divs":
|
82 |
+
data['name'] = getInputValue(tr, 0, 'input');
|
83 |
+
data['type'] = getInputValue(tr, 1, 'select');
|
84 |
+
data['category'] = getInputValue(tr, 2, 'input');
|
85 |
+
data['action'] = getInputValue(tr, 3, 'input');
|
86 |
+
data['label'] = getInputValue(tr, 4, 'input');
|
87 |
+
data['value'] = getInputValue(tr, 5, 'input');
|
88 |
+
data['interaction'] = getInputValue(tr, 6, 'select');
|
89 |
+
break;
|
90 |
+
default:
|
91 |
+
break;
|
92 |
+
}
|
93 |
+
return JSON.stringify(data);
|
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');
|
101 |
+
var tbody = tr.closest('tbody');
|
102 |
+
var table = tbody.closest('table');
|
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",
|
114 |
+
url: wpgae_ajax.ajaxurl,
|
115 |
+
data: {
|
116 |
+
action: 'remove_wpgae_event',
|
117 |
+
security: wpgae_ajax.ajaxnonce,
|
118 |
+
event: tblName,
|
119 |
+
index: index
|
120 |
+
},
|
121 |
+
success: function (response) {
|
122 |
+
if (response.success) {
|
123 |
+
tr.remove();
|
124 |
+
}
|
125 |
+
}
|
126 |
+
});
|
127 |
+
});
|
128 |
+
|
129 |
+
jQuery(document).on('click', '.btn-add', function (event) {
|
130 |
+
|
131 |
+
event.preventDefault();
|
132 |
+
var button = jQuery(this);
|
133 |
+
var tr = button.closest('tr');
|
134 |
+
var tbody = tr.closest('tbody');
|
135 |
+
var table = tbody.closest('table');
|
136 |
+
var tblName = table.data('name');
|
137 |
+
var index = tr.index();
|
138 |
+
var input = getEventData(tr, tblName);
|
139 |
+
|
140 |
+
var newRow = getNewRow(tblName, index, wpgae_ajax.advanced);
|
141 |
+
var removeBtn = "<td><a class='btn-remove' href='#'><i class='fa fa-times' title='Remove' aria-hidden='true'></i></a></td>";
|
142 |
+
|
143 |
+
jQuery.ajax({
|
144 |
+
type: "post",
|
145 |
+
dataType: "json",
|
146 |
+
url: wpgae_ajax.ajaxurl,
|
147 |
+
data: {
|
148 |
+
action: 'add_wpgae_event',
|
149 |
+
security: wpgae_ajax.ajaxnonce,
|
150 |
+
event: tblName,
|
151 |
+
input: input
|
152 |
+
},
|
153 |
+
success: function (response) {
|
154 |
+
if (response.success) {
|
155 |
+
tbody.append(newRow);
|
156 |
+
button.closest('td').after(removeBtn);
|
157 |
+
button.html("<i class='fa fa-floppy-o' title='Update' aria-hidden='true'></i>");
|
158 |
+
button.attr('class', 'btn-update');
|
159 |
+
}
|
160 |
+
}
|
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');
|
168 |
+
var tbody = tr.closest('tbody');
|
169 |
+
var table = tbody.closest('table');
|
170 |
+
var tblName = table.data('name');
|
171 |
+
|
172 |
+
var index = tr.index();
|
173 |
+
|
174 |
+
var input = getEventData(tr, tblName);
|
175 |
+
jQuery(this).hide();
|
176 |
+
var self = this;
|
177 |
+
jQuery.ajax({
|
178 |
+
type: "post",
|
179 |
+
dataType: "json",
|
180 |
+
url: wpgae_ajax.ajaxurl,
|
181 |
+
data: {
|
182 |
+
action: 'update_wpgae_event',
|
183 |
+
security: wpgae_ajax.ajaxnonce,
|
184 |
+
event: tblName,
|
185 |
+
index: index,
|
186 |
+
input: input
|
187 |
+
},
|
188 |
+
success: function (response) {
|
189 |
+
jQuery(self).show();
|
190 |
+
}
|
191 |
+
});
|
192 |
+
});
|
193 |
+
})
|
js/ga-scroll-events.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
/*!
|
2 |
-
* WP Googel Analytics Events | v2.4.
|
3 |
* Copyright (c) 2013 Yuval Oren (@yuvalo)
|
4 |
* License: GPLv2
|
5 |
*/
|
@@ -13,13 +13,15 @@ var scroll_events = (function ($) {
|
|
13 |
var scroll_elements = [];
|
14 |
var click_elements = [];
|
15 |
var universal = 0;
|
16 |
-
|
|
|
17 |
|
18 |
-
var track_event = function (category, action, label, universal, bounce ){
|
19 |
var event_category = !category ? '' : category;
|
20 |
var event_action = !action ? '' : action;
|
21 |
var event_label = !label ? '' : label;
|
22 |
var event_bounce = !bounce ? false : bounce;
|
|
|
23 |
|
24 |
if( typeof ga_element === "undefined" ){
|
25 |
if( typeof ga !== 'undefined' ){
|
@@ -30,24 +32,40 @@ var scroll_events = (function ($) {
|
|
30 |
}
|
31 |
else if( typeof __gaTracker === "function" ){
|
32 |
ga_element = __gaTracker;
|
33 |
-
}
|
|
|
|
|
34 |
}
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
// ga_element('send','event', category, action, label);
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
}
|
41 |
else {
|
42 |
// ga_element.push(['_trackEvent',category, action, label]);
|
43 |
-
ga_element.push( ['_trackEvent',category, action, label,
|
44 |
}
|
45 |
|
46 |
};
|
47 |
|
48 |
var click_event = function( event ){
|
49 |
|
50 |
-
track_event(event.data.category, event.data.action, event.data.label, event.data.universal, event.data.bounce);
|
51 |
var hasHref = event.currentTarget.href;
|
52 |
if (hasHref && hasHref !== "") {
|
53 |
event.preventDefault();
|
@@ -62,14 +80,52 @@ var scroll_events = (function ($) {
|
|
62 |
}
|
63 |
};
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
return {
|
66 |
bind_events : function (settings) {
|
67 |
scroll_elements = settings.scroll_elements;
|
68 |
click_elements = settings.click_elements;
|
69 |
universal = settings.universal;
|
|
|
|
|
70 |
var i;
|
71 |
for (i = 0; i < click_elements.length; i++) {
|
72 |
-
var clicked = click_elements[i];
|
73 |
clicked.universal = universal;
|
74 |
$(clicked.select).on('click', clicked, click_event);
|
75 |
}
|
@@ -82,9 +138,9 @@ var scroll_events = (function ($) {
|
|
82 |
var i;
|
83 |
for (i = 0; i < scroll_elements.length; i++) {
|
84 |
if (!scroll_elements[i].sent) {
|
85 |
-
scroll_elements[i].offset = $(scroll_elements[i].select).offset();
|
86 |
if (scroll_elements[i].offset && ga_scroll_top + ga_window >= scroll_elements[i].offset.top + $(scroll_elements[i].select).height()) {
|
87 |
-
track_event(scroll_elements[i].category, scroll_elements[i].action, scroll_elements[i].label, universal, scroll_elements[i].bounce);
|
88 |
scroll_elements[i].sent = true;
|
89 |
}
|
90 |
}
|
1 |
/*!
|
2 |
+
* WP Googel Analytics Events | v2.4.2
|
3 |
* Copyright (c) 2013 Yuval Oren (@yuvalo)
|
4 |
* License: GPLv2
|
5 |
*/
|
13 |
var scroll_elements = [];
|
14 |
var click_elements = [];
|
15 |
var universal = 0;
|
16 |
+
var gtm = 0;
|
17 |
+
var ga_element;
|
18 |
|
19 |
+
var track_event = function (category, action, label, universal, bounce, evalue ){
|
20 |
var event_category = !category ? '' : category;
|
21 |
var event_action = !action ? '' : action;
|
22 |
var event_label = !label ? '' : label;
|
23 |
var event_bounce = !bounce ? false : bounce;
|
24 |
+
var event_value = !evalue ? false : evalue;
|
25 |
|
26 |
if( typeof ga_element === "undefined" ){
|
27 |
if( typeof ga !== 'undefined' ){
|
32 |
}
|
33 |
else if( typeof __gaTracker === "function" ){
|
34 |
ga_element = __gaTracker;
|
35 |
+
} else if (!gtm){
|
36 |
+
return;
|
37 |
+
}
|
38 |
}
|
39 |
+
|
40 |
+
if (gtm) {
|
41 |
+
dataLayer.push({
|
42 |
+
'event' : 'WPGAE',
|
43 |
+
'eventCategory' : category,
|
44 |
+
'eventAction' : action,
|
45 |
+
'eventLabel' : label,
|
46 |
+
'eventValue' : event_value,
|
47 |
+
'nonInteraction': event_bounce
|
48 |
+
});
|
49 |
+
} else if( universal ){
|
50 |
// ga_element('send','event', category, action, label);
|
51 |
+
if (event_value) {
|
52 |
+
ga_element('send','event', category, action, label, event_value,{'nonInteraction': event_bounce});
|
53 |
+
}else{
|
54 |
+
ga_element('send','event', category, action, label, {'nonInteraction': event_bounce});
|
55 |
+
}
|
56 |
+
|
57 |
|
58 |
}
|
59 |
else {
|
60 |
// ga_element.push(['_trackEvent',category, action, label]);
|
61 |
+
ga_element.push( ['_trackEvent',category, action, label, event_value, event_bounce] );
|
62 |
}
|
63 |
|
64 |
};
|
65 |
|
66 |
var click_event = function( event ){
|
67 |
|
68 |
+
track_event(event.data.category, event.data.action, event.data.label, event.data.universal, event.data.bounce, event.data.evalue);
|
69 |
var hasHref = event.currentTarget.href;
|
70 |
if (hasHref && hasHref !== "") {
|
71 |
event.preventDefault();
|
80 |
}
|
81 |
};
|
82 |
|
83 |
+
var unescapeChars = function (text) {
|
84 |
+
|
85 |
+
var map = {
|
86 |
+
'&': '&',
|
87 |
+
'<': '<',
|
88 |
+
'>': '>',
|
89 |
+
'"': '"',
|
90 |
+
'\"': '"',
|
91 |
+
''': "'"
|
92 |
+
};
|
93 |
+
|
94 |
+
if (typeof text != 'string') {
|
95 |
+
|
96 |
+
var cleanObj;
|
97 |
+
|
98 |
+
// if param text is non-string (assuming JSON object), we convert it first to string
|
99 |
+
cleanObj = JSON.stringify(text);
|
100 |
+
|
101 |
+
// we replace other chars
|
102 |
+
cleanObj.replace(/<|>|"|''/gi, function (m) {
|
103 |
+
return map[m];
|
104 |
+
});
|
105 |
+
|
106 |
+
// convert it back to JSON obj
|
107 |
+
cleanObj = JSON.parse(cleanObj);
|
108 |
+
return cleanObj;
|
109 |
+
}else{
|
110 |
+
return text.replace(/<|>|"|''/gi, function (m) {
|
111 |
+
return map[m];
|
112 |
+
});
|
113 |
+
}
|
114 |
+
|
115 |
+
return ''; //fallback
|
116 |
+
};
|
117 |
+
|
118 |
+
|
119 |
return {
|
120 |
bind_events : function (settings) {
|
121 |
scroll_elements = settings.scroll_elements;
|
122 |
click_elements = settings.click_elements;
|
123 |
universal = settings.universal;
|
124 |
+
gtm = settings.gtm;
|
125 |
+
|
126 |
var i;
|
127 |
for (i = 0; i < click_elements.length; i++) {
|
128 |
+
var clicked = unescapeChars(click_elements[i]);
|
129 |
clicked.universal = universal;
|
130 |
$(clicked.select).on('click', clicked, click_event);
|
131 |
}
|
138 |
var i;
|
139 |
for (i = 0; i < scroll_elements.length; i++) {
|
140 |
if (!scroll_elements[i].sent) {
|
141 |
+
scroll_elements[i].offset = $( unescapeChars( scroll_elements[i].select) ).offset();
|
142 |
if (scroll_elements[i].offset && ga_scroll_top + ga_window >= scroll_elements[i].offset.top + $(scroll_elements[i].select).height()) {
|
143 |
+
track_event(scroll_elements[i].category, scroll_elements[i].action, scroll_elements[i].label, universal, scroll_elements[i].bounce, scroll_elements[i].evalue);
|
144 |
scroll_elements[i].sent = true;
|
145 |
}
|
146 |
}
|
readme.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
=== WP Google Analytics Events ===
|
2 |
Contributors: yuvalo, claconsay
|
3 |
Tags: analytics, google, events, ga, google analytics, tracking
|
4 |
-
Tested up to: 4.7.
|
5 |
-
Stable tag: 2.4.
|
6 |
License: GPLv2
|
7 |
Requires at least: 3.0
|
8 |
|
@@ -33,13 +33,18 @@ There are many benefits for using events, and you can get very creative:
|
|
33 |
4. Understanding what percentage of your visitors got to the end of an article
|
34 |
5. Tracking contact form submissions
|
35 |
6. Track Links
|
|
|
36 |
|
37 |
|
38 |
If you want to learn more about Event Tracking or how to use this plugin, visit our documentation page here -
|
39 |
|
40 |
[Plugin Documentation](http://wpflow.com/documentation/ "Documentation")
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
## Where can I see the events in Google Analytics?
|
44 |
There are two places that show events in GA -
|
45 |
|
@@ -59,6 +64,9 @@ There are many benefits of using events, and you can get very creative:
|
|
59 |
5. Tracking contact form submissions
|
60 |
6. Track Links
|
61 |
|
|
|
|
|
|
|
62 |
|
63 |
## I'm stuck and need support
|
64 |
You can always use the support tab to open a ticket.
|
1 |
=== WP Google Analytics Events ===
|
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 |
|
33 |
4. Understanding what percentage of your visitors got to the end of an article
|
34 |
5. Tracking contact form submissions
|
35 |
6. Track Links
|
36 |
+
7. Google Tag Manager Support
|
37 |
|
38 |
|
39 |
If you want to learn more about Event Tracking or how to use this plugin, visit our documentation page here -
|
40 |
|
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 |
|
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.
|