Enhanced Ecommerce Google Analytics Plugin for WooCommerce - Version 1.0.12

Version Description

  • 19/11/2014 =
    • Fixed - Settings not getting saved on few stores
    • Fixed - Broken layout issue

Important Note: When you update the plugin, please save your settings again.

Download this release

Release Info

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

Code changes from version 1.0.11 to 1.0.12

includes/class-wc-enhanced-ecommerce-google-analytics-integration.php CHANGED
@@ -19,38 +19,50 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
19
  * @return void
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");
26
 
27
- // Load the settings.
 
 
 
 
28
  $this->init_form_fields();
 
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");
35
- $this->ga_local_curr = $this->get_option("ga_local_curr");
36
- $this->ga_standard_tracking_enabled = $this->get_option("ga_standard_tracking_enabled");
37
- $this->enable_guest_checkout = get_option("woocommerce_enable_guest_checkout") == "yes" ? true : false; //guest checkout
38
- $this->track_login_step_for_guest_user = $this->get_option("track_login_step_for_guest_user") == "yes" ? true : false; //guest checkout
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"));
48
  add_action("woocommerce_thankyou", array($this, "ecommerce_tracking_code"));
49
 
50
  // Enhanced Ecommerce product impression hook
51
- add_action("wp_footer", array($this, "homepage_impression"));
52
- add_action("wp_footer", array($this, "cate_page_prod_impression")); // Hook for category page
53
- add_action("woocommerce_after_shop_loop_item", array($this, "bind_product_metadata"));
54
  add_action("woocommerce_after_single_product", array($this, "product_detail_view"));
55
  add_action("woocommerce_after_cart", array($this, "remove_cart_tracking"));
56
  add_action("woocommerce_before_checkout_billing_form", array($this, "checkout_step_1_tracking"));
@@ -59,9 +71,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
59
 
60
  // Event tracking code
61
  add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
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"));
@@ -70,7 +79,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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);
@@ -86,32 +95,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
86
  echo "<script>(window.gaDevIds=window.gaDevIds||[]).push('5CDcaG');</script>";
87
  }
88
 
89
- /**
90
- * add custom div before product shop loop
91
- *
92
- * @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
- }
100
- }
101
-
102
- /**
103
- * add custom div after product shop loop
104
- *
105
- * @access public
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
- }
113
- }
114
-
115
  /**
116
  * display details of plugin
117
  *
@@ -119,8 +102,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
119
  * @return void
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
  /**
@@ -140,81 +122,89 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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"),
161
  "description" => __("Find your Local Currency Code by visiting this <a href='https://developers.google.com/analytics/devguides/platform/currencies#supported-currencies' target='_blank'>link</a>", "woocommerce"),
162
  "type" => "select",
163
  "required" => "required",
164
- "default" => "USD", // Backwards compat
165
  "options" => $ga_currency_code
166
  ),
167
- "ga_standard_tracking_enabled" => array(
168
  "title" => __("Tracking code", "woocommerce"),
169
  "label" => __("Add Universal Analytics Tracking Code (Optional)", "woocommerce"),
170
- "description" => sprintf(__("This feature adds Universal Analytics Tracking Code to your Store. You don't need to enable this if using a 3rd party analytics plugin. If you chose to add Universal Analytics code snippet via Third party plugins, add <code>ga(\"require\", \"ec\", \"ec.js\");</code> below <code>ga(\"create\",\"UA-XXXXX-X\")</code> in your standard code snippet. Also ensure that the Universal Analytics code is present in the &lt;head&gt; section of the website.", "woocommerce")),
171
  "type" => "checkbox",
172
  "checkboxgroup" => "start",
173
- "default" => get_option("woocommerce_ga_standard_tracking_enabled") ? get_option("woocommerce_ga_standard_tracking_enabled") : "no" // Backwards compat
 
174
  ),
175
- "ga_display_feature_plugin" => array(
176
  "label" => __("Add Display Advertising Feature Code (Optional)", "woocommerce"),
177
  "type" => "checkbox",
178
  "checkboxgroup" => "",
179
  "description" => sprintf(__("This feature enables remarketing with Google Analytics & Demographic reports. Adding the code is the first step in a 3 step process. <a href='https://support.google.com/analytics/answer/2819948?hl=en' target='_blank'>Learn More</a><br/>This feature can only be enabled if you have enabled UA Tracking from our Plugin. If not, you can still manually add the display advertising code by following the instructions from this <a href='https://developers.google.com/analytics/devguides/collection/analyticsjs/display-features' target='_blank'>link</a>", "woocommerce")),
180
- "default" => get_option("woocommerce_ga_display_feature_plugin") ? get_option("woocommerce_ga_display_feature_plugin") : "no" // Backwards compat
181
  ),
182
- "ga_enhanced_ecommerce_tracking_enabled" => array(
183
  "label" => __("Add Enhanced Ecommerce Tracking Code", "woocommerce"),
184
  "type" => "checkbox",
185
  "checkboxgroup" => "",
 
186
  "description" => sprintf(__("This feature adds Enhanced Ecommerce Tracking Code to your Store", "woocommerce")),
187
- "default" => get_option("woocommerce_ga_ecommerce_tracking_enabled") ? get_option("woocommerce_ga_ecommerce_tracking_enabled") : "no" // Backwards compat
188
  ),
189
- "track_login_step_for_guest_user" => array(
190
  "label" => __("Add Code to Track the Login Step of Guest Users (Optional)", "woocommerce"),
191
  "type" => "checkbox",
192
  "checkboxgroup" => "",
 
193
  "description" => sprintf(__("If you have Guest Check out enable, we recommend you to add this code", "woocommerce")),
194
- "default" => get_option("track_login_step_for_guest_user") ? get_option("track_login_step_for_guest_user") : "no" // Backwards compat
195
  ),
196
- "ga_enhanced_ecommerce_category_page_impression_threshold" => array(
197
  "title" => __("Impression Threshold", "woocommerce"),
198
  "description" => sprintf(__("This feature sets Impression threshold for category page. It sends hit after these many numbers of products impressions", "woocommerce")),
199
- "type" => "input",
200
- "default" => "6"
201
- )
 
 
 
 
 
202
  );
203
  /* When user updates the email, post it to the remote server */
204
- if (isset($_GET["tab"]) && isset($_REQUEST["section"]) && isset($_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_email"])) {
205
 
206
  $current_tab = ( empty($_GET["tab"]) ) ? false : sanitize_text_field(urldecode($_GET["tab"]));
207
  $current_section = ( empty($_REQUEST["section"]) ) ? false : sanitize_text_field(urldecode($_REQUEST["section"]));
 
208
 
209
- $save_for_the_plugin = ($current_tab == "integration" ) && ($current_section == "enhanced_ecommerce_google_analytics");
210
- $update_made_for_email = $_REQUEST["woocommerce_enhanced_ecommerce_google_analytics_ga_email"] != $this->get_option("woocommerce_enhanced_ecommerce_google_analytics_ga_email");
211
-
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
  }
@@ -227,12 +217,10 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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
  *
238
  * @access public
@@ -242,7 +230,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
242
  global $woocommerce;
243
 
244
  //common validation----start
245
- if (is_admin() || current_user_can("manage_options") || $this->ga_standard_tracking_enabled == "no") {
246
  return;
247
  }
248
 
@@ -254,14 +242,14 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
254
 
255
  //common validation----end
256
 
257
- if (!empty($this->ga_set_domain_name)) {
258
- $set_domain_name = esc_js($this->ga_set_domain_name);
259
  } else {
260
  $set_domain_name = "auto";
261
  }
262
 
263
  //add display features
264
- if ($this->ga_display_feature_plugin) {
265
  $ga_display_feature_code = 'ga("require", "displayfeatures");';
266
  } else {
267
  $ga_display_feature_code = "";
@@ -274,7 +262,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
274
  })(window,document,"script","//www.google-analytics.com/analytics.js","ga");
275
  ga("create", "' . esc_js($tracking_id) . '", "' . $set_domain_name . '");
276
  ' . $ga_display_feature_code . '
277
- ga("require", "ec", "ec.js");
278
  ga("send", "pageview");';
279
 
280
  //include this on all pages except order confirmation page.
@@ -293,7 +281,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
293
  function ecommerce_tracking_code($order_id) {
294
  global $woocommerce;
295
 
296
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled) || current_user_can("manage_options") || get_post_meta($order_id, "_ga_tracked", true) == 1)
297
  return;
298
 
299
  $tracking_id = $this->ga_id;
@@ -320,21 +308,21 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
320
  }
321
 
322
  //get domain name if value is set
323
- if (!empty($this->ga_set_domain_name)) {
324
- $set_domain_name = esc_js($this->ga_set_domain_name);
325
  } else {
326
  $set_domain_name = "auto";
327
  }
328
 
329
  //add display features
330
- if ($this->ga_display_feature_plugin) {
331
  $ga_display_feature_code = 'ga("require", "displayfeatures");';
332
  } else {
333
  $ga_display_feature_code = "";
334
  }
335
 
336
  //add Pageview on order page if user checked Add Standard UA code
337
- if ($this->ga_standard_tracking_enabled) {
338
  $ga_pageview = 'ga("send", "pageview");';
339
  } else {
340
  $ga_pageview = "";
@@ -355,15 +343,8 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
355
  foreach ($order->get_items() as $item) {
356
  $_product = $order->get_product_from_item($item);
357
 
358
- //set local currencies
359
- $code .= 'ga("set", "&cu", "' . $this->ga_local_curr . '");';
360
- $code .= 'ga("ec:addProduct", {';
361
- $code .= '"id": "' . esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id) . '",';
362
- $code .= '"name": "' . esc_js($item["name"]) . '",';
363
-
364
  if (isset($_product->variation_data)) {
365
-
366
- $code .= '"category": "' . esc_js(woocommerce_get_formatted_variation($_product->variation_data, true)) . '",';
367
  } else {
368
  $out = array();
369
  $categories = get_the_terms($_product->id, "product_cat");
@@ -372,22 +353,54 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
372
  $out[] = $category->name;
373
  }
374
  }
