Enhanced Ecommerce Google Analytics Plugin for WooCommerce - Version 1.0.11

Version Description

  • 28/10/2014 =
    • Fixed - Minor bugs
Download this release

Release Info

Developer Tatvic
Plugin Icon 128x128 Enhanced Ecommerce Google Analytics Plugin for WooCommerce
Version 1.0.11
Comparing to
See all releases

Code changes from version 1.0.10 to 1.0.11

includes/class-wc-enhanced-ecommerce-google-analytics-integration.php CHANGED
@@ -7,7 +7,8 @@
7
  *
8
  * @class WC_Enhanced_Ecommerce_Google_Analytics
9
  * @extends WC_Integration
10
- * @author Sudhir Mishra <sudhir@tatvic.com>
 
11
  */
12
  class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
13
 
@@ -19,12 +20,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
19
  */
20
  public function __construct() {
21
  global $homepage_json_fp, $homepage_json_rp;
22
- //incase of admin setting not saved
23
- /* $path = plugins_url();
24
- $admin_setting_handle = file($path . "/enhanced-e-commerce-for-woocommerce-store/includes/settings.txt");
25
- $flag_for_admin = $this->explode_admin_setting($admin_setting_handle[0]); //settings handle either to file or screen
26
- */
27
-
28
  $this->id = "enhanced_ecommerce_google_analytics";
29
  $this->method_title = __("Enhanced Ecommerce Google Analytics", "woocommerce");
30
  $this->method_description = __("Enhanced Ecommerce is a new feature of Universal Analytics that generates detailed statistics about the users journey from product page to thank you page on your e-store. <br/><a href='http://www.tatvic.com/blog/enhanced-ecommerce/' target='_blank'>Know more about Enhanced Ecommerce.</a>", "woocommerce");
@@ -34,7 +29,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
34
  $this->init_settings();
35
 
36
  // Define user set variables -- check for where to read settings
37
- // if ($flag_for_admin == "yes") {
38
  $this->ga_email = $this->get_option("ga_email");
39
  $this->ga_id = $this->get_option("ga_id");
40
  $this->ga_set_domain_name = $this->get_option("ga_set_domain_name");
@@ -45,22 +39,9 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
45
  $this->ga_enhanced_ecommerce_tracking_enabled = $this->get_option("ga_enhanced_ecommerce_tracking_enabled");
46
  $this->ga_display_feature_plugin = $this->get_option("ga_display_feature_plugin") == "yes" ? true : false;
47
  $this->ga_enhanced_ecommerce_category_page_impression_threshold = $this->get_option("ga_enhanced_ecommerce_category_page_impression_threshold");
48
- /* } else {
49
- //read from settings.txt
50
- $this->ga_email = $this->explode_admin_setting($admin_setting_handle[1]);
51
- $this->ga_id = $this->explode_admin_setting($admin_setting_handle[2]);
52
- $this->ga_set_domain_name = $this->explode_admin_setting($admin_setting_handle[3]);
53
- $this->ga_local_curr = $this->explode_admin_setting($admin_setting_handle[4]);
54
- $this->ga_standard_tracking_enabled = $this->explode_admin_setting($admin_setting_handle[5]);
55
- $this->enable_guest_checkout = get_option("woocommerce_enable_guest_checkout") == "yes" ? true : false; //guest checkout
56
- $this->track_login_step_for_guest_user = $this->explode_admin_setting($admin_setting_handle[6]) === "yes" ? true : false;
57
- $this->ga_enhanced_ecommerce_tracking_enabled = $this->explode_admin_setting($admin_setting_handle[7]);
58
- $this->ga_display_feature_plugin = $this->explode_admin_setting($admin_setting_handle[8]) == "yes" ? true : false;
59
- $this->ga_enhanced_ecommerce_category_page_impression_threshold = $this->explode_admin_setting($admin_setting_handle[9]);
60
- }*/
61
 
62
  // Actions
63
- add_action("woocommerce_update_options_integration_enhanced_ecommerce_google_analytics", array($this, "process_admin_options"));
64
  // API Call to LS with e-mail
65
  // Tracking code
66
  add_action("wp_head", array($this, "google_tracking_code"));
@@ -81,32 +62,21 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
81
  add_action("woocommerce_before_shop_loop_item", array($this, "add_divwrap_before_product"));
82
  add_action("woocommerce_after_shop_loop_item", array($this, "add_divwrap_after_product"));
83
  add_action("wp_footer", array($this, "loop_add_to_cart"));
84
- //add_action("wp_footer", array($this, "default_pageview"));
85
- //Enable display feature code checkbox
86
  add_action("admin_footer", array($this, "admin_check_UA_enabled"));
87
 
88
  //add version details in footer
89
  add_action("wp_footer", array($this, "add_plugin_details"));
90
-
91
- //Add Nearest JQuery
92
- add_action("wp_head", array($this, "add_nearest_jQuery"));
93
-
94
  //Add Dev ID
95
- add_action("wp_head", array($this, "add_dev_id"),1);
96
- }
97
-
98
- /**
99
- * explode patch settings from settings.txt file
100
- *
101
- * @access public
102
- * @return void
103
- */
104
- function explode_admin_setting($admin_setting_handle) {
105
- $ex_Arr = explode("=", $admin_setting_handle);
106
- return preg_replace('/\s+/', '', $ex_Arr[1]);
107
  }
