Enhanced Ecommerce Google Analytics Plugin for WooCommerce - Version 1.0.13

Version Description

  • 19/12/2014 =
    • Currency as field removed from the plugin. Reason: we now automatically passed the currency which you may have set in WooCommerce store
    • Fixed - Minor bugs
Download this release

Release Info

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

Code changes from version 1.0.12 to 1.0.13

includes/class-wc-enhanced-ecommerce-google-analytics-integration.php CHANGED
@@ -18,6 +18,8 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
18
  * @access public
19
  * @return void
20
  */
 
 
21
  public function __construct() {
22
 
23
  //Set Global Variables
@@ -42,7 +44,9 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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
@@ -78,11 +82,35 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
78
  //add version details in footer
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);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
 
88
  /**
@@ -102,7 +130,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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
  /**
@@ -112,7 +140,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
112
  * @return void
113
  */
114
  function init_form_fields() {
115
- $ga_currency_code = array("USD" => "USD", "AED" => "AED", "ARS" => "ARS", "AUD" => "AUD", "BGN" => "BGN", "BOB" => "BOB", "BRL" => "BRL", "CAD" => "CAD", "CHF" => "CHF", "CLP" => "CLP", "CNY" => "CNY", "COP" => "COP", "CZK" => "CZK", "DKK" => "DKK", "EGP" => "EGP", "EUR" => "EUR", "FRF" => "FRF", "GBP" => "GBP", "HKD" => "HKD", "HRK" => "HRK", "HUF" => "HUF", "IDR" => "IDR", "ILS" => "ILS", "INR" => "INR", "JPY" => "JPY", "KRW" => "KRW", "LTL" => "LTL", "MAD" => "MAD", "MXN" => "MXN", "MYR" => "MYR", "NOK" => "NOK", "NZD" => "NZD", "PEN" => "PEN", "PHP" => "PHP", "PKR" => "PKR", "PLN" => "PLN", "RON" => "RON", "RSD" => "RSD", "RUB" => "RUB", "SAR" => "SAR", "SEK" => "SEK", "SGD" => "SGD", "THB" => "THB", "TRY" => "TRY", "TWD" => "TWD", "UAH" => "UAH", "VEF" => "VEF", "VND" => "VND", "ZAR" => "ZAR");
116
  $this->form_fields = array(
117
  "ga_email" => array(
118
  "title" => __("Email Address", "woocommerce"),
@@ -122,7 +149,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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(
@@ -141,14 +168,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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"),
@@ -211,16 +230,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
211
  }
212
 
213
  /**
214
- * Notify server that plugin is deactivated
215
- *
216
- * @access public
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
@@ -368,7 +377,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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(
@@ -384,7 +392,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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,
@@ -411,7 +419,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
411
  update_post_meta($order_id, "_ga_tracked", 1);
412
  }
413
 
414
-
415
  /**
416
  * Enhanced E-commerce tracking for single product add to cart
417
  *
@@ -437,7 +444,8 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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", {
@@ -478,14 +486,15 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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) . ";");
@@ -563,7 +572,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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(
@@ -593,7 +601,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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()) {
@@ -613,7 +620,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
613
  "tvc_po" => ++$_SESSION['t_npcnt'],
614
  );
615
  }
616
-
617
  }
618
 
619
  /**
@@ -668,6 +674,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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;
@@ -907,6 +914,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
907
 
908
  $code = '
909
  ga("require", "ec", "ec.js");
 
910
  $("a[href*=\"?remove_item\"]").click(function(){
911
  t_url=jQuery(this).attr("href");
912
 
@@ -939,6 +947,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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,
@@ -1054,6 +1063,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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()),
@@ -1061,7 +1071,6 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
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
18
  * @access public
19
  * @return void
20
  */
21
+ //set plugin version
22
+ public $tvc_eeVer = '1.0.13';
23
  public function __construct() {
24
 
25
  //Set Global Variables
44
  $this->ga_email = $this->get_option("ga_email");
45
  $this->ga_id = $this->get_option("ga_id");
46
  $this->ga_Dname = $this->get_option("ga_Dname");
47
+ $this->ga_LC = get_woocommerce_currency(); //Local Currency yuppi! Got from Back end
48
+ //set local currency variable on all page
49
+ $this->wc_version_compare("tvc_lc=" . json_encode($this->ga_LC) . ";");
50
  $this->ga_ST = $this->get_option("ga_ST");
51
  $this->ga_gCkout = $this->get_option("ga_gCkout") == "yes" ? true : false; //guest checkout
52
  $this->ga_gUser = $this->get_option("ga_gUser") == "yes" ? true : false; //guest checkout
82
  //add version details in footer
83
  add_action("wp_footer", array($this, "add_plugin_details"));
84
 
 
 
 
85
  //Add Dev ID
86
  add_action("wp_head", array($this, "add_dev_id"), 1);
87
+
88
+ //Advanced Store data Tracking
89
+ add_action("wp_footer", array($this, "tvc_store_meta_data"));
90
+ }
91
+ /**
92
+ * Get store meta data for trouble shoot
93
+ * @access public
94
+ * @return void
95
+ */
96
+ function tvc_store_meta_data() {
97
+ //only on home page
98
+ global $woocommerce;
99
+ $tvc_sMetaData = array();
100
+
101
+ $tvc_sMetaData = array(
102
+ 'tvc_wcv' => $woocommerce->version,
103
+ 'tvc_wpv' => get_bloginfo('version'),
104
+ 'tvc_eev' => $this->tvc_eeVer,
105
+ 'tvc_cnf' => array(
106
+ 't_ee' => $this->ga_eeT,
107
+ 't_df' => $this->ga_DF,
108
+ 't_gUser'=>$this->ga_gUser,
109
+ 't_UAen'=>$this->ga_ST,
110
+ 't_thr' => $this->ga_imTh,
111
+ )
112
+ );
113
+ $this->wc_version_compare("tvc_smd=" . json_encode($tvc_sMetaData) . ";");
114
  }
115
 
116
  /**
130
  * @return void
131
  */
132
  function add_plugin_details() {
133
+ echo '<!--Enhanced Ecommerce Google Analytics Plugin for Woocommerce by Tatvic Plugin Version:'.$this->tvc_eeVer.'-->';
134
  }
135
 
136
  /**
140
  * @return void
141
  */
142
  function init_form_fields() {
 
143
  $this->form_fields = array(
144
  "ga_email" => array(
145
  "title" => __("Email Address", "woocommerce"),
149
  'custom_attributes' => array(
150
  'required' => "required",
151
  ),
152
+ "desc_tip" => true,
153
  "default" => get_option("ga_email") // Backwards compat
154
  ),
155
  "ga_id" => array(
168
  "desc_tip" => true,
169
  "default" => get_option("ga_Dname") ? get_option("ga_Dname") : "auto"
170
  ),
 
 
 
 
 
 
 
 
171
  "ga_ST" => array(
172
  "title" => __("Tracking code", "woocommerce"),
173
  "label" => __("Add Universal Analytics Tracking Code (Optional)", "woocommerce"),
230
  }
231
 
232
  /**
 
 
 
 
 
 
 
 
 
 
233
  * Google Analytics standard tracking
234
  *
235
  * @access public
377
  }
378
  //make json for prod meta data on order page
379
  $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
 
380
  }
381
  //orderpage transcation data json
382
  $orderpage_trans_Array=array(
392
 
393
  $code.='
394
  //set local currencies
395
+ ga("set", "&cu", tvc_lc);
396
  for(var t_item in tvc_oc){
397
  ga("ec:addProduct", {
398
  "id": tvc_oc[t_item].tvc_i,
419
  update_post_meta($order_id, "_ga_tracked", 1);
420
  }
421
 
 
422
  /**
423
  * Enhanced E-commerce tracking for single product add to cart
424
  *
444
 
445
  $code = '
446
  ga("require", "ec", "ec.js");
447
+ ga("set", "&cu", tvc_lc);
448
+ jQuery("button[class*=single_add_to_cart_button]").click(function() {
449
 
450
  // Enhanced E-commerce Add to cart clicks
451
  ga("ec:addProduct", {
486
  //remove last comma(,) if multiple categories are there
487
  $categories = rtrim($categories, ",");
488
  //product detail view json
489
+ $prodpage_detail_json = array(
490
+ "tvc_id" => esc_html($product->id),
491
  "tvc_i" => $product->get_sku() ? $product->get_sku() : $product->id,
492
+ "tvc_n" => $product->get_title(),
493
+ "tvc_c" => $categories,
494
+ "tvc_p" => $product->get_price()
495
  );
496
+ if (empty($prodpage_detail_json)) { //prod page array
497
+ $prodpage_detail_json = array();
498
  }
499
  //prod page detail view json
500
  $this->wc_version_compare("tvc_po=" . json_encode($prodpage_detail_json) . ";");
572
  "tvc_c" => esc_html($categories)
573
  );
574
  }
 
575
  } else {
576
  //else prod add in homepage recent json
577
  $homepage_json_rp[get_permalink($product->id)] =array(
601
  "tvc_c" => esc_html($categories),
602
  "tvc_po" => ++$_SESSION['t_npcnt'],
603
  );
 
604
  }
605
  //category page, search page and shop page json
606
  else if (is_product_category() || is_search() || is_shop()) {
620
  "tvc_po" => ++$_SESSION['t_npcnt'],
621
  );
622
  }
 
623
  }
624
 
625
  /**
674
 
675
  $hmpg_impressions_jQ = '
676
  ga("require", "ec", "ec.js");
677
+ ga("set", "&cu", tvc_lc);
678
  function t_products_impre_clicks(t_json_name,t_action,t_list){
679
  t_send_threshold=0;
680
  t_prod_pos=0;
914
 
915
  $code = '
916
  ga("require", "ec", "ec.js");
917
+ ga("set", "&cu", tvc_lc);
918
  $("a[href*=\"?remove_item\"]").click(function(){
919
  t_url=jQuery(this).attr("href");
920
 
947
  $this->get_ordered_items();
948
  $code= '
949
  ga("require", "ec", "ec.js");
950
+ ga("set", "&cu", tvc_lc);
951
  for(var t_item in tvc_ch){
952
  ga("ec:addProduct", {
953
  "id": tvc_ch[t_item].tvc_i,
1063
  //remove last comma(,) if multiple categories are there
1064
  $categories = rtrim($categories, ",");
1065
  $chkout_json[get_permalink($p->id)] = array(
1066
+ "tvc_id" => esc_html($p->id),
1067
  "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->id),
1068
  "tvc_n" => esc_js($p->get_title()),
1069
  "tvc_p" => esc_js($p->get_price()),
1071
  "tvc_q" => esc_js($item["quantity"]),
1072
  "isfeatured"=>$p->is_featured()
1073
  );
 
1074
  }
1075
  //return $code;
1076
  //make product data json on check out page
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.12
11
- Version: 1.0.12
12
  License: GPLv3
13
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
14
 
@@ -131,3 +131,7 @@ Our existing plugin does not track product refund data, however we are currently
131
  * Fixed - Broken layout issue
132
 
133
  Important Note: When you update the plugin, please save your settings again.
 
 
 
 
7
  Author: Tatvic
8
  Requires at least: 3.6
9
  Tested up to: 3.9.2
10
+ Stable tag: 1.0.13
11
+ Version: 1.0.13
12
  License: GPLv3
13
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
14
 
131
  * Fixed - Broken layout issue
132
 
133
  Important Note: When you update the plugin, please save your settings again.
134
+
135
+ = 1.0.13 - 19/12/2014 =
136
+ * Currency as field removed from the plugin. Reason: we now automatically passed the currency which you may have set in WooCommerce store
137
+ * Fixed - Minor bugs
woocommerce-enhanced-ecommerce-google-analytics-integration.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- /* Copyright 2014 Sudhir Mishra (email : sudhir@tatvic.com)
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License, version 2, as
@@ -21,8 +21,11 @@
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
28
  function wc_enhanced_ecommerce_google_analytics_add_integration($integrations) {
@@ -31,29 +34,77 @@ function wc_enhanced_ecommerce_google_analytics_add_integration($integrations) {
31
  if (is_object($woocommerce)) {
32
  include_once( 'includes/class-wc-enhanced-ecommerce-google-analytics-integration.php' );
33
  $integrations[] = 'WC_Enhanced_Ecommerce_Google_Analytics';
34
- }
35
-
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() {
@@ -62,45 +113,47 @@ function ee_plugin_activate() {
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
  ?>
1
  <?php
2
 
3
+ /* Copyright 2014 Tatvic
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License, version 2, as
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.13
25
  */
26
+ if (!defined('ABSPATH')) {
27
+ exit; // Exit if accessed directly
28
+ }
29
 
30
  // Add the integration to WooCommerce
31
  function wc_enhanced_ecommerce_google_analytics_add_integration($integrations) {
34
  if (is_object($woocommerce)) {
35
  include_once( 'includes/class-wc-enhanced-ecommerce-google-analytics-integration.php' );
36
  $integrations[] = 'WC_Enhanced_Ecommerce_Google_Analytics';
37
+ }
 
38
  return $integrations;
39
+ }
40
 
41
+ //function to call controller
42
  function send_email_to_tatvic($email, $status) {
43
+ $url = "http://dev.tatvic.com/leadgen/woocommerce-plugin/store_email/";
44
+ //set POST variables
45
+ $fields = array(
46
+ "email" => urlencode($email),
47
+ "domain_name" => urlencode(get_site_url()),
48
  "status" => urlencode($status)
49
+ );
50
+ wp_remote_post($url, array(
51
+ "method" => "POST",
52
+ "timeout" => 1,
53
+ "httpversion" => "1.0",
54
+ "blocking" => false,
55
+ "headers" => array(),
56
+ "body" => $fields
57
+ )
58
+ );
59
+ }
60
+
61
+ add_filter('woocommerce_integrations', 'wc_enhanced_ecommerce_google_analytics_add_integration', 10);
62
+
63
+ //plugin action links on plugin page
64
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'tvc_plugin_action_links');
65
+
66
+ function tvc_plugin_action_links($links) {
67
+ global $woocommerce;
68
+ if (version_compare($woocommerce->version, "2.1", ">=")) {
69
+ $setting_url = 'admin.php?page=wc-settings&tab=integration';
70
+ } else {
71
+ $setting_url = 'admin.php?page=woocommerce_settings&tab=integration';
72
+ }
73
+ $links[] = '<a href="' . get_admin_url(null, $setting_url) . '">Settings</a>';
74
+ $links[] = '<a href="https://wordpress.org/plugins/enhanced-e-commerce-for-woocommerce-store/faq/" target="_blank">FAQ</a>';
75
+ return $links;
76
+ }
77
+
78
+ //Custom Admin Header Notifications
79
+ add_action('admin_notices', 'tvc_admin_notice');
80
+
81
+ function tvc_admin_notice() {
82
+ global $current_user, $pagenow;
83
+ $user_id = $current_user->ID;
84
+ global $woocommerce;
85
+ if (version_compare($woocommerce->version, "2.1", ">=")) {
86
+ $setting_url = 'admin.php?page=wc-settings&tab=integration';
87
+ } else {
88
+ $setting_url = 'admin.php?page=woocommerce_settings&tab=integration';
89
+ }
90
+ /* Check that the user hasn't already clicked to ignore the message */
91
+ if (!get_user_meta($user_id, 'tvc_hide_msg') && $pagenow == 'plugins.php') {
92
+ echo '<div class="updated" style="background: #913428; color: #fff; padding-left: 16px;"><p>';
93
+ printf(__('Important Note: Kindly Save Again Your Enhanced Ecommerce WooCommerce Plugin Settings by visiting this <a href="' . get_admin_url(null, $setting_url) . '" 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');
94
+ echo "</p></div>";
95
+ }
96
+ }
97
+
98
+ add_action('admin_init', 'tvc_custom_header_notification');
99
+
100
+ function tvc_custom_header_notification() {
101
+ global $current_user;
102
+ $user_id = $current_user->ID;
103
+ /* If user clicks to ignore the notice, add that to their user meta */
104
+ if (isset($_GET['tvc_hide_msg']) && '0' == $_GET['tvc_hide_msg']) {
105
+ add_user_meta($user_id, 'tvc_hide_msg', 'true', true);
106
  }
107
+ }
108
 
109
  //function to catch Plugin activation
110
  function ee_plugin_activate() {
113
  if ($chk_Settings) {
114
  if (array_key_exists("ga_email", $chk_Settings)) {
115
  send_email_to_tatvic($chk_Settings['ga_email'], 'active');
 
116
  }
117
  }
118
+ }
119
 
120
+ //function to catch Plugin deactivation
121
+ function ee_plugin_dectivate() {
122
+ if (!current_user_can('activate_plugins'))
123
+ return;
124
+ $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
125
+ $chk_nonce = check_admin_referer("deactivate-plugin_{$plugin}");
126
 
127
+ $PID = "enhanced_ecommerce_google_analytics";
128
+ $chk_Settings = get_option('woocommerce_' . $PID . '_settings');
129
 
130
+ if ($chk_nonce && $chk_Settings) {
131
+ if (array_key_exists("ga_email", $chk_Settings)) {
132
+ send_email_to_tatvic($chk_Settings['ga_email'], 'inactive');
133
+ }
134
+ }
135
  }
136
 
137
+ //function to catch Plugin deletion
138
+ function ee_plugin_delete() {
139
 
140
+ if (!current_user_can('activate_plugins'))
141
+ return;
 
 
 
 
 
 
 
 
142
 
143
+ $chk_nonce = check_admin_referer('bulk-plugins');
144
 
145
+ if ($_GET['action'] == 'delete-selected') {
146
+ $PID = "enhanced_ecommerce_google_analytics";
147
+ $chk_Settings = get_option('woocommerce_' . $PID . '_settings');
148
+ if ($chk_nonce && $chk_Settings) {
149
+ if (array_key_exists("ga_email", $chk_Settings)) {
150
+ send_email_to_tatvic($chk_Settings['ga_email'], 'delete');
151
+ }
152
+ }
153
+ }
154
  }
155
+
156
+ register_activation_hook(__FILE__, 'ee_plugin_activate');
157
+ register_deactivation_hook(__FILE__, 'ee_plugin_dectivate');
158
+ register_uninstall_hook(__FILE__, 'ee_plugin_delete');
159
  ?>