375
- $code .= '"category": "' . esc_js(join(",", $out)) . '",';
376
  }
377
 
378
- $code .= '"price": "' . esc_js($order->get_item_total($item)) . '",';
379
- $code .= '"quantity": "' . esc_js($item["qty"]) . '"';
380
- $code .= "});";
 
 
 
 
 
 
381
  }
 
 
 
382
  }
383
-
384
- $code .='ga("ec:setAction","purchase", {
385
- "id": "' . esc_js($order->get_order_number()) . '", // Transaction ID. Required
386
- "affiliation": "' . esc_js(get_bloginfo("name")) . '", // Affiliation or store name
387
- "revenue": "' . esc_js($order->get_total()) . '", // Grand Total
388
- "tax": "' . esc_js($order->get_total_tax()) . '", // Tax
389
- "shipping": "' . esc_js($order->get_shipping()) . '", // Shipping
390
- "coupon":"' . $coupons_list . '"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  });
392
 
393
  ga("send", "event", "Enhanced-Ecommerce","load", "order_confirmation", {"nonInteraction": 1});
@@ -398,99 +411,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
398
  update_post_meta($order_id, "_ga_tracked", 1);
399
  }
400
 
401
- /**
402
- * Enhanced E-commerce tracking for product impressions on category page
403
- *
404
- * @access public
405
- * @return void
406
- */
407
- public function cate_page_prod_impression() {
408
- global $product;
409
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
410
- return;
411
- }
412
-
413
- //Identify List of product listing page wise :
414
- //Included Pages: Home page ,Category Page , Search page
415
-
416
- $t_list = "";
417
- $t_list_clk = "";
418
- $t_load_action = "";
419
- $t_click_action = "";
420
-
421
- if (is_search()) {
422
- $t_list_clk = '"list":"Search Results"';
423
- $t_list = $t_list_clk . ',';
424
- $t_load_action = "product_impression_srch";
425
- $t_click_action = "product_click_srch";
426
- } else if (is_product_category()) {
427
- $t_list_clk = '"list":"Category Page"';
428
- $t_list = $t_list_clk . ',';
429
- $t_load_action = "product_impression_cp";
430
- $t_click_action = "product_click_cp";
431
- } else if (is_product()) {
432
- //Considered only Related Products
433
- $t_list_clk = '"list":"Related Products"';
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;
446
-
447
- $code = 't_cnt=0;
448
- t_ttl_prod=jQuery(".ls-pro-sku").length;
449
- jQuery(".t_singleproduct_cont").each(function(index){
450
- t_cnt++;
451
- ga("ec:addImpression", {
452
- "id": jQuery(this).find(".ls-pro-sku").val(),
453
- "name": jQuery(this).find(".ls-pro-name").val(),
454
- "category": jQuery(this).find(".ls-pro-category").val(),
455
- ' . $t_list . '
456
- "price": jQuery(this).find(".ls-pro-price").val(),
457
- "position": index+1
458
- });
459
-
460
- if(t_ttl_prod > ' . esc_js($impression_threshold) . '){
461
- if((t_cnt%' . esc_js($impression_threshold) . ')==0){
462
- t_ttl_prod=t_ttl_prod-' . esc_js($impression_threshold) . ';
463
- ga("send", "event", "Enhanced-Ecommerce","load","' . $t_load_action . '", {"nonInteraction": 1});
464
- }
465
- }else{
466
- t_ttl_prod--;
467
- if(t_ttl_prod==0){
468
- ga("send", "event", "Enhanced-Ecommerce","load", "' . $t_load_action . '", {"nonInteraction": 1});
469
- }
470
- }
471
-
472
- jQuery(this).find("a:not(.add_to_cart_button)").on("click",function(){
473
-
474
- ga("ec:addProduct", {
475
- "id": jQuery(this).parents("li").find(".ls-pro-sku").val(),
476
- "name": jQuery(this).parents("li").find(".ls-pro-name").val(),
477
- "category": jQuery(this).parents("li").find(".ls-pro-category").val(),
478
- "price": jQuery(this).parents("li").find(".ls-pro-price").val(),
479
- "position": index+1
480
- });
481
- ga("ec:setAction", "click", {' . $t_list_clk . '});
482
- ga("send", "event", "Enhanced-Ecommerce","click","' . $t_click_action . '", {"nonInteraction": 1});
483
-
484
-
485
- });
486
- });
487
- ';
488
-
489
- if (!is_home()) {
490
- //check woocommerce version
491
- $this->wc_version_compare($code);
492
- }
493
- }
494
 
495
  /**
496
  * Enhanced E-commerce tracking for single product add to cart
@@ -499,7 +419,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
499
  * @return void
500
  */
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())
@@ -515,14 +435,16 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
515
  //remove last comma(,) if multiple categories are there
516
  $categories = rtrim($categories, ",");
517
 
518
- $code = '$(".single_add_to_cart_button").click(function() {
 
 
519
 
520
  // Enhanced E-commerce Add to cart clicks
521
  ga("ec:addProduct", {
522
- "id" : "' . esc_js($product->get_sku() ? $product->get_sku() : $product->id ) . '",
523
- "name": "' . esc_js($product->get_title()) . '",
524
- "category" :"' . $categories . '",
525
- "price": "' . esc_js($product->get_price()) . '",
526
  "quantity" :jQuery(this).parent().find("input[name=quantity]").val()
527
  });
528
  ga("ec:setAction", "add");
@@ -533,41 +455,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
533
  $this->wc_version_compare($code);
534
  }
535
 
536
- /**
537
- * Enhanced E-commerce tracking for loop add to cart
538
- *
539
- * @access public
540
- * @return void
541
- */
542
- function loop_add_to_cart() {
543
-
544
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
545
- return;
546
- }
547
-
548
- $code = '$(".add_to_cart_button:not(.product_type_variable, .product_type_grouped)").click(function() {
549
-
550
- t_qty=$(this).parent().find("input[name=quantity]").val();
551
- //default quantity 1 if quantity box is not there
552
- if(t_qty=="" || t_qty===undefined){
553
- t_qty="1";
554
- }
555
- // Enhanced E-commerce Add to cart clicks
556
- ga("ec:addProduct", {
557
- "id": $(this).parents("li").find(".ls-pro-sku").val(),
558
- "name": $(this).parents("li").find(".ls-pro-name").val(),
559
- "category": $(this).parents("li").find(".ls-pro-category").val(),
560
- "price": $(this).parents("li").find(".ls-pro-price").val(),
561
- "quantity" :t_qty
562
- });
563
- ga("ec:setAction", "add");
564
- ga("send", "event", "Enhanced-Ecommerce","click", "add_to_cart_click",{"nonInteraction": 1});
565
- });
566
- ';
567
- //check woocommerce version
568
- $this->wc_version_compare($code);
569
- }
570
-
571
  /**
572
  * Enhanced E-commerce tracking for product detail view
573
  *
@@ -576,7 +463,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
576
  */
577
  public function product_detail_view() {
578
 
579
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
580
  return;
581
  }
582
 
@@ -590,28 +477,44 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
590
  }
591
  //remove last comma(,) if multiple categories are there
592
  $categories = rtrim($categories, ",");
593
-
594
- $code = 'ga("ec:addProduct", {
595
- "id": "' . esc_js($product->get_sku() ? $product->get_sku() : $product->id) . '", // Product details are provided in an impressionFieldObject.
596
- "name": "' . $product->get_title() . '",
597
- "category": "' . $categories . '",
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  });
599
  ga("ec:setAction", "detail");
600
  ga("send", "event", "Enhanced-Ecommerce", "load","product_impression_pp", {"nonInteraction": 1});
601
  ';
602
  //check woocommerce version
 
603
  $this->wc_version_compare($code);
604
  }
 
605
 
606
  /**
607
- * Enhanced E-commerce tracking for product impressions on category pages
 
608
  *
609
  * @access public
610
  * @return void
611
  */
612
  public function bind_product_metadata() {
613
 
614
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
615
  return;
616
  }
617
 
@@ -625,39 +528,92 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
625
  }
626
  //remove last comma(,) if multiple categories are there
627
  $categories = rtrim($categories, ",");