108
 
109
- /**
110
  * add dev id
111
  *
112
  * @access public
@@ -123,7 +93,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
123
  * @return void
124
  */
125
  function add_divwrap_before_product() {
126
- //restrict home page
127
  if (!is_home()) {
128
  echo "<div class=t_singleproduct_cont>";
129
  }
@@ -136,7 +106,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
136
  * @return void
137
  */
138
  function add_divwrap_after_product() {
139
- //restrict home page
140
  if (!is_home()) {
141
  echo "</div>";
142
  }
@@ -150,7 +120,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
150
  */
151
  function add_plugin_details() {
152
  echo '<!--Enhanced Ecommerce Google Analytics Plugin for Woocommerce by Tatvic.'
153
- . 'Plugin Version: 1.0.10-->';
154
  }
155
 
156
  /**
@@ -166,20 +136,25 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
166
  "title" => __("Email Address", "woocommerce"),
167
  "description" => __("Provide your work email address to receive plugin enhancement updates", "woocommerce"),
168
  "type" => "email",
169
- "required" => "required",
 
 
 
170
  "default" => get_option("woocommerce_ga_email") // Backwards compat
171
  ),
172
  "ga_id" => array(
173
  "title" => __("Google Analytics ID", "woocommerce"),
174
  "description" => __("Enter your Google Analytics ID here. You can login into your Google Analytics account to find your ID. e.g.<code>UA-XXXXX-X</code>", "woocommerce"),
175
  "type" => "text",
 
176
  "default" => get_option("woocommerce_ga_id") // Backwards compat
177
  ),
178
  "ga_set_domain_name" => array(
179
  "title" => __("Set Domain Name", "woocommerce"),
180
  "description" => sprintf(__("Enter your domain name here (Optional)")),
181
  "type" => "text",
182
- "default" => ""
 
183
  ),
184
  "ga_local_curr" => array(
185
  "title" => __("Set Currency", "woocommerce"),
@@ -237,13 +212,26 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
237
  if ($save_for_the_plugin && $update_made_for_email) {
238
  if ($_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_email"] != "") {
239
  $email = $_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_email"];
240
- $domain_name = $_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_set_domain_name"];
241
- $this->send_email_to_tatvic($email, $domain_name);
 
242
  }
243
  }
244
  }
245
  }
246
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  /**
248
  * Google Analytics standard tracking
249
  *
@@ -446,6 +434,12 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
446
  $t_list = $t_list_clk . ',';
447
  $t_load_action = "product_impression_rdp";
448
  $t_click_action = "product_click_rdp";
 
 
 
 
 
 
449
  }
450
 
451
  $impression_threshold = $this->ga_enhanced_ecommerce_category_page_impression_threshold;
@@ -507,6 +501,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
507
  function add_to_cart() {
508
  if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled))
509
  return;
 
510
  if (!is_single())
511
  return;
512
  global $product;
@@ -873,7 +868,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
873
  //first name on focus call fire
874
  $step2_onFocus = 't_tracked_focus=0; jQuery("input[name=billing_first_name]").on("focus",function(){ if(t_tracked_focus===0){' . $code_step_2 . ' t_tracked_focus++;}});';
875
  }
876
-
877
  //check woocommerce version and add code
878
  $this->wc_version_compare($step2_onFocus);
879
  }
@@ -940,30 +934,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
940
  return $code;
941
  }
942
 
943
- /**
944
- * Sending hits with event
945
- *
946
- * @access public
947
- * @return void
948
- */
949
- /* public function default_pageview() {
950
-
951
- global $woocommerce;
952
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
953
- return;
954
- }
955
- if (!is_order_received_page()) {
956
- if (!$this->disable_tracking($this->ga_standard_tracking_enabled)) {
957
- $inline_js = 'ga("send", "event", "Enhanced-Ecommerce", "pageview", "footer",{"nonInteraction": 1})';
958
- } else {
959
- $inline_js = 'ga("send", "event", "Enhanced-Ecommerce", "pageview", "footer",{"nonInteraction": 1});';
960
- }
961
- }
962
-
963
- //check woocommerce version and add code
964
- $this->wc_version_compare($inline_js);
965
- } */
966
-
967
  /**
968
  * Check if tracking is disabled
969
  *
@@ -1014,68 +984,19 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
1014
  </script>';
1015
  }
1016
 
1017
- /**
1018
- * Adding Nearest Javascript Ref. code
1019
- *
1020
- * @access public
1021
- * @return void
1022
- */
1023
- function add_nearest_jQuery() {
1024
- $nearest_jQ = "(function($, d) {
1025
- $.fn.nearest = function(selector) {
1026
- var self, nearest, el, s, p,
1027
- hasQsa = d.querySelectorAll;
1028
-
1029
- function update(el) {
1030
- nearest = nearest ? nearest.add(el) : $(el);
1031
- }
1032
-
1033
- this.each(function() {
1034
- self = this;
1035
-
1036
- $.each(selector.split(', '), function() {
1037
- s = $.trim(this);
1038
-
1039
- if (!s.indexOf('#')) {
1040
- // selector starts with an ID
1041
- update((hasQsa ? d.querySelectorAll(s) : $(s)));
1042
- } else {
1043
- // is a class or tag selector
1044
- // so need to traverse
1045
- p = self . parentNode;
1046
- while (p) {
1047
- el = hasQsa ? p.querySelectorAll(s) : $(p) . find(s);
1048
- if (el . length) {
1049
- update(el);
1050
- break;
1051
- }
1052
- p = p . parentNode;
1053
- }
1054
- }
1055
- });
1056
-
1057
- });
1058
-
1059
- return nearest || $();
1060
- };
1061
- }(jQuery, document));
1062
- ";
1063
-
1064
- $this->wc_version_compare($nearest_jQ);
1065
- }
1066
-
1067
  /**
1068
  * Sending email to remote server
1069
  *
1070
  * @access public
1071
  * @return void
1072
  */