628
-
629
- echo '<input type="hidden" class="ls-pro-price" value="' . esc_html($product->get_price()) . '" />'
630
- . '<input type="hidden" class="ls-pro-sku" value="' . esc_html($product->get_sku() ? $product->get_sku() : $product->id) . '"/>'
631
- . '<input type="hidden" class="ls-pro-name" value="' . esc_html($product->get_title()) . '"/>'
632
- . '<input type="hidden" class="ls-pro-category" value="' . esc_html($categories) . '"/>'
633
- . '<input type="hidden" class="ls-pro-isfeatured" value="' . $product->is_featured() . '"/> ';
634
-
635
- global $homepage_json_fp, $homepage_json_rp;
636
  if (is_home()) {
637
- if (!is_array($homepage_json_fp) && !is_array($homepage_json_rp)) {
638
  $homepage_json_fp = array();
639
  $homepage_json_rp = array();
 
640
  }
 
 
 
641
  if ($product->is_featured()) {
642
- $jsonArr_prod_fp = array(get_permalink($product->id) => array(
643
- "id" => esc_html($product->id),
644
- "sku" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
645
- "name" => esc_html($product->get_title()),
646
- "price" => esc_html($product->get_price()),
647
- "category" => esc_html($categories)
648
- ));
649
- array_push($homepage_json_fp, $jsonArr_prod_fp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650
  } else {
651
- $jsonArr_prod_rp = array(get_permalink($product->id) => array(
652
- "id" => esc_html($product->id),
653
- "sku" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
654
- "name" => esc_html($product->get_title()),
655
- "price" => esc_html($product->get_price()),
656
- "category" => esc_html($categories)
657
- ));
658
- array_push($homepage_json_rp, $jsonArr_prod_rp);
 
659
  }
660
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
661
  }
662
 
663
  /**
@@ -666,37 +622,69 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
666
  * @access public
667
  * @return void
668
  */
669
- function homepage_impression() {
670
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
671
  return;
672
  }
673
  //get impression threshold
674
- $impression_threshold = $this->ga_enhanced_ecommerce_category_page_impression_threshold;
675
 
676
  //Product impression on Home Page
677
- global $homepage_json_fp, $homepage_json_rp;
678
- $this->wc_version_compare("homepage_json_fp=" . json_encode($homepage_json_fp) . ";");
679
- $this->wc_version_compare("homepage_json_rp=" . json_encode($homepage_json_rp) . ";");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
680
  $hmpg_impressions_jQ = '
681
-
682
- function hmpg_impressions(t_json_name,t_action,t_list){
683
  t_send_threshold=0;
684
  t_prod_pos=0;
685
 
686
- t_json_length=t_json_name.length;
687
 
688
- for(i = 0;i < t_json_name.length;i++) {
689
  t_send_threshold++;
690
- t_prod_url_key=Object.keys(t_json_name[i]);
691
  t_prod_pos++;
692
 
693
  ga("ec:addImpression", {
694
- "id": t_json_name[i][t_prod_url_key]["sku"],
695
- "name": t_json_name[i][t_prod_url_key]["name"],
696
- "category": t_json_name[i][t_prod_url_key]["category"],
697
  "list":t_list,
698
- "price": t_json_name[i][t_prod_url_key]["price"],
699
- "position": t_prod_pos
700
  });
701
 
702
  if(t_json_length > ' . esc_js($impression_threshold) . '){
@@ -713,38 +701,165 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
713
  }
714
  }
715
  }
716
- jQuery("a").on("click",function(){
717
- t_url=jQuery(this).attr("href");
718
- prod_exists_in_JSON(t_url,homepage_json_fp,"Featured Products","fp");
719
- prod_exists_in_JSON(t_url,homepage_json_rp,"Recent Products","rp");
720
- });
721
  //function for comparing urls in json object
722
  function prod_exists_in_JSON(t_url,t_json_name,t_list,t_action){
723
- for(i=0;i<t_json_name.length;i++){
724
- if(t_url==Object.keys(t_json_name[i])){
725
- t_prod_url_key=Object.keys(t_json_name[i]);
726
  ga("ec:addProduct", {
727
- "id": t_json_name[i][t_prod_url_key]["sku"],
728
- "name": t_json_name[i][t_prod_url_key]["name"],
729
- "category": t_json_name[i][t_prod_url_key]["category"],
730
- "price": t_json_name[i][t_prod_url_key]["price"],
731
- "position": ++i
732
- });
733
- ga("ec:setAction", "click", {
734
- "list": t_list
735
  });
 
736
  ga("send", "event", "Enhanced-Ecommerce","click", "product_click_"+t_action, {"nonInteraction": 1});
 
 
737
  }
 
738
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
739
  }
740
- if(homepage_json_fp.length !== 0){
741
- hmpg_impressions(homepage_json_fp,"fp","Featured Products");
742
  }
743
- if(homepage_json_rp.length !== 0){
744
- hmpg_impressions(homepage_json_rp,"rp","Recent Products");
 
 
 
 
745
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746
  ';
747
- if (is_home()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  $this->wc_version_compare($hmpg_impressions_jQ);
749
  }
750
  }
@@ -756,13 +871,17 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
756
  * @return void
757
  */
758
  public function remove_cart_tracking() {
759
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
760
  return;
761
  }
762
  global $woocommerce;
763
  $cartpage_prod_array_main = array();
 
764
  foreach ($woocommerce->cart->cart_contents as $key => $item) {
765
  $prod_meta = get_product($item["product_id"]);
 
 
 
766
  $category = get_the_terms($item["product_id"], "product_cat");
767
  $categories = "";
768
  if ($category) {
@@ -772,52 +891,31 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
772
  }
773
  //remove last comma(,) if multiple categories are there
774
  $categories = rtrim($categories, ",");
775
- $cartpage_prod_array = array($key => array(
776
- "id" => esc_html($prod_meta->id),
777
- "sku" => esc_html($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->id),
778
- "name" => esc_html($prod_meta->get_title()),
779
- "price" => esc_html($prod_meta->get_price()),
780
- "category" => esc_html($categories)
781
- ));
782
- array_push($cartpage_prod_array_main, $cartpage_prod_array);
 
783
  }
784
 
785
  //Cart Page item Array to Json
786
- $this->wc_version_compare("cartpage_prod_json=" . json_encode($cartpage_prod_array_main) . ";");
787
 
788
  $code = '
789
- $.urlParam = function(name,t_url){
790
- var results = new RegExp("[\?&]" + name + "=([^&#]*)").exec(t_url);
791
- if (results==null){
792
- return null;
793
- }
794
- else{
795
- return results[1] || 0;
796
- }
797
- }
798
 
799
- $(".remove").click(function(){
800
- t_get_session_id=jQuery(this).attr("href");
801
- t_get_session_id=$.urlParam("remove_item",t_get_session_id);
802
- for(i=0;i<cartpage_prod_json.length;i++){
803
- if(t_get_session_id==Object.keys(cartpage_prod_json[i])){
804
- if(cartpage_prod_json[i][t_get_session_id]["sku"]!==""){
805
- t_prod_id=cartpage_prod_json[i][t_get_session_id]["sku"];
806
- }else{
807
- t_prod_id=cartpage_prod_json[i][t_get_session_id]["id"];
808
- }
809
- t_prod_name=cartpage_prod_json[i][t_get_session_id]["name"];
810
- t_prod_price=cartpage_prod_json[i][t_get_session_id]["price"];
811
- t_prod_cat=cartpage_prod_json[i][t_get_session_id]["category"];
812
-
813
- }
814
- }
815
  ga("ec:addProduct", {
816
- "id":t_prod_id,
817
- "name": t_prod_name,
818
- "category":t_prod_cat,
819
- "price": t_prod_price,
820
- "quantity": $(this).parents("tr").find(".product-quantity .qty").val()
821
  });
822
  ga("ec:setAction", "remove");
823
  ga("send", "event", "Enhanced-Ecommerce", "click", "remove_from_cart_click",{"nonInteraction": 1});
@@ -834,10 +932,22 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
834
  * @return void
835
  */
836
  public function checkout_step_1_tracking() {
837
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
838
  return;
839
  }
840
- $code = $this->get_ordered_items();
 
 
 
 
 
 
 
 
 
 
 
 
841
 
842
  $code_step_1 = $code . 'ga("ec:setAction","checkout",{"step": 1});';
843
  $code_step_1 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_1",{"nonInteraction": 1});';
@@ -853,10 +963,20 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
853
  * @return void
854
  */
855
  public function checkout_step_2_tracking() {
856
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
857
  return;
858
  }
859
- $code = $this->get_ordered_items();
 
 
 
 
 
 
 
 
 
 
860
 
861
  $code_step_2 = $code . 'ga("ec:setAction","checkout",{"step": 2});';
862
  $code_step_2 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_2",{"nonInteraction": 1});';
@@ -879,13 +999,22 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
879
  * @return void
880
  */
881
  public function checkout_step_3_tracking() {
882
- if ($this->disable_tracking($this->ga_enhanced_ecommerce_tracking_enabled)) {
883
  return;
884
  }
885
- $code = $this->get_ordered_items();
 
 
 
 
 
 
 
 
 
886
 
887
  //check if guest check out is enabled or not
888
- $step_2_on_proceed_to_pay = (!is_user_logged_in() && !$this->enable_guest_checkout ) || (!is_user_logged_in() && $this->enable_guest_checkout && $this->track_login_step_for_guest_user);
889
 
890
  $code_step_3 = $code . 'ga("ec:setAction","checkout",{"step": 3});';
891
  $code_step_3 .= 'ga("send", "event", "Enhanced-Ecommerce","load", "checkout_step_3",{"nonInteraction": 1});';
@@ -924,14 +1053,19 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
924
  }
925
  //remove last comma(,) if multiple categories are there
926
  $categories = rtrim($categories, ",");
 
 
 
 
 
 
 
 
927
 
928
- $code .= 'ga("ec:addProduct", {"id": "' . esc_js($p->get_sku() ? $p->get_sku() : $p->id) . '",';
929
- $code .= '"name": "' . esc_js($p->get_title()) . '",';
930
- $code .= '"category": "' . esc_js($categories) . '",';
931
- $code .= '"price": "' . esc_js($p->get_price()) . '",';
932
- $code .= '"quantity": "' . esc_js($item["quantity"]) . '"});';
933
  }
934
- return $code;
 
 
935
  }
936
 
937
  /**
@@ -969,16 +1103,16 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
969
  */
970
  function admin_check_UA_enabled() {
971
  echo '<script>
972
- jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_standard_tracking_enabled").change(function(){
973
  t_ga_chk=jQuery(this).is(":checked");
974
 
975
  if(t_ga_chk){
976
- jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_display_feature_plugin").removeAttr("disabled");
977
  }else{
978
- jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_display_feature_plugin").attr("disabled",true);
979
- t_display_chk=jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_display_feature_plugin").is(":checked");
980
  if(t_display_chk){
981
- jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_display_feature_plugin").removeAttr("checked");
982
  } }
983
  });
984
  </script>';
@@ -990,15 +1124,15 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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",
1003
  "timeout" => 1,
1004
  "httpversion" => "1.0",
@@ -1006,7 +1140,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
1006
  "headers" => array(),
1007
  "body" => $fields
1008
  )
1009
- );
1010
  }
1011
 
1012
  }
19
  * @return void
20
  */
21
  public function __construct() {
22
+
23
+ //Set Global Variables
24
+ global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,
25
+ $prodpage_json_ATC_link,$catpage_json_ATC_link;
26
+
27
+ //define plugin ID
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");
31
 
32
+ //start session for product position count
33
+ session_start();
34
+ $_SESSION['t_npcnt']=0;
35
+ $_SESSION['t_fpcnt']=0;
36
+ // Load the integration form
37
  $this->init_form_fields();
38
+ //load all the settings
39
  $this->init_settings();
40
 
41
+ // Define user set variables -- Always use short names
42
  $this->ga_email = $this->get_option("ga_email");
43
  $this->ga_id = $this->get_option("ga_id");
44
+ $this->ga_Dname = $this->get_option("ga_Dname");
45
+ $this->ga_LC = $this->get_option("ga_LC");
46
+ $this->ga_ST = $this->get_option("ga_ST");
47
+ $this->ga_gCkout = $this->get_option("ga_gCkout") == "yes" ? true : false; //guest checkout
48
+ $this->ga_gUser = $this->get_option("ga_gUser") == "yes" ? true : false; //guest checkout
49
+ $this->ga_eeT = $this->get_option("ga_eeT");
50
+ $this->ga_DF = $this->get_option("ga_DF") == "yes" ? true : false;
51
+ $this->ga_imTh = $this->get_option("ga_imTh");
52
+
53
+
54
+ //Save Changes action for admin settings
55
+ add_action("woocommerce_update_options_integration_" . $this->id, array($this, "process_admin_options"));
56
+
57
  // API Call to LS with e-mail
58
  // Tracking code
59
  add_action("wp_head", array($this, "google_tracking_code"));
60
  add_action("woocommerce_thankyou", array($this, "ecommerce_tracking_code"));
61
 
62
  // Enhanced Ecommerce product impression hook
63
+ add_action("wp_footer", array($this, "t_products_impre_clicks"));
64
+
65
+ add_action("woocommerce_after_shop_loop_item", array($this, "bind_product_metadata")); //for cat, shop, prod(related),search and home page
66
  add_action("woocommerce_after_single_product", array($this, "product_detail_view"));
67
  add_action("woocommerce_after_cart", array($this, "remove_cart_tracking"));
68
  add_action("woocommerce_before_checkout_billing_form", array($this, "checkout_step_1_tracking"));
71
 
72
  // Event tracking code
73
  add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
 
 
 
74
 
75
  //Enable display feature code checkbox
76
  add_action("admin_footer", array($this, "admin_check_UA_enabled"));
79
  add_action("wp_footer", array($this, "add_plugin_details"));
80
 
81
  //check if plugin is deactivated or not
82
+ add_action("deactivate_plugin", array($this, "detect_plugin_deactivation"));
83
 
84
  //Add Dev ID
85
  add_action("wp_head", array($this, "add_dev_id"), 1);
95
  echo "<script>(window.gaDevIds=window.gaDevIds||[]).push('5CDcaG');</script>";
96
  }
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  /**
99
  * display details of plugin
100
  *
102
  * @return void
103
  */
104
  function add_plugin_details() {
105
+ echo '<!--Enhanced Ecommerce Google Analytics Plugin for Woocommerce by Tatvic Plugin Version: 1.0.12-->';
 
106
  }
107
 
108
  /**
122
  'custom_attributes' => array(
123
  'required' => "required",
124
  ),
125
+ "desc_tip" => true,
126
+ "default" => get_option("ga_email") // Backwards compat
127
  ),
128
  "ga_id" => array(
129
  "title" => __("Google Analytics ID", "woocommerce"),
130
  "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"),
131
  "type" => "text",
132
  "placeholder" => "UA-XXXXX-X",
133
+ "desc_tip" => true,
134
+ "default" => get_option("ga_id") // Backwards compat
135
  ),
136
+ "ga_Dname" => array(
137
  "title" => __("Set Domain Name", "woocommerce"),
138
  "description" => sprintf(__("Enter your domain name here (Optional)")),
139
  "type" => "text",
140
  "placeholder" => "",
141
+ "desc_tip" => true,
142
+ "default" => get_option("ga_Dname") ? get_option("ga_Dname") : "auto"
143
  ),
144
+ "ga_LC" => array(
145
  "title" => __("Set Currency", "woocommerce"),
146
  "description" => __("Find your Local Currency Code by visiting this <a href='https://developers.google.com/analytics/devguides/platform/currencies#supported-currencies' target='_blank'>link</a>", "woocommerce"),
147
  "type" => "select",
148
  "required" => "required",
149
+ "default" => get_option('ga_LC'),
150
  "options" => $ga_currency_code
151
  ),
152
+ "ga_ST" => array(
153
  "title" => __("Tracking code", "woocommerce"),
154
  "label" => __("Add Universal Analytics Tracking Code (Optional)", "woocommerce"),
155
+ "description" => sprintf(__("This feature adds Universal Analytics Tracking Code to your Store. You don't need to enable this if using a 3rd party analytics plugin.", "woocommerce")),
156
  "type" => "checkbox",
157
  "checkboxgroup" => "start",
158
+ "desc_tip" => true,
159
+ "default" => get_option("ga_ST") ? get_option("ga_ST") : "no" // Backwards compat
160
  ),
161
+ "ga_DF" => array(
162
  "label" => __("Add Display Advertising Feature Code (Optional)", "woocommerce"),
163
  "type" => "checkbox",
164
  "checkboxgroup" => "",
165
  "description" => sprintf(__("This feature enables remarketing with Google Analytics & Demographic reports. Adding the code is the first step in a 3 step process. <a href='https://support.google.com/analytics/answer/2819948?hl=en' target='_blank'>Learn More</a><br/>This feature can only be enabled if you have enabled UA Tracking from our Plugin. If not, you can still manually add the display advertising code by following the instructions from this <a href='https://developers.google.com/analytics/devguides/collection/analyticsjs/display-features' target='_blank'>link</a>", "woocommerce")),
166
+ "default" => get_option("ga_DF") ? get_option("ga_DF") : "no" // Backwards compat
167
  ),
168
+ "ga_eeT" => array(
169
  "label" => __("Add Enhanced Ecommerce Tracking Code", "woocommerce"),
170
  "type" => "checkbox",
171
  "checkboxgroup" => "",
172
+ "desc_tip" => true,
173
  "description" => sprintf(__("This feature adds Enhanced Ecommerce Tracking Code to your Store", "woocommerce")),
174
+ "default" => get_option("ga_eeT") ? get_option("ga_eeT") : "no" // Backwards compat
175
  ),
176
+ "ga_gUser" => array(
177
  "label" => __("Add Code to Track the Login Step of Guest Users (Optional)", "woocommerce"),
178
  "type" => "checkbox",
179
  "checkboxgroup" => "",
180
+ "desc_tip" => true,
181
  "description" => sprintf(__("If you have Guest Check out enable, we recommend you to add this code", "woocommerce")),
182
+ "default" => get_option("ga_gUser") ? get_option("ga_gUser") : "no" // Backwards compat
183
  ),
184
+ "ga_imTh" => array(
185
  "title" => __("Impression Threshold", "woocommerce"),
186
  "description" => sprintf(__("This feature sets Impression threshold for category page. It sends hit after these many numbers of products impressions", "woocommerce")),
187
+ "type" => "number",
188
+ "desc_tip" => true,
189
+ "css"=>"width:112px !important;",
190
+ 'custom_attributes' => array(
191
+ 'min' => "1",
192
+ ),
193
+ "default" => get_option("ga_imTh") ? get_option("ga_imTh") : "6" // Backwards compat
194
+ ),
195
  );
196
  /* When user updates the email, post it to the remote server */
197
+ if (isset($_GET["tab"]) && isset($_REQUEST["section"]) && isset($_REQUEST["woocommerce_".$this->id."_ga_email"])) {
198
 
199
  $current_tab = ( empty($_GET["tab"]) ) ? false : sanitize_text_field(urldecode($_GET["tab"]));
200
  $current_section = ( empty($_REQUEST["section"]) ) ? false : sanitize_text_field(urldecode($_REQUEST["section"]));
201
+ $save_for_the_plugin = ($current_tab == "integration" ) && ($current_section == $this->id);
202
 
203
+ $update_made_for_email = $_REQUEST["woocommerce_".$this->id."_ga_email"] != $this->get_option("ga_email");
 
 
204
  if ($save_for_the_plugin && $update_made_for_email) {
205
+ if ($_REQUEST["woocommerce_".$this->id."_ga_email"] != "") {
206
+ $email = $_REQUEST["woocommerce_".$this->id."_ga_email"];
207
+ $this->send_email_to_tatvic($email,'active');
 
 
208
  }
209
  }
210
  }
217
  * @return void
218
  */
219
  function detect_plugin_deactivation() {
220
+ $email_id=$this->get_option('ga_email');
221
+ $this->send_email_to_tatvic($email_id,'deactivate');
 
222
  }