1073
- public function send_email_to_tatvic($email, $domain_name) {
1074
- //set POST variables
1075
  $url = "http://dev.tatvic.com/leadgen/woocommerce-plugin/store_email/";
 
1076
  $fields = array(
1077
  "email" => urlencode($email),
1078
- "domain_name" => urlencode($domain_name)
 
1079
  );
1080
  wp_remote_post($url, array(
1081
  "method" => "POST",
7
  *
8
  * @class WC_Enhanced_Ecommerce_Google_Analytics
9
  * @extends WC_Integration
10
+ * @author Sudhir Mishra <sudhir@tatvic.com>
11
+ * @contributor Jigar Navadiya <jigar@tatvic.com>
12
  */
13
  class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
14
 
20
  */
21
  public function __construct() {
22
  global $homepage_json_fp, $homepage_json_rp;
 
 
 
 
 
 
23
  $this->id = "enhanced_ecommerce_google_analytics";
24
  $this->method_title = __("Enhanced Ecommerce Google Analytics", "woocommerce");
25
  $this->method_description = __("Enhanced Ecommerce is a new feature of Universal Analytics that generates detailed statistics about the users journey from product page to thank you page on your e-store. <br/><a href='http://www.tatvic.com/blog/enhanced-ecommerce/' target='_blank'>Know more about Enhanced Ecommerce.</a>", "woocommerce");
29
  $this->init_settings();
30
 
31
  // Define user set variables -- check for where to read settings
 
32
  $this->ga_email = $this->get_option("ga_email");
33
  $this->ga_id = $this->get_option("ga_id");
34
  $this->ga_set_domain_name = $this->get_option("ga_set_domain_name");
39
  $this->ga_enhanced_ecommerce_tracking_enabled = $this->get_option("ga_enhanced_ecommerce_tracking_enabled");
40
  $this->ga_display_feature_plugin = $this->get_option("ga_display_feature_plugin") == "yes" ? true : false;
41
  $this->ga_enhanced_ecommerce_category_page_impression_threshold = $this->get_option("ga_enhanced_ecommerce_category_page_impression_threshold");
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  // Actions
44
+ add_action("woocommerce_update_options_integration_".$this->id, array($this, "process_admin_options"));
45
  // API Call to LS with e-mail
46
  // Tracking code
47
  add_action("wp_head", array($this, "google_tracking_code"));
62
  add_action("woocommerce_before_shop_loop_item", array($this, "add_divwrap_before_product"));
63
  add_action("woocommerce_after_shop_loop_item", array($this, "add_divwrap_after_product"));
64
  add_action("wp_footer", array($this, "loop_add_to_cart"));
65
+
66
+ //Enable display feature code checkbox
67
  add_action("admin_footer", array($this, "admin_check_UA_enabled"));
68
 
69
  //add version details in footer
70
  add_action("wp_footer", array($this, "add_plugin_details"));
71
+
72
+ //check if plugin is deactivated or not
73
+ add_action("deactivated_plugin", array($this, "detect_plugin_deactivation"));
74
+
75
  //Add Dev ID
76
+ add_action("wp_head", array($this, "add_dev_id"), 1);
 
 
 
 
 
 
 
 
 
 
 
77
  }
78
 
79
+ /**
80
  * add dev id
81
  *
82
  * @access public
93
  * @return void
94
  */
95
  function add_divwrap_before_product() {
96
+ //add div tag before every product data - Restricted page : Home page
97
  if (!is_home()) {
98
  echo "<div class=t_singleproduct_cont>";
99
  }
106
  * @return void
107
  */
108
  function add_divwrap_after_product() {
109
+ //add div tag before every product data - Restricted page : Home page
110
  if (!is_home()) {
111
  echo "</div>";
112
  }
120
  */
121
  function add_plugin_details() {
122
  echo '<!--Enhanced Ecommerce Google Analytics Plugin for Woocommerce by Tatvic.'
123
+ . 'Plugin Version: 1.0.11-->';
124
  }
125
 
126
  /**
136
  "title" => __("Email Address", "woocommerce"),
137
  "description" => __("Provide your work email address to receive plugin enhancement updates", "woocommerce"),
138
  "type" => "email",
139
+ "placeholder" => "example@test.com",
140
+ 'custom_attributes' => array(
141
+ 'required' => "required",
142
+ ),
143
  "default" => get_option("woocommerce_ga_email") // Backwards compat
144
  ),
145
  "ga_id" => array(
146
  "title" => __("Google Analytics ID", "woocommerce"),
147
  "description" => __("Enter your Google Analytics ID here. You can login into your Google Analytics account to find your ID. e.g.<code>UA-XXXXX-X</code>", "woocommerce"),
148
  "type" => "text",
149
+ "placeholder" => "UA-XXXXX-X",
150
  "default" => get_option("woocommerce_ga_id") // Backwards compat
151
  ),
152
  "ga_set_domain_name" => array(
153
  "title" => __("Set Domain Name", "woocommerce"),
154
  "description" => sprintf(__("Enter your domain name here (Optional)")),
155
  "type" => "text",
156
+ "placeholder" => "",
157
+ "default" => get_option("woocommerce_ga_set_domain_name")
158
  ),
159
  "ga_local_curr" => array(
160
  "title" => __("Set Currency", "woocommerce"),
212
  if ($save_for_the_plugin && $update_made_for_email) {
213
  if ($_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_email"] != "") {
214
  $email = $_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_email"];
215
+ setcookie("t_store_email_id",$email, 3600 * 1000 * 24 * 365 * 10);
216
+ $domain_name = get_site_url();//$_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_set_domain_name"];
217
+ $this->send_email_to_tatvic($email, $domain_name,'active');
218
  }
219
  }
220
  }
221
  }
222
 
223
+ /**
224
+ * Notify server that plugin is deactivated
225
+ *
226
+ * @access public
227
+ * @return void
228
+ */
229
+ function detect_plugin_deactivation() {
230
+ $email_id=$_COOKIE['t_store_email_id'];
231
+ $domain_name = get_site_url();
232
+ $this->send_email_to_tatvic($email_id, $domain_name,'deactivate');
233
+ }
234
+
235
  /**
236
  * Google Analytics standard tracking
237
  *
434
  $t_list = $t_list_clk . ',';
435
  $t_load_action = "product_impression_rdp";
436
  $t_click_action = "product_click_rdp";
437
+ } else if (is_shop()) {
438
+ //Considered only Related Products
439
+ $t_list_clk = '"list":"Shop Page"';
440
+ $t_list = $t_list_clk. ',';
441
+ $t_load_action = "product_impression_sp";
442
+ $t_click_action = "product_click_sp";
443
  }
444
 
445
  $impression_threshold = $this->ga_enhanced_ecommerce_category_page_impression_threshold;
501
  function add_to_cart() {
502
  if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled))
503
  return;
504
+ //return if not product page
505
  if (!is_single())
506
  return;
507
  global $product;
868
  //first name on focus call fire
869
  $step2_onFocus = 't_tracked_focus=0; jQuery("input[name=billing_first_name]").on("focus",function(){ if(t_tracked_focus===0){' . $code_step_2 . ' t_tracked_focus++;}});';
870
  }
 
871
  //check woocommerce version and add code
872
  $this->wc_version_compare($step2_onFocus);
873
  }
934
  return $code;
935
  }
936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
937
  /**
938
  * Check if tracking is disabled
939
  *
984
  </script>';
985
  }
986
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
987
  /**
988
  * Sending email to remote server
989
  *
990
  * @access public
991
  * @return void
992
  */
993
+ public function send_email_to_tatvic($email, $domain_name, $status) {
 
994
  $url = "http://dev.tatvic.com/leadgen/woocommerce-plugin/store_email/";
995
+ //set POST variables
996
  $fields = array(
997
  "email" => urlencode($email),
998
+ "domain_name" => urlencode($domain_name),
999
+ "status"=>urlencode($status)
1000
  );
1001
  wp_remote_post($url, array(
1002
  "method" => "POST",
readme.txt CHANGED
@@ -7,8 +7,8 @@ Author URI: http://www.tatvic.com/
7
  Author: Tatvic
8
  Requires at least: 3.6
9
  Tested up to: 3.9.2
10
- Stable tag: 1.0.10
11
- Version: 1.0.10
12
  License: GPLv3
13
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
14
 
@@ -107,7 +107,10 @@ Starting the WooCommerce 2.1 release there are no conflicts. However for earlier
107
  = 1.0.9.1 - 09/11/2014 =
108
  * Fixed- Minor bug on order page
109
 
110
- = 1.0.10 - 09/26/2014 =
111
  * Allows user to set local currency
112
  * Captures Impressions, Product Clicks and Add to Cart on Featured Product section and Recent Product section on Homepage
113
  * Captures Impressions, Product Clicks and Add to Cart on Related Product section on Product Page
 
 
 
7
  Author: Tatvic
8
  Requires at least: 3.6
9
  Tested up to: 3.9.2
10
+ Stable tag: 1.0.11
11
+ Version: 1.0.11
12
  License: GPLv3
13
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
14
 
107
  = 1.0.9.1 - 09/11/2014 =
108
  * Fixed- Minor bug on order page
109
 
110
+ = 1.0.10 - 26/09/2014 =
111
  * Allows user to set local currency
112
  * Captures Impressions, Product Clicks and Add to Cart on Featured Product section and Recent Product section on Homepage
113
  * Captures Impressions, Product Clicks and Add to Cart on Related Product section on Product Page
114
+
115
+ = 1.0.11 - 28/10/2014 =
116
+ * Fixed - Minor bugs
woocommerce-enhanced-ecommerce-google-analytics-integration.php CHANGED
@@ -21,7 +21,7 @@
21
  Description: Allows Enhanced E-commerce Google Analytics tracking code to be inserted into WooCommerce store pages.
22
  Author: Tatvic
23
  Author URI: http://www.tatvic.com
24
- Version: 1.0.10
25
  */
26
 
27
  // Add the integration to WooCommerce
21
  Description: Allows Enhanced E-commerce Google Analytics tracking code to be inserted into WooCommerce store pages.
22
  Author: Tatvic
23
  Author URI: http://www.tatvic.com
24
+ Version: 1.0.11
25
  */
26
 
27
  // Add the integration to WooCommerce