223
+ /**
 
224
  * Google Analytics standard tracking
225
  *
226
  * @access public
230
  global $woocommerce;
231
 
232
  //common validation----start
233
+ if (is_admin() || current_user_can("manage_options") || $this->ga_ST == "no") {
234
  return;
235
  }
236
 
242
 
243
  //common validation----end
244
 
245
+ if (!empty($this->ga_Dname)) {
246
+ $set_domain_name = esc_js($this->ga_Dname);
247
  } else {
248
  $set_domain_name = "auto";
249
  }
250
 
251
  //add display features
252
+ if ($this->ga_DF) {
253
  $ga_display_feature_code = 'ga("require", "displayfeatures");';
254
  } else {
255
  $ga_display_feature_code = "";
262
  })(window,document,"script","//www.google-analytics.com/analytics.js","ga");
263
  ga("create", "' . esc_js($tracking_id) . '", "' . $set_domain_name . '");
264
  ' . $ga_display_feature_code . '
265
+
266
  ga("send", "pageview");';
267
 
268
  //include this on all pages except order confirmation page.
281
  function ecommerce_tracking_code($order_id) {
282
  global $woocommerce;
283
 
284
+ if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_ga_tracked", true) == 1)
285
  return;
286
 
287
  $tracking_id = $this->ga_id;
308
  }
309
 
310
  //get domain name if value is set
311
+ if (!empty($this->ga_Dname)) {
312
+ $set_domain_name = esc_js($this->ga_Dname);
313
  } else {
314
  $set_domain_name = "auto";
315
  }
316
 
317
  //add display features
318
+ if ($this->ga_DF) {
319
  $ga_display_feature_code = 'ga("require", "displayfeatures");';
320
  } else {
321
  $ga_display_feature_code = "";
322
  }
323
 
324
  //add Pageview on order page if user checked Add Standard UA code
325
+ if ($this->ga_ST) {
326
  $ga_pageview = 'ga("send", "pageview");';
327
  } else {
328
  $ga_pageview = "";
343
  foreach ($order->get_items() as $item) {
344
  $_product = $order->get_product_from_item($item);
345
 
 
 
 
 
 
 
346
  if (isset($_product->variation_data)) {
347
+ $categories=esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
 
348
  } else {
349
  $out = array();
350
  $categories = get_the_terms($_product->id, "product_cat");
353
  $out[] = $category->name;
354
  }
355
  }
356
+ $categories=esc_js(join(",", $out));
357
  }
358
 
359
+ //orderpage Prod json
360
+ $orderpage_prod_Array[get_permalink($_product->id)]=array(
361
+ "tvc_id" => esc_html($_product->id),
362
+ "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id),
363
+ "tvc_n" => esc_js($item["name"]),
364
+ "tvc_p" => esc_js($order->get_item_total($item)),
365
+ "tvc_c" => $categories,
366
+ "tvc_q"=>esc_js($item["qty"])
367
+ );
368
  }
369
+ //make json for prod meta data on order page
370
+ $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
371
+
372
  }
373
+ //orderpage transcation data json
374
+ $orderpage_trans_Array=array(
375
+ "id"=> esc_js($order->get_order_number()), // Transaction ID. Required
376
+ "affiliation"=> esc_js(get_bloginfo('name')), // Affiliation or store name
377
+ "revenue"=>esc_js($order->get_total()), // Grand Total
378
+ "tax"=> esc_js($order->get_total_tax()), // Tax
379
+ "shipping"=> esc_js($order->get_shipping()), // Shipping
380
+ "coupon"=>$coupons_list
381
+ );
382
+ //make json for trans data on order page
383
+ $this->wc_version_compare("tvc_td=" . json_encode($orderpage_trans_Array) . ";");
384
+
385
+ $code.='
386
+ //set local currencies
387
+ ga("set", "&cu", "' . $this->ga_LC . '");
388
+ for(var t_item in tvc_oc){
389
+ ga("ec:addProduct", {
390
+ "id": tvc_oc[t_item].tvc_i,
391
+ "name": tvc_oc[t_item].tvc_n,
392
+ "category": tvc_oc[t_item].tvc_c,
393
+ "price": tvc_oc[t_item].tvc_p,
394
+ "quantity": tvc_oc[t_item].tvc_q,
395
+ });
396
+ }
397
+ ga("ec:setAction","purchase", {
398
+ "id": tvc_td.id,
399
+ "affiliation": tvc_td.affiliation,
400
+ "revenue": tvc_td.revenue,
401
+ "tax": tvc_td.tax,
402
+ "shipping": tvc_td.shipping,
403
+ "coupon": tvc_td.coupon
404
  });
405
 
406
  ga("send", "event", "Enhanced-Ecommerce","load", "order_confirmation", {"nonInteraction": 1});
411
  update_post_meta($order_id, "_ga_tracked", 1);
412
  }
413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
 
415
  /**
416
  * Enhanced E-commerce tracking for single product add to cart
419
  * @return void
420
  */
421
  function add_to_cart() {
422
+ if ($this->disable_tracking($this->ga_eeT))
423
  return;
424
  //return if not product page
425
  if (!is_single())
435
  //remove last comma(,) if multiple categories are there
436
  $categories = rtrim($categories, ",");
437
 
438
+ $code = '
439
+ ga("require", "ec", "ec.js");
440
+ $(".single_add_to_cart_button").click(function() {
441
 
442
  // Enhanced E-commerce Add to cart clicks
443
  ga("ec:addProduct", {
444
+ "id" : tvc_po.tvc_i,
445
+ "name": tvc_po.tvc_n,
446
+ "category" :tvc_po.tvc_c,
447
+ "price": tvc_po.tvc_p,
448
  "quantity" :jQuery(this).parent().find("input[name=quantity]").val()
449
  });
450
  ga("ec:setAction", "add");
455
  $this->wc_version_compare($code);
456
  }
457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
458
  /**
459
  * Enhanced E-commerce tracking for product detail view
460
  *
463
  */
464
  public function product_detail_view() {
465
 
466
+ if ($this->disable_tracking($this->ga_eeT)) {
467
  return;
468
  }
469
 
477
  }
478
  //remove last comma(,) if multiple categories are there
479
  $categories = rtrim($categories, ",");
480
+ //product detail view json
481
+ $prodpage_detail_json=array(
482
+ "tvc_i" => $product->get_sku() ? $product->get_sku() : $product->id,
483
+ "tvc_n"=> $product->get_title(),
484
+ "tvc_c"=>$categories,
485
+ "tvc_p"=>$product->get_price()
486
+ );
487
+ if(empty($prodpage_detail_json)){ //prod page array
488
+ $prodpage_detail_json=array();
489
+ }
490
+ //prod page detail view json
491
+ $this->wc_version_compare("tvc_po=" . json_encode($prodpage_detail_json) . ";");
492
+ $code = '
493
+ ga("require", "ec", "ec.js");
494
+ ga("ec:addProduct", {
495
+ "id": tvc_po.tvc_i, // Product details are provided in an impressionFieldObject.
496
+ "name": tvc_po.tvc_n,
497
+ "category":tvc_po.tvc_c,
498
  });
499
  ga("ec:setAction", "detail");
500
  ga("send", "event", "Enhanced-Ecommerce", "load","product_impression_pp", {"nonInteraction": 1});
501
  ';
502
  //check woocommerce version
503
+ if(is_product()){
504
  $this->wc_version_compare($code);
505
  }
506
+ }
507
 
508
  /**
509
+ * Enhanced E-commerce tracking for product impressions on category pages (hidden fields) , product page (related section)
510
+ * home page (featured section and recent section)
511
  *
512
  * @access public
513
  * @return void
514
  */
515
  public function bind_product_metadata() {
516
 
517
+ if ($this->disable_tracking($this->ga_eeT)) {
518
  return;
519
  }
520
 
528
  }
529
  //remove last comma(,) if multiple categories are there
530
  $categories = rtrim($categories, ",");
531
+ //declare all variable as a global which will used for make json
532
+ global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
533
+ //is home page then make all necessory json
 
 
 
 
 
534
  if (is_home()) {
535
+ if (!is_array($homepage_json_fp) && !is_array($homepage_json_rp) && !is_array($homepage_json_ATC_link)) {
536
  $homepage_json_fp = array();
537
  $homepage_json_rp = array();
538
+ $homepage_json_ATC_link=array();
539
  }
540
+ // ATC link Array
541
+ $homepage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
542
+ //check if product is featured product or not
543
  if ($product->is_featured()) {
544
+ //check if product is already exists in homepage featured json
545
+ if(!array_key_exists(get_permalink($product->id),$homepage_json_fp)){
546
+ $homepage_json_fp[get_permalink($product->id)] = array(
547
+ "tvc_id" => esc_html($product->id),
548
+ "tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
549
+ "tvc_n" => esc_html($product->get_title()),
550
+ "tvc_n" => esc_html($product->get_price()),
551
+ "tvc_c" => esc_html($categories),
552
+ "tvc_po" => ++$_SESSION['t_fpcnt'],
553
+ "ATC-link"=>$product->add_to_cart_url()
554
+ );
555
+ //else add product in homepage recent product json
556
+ }else {
557
+ $homepage_json_rp[get_permalink($product->id)] =array(
558
+ "tvc_id" => esc_html($product->id),
559
+ "tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
560
+ "tvc_n" => esc_html($product->get_title()),
561
+ "tvc_p" => esc_html($product->get_price()),
562
+ "tvc_po" => ++$_SESSION['t_npcnt'],
563
+ "tvc_c" => esc_html($categories)
564
+ );
565
+ }
566
+
567
  } else {
568
+ //else prod add in homepage recent json
569
+ $homepage_json_rp[get_permalink($product->id)] =array(
570
+ "tvc_id" => esc_html($product->id),
571
+ "tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
572
+ "tvc_n" => esc_html($product->get_title()),
573
+ "tvc_p" => esc_html($product->get_price()),
574
+ "tvc_po" => ++$_SESSION['t_npcnt'],
575
+ "tvc_c" => esc_html($categories)
576
+ );
577
  }
578
  }
579
+ //if product page then related product page array
580
+ else if(is_product()){
581
+ if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
582
+ $prodpage_json_relProd = array();
583
+ $prodpage_json_ATC_link = array();
584
+ }
585
+ // ATC link Array
586
+ $prodpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
587
+
588
+ $prodpage_json_relProd[get_permalink($product->id)] = array(
589
+ "tvc_id" => esc_html($product->id),
590
+ "tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
591
+ "tvc_n" => esc_html($product->get_title()),
592
+ "tvc_p" => esc_html($product->get_price()),
593
+ "tvc_c" => esc_html($categories),
594
+ "tvc_po" => ++$_SESSION['t_npcnt'],
595
+ );
596
+
597
+ }
598
+ //category page, search page and shop page json
599
+ else if (is_product_category() || is_search() || is_shop()) {
600
+ if (!is_array($catpage_json) && !is_array($catpage_json_ATC_link)){
601
+ $catpage_json=array();
602
+ $catpage_json_ATC_link=array();
603
+ }
604
+ //cat page ATC array
605
+ $catpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
606
+
607
+ $catpage_json[get_permalink($product->id)] =array(
608
+ "tvc_id" => esc_html($product->id),
609
+ "tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
610
+ "tvc_n" => esc_html($product->get_title()),
611
+ "tvc_p" => esc_html($product->get_price()),
612
+ "tvc_c" => esc_html($categories),
613
+ "tvc_po" => ++$_SESSION['t_npcnt'],
614
+ );
615
+ }
616
+
617
  }
618
 
619
  /**
622
  * @access public
623
  * @return void
624
  */
625
+ function t_products_impre_clicks() {
626
+ if ($this->disable_tracking($this->ga_eeT)) {
627
  return;
628
  }
629
  //get impression threshold
630
+ $impression_threshold = $this->ga_imTh;
631
 
632
  //Product impression on Home Page
633
+ global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
634
+ //home page json for featured products and recent product sections
635
+ //check if php array is empty
636
+ if(empty($homepage_json_ATC_link)){
637
+ $homepage_json_ATC_link=array(); //define empty array so if empty then in json will be []
638
+ }
639
+ if(empty($homepage_json_fp)){
640
+ $homepage_json_fp=array(); //define empty array so if empty then in json will be []
641
+ }
642
+ if(empty($homepage_json_rp)){ //home page recent product array
643
+ $homepage_json_rp=array();
644
+ }
645
+ if(empty($prodpage_json_relProd)){ //prod page related section array
646
+ $prodpage_json_relProd=array();
647
+ }
648
+ if(empty($prodpage_json_ATC_link)){
649
+ $prodpage_json_ATC_link=array(); //prod page ATC link json
650
+ }
651
+ if(empty($catpage_json)){ //category page array
652
+ $catpage_json=array();
653
+ }
654
+ if(empty($catpage_json_ATC_link)){ //category page array
655
+ $catpage_json_ATC_link=array();
656
+ }
657
+ //home page json
658
+ $this->wc_version_compare("homepage_json_ATC_link=" . json_encode($homepage_json_ATC_link) . ";");
659
+ $this->wc_version_compare("tvc_fp=" . json_encode($homepage_json_fp) . ";");
660
+ $this->wc_version_compare("tvc_rcp=" . json_encode($homepage_json_rp) . ";");
661
+ //product page json
662
+ $this->wc_version_compare("tvc_rdp=" . json_encode($prodpage_json_relProd) . ";");
663
+ $this->wc_version_compare("prodpage_json_ATC_link=" . json_encode($prodpage_json_ATC_link) . ";");
664
+ //category page json
665
+ $this->wc_version_compare("tvc_pgc=" . json_encode($catpage_json) . ";");
666
+ $this->wc_version_compare("catpage_json_ATC_link=" . json_encode($catpage_json_ATC_link) . ";");
667
+
668
+
669
  $hmpg_impressions_jQ = '
670
+ ga("require", "ec", "ec.js");
671
+ function t_products_impre_clicks(t_json_name,t_action,t_list){
672
  t_send_threshold=0;
673
  t_prod_pos=0;
674
 
675
+ t_json_length=Object.keys(t_json_name).length
676
 
677
+ for(var t_item in t_json_name) {
678
  t_send_threshold++;
 
679
  t_prod_pos++;
680
 
681
  ga("ec:addImpression", {
682
+ "id": t_json_name[t_item].tvc_i,
683
+ "name": t_json_name[t_item].tvc_n,
684
+ "category": t_json_name[t_item].tvc_c,
685
  "list":t_list,
686
+ "price": t_json_name[t_item].tvc_p,
687
+ "position": t_json_name[t_item].tvc_po,
688
  });
689
 
690
  if(t_json_length > ' . esc_js($impression_threshold) . '){
701
  }
702
  }
703
  }
704
+
 
 
 
 
705
  //function for comparing urls in json object
706
  function prod_exists_in_JSON(t_url,t_json_name,t_list,t_action){
707
+ if(t_json_name.hasOwnProperty(t_url)){
708
+ t_call_fired=true;
 
709
  ga("ec:addProduct", {
710
+ "id": t_json_name[t_url].tvc_i,
711
+ "name": t_json_name[t_url].tvc_n,
712
+ "category": t_json_name[t_url].tvc_c,
713
+ "price": t_json_name[t_url].tvc_p,
714
+ "position": t_json_name[t_url].tvc_po,
 
 
 
715
  });
716
+ ga("ec:setAction", "click", {"list": t_list});
717
  ga("send", "event", "Enhanced-Ecommerce","click", "product_click_"+t_action, {"nonInteraction": 1});
718
+ }else{
719
+ t_call_fired=false;
720
  }
721
+ return t_call_fired;
722
  }
723
+ function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
724
+ t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
725
+
726
+ if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
727
+ t_call_fired=true;
728
+ // Enhanced E-commerce Add to cart clicks
729
+ ga("ec:addProduct", {
730
+ "id": t_prod_data_json[t_prod_url_key].tvc_i,
731
+ "name": t_prod_data_json[t_prod_url_key].tvc_n,
732
+ "category": t_prod_data_json[t_prod_url_key].tvc_c,
733
+ "price": t_prod_data_json[t_prod_url_key].tvc_p,
734
+ "quantity" : t_qty
735
+ });
736
+ ga("ec:setAction", "add");
737
+ ga("send", "event", "Enhanced-Ecommerce","click", "add_to_cart_click",{"nonInteraction": 1});
738
+ }else{
739
+ t_call_fired=false;
740
  }
741
+ return t_call_fired;
742
+
743
  }
744
+
745
+ ';
746
+ if(is_home()){
747
+ $hmpg_impressions_jQ .='
748
+ if(tvc_fp.length !== 0){
749
+ t_products_impre_clicks(tvc_fp,"fp","Featured Products");
750
  }
751
+ if(tvc_rcp.length !== 0){
752
+ t_products_impre_clicks(tvc_rcp,"rp","Recent Products");
753
+ }
754
+ jQuery("a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped)").on("click",function(){
755
+ t_url=jQuery(this).attr("href");
756
+ //home page call for click
757
+ t_call_fired=prod_exists_in_JSON(t_url,tvc_fp,"Featured Products","fp");
758
+ if(!t_call_fired){
759
+ prod_exists_in_JSON(t_url,tvc_rcp,"Recent Products","rp");
760
+ }
761
+ });
762
+ //ATC click
763
+ jQuery("a[href*=add-to-cart]").on("click",function(){
764
+ t_url=jQuery(this).attr("href");
765
+ t_qty=$(this).parent().find("input[name=quantity]").val();
766
+ //default quantity 1 if quantity box is not there
767
+ if(t_qty=="" || t_qty===undefined){
768
+ t_qty="1";
769
+ }
770
+ t_call_fired=prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_fp,t_qty);
771
+ if(!t_call_fired){
772
+ prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_rcp,t_qty);
773
+ }
774
+ });
775
+
776
  ';
777
+ }else if (is_product()) {
778
+ //product page releted products
779
+ $hmpg_impressions_jQ .='
780
+ if(tvc_rdp.length !== 0){
781
+ t_products_impre_clicks(tvc_rdp,"rdp","Related Products");
782
+ }
783
+ //product click - image and product name
784
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
785
+ t_url=jQuery(this).attr("href");
786
+ //prod page related call for click
787
+ prod_exists_in_JSON(t_url,tvc_rdp,"Related Products","rdp");
788
+ });
789
+ //Prod ATC link click in related product section
790
+ jQuery("a[href*=add-to-cart]").on("click",function(){
791
+ t_url=jQuery(this).attr("href");
792
+ t_qty=$(this).parent().find("input[name=quantity]").val();
793
+ //default quantity 1 if quantity box is not there
794
+ if(t_qty=="" || t_qty===undefined){
795
+ t_qty="1";
796
+ }
797
+ prod_ATC_link_exists(t_url,prodpage_json_ATC_link,tvc_rdp,t_qty);
798
+ });
799
+ ';
800
+ }else if (is_product_category()) {
801
+ $hmpg_impressions_jQ .='
802
+ //category page json
803
+ if(tvc_pgc.length !== 0){
804
+ t_products_impre_clicks(tvc_pgc,"cp","Category Page");
805
+ }
806
+ //Prod category ATC link click in related product section
807
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
808
+ t_url=jQuery(this).attr("href");
809
+ //cat page prod call for click
810
+ prod_exists_in_JSON(t_url,tvc_pgc,"Category Page","cp");
811
+ });
812
+
813
+ ';
814
+ }else if(is_shop()){
815
+ $hmpg_impressions_jQ .='
816
+ //shop page json
817
+ if(tvc_pgc.length !== 0){
818
+ t_products_impre_clicks(tvc_pgc,"sp","Shop Page");
819
+ }
820
+ //shop page prod click
821
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
822
+ t_url=jQuery(this).attr("href");
823
+ //cat page prod call for click
824
+ prod_exists_in_JSON(t_url,tvc_pgc,"Shop Page","sp");
825
+ });
826
+
827
+
828
+ ';
829
+ }else if(is_search()){
830
+ $hmpg_impressions_jQ .='
831
+ //shop page json
832
+ if(tvc_pgc.length !== 0){
833
+ t_products_impre_clicks(tvc_pgc,"srch","Search Results");
834
+ }
835
+ //shop page prod click
836
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
837
+ t_url=jQuery(this).attr("href");
838
+ //cat page prod call for click
839
+ prod_exists_in_JSON(t_url,catpage_json,"Search Results","srch");
840
+ });
841
+
842
+
843
+ ';
844
+ }
845
+ //common ATC link for Category page , Shop Page and Search Page
846
+ if(is_product_category() || is_shop() || is_search()){
847
+ $hmpg_impressions_jQ .='
848
+ //ATC link click
849
+ jQuery("a[href*=add-to-cart]").on("click",function(){
850
+ t_url=jQuery(this).attr("href");
851
+ t_qty=$(this).parent().find("input[name=quantity]").val();
852
+ //default quantity 1 if quantity box is not there
853
+ if(t_qty=="" || t_qty===undefined){
854
+ t_qty="1";
855
+ }
856
+ prod_ATC_link_exists(t_url,catpage_json_ATC_link,tvc_pgc,t_qty);
857
+ });
858
+ ';
859
+ }
860
+
861
+ //on home page, product page , category page
862
+ if (is_home() || is_product() || is_product_category() || is_search() || is_shop()){
863
  $this->wc_version_compare($hmpg_impressions_jQ);
864
  }
865
  }
871
  * @return void
872
  */
873
  public function remove_cart_tracking() {
874
+ if ($this->disable_tracking($this->ga_eeT)) {
875
  return;
876
  }
877
  global $woocommerce;
878
  $cartpage_prod_array_main = array();
879
+ //echo "<pre>".print_r($woocommerce->cart->cart_contents,TRUE)."</pre>";
880
  foreach ($woocommerce->cart->cart_contents as $key => $item) {
881
  $prod_meta = get_product($item["product_id"]);
882
+
883
+ $cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
884
+
885
  $category = get_the_terms($item["product_id"], "product_cat");
886
  $categories = "";
887
  if ($category) {
891
  }
892
  //remove last comma(,) if multiple categories are there
893
  $categories = rtrim($categories, ",");
894
+ $cartpage_prod_array_main[$cart_remove_link] =array(
895
+ "tvc_id" => esc_html($prod_meta->id),
896
+ "tvc_i" => esc_html($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->id),
897
+ "tvc_n" => esc_html($prod_meta->get_title()),
898
+ "tvc_p" => esc_html($prod_meta->get_price()),
899
+ "tvc_c" => esc_html($categories),
900
+ "tvc_q"=>$woocommerce->cart->cart_contents[$key]["quantity"]
901
+ );
902
+
903
  }
904
 
905
  //Cart Page item Array to Json
906
+ $this->wc_version_compare("tvc_cc=" . json_encode($cartpage_prod_array_main) . ";");
907
 
908
  $code = '
909
+ ga("require", "ec", "ec.js");
910
+ $("a[href*=\"?remove_item\"]").click(function(){
911
+ t_url=jQuery(this).attr("href");
 
 
 
 
 
 
912
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
913
  ga("ec:addProduct", {
914
+ "id":tvc_cc[t_url].tvc_i,
915
+ "name": tvc_cc[t_url].tvc_n,
916
+ "category":tvc_cc[t_url].tvc_c,
917
+ "price": tvc_cc[t_url].tvc_p,
918
+ "quantity": tvc_cc[t_url].tvc_q
919
  });
920
  ga("ec:setAction", "remove");
921
  ga("send", "event", "Enhanced-Ecommerce", "click", "remove_from_cart_click",{"nonInteraction": 1});
932
  * @return void
933
  */
934
  public function checkout_step_1_tracking() {
935
+ if ($this->disable_tracking($this->ga_eeT)) {
936
  return;
937
  }
938
+ //call fn to make json
939
+ $this->get_ordered_items();
940
+ $code= '
941
+ ga("require", "ec", "ec.js");
942
+ for(var t_item in tvc_ch){
943
+ ga("ec:addProduct", {
944
+ "id": tvc_ch[t_item].tvc_i,
945
+ "name": tvc_ch[t_item].tvc_n,
946
+ "category": tvc_ch[t_item].tvc_c,
947
+ "price": tvc_ch[t_item].tvc_p,
948
+ "quantity": tvc_ch[t_item].tvc_q
949
+ });
950
+ }';
951
 
952
  $code_step_1 = $code . 'ga("ec:setAction","checkout",{"step": 1});';
953
  $code_step_1 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_1",{"nonInteraction": 1});';
963
  * @return void
964
  */
965
  public function checkout_step_2_tracking() {
966
+ if ($this->disable_tracking($this->ga_eeT)) {
967
  return;
968
  }
969
+ $code= '
970
+
971
+ for(var t_item in tvc_ch){
972
+ ga("ec:addProduct", {
973
+ "id": tvc_ch[t_item].tvc_i,
974
+ "name": tvc_ch[t_item].tvc_n,
975
+ "category": tvc_ch[t_item].tvc_c,
976
+ "price": tvc_ch[t_item].tvc_p,
977
+ "quantity": tvc_ch[t_item].tvc_q
978
+ });
979
+ }';
980
 
981
  $code_step_2 = $code . 'ga("ec:setAction","checkout",{"step": 2});';
982
  $code_step_2 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_2",{"nonInteraction": 1});';
999
  * @return void
1000
  */
1001
  public function checkout_step_3_tracking() {
1002
+ if ($this->disable_tracking($this->ga_eeT)) {
1003
  return;
1004
  }
1005
+ $code= '
1006
+ for(var t_item in tvc_ch){
1007
+ ga("ec:addProduct", {
1008
+ "id": tvc_ch[t_item].tvc_i,
1009
+ "name": tvc_ch[t_item].tvc_n,
1010
+ "category": tvc_ch[t_item].tvc_c,
1011
+ "price": tvc_ch[t_item].tvc_p,
1012
+ "quantity": tvc_ch[t_item].tvc_q
1013
+ });
1014
+ }';
1015
 
1016
  //check if guest check out is enabled or not
1017
+ $step_2_on_proceed_to_pay = (!is_user_logged_in() && !$this->ga_gCkout ) || (!is_user_logged_in() && $this->ga_gCkout && $this->ga_gUser);
1018
 
1019
  $code_step_3 = $code . 'ga("ec:setAction","checkout",{"step": 3});';
1020
  $code_step_3 .= 'ga("send", "event", "Enhanced-Ecommerce","load", "checkout_step_3",{"nonInteraction": 1});';
1053
  }
1054
  //remove last comma(,) if multiple categories are there
1055
  $categories = rtrim($categories, ",");
1056
+ $chkout_json[get_permalink($p->id)] = array(
1057
+ "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->id),
1058
+ "tvc_n" => esc_js($p->get_title()),
1059
+ "tvc_p" => esc_js($p->get_price()),
1060
+ "tvc_c" => $categories,
1061
+ "tvc_q" => esc_js($item["quantity"]),
1062
+ "isfeatured"=>$p->is_featured()
1063
+ );
1064
 
 
 
 
 
 
1065
  }
1066
+ //return $code;
1067
+ //make product data json on check out page
1068
+ $this->wc_version_compare("tvc_ch=" . json_encode($chkout_json) . ";");
1069
  }
1070
 
1071
  /**
1103
  */
1104
  function admin_check_UA_enabled() {
1105
  echo '<script>
1106
+ jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_ST").change(function(){
1107
  t_ga_chk=jQuery(this).is(":checked");
1108
 
1109
  if(t_ga_chk){
1110
+ jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_DF").removeAttr("disabled");
1111
  }else{
1112
+ jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_DF").attr("disabled",true);
1113
+ t_display_chk=jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_DF").is(":checked");
1114
  if(t_display_chk){
1115
+ jQuery("#woocommerce_enhanced_ecommerce_google_analytics_ga_DF").removeAttr("checked");
1116
  } }
1117
  });
1118
  </script>';
1124
  * @access public
1125
  * @return void
1126
  */
1127
+ public function send_email_to_tatvic($email,$status) {
1128
  $url = "http://dev.tatvic.com/leadgen/woocommerce-plugin/store_email/";
1129
  //set POST variables
1130
  $fields = array(
1131
  "email" => urlencode($email),
1132
+ "domain_name" => urlencode(get_site_url()),
1133
  "status"=>urlencode($status)
1134
  );
1135
+ wp_remote_post($url, array(
1136
  "method" => "POST",
1137
  "timeout" => 1,
1138
  "httpversion" => "1.0",
1140
  "headers" => array(),
1141
  "body" => $fields
1142
  )
1143
+ );
1144
  }
1145
 
1146
  }
includes/settings.txt DELETED
@@ -1,11 +0,0 @@
1
- screen=yes
2
- email=test@test.com
3
- ga_id=UA-XXXXXX-1
4
- domain=auto
5
- setcurrency=INR
6
- UA_code=yes
7
- display_feature=yes
8
- EE_code=yes
9
- enabled for Guest Users=yes
10
- impression_threshold=6
11
-
 
 
 
 
 
 
 
 
 
 
 
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.11
11
- Version: 1.0.11
12
  License: GPLv3
13
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
14
 
@@ -33,33 +33,16 @@ Provides integration between Google Analytics Enhanced Ecommerce and WooCommerce
33
  9. Captures Product Impressions, Add to Cart & Product Clicks events on Related Product Section on Productpage
34
  10. Set your local currency
35
 
36
- = Things to keep in mind before enabling the Enhanced E-commerce plugin =
37
  * Enable Enhanced E-commerce for your profile/view. This is a profile / view level setting and can be accessed under Admin > View > E-commerce Settings
38
 
39
- * Also, add meaningful labels for your checkout steps. We recommend you to label as, Step 1 : Checkout View; Step 2 : Login; Step 3 : Proceed to payment
40
 
41
  * Remove standard E-commerce code from thank you along with the ecommerce.js which is included by <code>ga('require', 'ecommerce', 'ecommerce.js');</code>. If you are using a third party plugin for e-commerce tracking, you would have to disable the plugin.
42
 
43
- * You need to include ec.js. This can be done by adding a single line of code below your default Google Analytics code snippet <code>ga('require', 'ec', 'ec.js');</code>
44
-
45
- * Users who are using Universal Analytics Tag in GTM, you will have to replace it with a custom HTML tag. Add the following code in your customer HTML tag. After adding the code, kindly replace UA-XXXXXXX-Y with your Google Analytics Property ID.
46
- <pre>
47
- <!-- Google Analytics tag -->
48
- <script>
49
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
50
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
51
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
52
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
53
-
54
- ga('create', 'UA-XXXX-Y', 'auto');
55
- ga('send', 'pageview');
56
- ga('require','ec','ec.js');
57
- </script>
58
- <!-- End Google Analytics -->
59
- </pre>
60
- * After adding the above code, you will have to activate your plug-in from the Settings page. You can access the setting page from here WooCommerce -> Settings ->Integration ->Enhanced Ecommerce Google Analytics.
61
-
62
- * Find “Add Enhanced Ecommerce Tracking Code” in the settings page and check the box to enable the plugin
63
 
64
  * If you have a guest checkout on your WooCommerce store, then Check the box “Add Code to Track the Login Step of Guest Users”. If you have a guest login but you do not check the box, then it might cause an uneven funnel reporting in Google Analytics.
65
 
@@ -88,6 +71,34 @@ This plugin will add the settings to the Integration tab, to be found in the Woo
88
 
89
  Starting the WooCommerce 2.1 release there are no conflicts. However for earlier the plugin might conflict with the default Google Analytics integration for WooCommerce.
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  == Changelog ==
92
 
93
  = 1.0 - 25/06/2014 =
@@ -113,4 +124,10 @@ Starting the WooCommerce 2.1 release there are no conflicts. However for earlier
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
 
 
 
 
 
 
7
  Author: Tatvic
8
  Requires at least: 3.6
9
  Tested up to: 3.9.2
10
+ Stable tag: 1.0.12
11
+ Version: 1.0.12
12
  License: GPLv3
13
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
14
 
33
  9. Captures Product Impressions, Add to Cart & Product Clicks events on Related Product Section on Productpage
34
  10. Set your local currency
35
 
36
+ = Installation Instructions =
37
  * Enable Enhanced E-commerce for your profile/view. This is a profile / view level setting and can be accessed under Admin > View > E-commerce Settings
38
 
39
+ * Add meaningful labels for your checkout steps. We recommend you to label as, Step 1 : Checkout View; Step 2 : Login; Step 3 : Proceed to payment
40
 
41
  * Remove standard E-commerce code from thank you along with the ecommerce.js which is included by <code>ga('require', 'ecommerce', 'ecommerce.js');</code>. If you are using a third party plugin for e-commerce tracking, you would have to disable the plugin.
42
 
43
+ * Activate our plug-in from the Settings page. You can access the setting page from here WooCommerce -> Settings ->Integration ->Enhanced Ecommerce Google Analytics.
44
+
45
+ * Find “Add Enhanced Ecommerce Tracking Code” in the settings page and check the box to add the tracking code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  * If you have a guest checkout on your WooCommerce store, then Check the box “Add Code to Track the Login Step of Guest Users”. If you have a guest login but you do not check the box, then it might cause an uneven funnel reporting in Google Analytics.
48
 
71
 
72
  Starting the WooCommerce 2.1 release there are no conflicts. However for earlier the plugin might conflict with the default Google Analytics integration for WooCommerce.
73
 
74
+ = Why are my PayPal transaction data not getting recorded in GA? =
75
+
76
+ If you are facing this issue, please check if you have configured auto return in PayPal settings. Configuring auto return will resolve your issue. Here’s a PayPal <a href="https://www.paypal.com/in/cgi-bin/webscr?cmd=p/mer/express_return_summary-outside" target="_blank">documentation</a> & WooCommerce <a href="http://docs.woothemes.com/document/paypal-standard/#section-5" target="_blank">documentation</a> on understanding & setting up Auto Return.
77
+
78
+ In case you have already configured auto return for your store, we request you to create a new support thread <a href="https://wordpress.org/support/plugin/enhanced-e-commerce-for-woocommerce-store" target="_blank">here</a> & reach out to us.
79
+
80
+ = I’ve install the plugin but I do not see any data in my GA =
81
+
82
+ Following are one or more reasons:
83
+
84
+ * Please make sure that you have Enabled Enhanced Ecommerce setting in your GA Account. Check out the Step 1 of this <a href="http://www.tatvic.com/blog/enhanced-ecommerce/#steps" target="_blank">blogpost</a>.
85
+
86
+ * If you have just installed our plugin, then please wait for at-least 24 hours before you start seeing any data in your GA. If you still face this issue after 24 hours, please reach out to us via <a href="https://wordpress.org/support/plugin/enhanced-e-commerce-for-woocommerce-store" target="_blank">support thread</a>.
87
+
88
+ = Products with Multi variant not getting recorded in GA =
89
+
90
+ Currently our plugin does not support products with multiple variant & hence you may not see their transaction data in GA. Additionally, we have planned to add the same feature in our upcoming release
91
+
92
+ = My Ecommerce transaction data are not getting recorded in GA =
93
+
94
+ Please check if you have auto return configured in your payment gateway settings. If a user completes the transaction via a 3rd party payment gateway and is not redirected back to your store’s thank you page, our plugin will not be able to send the transaction data.
95
+
96
+ Hence, this may result into missing transaction data in your GA. You can resolve this issue by configuring auto return in your payment gateway settings.
97
+
98
+ = Does your Plugin support Product Refund? =
99
+
100
+ Our existing plugin does not track product refund data, however we are currently building a pro plugin that gives you access to product Refund data. It's a paid plugin that will give you access to all the important features of Universal Analytics including Access to all the reports of Enhanced Ecommerce, User ID Tracking, Product Refund, I.P Anonymization, etc. If you are interested in our paid Plugin, please reach out to us at <a href="mailto:marketing@tatvic.com">marketing@tatvic.com</a>
101
+
102
  == Changelog ==
103
 
104
  = 1.0 - 25/06/2014 =
124
  * Captures Impressions, Product Clicks and Add to Cart on Related Product section on Product Page
125
 
126
  = 1.0.11 - 28/10/2014 =
127
+ * Fixed - Minor bugs
128
+
129
+ = 1.0.12 - 19/11/2014 =
130
+ * Fixed - Settings not getting saved on few stores
131
+ * Fixed - Broken layout issue
132
+
133
+ Important Note: When you update the plugin, please save your settings again.
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.11
25
  */
26
 
27
  // Add the integration to WooCommerce
@@ -36,4 +36,71 @@ function wc_enhanced_ecommerce_google_analytics_add_integration($integrations) {
36
  return $integrations;
37
  }
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  add_filter('woocommerce_integrations', 'wc_enhanced_ecommerce_google_analytics_add_integration', 10);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.12
25
  */
26
 
27
  // Add the integration to WooCommerce
36
  return $integrations;
37
  }
38
 
39
+ function send_email_to_tatvic($email, $status) {
40
+ $url = "http://dev.tatvic.com/leadgen/woocommerce-plugin/store_email/";
41
+ //set POST variables
42
+ $fields = array(
43
+ "email" => urlencode($email),
44
+ "domain_name" => urlencode(get_site_url()),
45
+ "status" => urlencode($status)
46
+ );
47
+ wp_remote_post($url, array(
48
+ "method" => "POST",
49
+ "timeout" => 1,
50
+ "httpversion" => "1.0",
51
+ "blocking" => false,
52
+ "headers" => array(),
53
+ "body" => $fields
54
+ )
55
+ );
56
+ }
57
+
58
+ //function to catch Plugin activation
59
+ function ee_plugin_activate() {
60
+ $PID = "enhanced_ecommerce_google_analytics";
61
+ $chk_Settings = get_option('woocommerce_' . $PID . '_settings');
62
+ if ($chk_Settings) {
63
+ if (array_key_exists("ga_email", $chk_Settings)) {
64
+ send_email_to_tatvic($chk_Settings['ga_email'], 'active');
65
+ }
66
+ }
67
+ }
68
+
69
+ register_activation_hook(__FILE__, 'ee_plugin_activate');
70
+
71
  add_filter('woocommerce_integrations', 'wc_enhanced_ecommerce_google_analytics_add_integration', 10);
72
+
73
+ //plugin action links on plugin page
74
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'tvc_plugin_action_links' );
75
+
76
+ function tvc_plugin_action_links( $links ) {
77
+ $links[] = '<a href="'. get_admin_url(null, 'admin.php?page=wc-settings&tab=integration').'">Settings</a>';
78
+ $links[] = '<a href="https://wordpress.org/plugins/enhanced-e-commerce-for-woocommerce-store/faq/" target="_blank">FAQ</a>';
79
+ return $links;
80
+ }
81
+
82
+ //Custom Admin Header Notifications
83
+ add_action('admin_notices', 'tvc_admin_notice');
84
+
85
+ function tvc_admin_notice() {
86
+ global $current_user,$pagenow ;
87
+ $user_id = $current_user->ID;
88
+ /* Check that the user hasn't already clicked to ignore the message */
89
+ if ( ! get_user_meta($user_id, 'tvc_hide_msg') && $pagenow =='plugins.php') {
90
+ echo '<div class="updated" style="background: #913428; color: #fff; padding-left: 16px;"><p>';
91
+ printf(__('Important Note: Kindly Save Again Your Enhanced Ecommerce WooCommerce Plugin Settings by visiting this <a href="'. get_admin_url(null, 'admin.php?page=wc-settings&tab=integration').'" style="color: #F9F76B; text-decoration: underline; font-weight: bold;">Tab</a> - Tatvic | <a href="%1$s" style="color: #fff;">Hide Notice</a>'), '?tvc_hide_msg=0');
92
+ echo "</p></div>";
93
+ }
94
+ }
95
+
96
+ add_action('admin_init', 'tvc_custom_header_notification');
97
+
98
+ function tvc_custom_header_notification() {
99
+ global $current_user;
100
+ $user_id = $current_user->ID;
101
+ /* If user clicks to ignore the notice, add that to their user meta */
102
+ if ( isset($_GET['tvc_hide_msg']) && '0' == $_GET['tvc_hide_msg'] ) {
103
+ add_user_meta($user_id, 'tvc_hide_msg', 'true', true);
104
+ }
105
+ }
106
+ ?>