Enhanced Ecommerce Google Analytics Plugin for WooCommerce - Version 4.6.6

Version Description

  • 03/03/2022 =
  • New: In this release, we have Enhanced and optimized in Google Analytics tracking event.
  • Tweak: Now, the admin user will be able to change the thank you page conversion tracking method while setting up the plugin under Google Analytics tab.
  • Tweak: Plugin will no longer be supported for the woocommerce versions anything less than 2.8
Download this release

Release Info

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

Code changes from version 4.6.5 to 4.6.6

admin/css/style.css CHANGED
@@ -2,6 +2,14 @@
2
  @import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,500&display=swap');
3
  /*rc */
4
  /* 11 */
 
 
 
 
 
 
 
 
5
  .btn-11 {
6
  overflow: hidden;
7
  animation: shiny-btn2 2s ease-in-out infinite;
2
  @import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,500&display=swap');
3
  /*rc */
4
  /* 11 */
5
+ select#tvc_conversion_tracking_type{
6
+ border: 1px solid #C6C6C6;
7
+ border-radius: 6px;
8
+ box-sizing: border-box;
9
+ cursor: pointer;
10
+ -webkit-user-select: none;
11
+ padding-right: 30px;
12
+ }
13
  .btn-11 {
14
  overflow: hidden;
15
  animation: shiny-btn2 2s ease-in-out infinite;
admin/partials/general-fields.php CHANGED
@@ -162,6 +162,7 @@ if (isset($_POST['ee_submit_plugin'])) {
162
  $settings['ga_OPTOUT'] = isset($_POST["ga_OPTOUT"])?sanitize_text_field($_POST["ga_OPTOUT"]):"";
163
  $settings['ga_PrivacyPolicy'] = isset($_POST["ga_PrivacyPolicy"])?sanitize_text_field($_POST["ga_PrivacyPolicy"]):"";
164
  $settings['google-analytic'] = '';
 
165
 
166
  $TVC_Admin_Helper->save_ee_options_settings($settings);
167
 
@@ -339,6 +340,19 @@ if(isset($google_detail['setting'])){
339
  </label>
340
  </td>
341
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  <tr>
343
  <th>
344
  <label class = "align-middle" for="ga_OPTOUT"><?php esc_html_e("Google Analytics Opt Out","conversios"); ?></label>
162
  $settings['ga_OPTOUT'] = isset($_POST["ga_OPTOUT"])?sanitize_text_field($_POST["ga_OPTOUT"]):"";
163
  $settings['ga_PrivacyPolicy'] = isset($_POST["ga_PrivacyPolicy"])?sanitize_text_field($_POST["ga_PrivacyPolicy"]):"";
164
  $settings['google-analytic'] = '';
165
+ $settings['tvc_conversion_tracking_type'] = isset($_POST["tvc_conversion_tracking_type"])?sanitize_text_field($_POST["tvc_conversion_tracking_type"]):"";
166
 
167
  $TVC_Admin_Helper->save_ee_options_settings($settings);
168
 
340
  </label>
341
  </td>
342
  </tr>
343
+ <tr>
344
+ <th>
345
+ <label class = "align-middle" for="ga_PrivacyPolicy"><?php esc_html_e("Order Conversion Trigger","conversios"); ?></label>
346
+ </th>
347
+ <td>
348
+ <?php $tvc_con_tracking_type = isset($data['tvc_conversion_tracking_type'])?$data['tvc_conversion_tracking_type']:""; ?>
349
+ <select name="tvc_conversion_tracking_type" id="tvc_conversion_tracking_type">
350
+ <option value="woo-thankyou-hook" <?php echo ($tvc_con_tracking_type != "on-thankyou-page")?"selected":""; ?>><?php esc_html_e("Woo Thankyou Hook","conversios"); ?></option>
351
+ <option value="on-thankyou-page" <?php echo ($tvc_con_tracking_type == "on-thankyou-page")?"selected":""; ?>><?php esc_html_e("On Thankyou Page","conversios"); ?></option>
352
+ </select>
353
+ <i style="cursor: help;" class="fas fa-question-circle" title="<?php esc_html_e("If your thank you page conversion tracking does not work with the current tracking method then switch to another method.","conversios"); ?>"></i>
354
+ </td>
355
+ </tr>
356
  <tr>
357
  <th>
358
  <label class = "align-middle" for="ga_OPTOUT"><?php esc_html_e("Google Analytics Opt Out","conversios"); ?></label>
enhanced-ecommerce-google-analytics.php CHANGED
@@ -15,7 +15,7 @@
15
  * Plugin Name: Conversios.io - Google Analytics and Google Shopping plugin for WooCommerce
16
  * Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
17
  * Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
18
- * Version: 4.6.5
19
  * Author: Tatvic
20
  * Author URI: www.tatvic.com
21
  * License: GPL-2.0+
@@ -23,7 +23,7 @@
23
  * Text Domain: www.tatvic.com
24
  * Domain Path: /languages
25
  * WC requires at least: 3.5.0
26
- * WC tested up to: 6.1.1
27
  */
28
 
29
  /**
@@ -37,7 +37,7 @@ if ( ! defined( 'WPINC' ) ) {
37
  * Start at version 1.0.0 and use SemVer - https://semver.org
38
  * Rename this for your plugin and update it as you release new versions.
39
  */
40
- define( 'PLUGIN_TVC_VERSION', '4.6.5' );
41
  $fullName = plugin_basename( __FILE__ );
42
  $dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
43
  if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
15
  * Plugin Name: Conversios.io - Google Analytics and Google Shopping plugin for WooCommerce
16
  * Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
17
  * Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
18
+ * Version: 4.6.6
19
  * Author: Tatvic
20
  * Author URI: www.tatvic.com
21
  * License: GPL-2.0+
23
  * Text Domain: www.tatvic.com
24
  * Domain Path: /languages
25
  * WC requires at least: 3.5.0
26
+ * WC tested up to: 6.2.1
27
  */
28
 
29
  /**
37
  * Start at version 1.0.0 and use SemVer - https://semver.org
38
  * Rename this for your plugin and update it as you release new versions.
39
  */
40
+ define( 'PLUGIN_TVC_VERSION', '4.6.6' );
41
  $fullName = plugin_basename( __FILE__ );
42
  $dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
43
  if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
includes/class-enhanced-ecommerce-google-analytics.php CHANGED
@@ -76,7 +76,8 @@ class Enhanced_Ecommerce_Google_Analytics {
76
  $this->load_dependencies();
77
  $this->set_locale();
78
  $this->define_admin_hooks();
79
- $this->define_public_hooks();
 
80
  $this->check_dependency();
81
  add_filter( 'plugin_action_links_' .plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' ), array($this,'tvc_plugin_action_links'),10 );
82
  }
@@ -98,61 +99,55 @@ class Enhanced_Ecommerce_Google_Analytics {
98
  * @access private
99
  */
100
  private function load_dependencies() {
 
 
 
 
 
101
 
102
-
103
-
104
- /**
105
- * The class responsible for orchestrating the actions and filters of the
106
- * core plugin.
107
- */
108
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-enhanced-ecommerce-google-analytics-loader.php';
109
-
110
- /**
111
- * The class responsible for defining internationalization functionality
112
- * of the plugin.
113
- */
114
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-enhanced-ecommerce-google-analytics-i18n.php';
115
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-db-helper.php';
116
-
117
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-ajax-calls.php';
118
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-ajax-file.php';
119
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-taxonomies.php';
120
-
121
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-tvc-register-scripts.php';
122
- /**
123
- * The class responsible for defining all actions that occur in the admin area.
124
- */
125
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-enhanced-ecommerce-google-analytics-admin.php';
126
-
127
- /**
128
- * New conversios UI file list
129
- */
130
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-conversios-onboarding.php';
131
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/helper/class-onboarding-helper.php';
132
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/helper/class-dashboard-helper.php';
133
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-conversios-admin.php';
134
- /**
135
- * End New conversios UI file list
136
- */
137
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-auto-product-sync-helper.php';
138
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-survey.php';
139
-
140
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
- /**
143
- * The class responsible for defining all actions that occur in the public-facing
144
- * side of the site.
145
- */
146
-
147
- $TVC_Admin_Helper = new TVC_Admin_Helper();
148
- $plan_id = $TVC_Admin_Helper->get_plan_id();
149
- if($plan_id == 1){
150
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-enhanced-ecommerce-google-analytics-public.php';
151
- }else{
152
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-enhanced-ecommerce-google-analytics-public-pro.php';
153
- }
154
- $this->loader = new Enhanced_Ecommerce_Google_Analytics_Loader();
155
 
 
 
 
 
 
 
 
 
156
  }
157
 
158
  /**
@@ -194,8 +189,8 @@ class Enhanced_Ecommerce_Google_Analytics {
194
  * @since 1.0.0
195
  * @access private
196
  */
197
- private function define_public_hooks() {
198
- $plugin_public = new Enhanced_Ecommerce_Google_Analytics_Public( $this->get_plugin_name(), $this->get_version() );
199
  }
200
 
201
  /**
@@ -204,21 +199,21 @@ class Enhanced_Ecommerce_Google_Analytics {
204
  * @since 1.0.0
205
  */
206
  public function run() {
207
- if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
208
- add_action('woocommerce_init' , function (){
209
- $this->loader->run();
210
- });
211
- }
212
- else{
213
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
214
- if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
215
- $this->loader->run();
216
- }else if( is_plugin_active( 'enhanced-e-commerce-for-woocommerce-store/enhanced-ecommerce-google-analytics.php' ) ){
217
- if(!isset($_POST['action'])){
218
- printf('<div class="notice tvc-notice notice-error"><p>%s</p></div>',esc_html__("Hey, It seems WooCommerce plugin is not active on your wp-admin. Conversios.io - Google Analytics and Google Shopping plugin can only be activated if you have active WooCommerce plugin in your wp-admin.","conversios"));
219
- }
220
- }
221
  }
 
222
  }
223
 
224
  /**
76
  $this->load_dependencies();
77
  $this->set_locale();
78
  $this->define_admin_hooks();
79
+ //$this->define_public_hooks();
80
+ add_action('init', array($this, 'define_public_hooks'));
81
  $this->check_dependency();
82
  add_filter( 'plugin_action_links_' .plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' ), array($this,'tvc_plugin_action_links'),10 );
83
  }
99
  * @access private
100
  */
101
  private function load_dependencies() {
102
+ /**
103
+ * The class responsible for orchestrating the actions and filters of the
104
+ * core plugin.
105
+ */
106
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-enhanced-ecommerce-google-analytics-loader.php';
107
 
108
+ /**
109
+ * The class responsible for defining internationalization functionality
110
+ * of the plugin.
111
+ */
112
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-enhanced-ecommerce-google-analytics-i18n.php';
113
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-db-helper.php';
114
+
115
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-ajax-calls.php';
116
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-ajax-file.php';
117
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-taxonomies.php';
118
+
119
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-tvc-register-scripts.php';
120
+ /**
121
+ * The class responsible for defining all actions that occur in the admin area.
122
+ */
123
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-enhanced-ecommerce-google-analytics-admin.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
+ /**
126
+ * New conversios UI file list
127
+ */
128
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-conversios-onboarding.php';
129
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/helper/class-onboarding-helper.php';
130
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/helper/class-dashboard-helper.php';
131
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-conversios-admin.php';
132
+ /**
133
+ * End New conversios UI file list
134
+ */
135
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-auto-product-sync-helper.php';
136
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-survey.php';
137
 
138
+ /**
139
+ * The class responsible for defining all actions that occur in the public-facing
140
+ * side of the site.
141
+ */
 
 
 
 
 
 
 
 
 
142
 
143
+ $TVC_Admin_Helper = new TVC_Admin_Helper();
144
+ $plan_id = $TVC_Admin_Helper->get_plan_id();
145
+ if($plan_id == 1){
146
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-enhanced-ecommerce-google-analytics-public.php';
147
+ }else{
148
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-enhanced-ecommerce-google-analytics-public-pro.php';
149
+ }
150
+ $this->loader = new Enhanced_Ecommerce_Google_Analytics_Loader();
151
  }
152
 
153
  /**
189
  * @since 1.0.0
190
  * @access private
191
  */
192
+ public function define_public_hooks() {
193
+ new Enhanced_Ecommerce_Google_Analytics_Public( $this->get_plugin_name(), $this->get_version() );
194
  }
195
 
196
  /**
199
  * @since 1.0.0
200
  */
201
  public function run() {
202
+ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
203
+ add_action('woocommerce_init' , function (){
204
+ $this->loader->run();
205
+ });
206
+ }
207
+ else{
208
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
209
+ if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
210
+ $this->loader->run();
211
+ }else if( is_plugin_active( 'enhanced-e-commerce-for-woocommerce-store/enhanced-ecommerce-google-analytics.php' ) ){
212
+ if(!isset($_POST['action'])){
213
+ printf('<div class="notice tvc-notice notice-error"><p>%s</p></div>',esc_html__("Hey, It seems WooCommerce plugin is not active on your wp-admin. Conversios.io - Google Analytics and Google Shopping plugin can only be activated if you have active WooCommerce plugin in your wp-admin.","conversios"));
214
+ }
 
215
  }
216
+ }
217
  }
218
 
219
  /**
public/class-enhanced-ecommerce-google-analytics-public-pro.php CHANGED
@@ -64,6 +64,9 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
64
  protected $remarketing_snippet_id;
65
  protected $remarketing_snippets;
66
  protected $conversio_send_to;
 
 
 
67
 
68
  /**
69
  * Enhanced_Ecommerce_Google_Analytics_Public constructor.
@@ -75,6 +78,8 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
75
  $this->TVC_Admin_Helper = new TVC_Admin_Helper();
76
  $this->plugin_name = sanitize_text_field($plugin_name);
77
  $this->version = sanitize_text_field($version);
 
 
78
  $this->tvc_call_hooks();
79
 
80
  $this->ga_Dname = "auto";
@@ -106,57 +111,54 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
106
  $this->remarketing_snippets = base64_decode($remarketing['snippets']);
107
  $this->remarketing_snippet_id = sanitize_text_field(isset($remarketing['id'])?esc_attr($remarketing['id']):"");
108
  }
109
- if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
110
- // Put your plugin code here
111
- add_action('woocommerce_init' , function (){
112
- $this->ga_LC = get_woocommerce_currency(); //Local Currency from Back end
113
- $this->wc_version_compare("tvc_lc=" . json_encode(esc_js($this->ga_LC)) . ";");
114
- /*
115
- * start tvc_options
116
- */
117
- $current_user = wp_get_current_user();
118
- //$current_user ="";
119
- $user_id = "";
120
- $user_type = "guest_user";
121
- if ( isset($current_user->ID) && $current_user->ID != 0 ) {
122
- $user_id = $current_user->ID;
123
- $current_user_type = 'register_user';
124
- }
125
- $this->tvc_options = array(
126
- "feature_product_label"=>esc_html__("Feature Product"),
127
- "on_sale_label"=>esc_html__("On Sale"),
128
- "affiliation"=>esc_js(get_bloginfo('name')),
129
- "local_time"=>esc_js(time()),
130
- "is_admin"=>esc_attr(is_admin()),
131
- "currency"=>esc_js($this->ga_LC),
132
- "tracking_option"=>esc_js($this->tracking_option),
133
- "property_id"=>esc_js($this->ga_id),
134
- "measurement_id"=>esc_js($this->gm_id),
135
- "google_ads_id"=>esc_js($this->google_ads_id),
136
- "google_merchant_center_id"=>esc_js($this->google_merchant_id),
137
- "o_add_gtag_snippet"=>esc_js($this->ga_ST),
138
- "o_enhanced_e_commerce_tracking"=>esc_js($this->ga_eeT),
139
- "o_log_step_gest_user"=>esc_js($this->ga_gUser),
140
- "o_impression_thresold"=>esc_js($this->ga_imTh),
141
- "o_ip_anonymization"=>esc_js($this->ga_IPA),
142
- "o_ga_OPTOUT"=>esc_js($this->ga_OPTOUT),
143
- "ads_tracking_id"=>esc_js($this->ads_tracking_id),
144
- "remarketing_tags"=>esc_js($this->ads_ert),
145
- "dynamic_remarketing_tags"=>esc_js($this->ads_edrt),
146
- "google_ads_conversion_tracking"=>esc_js($this->google_ads_conversion_tracking),
147
- "conversio_send_to"=>esc_js($this->conversio_send_to),
148
- "page_type"=>esc_js($this->add_page_type()),
149
- "user_id"=>esc_js($user_id),
150
- "user_type"=>esc_js($user_type),
151
- "day_type"=>esc_js($this->add_day_type()),
152
- "remarketing_snippet_id"=>esc_js($this->remarketing_snippet_id),
153
- "tvc_ajax_url"=>esc_url_raw(admin_url( 'admin-ajax.php' ))
154
- );
155
- /*
156
- * end tvc_options
157
- */
158
- });
159
- } // end if woocommerce
160
  }
161
 
162
  public function tvc_call_hooks(){
@@ -166,13 +168,21 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
166
 
167
  add_action("wp_footer", array($this, "t_products_impre_clicks"));
168
  add_action("woocommerce_after_shop_loop_item", array($this, "bind_product_metadata"));
169
- add_action("woocommerce_thankyou", array($this, "ecommerce_tracking_code"));
170
- add_action("woocommerce_after_single_product", array($this, "product_detail_view"));
 
 
 
 
 
171
  add_action("woocommerce_after_cart", array($this, "remove_cart_tracking"));
172
  //check out step 1,2,3
173
- add_action("woocommerce_before_checkout_form", array($this, "checkout_step_1_tracking"));
174
- add_action("woocommerce_before_checkout_form", array($this, "checkout_step_2_tracking"));
175
- add_action("woocommerce_before_checkout_form", array($this, "checkout_step_3_tracking"));
 
 
 
176
  add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
177
  //add version details in footer
178
  add_action("wp_footer", array($this, "add_plugin_details"));
@@ -285,14 +295,11 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
285
  }
286
  }
287
  public function get_option($key){
288
- $ee_options = array();
289
- $my_option = get_option( 'ee_options' );
290
-
291
- if(!empty($my_option)){
292
- $ee_options = unserialize($my_option);
293
  }
294
- if(isset($ee_options[$key])){
295
- return $ee_options[$key];
296
  }
297
  }
298
  /**
@@ -396,13 +403,12 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
396
  * @return void
397
  */
398
  function wc_version_compare($codeSnippet) {
399
- global $woocommerce;
400
-
401
- if (version_compare($woocommerce->version, "2.1", ">=")) {
402
- wc_enqueue_js($codeSnippet);
403
- } else {
404
- $woocommerce->add_inline_js($codeSnippet);
405
- }
406
  }
407
  /**
408
  * Enhanced Ecommerce GA plugin Settings
@@ -414,7 +420,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
414
  global $woocommerce;
415
  //common validation----start
416
  if (is_admin() || $this->ga_ST == "" || current_user_can("manage_options") || !$this->ga_PrivacyPolicy) {
417
- return;
418
  }
419
  // IP Anonymization
420
  if ($this->ga_IPA) {
@@ -553,7 +559,45 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
553
  }
554
  }
555
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
  /**
558
  * Google Analytics eCommerce tracking
559
  *
@@ -561,11 +605,19 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
561
  * @param mixed $order_id
562
  * @return void
563
  */
564
- function ecommerce_tracking_code($order_id) {
565
  global $woocommerce;
566
- if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1){
567
- return;
 
 
 
 
568
  }
 
 
 
 
569
  // Doing eCommerce tracking so unhook standard tracking from the footer
570
  remove_action("wp_footer", array($this, "ee_settings"));
571
  /*
@@ -573,7 +625,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
573
  * var tvc_oc
574
  */
575
  $orderpage_prod_Array = array();
576
- $order = new WC_Order($order_id);
577
  //Get Applied Coupon Codes
578
  $coupons_list = '';
579
  if(version_compare($woocommerce->version, "3.7", ">")){
@@ -608,12 +660,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
608
  }
609
  }
610
  $categories=esc_js(join(",", $out));
611
- $product_type = "";
612
- if (version_compare($woocommerce->version, "2.7", "<")) {
613
- $product_type = $_product->product_type;
614
- }else{
615
- $product_type =$_product->get_type();
616
- }
617
  if($product_type == "variation"){
618
  $attributes=esc_js(wc_get_formatted_variation($_product->get_variation_attributes(), true));
619
  /*if ($_product->variation_has_weight) {
@@ -623,50 +670,28 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
623
  /*if ($_product->has_weight()) {
624
  //$p_weight = $_product->get_weight().' '.esc_attr(get_option('woocommerce_weight_unit'));
625
  }*/
626
- }
627
- if (version_compare($woocommerce->version, "2.7", "<")) {
628
- $orderpage_prod_Array[get_permalink($_product->ID)]=array(
629
- "tvc_id" => esc_js($_product->ID),
630
- "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->ID),
631
- "tvc_n" => html_entity_decode(esc_js($item["name"])),
632
- "tvc_p" => esc_js($order->get_item_total($item)),
633
- //"tvc_rp" => $_product->regular_price,
634
- //"tvc_sp" => $_product->sale_price,
635
- "tvc_pd" => esc_js($this->cal_prod_discount($_product->regular_price, $_product->sale_price)),
636
- "tvc_c" => esc_js($categories),
637
- "tvc_attr" => esc_js($attributes),
638
- "tvc_q"=>esc_js($item["qty"]),
639
- //"tvc_wt" => $p_weight,
640
- "tvc_var" => esc_js($this->getAttributesVariation($_product)),
641
- /*"tvc_di" => $_product->get_dimensions(), //dimensions
642
- "tvc_ss" => $_product->is_in_stock(),
643
- "tvc_st" => $_product->get_stock_quantity(),
644
- "tvc_tst" => $_product->get_total_stock(),
645
- "tvc_rc" => $_product->get_rating_count(),
646
- "tvc_rs" => $_product->get_average_rating()*/
647
- );
648
- }else{
649
- $orderpage_prod_Array[get_permalink($_product->get_id())]=array(
650
- "tvc_id" => esc_js($_product->get_id()),
651
- "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
652
- "tvc_n" => esc_js($_product->get_title()),
653
- "tvc_p" => esc_js($order->get_item_total($item)),
654
- // "tvc_rp" => $_product->get_regular_price(),
655
- // "tvc_sp" => $_product->get_sale_price(),
656
- "tvc_pd" => esc_js($this->cal_prod_discount($_product->get_regular_price(), $_product->get_sale_price())),
657
- "tvc_c" => esc_js($categories),
658
- "tvc_attr" => esc_js($attributes),
659
- "tvc_q"=>esc_js($item["qty"]),
660
- //"tvc_wt" => $p_weight,
661
- "tvc_var" => esc_js($this->getAttributesVariation($_product)),
662
- /*"tvc_di" => $_product->get_dimensions(), //dimensions
663
- "tvc_ss" => $_product->is_in_stock(),
664
- "tvc_st" => $_product->get_stock_quantity(),
665
- "tvc_tst" => $_product->get_total_stock(),
666
- "tvc_rc" => $_product->get_rating_count(),
667
- "tvc_rs" => $_product->get_average_rating()*/
668
- );
669
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
670
  }
671
  //make json for prod meta data on order page
672
  $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
@@ -676,13 +701,8 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
676
  * Get the trans data
677
  * Var tvc_td
678
  */
679
- //get shipping cost based on version >2.1 get_total_shipping() < get_shipping
680
- $tvc_sc = "";
681
- if (version_compare($woocommerce->version, "2.1", ">=")) {
682
- $tvc_sc = $order->get_total_shipping();
683
- } else {
684
- $tvc_sc = $order->get_shipping();
685
- }
686
  $user_bill_addr="";
687
  $user_ship_addr="";
688
  if(isset($this->tvc_options["user_id"]) && $this->tvc_options["user_id"]!="" ){
@@ -756,15 +776,12 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
756
  * @return void
757
  */
758
  public function product_detail_view() {
759
- if ($this->disable_tracking($this->ga_eeT)) {
760
  return;
761
  }
762
- global $product,$woocommerce;
763
- if(version_compare($woocommerce->version, "2.7", "<")){
764
- $category = get_the_terms($product->ID, "product_cat");
765
- }else{
766
- $category = get_the_terms($product->get_id(), "product_cat");
767
- }
768
  $categories = "";
769
  if ($category) {
770
  foreach ($category as $term) {
@@ -774,39 +791,21 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
774
  //remove last comma(,) if multiple categories are there
775
  $categories = rtrim($categories, ",");
776
  //product detail view json
777
- $prodpage_detail_json = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
778
 
779
- if(version_compare($woocommerce->version, "2.7", "<")){
780
- $prodpage_detail_json = array(
781
- "tvc_id" => esc_js($product->id),
782
- "tvc_i" => $product->get_sku() ? esc_js($product->get_sku()) : esc_js($product->id),
783
- "tvc_n" => esc_js($product->get_title()),
784
- "tvc_c" => esc_js($categories),
785
- "tvc_p" => esc_js($product->get_price()),
786
- "tvc_pd" => esc_js($this->cal_prod_discount($product->regular_price, $product->sale_price)),
787
- "tvc_ps" => esc_js($product->get_stock_status()),
788
- "tvc_tst" => esc_js($product->get_total_stock()),
789
- "tvc_q" => esc_js($product->get_stock_quantity()),
790
- "tvc_var" => esc_js($this->getAttributesVariation($product)),
791
- "is_featured" => esc_js($product->is_featured()),
792
- "is_onSale" => esc_js($product->is_on_sale())
793
- );
794
- }else{
795
- $prodpage_detail_json = array(
796
- "tvc_id" => esc_js($product->get_id()),
797
- "tvc_i" => $product->get_sku() ? esc_js($product->get_sku()) : esc_js($product->get_id()),
798
- "tvc_n" => esc_js($product->get_title()),
799
- "tvc_c" => esc_js($categories),
800
- "tvc_p" => esc_js($product->get_price()),
801
- "tvc_pd" => esc_js($this->cal_prod_discount($product->get_regular_price(), $product->get_sale_price())),
802
- "tvc_ps" => esc_js($product->get_stock_status()),
803
- "tvc_tst" => esc_js($product->get_stock_quantity()),
804
- "tvc_q" => esc_js($product->get_stock_quantity()),
805
- "tvc_var" => esc_js($this->getAttributesVariation($product)),
806
- "is_featured" => esc_js($product->is_featured()),
807
- "is_onSale" => esc_js($product->is_on_sale())
808
- );
809
- }
810
  //prod page detail view json
811
  $this->wc_version_compare("tvc_po=" . json_encode($prodpage_detail_json) . ";");
812
  ?>
@@ -820,615 +819,533 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
820
  <?php
821
  }
822
 
823
- /**
824
- * Enhanced E-commerce tracking for product impressions on category pages (hidden fields) , product page (related section)
825
- * home page (featured section and recent section)
826
- *
827
- * @access public
828
- * @return void
829
- */
830
- public function bind_product_metadata() {
831
- if ($this->disable_tracking($this->ga_eeT)) {
832
- return;
833
- }
834
-
835
- global $product,$woocommerce;
836
- if (version_compare($woocommerce->version, "2.7", "<")) {
837
- $category = get_the_terms($product->Id, "product_cat");
838
- } else {
839
- $category = get_the_terms($product->get_id(), "product_cat");
840
- }
841
-
842
- $categories = "";
843
 
844
- if ($category) {
845
- foreach ($category as $term) {
846
- $categories.=$term->name . ",";
847
- }
 
 
848
  }
849
- //remove last comma(,) if multiple categories are there
850
- $categories = rtrim($categories, ",");
851
- //declare all variable as a global which will used for make json
852
- global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
853
- //is home page then make all necessory json
854
- if (is_home() || is_front_page()) {
855
- if (!is_array($homepage_json_fp) && !is_array($homepage_json_rp) && !is_array($homepage_json_ATC_link)) {
856
- $homepage_json_fp = array();
857
- $homepage_json_rp = array();
858
- $homepage_json_ATC_link=array();
859
- }
860
-
861
- // ATC link Array
862
- if(version_compare($woocommerce->version, "2.7", "<")){
863
- $homepage_json_ATC_link[$product->add_to_cart_url()]=
864
- array(
865
- "ATC-link"=>esc_url_raw(get_permalink($product->id))
866
- );
867
- }else{
868
- $homepage_json_ATC_link[$product->add_to_cart_url()]=
869
- array(
870
- "ATC-link"=>esc_url_raw(get_permalink($product->get_id()))
871
- );
872
- }
873
- //check if product is featured product or not
874
- if ($product->is_featured()) {
875
- //check if product is already exists in homepage featured json
876
- if(version_compare($woocommerce->version, "2.7", "<")){
877
- if(!array_key_exists(get_permalink($product->id),$homepage_json_fp)){
878
- $homepage_json_fp[get_permalink($product->id)] = array(
879
- "tvc_id" => esc_js($product->id),
880
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
881
- "tvc_n" => esc_js($product->get_title()),
882
- "tvc_p" => esc_js($product->get_price()),
883
- "tvc_c" => esc_js($categories),
884
- "ATC-link"=> esc_url_raw($product->add_to_cart_url())
885
- );
886
- //else add product in homepage recent product json
887
- }else {
888
- $homepage_json_rp[get_permalink($product->get_id())] =array(
889
- "tvc_id" => esc_js($product->get_id()),
890
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
891
- "tvc_n" => esc_js($product->get_title()),
892
- "tvc_p" => esc_js($product->get_price()),
893
- "tvc_c" => esc_js($categories)
894
- );
895
- }
896
- }else{
897
- if(!array_key_exists(get_permalink($product->get_id()),$homepage_json_fp)){
898
- $homepage_json_fp[get_permalink($product->get_id())] = array(
899
- "tvc_id" => esc_js($product->get_id()),
900
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
901
- "tvc_n" => esc_js($product->get_title()),
902
- "tvc_p" => esc_js($product->get_price()),
903
- "tvc_c" => esc_js($categories),
904
- "ATC-link"=> esc_url_raw($product->add_to_cart_url())
905
- );
906
- //else add product in homepage recent product json
907
- }else {
908
- $homepage_json_rp[get_permalink($product->get_id())] =array(
909
- "tvc_id" => esc_js($product->get_id()),
910
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
911
- "tvc_n" => esc_js($product->get_title()),
912
- "tvc_p" => esc_js($product->get_price()),
913
- "tvc_c" => esc_js($categories)
914
- );
915
- }
916
- }
917
-
918
- } else {
919
- //else prod add in homepage recent json
920
- if(version_compare($woocommerce->version, "2.7", "<")){
921
- $homepage_json_rp[get_permalink($product->id)] =array(
922
- "tvc_id" => esc_js($product->id),
923
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
924
- "tvc_n" => esc_js($product->get_title()),
925
- "tvc_p" => esc_js($product->get_price()),
926
- "tvc_c" => esc_js($categories)
927
- );
928
- }else{
929
- $homepage_json_rp[get_permalink($product->get_id())] =array(
930
- "tvc_id" => esc_js($product->get_id()),
931
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
932
- "tvc_n" => esc_js($product->get_title()),
933
- "tvc_p" => esc_js($product->get_price()),
934
- "tvc_c" => esc_js($categories)
935
- );
936
- }
937
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
938
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
939
  }
940
- //if product page then related product page array
941
- else if(is_product()){
942
- if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
943
- $prodpage_json_relProd = array();
944
- $prodpage_json_ATC_link = array();
945
- }
946
- // ATC link Array
947
- if(version_compare($woocommerce->version, "2.7", "<")){
948
- $prodpage_json_ATC_link[$product->add_to_cart_url()]=
949
- array(
950
- "ATC-link"=> esc_url_raw(get_permalink($product->id))
951
- );
952
-
953
- $prodpage_json_relProd[get_permalink($product->id)] = array(
954
- "tvc_id" => esc_js($product->id),
955
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
956
- "tvc_n" => esc_js($product->get_title()),
957
- "tvc_p" => esc_js($product->get_price()),
958
- "tvc_c" => esc_js($categories),
959
- );
960
- }else{
961
- $prodpage_json_ATC_link[$product->add_to_cart_url()]=
962
- array(
963
- "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
964
- );
965
-
966
- $prodpage_json_relProd[get_permalink($product->get_id())] = array(
967
- "tvc_id" => esc_js($product->get_id()),
968
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
969
- "tvc_n" => esc_js($product->get_title()),
970
- "tvc_p" => esc_js($product->get_price()),
971
- "tvc_c" => esc_js($categories)
972
-
973
- );
974
- }
975
  }
976
- //category page, search page and shop page json
977
- else if (is_product_category() || is_search() || is_shop()) {
978
- if (!is_array($catpage_json) && !is_array($catpage_json_ATC_link)){
979
- $catpage_json=array();
980
- $catpage_json_ATC_link=array();
981
- }
982
- //cat page ATC array
983
- if(version_compare($woocommerce->version, "2.7", "<")){
984
- $catpage_json_ATC_link[$product->add_to_cart_url()]=
985
- array(
986
- "ATC-link"=>esc_url_raw(get_permalink($product->id))
987
- );
988
-
989
- $catpage_json[get_permalink($product->id)] =array(
990
- "tvc_id" => esc_js($product->id),
991
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
992
- "tvc_n" => esc_js($product->get_title()),
993
- "tvc_p" => esc_js($product->get_price()),
994
- "tvc_c" => esc_js($categories),
995
- );
996
- }else{
997
- $catpage_json_ATC_link[$product->add_to_cart_url()]=
998
- array(
999
- "ATC-link"=>esc_url_raw(get_permalink($product->get_id()))
1000
- );
1001
 
1002
- $catpage_json[get_permalink($product->get_id())] =array(
1003
- "tvc_id" => esc_js($product->get_id()),
1004
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
1005
- "tvc_n" => esc_js($product->get_title()),
1006
- "tvc_p" => esc_js($product->get_price()),
1007
- "tvc_c" => esc_js($categories)
 
 
 
1008
 
1009
- );
1010
- }
1011
- }
 
 
 
 
 
 
1012
  }
1013
 
1014
- /**
1015
- * Enhanced E-commerce tracking for product impressions,clicks on Home pages
1016
- *
1017
- * @access public
1018
- * @return void
1019
- */
1020
- function t_products_impre_clicks() {
1021
- if ($this->disable_tracking($this->ga_eeT)) {
1022
- return;
1023
- }
1024
-
1025
- //get impression threshold
1026
- $impression_threshold = $this->ga_imTh;
1027
 
1028
- //Product impression on Home Page
1029
- global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
1030
- //home page json for featured products and recent product sections
1031
- //check if php array is empty
1032
- if(empty($homepage_json_ATC_link)){
1033
- $homepage_json_ATC_link=array(); //define empty array so if empty then in json will be []
1034
- }
1035
- if(empty($homepage_json_fp)){
1036
- $homepage_json_fp=array(); //define empty array so if empty then in json will be []
1037
- }
1038
- if(empty($homepage_json_rp)){ //home page recent product array
1039
- $homepage_json_rp=array();
1040
- }
1041
- if(empty($prodpage_json_relProd)){ //prod page related section array
1042
- $prodpage_json_relProd=array();
1043
- }
1044
- if(empty($prodpage_json_ATC_link)){
1045
- $prodpage_json_ATC_link=array(); //prod page ATC link json
1046
- }
1047
- if(empty($catpage_json)){ //category page array
1048
- $catpage_json=array();
1049
- }
1050
- if(empty($catpage_json_ATC_link)){ //category page array
1051
- $catpage_json_ATC_link=array();
1052
- }
1053
- //home page json
1054
- $this->wc_version_compare("homepage_json_ATC_link=" . json_encode($homepage_json_ATC_link) . ";");
1055
- $this->wc_version_compare("tvc_fp=" . json_encode($homepage_json_fp) . ";");
1056
- $this->wc_version_compare("tvc_rcp=" . json_encode($homepage_json_rp) . ";");
1057
- //product page json
1058
- $this->wc_version_compare("tvc_rdp=" . json_encode($prodpage_json_relProd) . ";");
1059
- $this->wc_version_compare("prodpage_json_ATC_link=" . json_encode($prodpage_json_ATC_link) . ";");
1060
- //category page json
1061
- $this->wc_version_compare("tvc_pgc=" . json_encode($catpage_json) . ";");
1062
- $this->wc_version_compare("catpage_json_ATC_link=" . json_encode($catpage_json_ATC_link) . ";");
1063
- if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
1064
- $hmpg_impressions_jQ = '
1065
- var items = [];
1066
- //set local currencies
1067
- gtag("set", {"currency": tvc_lc});
1068
- function t_products_impre_clicks(t_json_name,t_action){
1069
- t_send_threshold=0;
1070
- t_prod_pos=0;
1071
- t_json_length=Object.keys(t_json_name).length;
1072
-
1073
- for(var t_item in t_json_name) {
1074
- t_send_threshold++;
1075
- t_prod_pos++;
1076
- items.push({
1077
- "id": t_json_name[t_item].tvc_i,
1078
- "name": t_json_name[t_item].tvc_n,
1079
- "category": t_json_name[t_item].tvc_c,
1080
- "price": t_json_name[t_item].tvc_p,
1081
- });
1082
-
1083
- if(t_json_length > ' . esc_js($impression_threshold) .' ){
1084
-
1085
- if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
1086
- t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
1087
- gtag("event", "view_item_list", { "event_category":"Enhanced-Ecommerce",
1088
- "event_label":"product_impression_"+t_action, "items":items,"non_interaction": true});
1089
- items = [];
1090
- }
1091
- if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1092
- gtag("event","view_item_list", {
1093
- "value": t_json_name[t_item].tvc_p,
1094
- "items": [
1095
- {
1096
- "id": t_json_name[t_item].tvc_id,
1097
- "google_business_vertical": "retail"
1098
- }
1099
- ]
1100
- });
1101
- }
1102
- }else{
1103
-
1104
- t_json_length--;
1105
- if(t_json_length==0){
1106
- gtag("event", "view_item_list", { "event_category":"Enhanced-Ecommerce",
1107
- "event_label":"product_impression_"+t_action, "items":items,"non_interaction": true});
1108
- items = [];
1109
- }
1110
- if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1111
- gtag("event","view_item_list", {
1112
- "value": t_json_name[t_item].tvc_p,
1113
- "items": [
1114
- {
1115
- "id": t_json_name[t_item].tvc_id,
1116
- "google_business_vertical": "retail"
1117
- }
1118
- ]
1119
- });
1120
- }
1121
- }
1122
- }
1123
- }
1124
-
1125
- //function for comparing urls in json object
1126
- function prod_exists_in_JSON(t_url,t_json_name,t_action){
1127
- if(t_json_name.hasOwnProperty(t_url)){
1128
- t_call_fired=true;
1129
- gtag("event", "select_content", {
1130
- "event_category":"Enhanced-Ecommerce",
1131
- "event_label":"product_click_"+t_action,
1132
- "content_type": "product",
1133
- "items": [
1134
  {
1135
- "id":t_json_name[t_url].tvc_i,
1136
- "name": t_json_name[t_url].tvc_n,
1137
- "category":t_json_name[t_url].tvc_c,
1138
- "price": t_json_name[t_url].tvc_p,
1139
  }
1140
- ],
1141
- "non_interaction": true
1142
- });
1143
- }else{
1144
- t_call_fired=false;
1145
- }
1146
- return t_call_fired;
1147
- }
1148
- function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
1149
- t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
1150
-
1151
- if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
1152
- t_call_fired=true;
1153
- // Enhanced E-commerce Add to cart clicks
1154
- gtag("event", "add_to_cart", {
1155
- "event_category":"Enhanced-Ecommerce",
1156
- "event_label":"add_to_cart_click",
1157
- "non_interaction": true,
1158
- "items": [{
1159
- "id" : t_prod_data_json[t_prod_url_key].tvc_i,
1160
- "name":t_prod_data_json[t_prod_url_key].tvc_n,
1161
- "category" : t_prod_data_json[t_prod_url_key].tvc_c,
1162
- "price": t_prod_data_json[t_prod_url_key].tvc_p,
1163
- "quantity" :t_qty
1164
- }]
1165
- });
1166
- if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1167
- gtag("event","add_to_cart", {
1168
- "value": t_prod_data_json[t_prod_url_key].tvc_p,
1169
- "items": [
 
 
 
 
 
1170
  {
1171
- "id": t_prod_data_json[t_prod_url_key].tvc_id,
1172
- "google_business_vertical": "retail"
 
 
1173
  }
1174
- ]
1175
- });
1176
- }
1177
-
1178
- }else{
1179
- t_call_fired=false;
1180
- }
1181
- return t_call_fired;
1182
-
1183
- }
1184
-
1185
- ';
1186
- }
1187
- if($this->gm_id && $this->tracking_option == "GA4") {
1188
- $hmpg_impressions_jQ = '
1189
- var items = [];
1190
- function t_products_impre_clicks(t_json_name,t_action){
1191
- t_send_threshold=0;
1192
- t_prod_pos=0;
1193
- t_json_length=Object.keys(t_json_name).length;
1194
- for(var t_item in t_json_name) {
1195
- t_send_threshold++;
1196
- t_prod_pos++;
1197
- items.push({
1198
- "item_id": t_json_name[t_item].tvc_i,
1199
- "item_name": t_json_name[t_item].tvc_n,
1200
- "item_category": t_json_name[t_item].tvc_c,
1201
- "price": t_json_name[t_item].tvc_p,
1202
- "currency": tvc_lc
1203
- });
1204
- if(t_json_length > ' . esc_js($impression_threshold) . ' ){
1205
- if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
1206
- t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
1207
- gtag("event", "view_item_list", {
1208
- "event_category":"Enhanced-Ecommerce",
1209
- "event_label":"product_impression_"+t_action,
1210
- "items":items,
1211
- "non_interaction": true
1212
- });
1213
- items = [];
1214
- }
1215
- if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1216
- gtag("event","view_item_list", {
1217
- "value": t_json_name[t_item].tvc_p,
1218
- "items": [
1219
- {
1220
- "id": t_json_name[t_item].tvc_id,
1221
- "google_business_vertical": "retail"
1222
- }
1223
- ]
1224
- });
1225
- }
1226
- }else{
1227
- t_json_length--;
1228
- if(t_json_length==0){
1229
- gtag("event", "view_item_list", {
1230
- "event_category":"Enhanced-Ecommerce",
1231
- "event_label":"product_impression_"+t_action,
1232
- "items":items,
1233
- "non_interaction": true
1234
- });
1235
- items = [];
1236
- }
1237
- if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1238
- gtag("event","view_item_list", {
1239
- "value": t_json_name[t_item].tvc_p,
1240
- "items": [
1241
- {
1242
- "id": t_json_name[t_item].tvc_id,
1243
- "google_business_vertical": "retail"
1244
  }
1245
- ]
1246
- });
1247
- }
1248
- }
1249
- }
1250
- }
1251
-
1252
- //function for comparing urls in json object
1253
- function prod_exists_in_JSON(t_url,t_json_name,t_action){
1254
- if(t_json_name.hasOwnProperty(t_url)){
1255
- t_call_fired=true;
1256
- gtag("event", "select_item", {
1257
- "event_category":"Enhanced-Ecommerce",
1258
- "event_label":"product_click_"+t_action,
1259
- "items": [
1260
- {
1261
- "item_id":t_json_name[t_url].tvc_i,
1262
- "item_name": t_json_name[t_url].tvc_n,
1263
- "item_category":t_json_name[t_url].tvc_c,
1264
- "price": t_json_name[t_url].tvc_p,
1265
- "currency": tvc_lc
1266
- }
1267
- ],
1268
- "non_interaction": true
1269
- });
1270
-
1271
- }else{
1272
- t_call_fired=false;
1273
- }
1274
- return t_call_fired;
1275
- }
1276
- function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
1277
- t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
1278
- if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
1279
- t_call_fired=true;
1280
- // Enhanced E-commerce Add to cart clicks
1281
- gtag("event", "add_to_cart", {
1282
- "event_category":"Enhanced-Ecommerce",
1283
- "event_label":"add_to_cart_click",
1284
- "non_interaction": true,
1285
- "items": [{
1286
- "item_id" : t_prod_data_json[t_prod_url_key].tvc_i,
1287
- "item_name":t_prod_data_json[t_prod_url_key].tvc_n,
1288
- "item_category" : t_prod_data_json[t_prod_url_key].tvc_c,
1289
- "price": t_prod_data_json[t_prod_url_key].tvc_p,
1290
- "currency": tvc_lc,
1291
- "quantity" :t_qty
1292
- }]
1293
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1294
 
1295
- if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1296
- gtag("event","add_to_cart", {
1297
- "value": t_prod_data_json[t_prod_url_key].tvc_p,
1298
- "items": [
1299
- {
1300
- "id": t_prod_data_json[t_prod_url_key].tvc_id,
1301
- "google_business_vertical": "retail"
1302
- }
1303
- ]
1304
- });
1305
- }
1306
- }else{
1307
- t_call_fired=false;
1308
- }
1309
- return t_call_fired;
1310
- }
1311
- ';
1312
- }
1313
- if(is_home() || is_front_page()){
1314
- $hmpg_impressions_jQ .='
1315
- if(tvc_fp.length !== 0){
1316
- t_products_impre_clicks(tvc_fp,"fp");
1317
- }
1318
- if(tvc_rcp.length !== 0){
1319
- t_products_impre_clicks(tvc_rcp,"rp");
1320
- }
1321
- jQuery("a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped)").on("click",function(){
1322
- t_url=jQuery(this).attr("href");
1323
- //home page call for click
1324
- t_call_fired=prod_exists_in_JSON(t_url,tvc_fp,"fp");
1325
- if(!t_call_fired){
1326
- prod_exists_in_JSON(t_url,tvc_rcp,"rp");
1327
- }
1328
- });
1329
- //ATC click
1330
- jQuery("a[href*=add-to-cart]").on("click",function(){
1331
- t_url=jQuery(this).attr("href");
1332
- t_qty=$(this).parent().find("input[name=quantity]").val();
1333
- //default quantity 1 if quantity box is not there
1334
- if(t_qty=="" || t_qty===undefined){
1335
- t_qty="1";
1336
- }
1337
- t_call_fired=prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_fp,t_qty);
1338
- if(!t_call_fired){
1339
- prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_rcp,t_qty);
1340
- }
1341
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1342
 
1343
- ';
1344
- }else if(is_search()){
1345
- $hmpg_impressions_jQ .='
1346
- //search page json
1347
- if(tvc_pgc.length !== 0){
1348
- t_products_impre_clicks(tvc_pgc,"srch");
1349
- }
1350
- //search page prod click
1351
- jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1352
- t_url=jQuery(this).attr("href");
1353
- //cat page prod call for click
1354
- prod_exists_in_JSON(t_url,tvc_pgc,"srch");
1355
- });
1356
-
1357
- ';
1358
- }else if (is_product()) {
1359
- //product page releted products
1360
- $hmpg_impressions_jQ .='
1361
- if(tvc_rdp.length !== 0){
1362
- t_products_impre_clicks(tvc_rdp,"rdp");
1363
- }
1364
- //product click - image and product name
1365
- jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1366
- t_url=jQuery(this).attr("href");
1367
- //prod page related call for click
1368
- prod_exists_in_JSON(t_url,tvc_rdp,"rdp");
1369
- });
1370
- //Prod ATC link click in related product section
1371
- jQuery("a[href*=add-to-cart]").on("click",function(){
1372
- t_url=jQuery(this).attr("href");
1373
-
1374
- t_qty=$(this).parent().find("input[name=quantity]").val();
1375
- //default quantity 1 if quantity box is not there
1376
- if(t_qty=="" || t_qty===undefined){
1377
- t_qty="1";
1378
- }
1379
- prod_ATC_link_exists(t_url,prodpage_json_ATC_link,tvc_rdp,t_qty);
1380
- });
1381
- ';
1382
- }else if (is_product_category()) {
1383
- $hmpg_impressions_jQ .='
1384
- //category page json
1385
- if(tvc_pgc.length !== 0){
1386
- t_products_impre_clicks(tvc_pgc,"cp");
1387
- }
1388
- //Prod category ATC link click in related product section
1389
- jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1390
- t_url=jQuery(this).attr("href");
1391
- //cat page prod call for click
1392
- prod_exists_in_JSON(t_url,tvc_pgc,"cp");
1393
- });
1394
-
1395
- ';
1396
- }else if(is_shop()){
1397
- $hmpg_impressions_jQ .='
1398
- //shop page json
1399
- if(tvc_pgc.length !== 0){
1400
- t_products_impre_clicks(tvc_pgc,"sp");
1401
- }
1402
- //shop page prod click
1403
- jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1404
- t_url=jQuery(this).attr("href");
1405
- //cat page prod call for click
1406
- prod_exists_in_JSON(t_url,tvc_pgc,"sp");
1407
- });
1408
-
1409
-
1410
- ';
1411
- }
1412
- //common ATC link for Category page , Shop Page and Search Page
1413
- if(is_product_category() || is_shop() || is_search()){
1414
- $hmpg_impressions_jQ .='
1415
- //ATC link click
1416
- jQuery("a[href*=add-to-cart]").on("click",function(){
1417
- t_url=jQuery(this).attr("href");
1418
- t_qty=$(this).parent().find("input[name=quantity]").val();
1419
- //default quantity 1 if quantity box is not there
1420
- if(t_qty=="" || t_qty===undefined){
1421
- t_qty="1";
1422
- }
1423
- prod_ATC_link_exists(t_url,catpage_json_ATC_link,tvc_pgc,t_qty);
1424
- });
1425
- ';
1426
- }
1427
- //on home page, product page , category page
1428
- if (is_home() || is_front_page() || is_product() || is_product_category() || is_search() || is_shop()){
1429
- $this->wc_version_compare($hmpg_impressions_jQ);
1430
- }
1431
- }
1432
 
1433
  /**
1434
  * Enhanced E-commerce tracking for remove from cart
@@ -1443,45 +1360,31 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1443
  global $woocommerce;
1444
  $cartpage_prod_array_main = array();
1445
  foreach ($woocommerce->cart->cart_contents as $key => $item) {
1446
- //Version compare
1447
- if (version_compare($woocommerce->version, "2.7", "<")) {
1448
- $prod_meta = get_product($item["product_id"]);
1449
- } else {
1450
- $prod_meta = wc_get_product($item["product_id"]);
1451
- }
1452
- if (version_compare($woocommerce->version, "3.3", "<")) {
1453
- $cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
1454
- } else {
1455
- $cart_remove_link=html_entity_decode(wc_get_cart_remove_url($key));
1456
- }
1457
- $category = get_the_terms($item["product_id"], "product_cat");
1458
- $categories = "";
1459
- if ($category) {
1460
- foreach ($category as $term) {
1461
- $categories.=$term->name . ",";
1462
- }
1463
- }
1464
- //remove last comma(,) if multiple categories are there
1465
- $categories = rtrim($categories, ",");
1466
- if(version_compare($woocommerce->version, "2.7", "<")){
1467
- $cartpage_prod_array_main[$cart_remove_link] =array(
1468
- "tvc_id" => esc_js($prod_meta->ID),
1469
- "tvc_i" => esc_js($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->ID),
1470
- "tvc_n" => html_entity_decode(esc_js($prod_meta->get_title())),
1471
- "tvc_p" => esc_js($prod_meta->get_price()),
1472
- "tvc_c" => esc_js($categories),
1473
- "tvc_q"=> esc_js($woocommerce->cart->cart_contents[$key]["quantity"])
1474
- );
1475
- }else{
1476
- $cartpage_prod_array_main[$cart_remove_link] =array(
1477
- "tvc_id" => esc_js($prod_meta->get_id()),
1478
- "tvc_i" => esc_js($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->get_id()),
1479
- "tvc_n" => html_entity_decode(esc_js($prod_meta->get_title())),
1480
- "tvc_p" => esc_js($prod_meta->get_price()),
1481
- "tvc_c" => esc_js($categories),
1482
- "tvc_q"=>esc_js($woocommerce->cart->cart_contents[$key]["quantity"])
1483
- );
1484
  }
 
 
 
 
 
 
 
 
 
 
 
1485
  }
1486
 
1487
  //Cart Page item Array to Json
@@ -1537,65 +1440,65 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1537
  }
1538
  }
1539
 
1540
- /**
1541
- * Enhanced E-commerce tracking checkout step 1
1542
- *
1543
- * @access public
1544
- * @return void
1545
- */
1546
- public function checkout_step_1_tracking() {
1547
- if ($this->disable_tracking($this->ga_eeT)) {
1548
- return;
1549
- }
1550
- //call fn to make json
1551
- $this->get_ordered_items();
1552
- if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
1553
- $code= '
1554
- var items = [];
1555
- gtag("set", {"currency": tvc_lc});
1556
- for(var t_item in tvc_ch){
1557
- items.push({
1558
- "id": tvc_ch[t_item].tvc_i,
1559
- "name": tvc_ch[t_item].tvc_n,
1560
- "category": tvc_ch[t_item].tvc_c,
1561
- "attributes": tvc_ch[t_item].tvc_attr,
1562
- "price": tvc_ch[t_item].tvc_p,
1563
- "quantity": tvc_ch[t_item].tvc_q
1564
- });
1565
- }';
1566
-
1567
- $code_step_1 = $code . 'gtag("event", "begin_checkout", {"event_category":"Enhanced-Ecommerce",
1568
- "event_label":"checkout_step_1","items":items,"non_interaction": true });';
1569
-
1570
- //check woocommerce version and add code
1571
- $this->wc_version_compare($code_step_1);
1572
- }
1573
 
1574
- if( $this->gm_id && $this->tracking_option == "GA4") {
1575
- $code = '
1576
- var items = [];
1577
- for(var t_item in tvc_ch){
1578
- items.push({
1579
- "item_id": tvc_ch[t_item].tvc_i,
1580
- "item_name": tvc_ch[t_item].tvc_n,
1581
- "item_category": tvc_ch[t_item].tvc_c,
1582
- "item_variant": tvc_ch[t_item].tvc_attr,
1583
- "price": tvc_ch[t_item].tvc_p,
1584
- "quantity": tvc_ch[t_item].tvc_q
1585
- });
1586
- }';
1587
 
1588
- $code_step_1 = $code . 'gtag("event", "begin_checkout", {
1589
- "event_category":"Enhanced-Ecommerce",
1590
- "event_label":"checkout_step_1",
1591
- "items":items,
1592
- "non_interaction": true
1593
- });';
1594
 
1595
- //check woocommerce version and add code
1596
- $this->wc_version_compare($code_step_1);
1597
- }
1598
- }
1599
 
1600
  /**
1601
  * Enhanced E-commerce tracking checkout step 2
@@ -1604,8 +1507,8 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1604
  * @return void
1605
  */
1606
  public function checkout_step_2_tracking() {
1607
- if ($this->disable_tracking($this->ga_eeT)) {
1608
- return;
1609
  }
1610
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1611
  $code= '
@@ -1643,10 +1546,9 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1643
  * @access public
1644
  * @return void
1645
  */
1646
- public function checkout_step_3_tracking() {
1647
-
1648
- if ($this->disable_tracking($this->ga_eeT)) {
1649
- return;
1650
  }
1651
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1652
  $code= '
@@ -1692,43 +1594,27 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1692
  $code = "";
1693
  //get all items added into the cart
1694
  foreach ($woocommerce->cart->cart_contents as $item) {
1695
- //Version Compare
1696
- if ( version_compare($woocommerce->version, "2.7", "<")) {
1697
- $p = get_product($item["product_id"]);
1698
- } else {
1699
- $p = wc_get_product($item["product_id"]);
1700
- }
1701
-
1702
- $category = get_the_terms($item["product_id"], "product_cat");
1703
- $categories = "";
1704
- if ($category) {
1705
- foreach ($category as $term) {
1706
- $categories.=$term->name . ",";
1707
- }
1708
- }
1709
- //remove last comma(,) if multiple categories are there
1710
- $categories = rtrim($categories, ",");
1711
- if(version_compare($woocommerce->version, "2.7", "<")){
1712
- $chkout_json[get_permalink($p->ID)] = array(
1713
- "tvc_id" => esc_js($p->ID),
1714
- "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->ID),
1715
- "tvc_n" => html_entity_decode(esc_js($p->get_title())),
1716
- "tvc_p" => esc_js($p->get_price()),
1717
- "tvc_c" => esc_js($categories),
1718
- "tvc_q" => esc_js($item["quantity"]),
1719
- "isfeatured"=>esc_js($p->is_featured())
1720
- );
1721
- }else{
1722
- $chkout_json[get_permalink($p->get_id())] = array(
1723
- "tvc_id" => esc_js($p->get_id()),
1724
- "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->get_id()),
1725
- "tvc_n" => html_entity_decode(esc_js($p->get_title())),
1726
- "tvc_p" => esc_js($p->get_price()),
1727
- "tvc_c" => esc_js($categories),
1728
- "tvc_q" => esc_js($item["quantity"]),
1729
- "isfeatured"=>esc_js($p->is_featured())
1730
- );
1731
  }
 
 
 
 
 
 
 
 
 
 
 
 
1732
  }
1733
  //return $code;
1734
  //make product data json on check out page
64
  protected $remarketing_snippet_id;
65
  protected $remarketing_snippets;
66
  protected $conversio_send_to;
67
+ protected $tvc_conversion_tracking_type;
68
+
69
+ protected $ee_options;
70
 
71
  /**
72
  * Enhanced_Ecommerce_Google_Analytics_Public constructor.
78
  $this->TVC_Admin_Helper = new TVC_Admin_Helper();
79
  $this->plugin_name = sanitize_text_field($plugin_name);
80
  $this->version = sanitize_text_field($version);
81
+ $this->ee_options = $this->TVC_Admin_Helper->get_ee_options_settings();
82
+ $this->tvc_conversion_tracking_type = sanitize_text_field($this->get_option("tvc_conversion_tracking_type"));
83
  $this->tvc_call_hooks();
84
 
85
  $this->ga_Dname = "auto";
111
  $this->remarketing_snippets = base64_decode($remarketing['snippets']);
112
  $this->remarketing_snippet_id = sanitize_text_field(isset($remarketing['id'])?esc_attr($remarketing['id']):"");
113
  }
114
+
115
+ $this->ga_LC = get_woocommerce_currency(); //Local Currency from Back end
116
+ $this->wc_version_compare("tvc_lc=" . json_encode(esc_js($this->ga_LC)) . ";");
117
+ /*
118
+ * start tvc_options
119
+ */
120
+ $current_user = wp_get_current_user();
121
+ //$current_user ="";
122
+ $user_id = "";
123
+ $user_type = "guest_user";
124
+ if ( isset($current_user->ID) && $current_user->ID != 0 ) {
125
+ $user_id = $current_user->ID;
126
+ $current_user_type = 'register_user';
127
+ }
128
+ $this->tvc_options = array(
129
+ "feature_product_label"=>esc_html__("Feature Product"),
130
+ "on_sale_label"=>esc_html__("On Sale"),
131
+ "affiliation"=>esc_js(get_bloginfo('name')),
132
+ "local_time"=>esc_js(time()),
133
+ "is_admin"=>esc_attr(is_admin()),
134
+ "currency"=>esc_js($this->ga_LC),
135
+ "tracking_option"=>esc_js($this->tracking_option),
136
+ "property_id"=>esc_js($this->ga_id),
137
+ "measurement_id"=>esc_js($this->gm_id),
138
+ "google_ads_id"=>esc_js($this->google_ads_id),
139
+ "google_merchant_center_id"=>esc_js($this->google_merchant_id),
140
+ "o_add_gtag_snippet"=>esc_js($this->ga_ST),
141
+ "o_enhanced_e_commerce_tracking"=>esc_js($this->ga_eeT),
142
+ "o_log_step_gest_user"=>esc_js($this->ga_gUser),
143
+ "o_impression_thresold"=>esc_js($this->ga_imTh),
144
+ "o_ip_anonymization"=>esc_js($this->ga_IPA),
145
+ "o_ga_OPTOUT"=>esc_js($this->ga_OPTOUT),
146
+ "ads_tracking_id"=>esc_js($this->ads_tracking_id),
147
+ "remarketing_tags"=>esc_js($this->ads_ert),
148
+ "dynamic_remarketing_tags"=>esc_js($this->ads_edrt),
149
+ "google_ads_conversion_tracking"=>esc_js($this->google_ads_conversion_tracking),
150
+ "conversio_send_to"=>esc_js($this->conversio_send_to),
151
+ "page_type"=>esc_js($this->add_page_type()),
152
+ "user_id"=>esc_js($user_id),
153
+ "user_type"=>esc_js($user_type),
154
+ "day_type"=>esc_js($this->add_day_type()),
155
+ "remarketing_snippet_id"=>esc_js($this->remarketing_snippet_id),
156
+ "tvc_ajax_url"=>esc_url_raw(admin_url( 'admin-ajax.php' ))
157
+ );
158
+ /*
159
+ * end tvc_options
160
+ */
161
+
 
 
 
162
  }
163
 
164
  public function tvc_call_hooks(){
168
 
169
  add_action("wp_footer", array($this, "t_products_impre_clicks"));
170
  add_action("woocommerce_after_shop_loop_item", array($this, "bind_product_metadata"));
171
+ if($this->tvc_conversion_tracking_type == "on-thankyou-page"){
172
+ add_action("wp_head", array($this, "ecommerce_tracking_code"));
173
+ }else{
174
+ add_action("woocommerce_thankyou", array($this, "ecommerce_tracking_code"));
175
+ }
176
+ //add_action("woocommerce_after_single_product", array($this, "product_detail_view"));
177
+ add_action("wp_head", array($this, "product_detail_view"));
178
  add_action("woocommerce_after_cart", array($this, "remove_cart_tracking"));
179
  //check out step 1,2,3
180
+ //add_action("woocommerce_before_checkout_form", array($this, "checkout_step_1_tracking"));
181
+ //add_action("woocommerce_before_checkout_form", array($this, "checkout_step_2_tracking"));
182
+ //add_action("woocommerce_before_checkout_form", array($this, "checkout_step_3_tracking"));
183
+ add_action("wp_head", array($this, "checkout_step_1_tracking"));
184
+ add_action("wp_head", array($this, "checkout_step_2_tracking"));
185
+ add_action("wp_head", array($this, "checkout_step_3_tracking"));
186
  add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
187
  //add version details in footer
188
  add_action("wp_footer", array($this, "add_plugin_details"));
295
  }
296
  }
297
  public function get_option($key){
298
+ if(empty($this->ee_options)){
299
+ $this->ee_options = $this->TVC_Admin_Helper->get_ee_options_settings();
 
 
 
300
  }
301
+ if(isset($this->ee_options[$key])){
302
+ return $this->ee_options[$key];
303
  }
304
  }
305
  /**
403
  * @return void
404
  */
405
  function wc_version_compare($codeSnippet) {
406
+ global $woocommerce;
407
+ if (version_compare($woocommerce->version, "2.1", ">=")) {
408
+ wc_enqueue_js($codeSnippet);
409
+ } else {
410
+ $woocommerce->add_inline_js($codeSnippet);
411
+ }
 
412
  }
413
  /**
414
  * Enhanced Ecommerce GA plugin Settings
420
  global $woocommerce;
421
  //common validation----start
422
  if (is_admin() || $this->ga_ST == "" || current_user_can("manage_options") || !$this->ga_PrivacyPolicy) {
423
+ return;
424
  }
425
  // IP Anonymization
426
  if ($this->ga_IPA) {
559
  }
560
  }
561
  }
562
+ protected function tvc_get_order_with_url_order_key(){
563
+ $_get = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING );
564
+ if ( isset( $_get['key'] ) ) {
565
+ $order_key = $_get['key'];
566
+ return wc_get_order( wc_get_order_id_by_order_key( $order_key ) );
567
+ }
568
+ }
569
+ protected function tvc_get_order_from_query_vars(){
570
+ global $wp ;
571
+ $order_id = absint( $wp->query_vars['order-received'] );
572
+ if ( $order_id && 0 != $order_id && wc_get_order( $order_id ) ) {
573
+ return wc_get_order( $order_id );
574
+ }
575
+ }
576
+ protected function tvc_get_order_from_order_received_page(){
577
+ if ( $this->tvc_get_order_from_query_vars() ) {
578
+ return $this->tvc_get_order_from_query_vars();
579
+ } else {
580
+ if ( $this->tvc_get_order_with_url_order_key() ) {
581
+ return $this->tvc_get_order_with_url_order_key();
582
+ } else {
583
+ return false;
584
+ }
585
+ }
586
+ }
587
 
588
+ /*protected function tvc_get_order_id(){
589
+ global $wp ;
590
+ $order_id = absint( $wp->query_vars['order-received'] );
591
+ if ( $order_id && 0 != $order_id && wc_get_order( $order_id ) ) {
592
+ return wc_get_order( $order_id );
593
+ }else{
594
+ $_get = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING );
595
+ if ( isset( $_get['key'] ) ) {
596
+ $order_key = $_get['key'];
597
+ return wc_get_order_id_by_order_key( $order_key );
598
+ }
599
+ }
600
+ }*/
601
  /**
602
  * Google Analytics eCommerce tracking
603
  *
605
  * @param mixed $order_id
606
  * @return void
607
  */
608
+ function ecommerce_tracking_code($order_id = null) {
609
  global $woocommerce;
610
+ $order = "";
611
+ if($order_id == null && is_order_received_page()){
612
+ $order = $this->tvc_get_order_from_order_received_page();
613
+ $order_id = $order->get_id();
614
+ }else{
615
+ $order = new WC_Order($order_id);
616
  }
617
+ if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1 || !is_order_received_page() ){
618
+ return;
619
+ }
620
+ get_post_meta($order_id, "_tracked", true);
621
  // Doing eCommerce tracking so unhook standard tracking from the footer
622
  remove_action("wp_footer", array($this, "ee_settings"));
623
  /*
625
  * var tvc_oc
626
  */
627
  $orderpage_prod_Array = array();
628
+
629
  //Get Applied Coupon Codes
630
  $coupons_list = '';
631
  if(version_compare($woocommerce->version, "3.7", ">")){
660
  }
661
  }
662
  $categories=esc_js(join(",", $out));
663
+ $product_type =$_product->get_type();
 
 
 
 
 
664
  if($product_type == "variation"){
665
  $attributes=esc_js(wc_get_formatted_variation($_product->get_variation_attributes(), true));
666
  /*if ($_product->variation_has_weight) {
670
  /*if ($_product->has_weight()) {
671
  //$p_weight = $_product->get_weight().' '.esc_attr(get_option('woocommerce_weight_unit'));
672
  }*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  }
674
+ $orderpage_prod_Array[get_permalink($_product->get_id())]=array(
675
+ "tvc_id" => esc_js($_product->get_id()),
676
+ "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
677
+ "tvc_n" => esc_js($_product->get_title()),
678
+ "tvc_p" => esc_js($order->get_item_total($item)),
679
+ // "tvc_rp" => $_product->get_regular_price(),
680
+ // "tvc_sp" => $_product->get_sale_price(),
681
+ "tvc_pd" => esc_js($this->cal_prod_discount($_product->get_regular_price(), $_product->get_sale_price())),
682
+ "tvc_c" => esc_js($categories),
683
+ "tvc_attr" => esc_js($attributes),
684
+ "tvc_q"=>esc_js($item["qty"]),
685
+ //"tvc_wt" => $p_weight,
686
+ "tvc_var" => esc_js($this->getAttributesVariation($_product)),
687
+ /*"tvc_di" => $_product->get_dimensions(), //dimensions
688
+ "tvc_ss" => $_product->is_in_stock(),
689
+ "tvc_st" => $_product->get_stock_quantity(),
690
+ "tvc_tst" => $_product->get_total_stock(),
691
+ "tvc_rc" => $_product->get_rating_count(),
692
+ "tvc_rs" => $_product->get_average_rating()*/
693
+ );
694
+
695
  }
696
  //make json for prod meta data on order page
697
  $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
701
  * Get the trans data
702
  * Var tvc_td
703
  */
704
+ //get shipping cost
705
+ $tvc_sc = $order->get_total_shipping();
 
 
 
 
 
706
  $user_bill_addr="";
707
  $user_ship_addr="";
708
  if(isset($this->tvc_options["user_id"]) && $this->tvc_options["user_id"]!="" ){
776
  * @return void
777
  */
778
  public function product_detail_view() {
779
+ if ( $this->disable_tracking($this->ga_eeT) || !is_product() ) {
780
  return;
781
  }
782
+ global $wp_query, $woocommerce ;
783
+ $product = wc_get_product();
784
+ $category = get_the_terms($product->get_id(), "product_cat");
 
 
 
785
  $categories = "";
786
  if ($category) {
787
  foreach ($category as $term) {
791
  //remove last comma(,) if multiple categories are there
792
  $categories = rtrim($categories, ",");
793
  //product detail view json
794
+ $prodpage_detail_json = array(
795
+ "tvc_id" => esc_js($product->get_id()),
796
+ "tvc_i" => $product->get_sku() ? esc_js($product->get_sku()) : esc_js($product->get_id()),
797
+ "tvc_n" => esc_js($product->get_title()),
798
+ "tvc_c" => esc_js($categories),
799
+ "tvc_p" => esc_js($product->get_price()),
800
+ "tvc_pd" => esc_js($this->cal_prod_discount($product->get_regular_price(), $product->get_sale_price())),
801
+ "tvc_ps" => esc_js($product->get_stock_status()),
802
+ "tvc_tst" => esc_js($product->get_stock_quantity()),
803
+ "tvc_q" => esc_js($product->get_stock_quantity()),
804
+ "tvc_var" => esc_js($this->getAttributesVariation($product)),
805
+ "is_featured" => esc_js($product->is_featured()),
806
+ "is_onSale" => esc_js($product->is_on_sale())
807
+ );
808
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809
  //prod page detail view json
810
  $this->wc_version_compare("tvc_po=" . json_encode($prodpage_detail_json) . ";");
811
  ?>
819
  <?php
820
  }
821
 
822
+ /**
823
+ * Enhanced E-commerce tracking for product impressions on category pages (hidden fields) , product page (related section)
824
+ * home page (featured section and recent section)
825
+ *
826
+ * @access public
827
+ * @return void
828
+ */
829
+ public function bind_product_metadata() {
830
+ if ($this->disable_tracking($this->ga_eeT)) {
831
+ return;
832
+ }
 
 
 
 
 
 
 
 
 
833
 
834
+ global $product,$woocommerce;
835
+ $category = get_the_terms($product->get_id(), "product_cat");
836
+ $categories = "";
837
+ if ($category) {
838
+ foreach ($category as $term) {
839
+ $categories.=$term->name . ",";
840
  }
841
+ }
842
+ //remove last comma(,) if multiple categories are there
843
+ $categories = rtrim($categories, ",");
844
+ //declare all variable as a global which will used for make json
845
+ global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
846
+ //is home page then make all necessory json
847
+ if (is_home() || is_front_page()) {
848
+ if (!is_array($homepage_json_fp) && !is_array($homepage_json_rp) && !is_array($homepage_json_ATC_link)) {
849
+ $homepage_json_fp = array();
850
+ $homepage_json_rp = array();
851
+ $homepage_json_ATC_link=array();
852
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
853
 
854
+ // ATC link Array
855
+ $homepage_json_ATC_link[$product->add_to_cart_url()]=
856
+ array(
857
+ "ATC-link"=>esc_url_raw(get_permalink($product->get_id()))
858
+ );
859
+
860
+ //check if product is featured product or not
861
+ if ($product->is_featured()) {
862
+ //check if product is already exists in homepage featured json
863
+ if(!array_key_exists(get_permalink($product->get_id()),$homepage_json_fp)){
864
+ $homepage_json_fp[get_permalink($product->get_id())] = array(
865
+ "tvc_id" => esc_js($product->get_id()),
866
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
867
+ "tvc_n" => esc_js($product->get_title()),
868
+ "tvc_p" => esc_js($product->get_price()),
869
+ "tvc_c" => esc_js($categories),
870
+ "ATC-link"=> esc_url_raw($product->add_to_cart_url())
871
+ );
872
+ //else add product in homepage recent product json
873
+ }else {
874
+ $homepage_json_rp[get_permalink($product->get_id())] =array(
875
+ "tvc_id" => esc_js($product->get_id()),
876
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
877
+ "tvc_n" => esc_js($product->get_title()),
878
+ "tvc_p" => esc_js($product->get_price()),
879
+ "tvc_c" => esc_js($categories)
880
+ );
881
  }
882
+ } else {
883
+ $homepage_json_rp[get_permalink($product->get_id())] =array(
884
+ "tvc_id" => esc_js($product->get_id()),
885
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
886
+ "tvc_n" => esc_js($product->get_title()),
887
+ "tvc_p" => esc_js($product->get_price()),
888
+ "tvc_c" => esc_js($categories)
889
+ );
890
+ }
891
+ } else if(is_product()){
892
+ //if product page then related product page array
893
+ if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
894
+ $prodpage_json_relProd = array();
895
+ $prodpage_json_ATC_link = array();
896
  }
897
+ // ATC link Array
898
+ $prodpage_json_ATC_link[$product->add_to_cart_url()]=
899
+ array(
900
+ "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
901
+ );
902
+ $prodpage_json_relProd[get_permalink($product->get_id())] = array(
903
+ "tvc_id" => esc_js($product->get_id()),
904
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
905
+ "tvc_n" => esc_js($product->get_title()),
906
+ "tvc_p" => esc_js($product->get_price()),
907
+ "tvc_c" => esc_js($categories)
908
+ );
909
+ } else if (is_product_category() || is_search() || is_shop()) {
910
+ //category page, search page and shop page json
911
+ if (!is_array($catpage_json) && !is_array($catpage_json_ATC_link)){
912
+ $catpage_json=array();
913
+ $catpage_json_ATC_link=array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
914
  }
915
+ //cat page ATC array
916
+ $catpage_json_ATC_link[$product->add_to_cart_url()]=
917
+ array(
918
+ "ATC-link"=>esc_url_raw(get_permalink($product->get_id()))
919
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
920
 
921
+ $catpage_json[get_permalink($product->get_id())] =array(
922
+ "tvc_id" => esc_js($product->get_id()),
923
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
924
+ "tvc_n" => esc_js($product->get_title()),
925
+ "tvc_p" => esc_js($product->get_price()),
926
+ "tvc_c" => esc_js($categories)
927
+ );
928
+ }
929
+ }
930
 
931
+ /**
932
+ * Enhanced E-commerce tracking for product impressions,clicks on Home pages
933
+ *
934
+ * @access public
935
+ * @return void
936
+ */
937
+ function t_products_impre_clicks() {
938
+ if ($this->disable_tracking($this->ga_eeT)) {
939
+ return;
940
  }
941
 
942
+ //get impression threshold
943
+ $impression_threshold = $this->ga_imTh;
 
 
 
 
 
 
 
 
 
 
 
944
 
945
+ //Product impression on Home Page
946
+ global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
947
+ //home page json for featured products and recent product sections
948
+ //check if php array is empty
949
+ if(empty($homepage_json_ATC_link)){
950
+ $homepage_json_ATC_link=array(); //define empty array so if empty then in json will be []
951
+ }
952
+ if(empty($homepage_json_fp)){
953
+ $homepage_json_fp=array(); //define empty array so if empty then in json will be []
954
+ }
955
+ if(empty($homepage_json_rp)){ //home page recent product array
956
+ $homepage_json_rp=array();
957
+ }
958
+ if(empty($prodpage_json_relProd)){ //prod page related section array
959
+ $prodpage_json_relProd=array();
960
+ }
961
+ if(empty($prodpage_json_ATC_link)){
962
+ $prodpage_json_ATC_link=array(); //prod page ATC link json
963
+ }
964
+ if(empty($catpage_json)){ //category page array
965
+ $catpage_json=array();
966
+ }
967
+ if(empty($catpage_json_ATC_link)){ //category page array
968
+ $catpage_json_ATC_link=array();
969
+ }
970
+ //home page json
971
+ $this->wc_version_compare("homepage_json_ATC_link=" . json_encode($homepage_json_ATC_link) . ";");
972
+ $this->wc_version_compare("tvc_fp=" . json_encode($homepage_json_fp) . ";");
973
+ $this->wc_version_compare("tvc_rcp=" . json_encode($homepage_json_rp) . ";");
974
+ //product page json
975
+ $this->wc_version_compare("tvc_rdp=" . json_encode($prodpage_json_relProd) . ";");
976
+ $this->wc_version_compare("prodpage_json_ATC_link=" . json_encode($prodpage_json_ATC_link) . ";");
977
+ //category page json
978
+ $this->wc_version_compare("tvc_pgc=" . json_encode($catpage_json) . ";");
979
+ $this->wc_version_compare("catpage_json_ATC_link=" . json_encode($catpage_json_ATC_link) . ";");
980
+ if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
981
+ $hmpg_impressions_jQ = '
982
+ var items = [];
983
+ //set local currencies
984
+ gtag("set", {"currency": tvc_lc});
985
+ function t_products_impre_clicks(t_json_name,t_action){
986
+ t_send_threshold=0;
987
+ t_prod_pos=0;
988
+ t_json_length=Object.keys(t_json_name).length;
989
+
990
+ for(var t_item in t_json_name) {
991
+ t_send_threshold++;
992
+ t_prod_pos++;
993
+ items.push({
994
+ "id": t_json_name[t_item].tvc_i,
995
+ "name": t_json_name[t_item].tvc_n,
996
+ "category": t_json_name[t_item].tvc_c,
997
+ "price": t_json_name[t_item].tvc_p,
998
+ });
999
+
1000
+ if(t_json_length > ' . esc_js($impression_threshold) .' ){
1001
+
1002
+ if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
1003
+ t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
1004
+ gtag("event", "view_item_list", { "event_category":"Enhanced-Ecommerce",
1005
+ "event_label":"product_impression_"+t_action, "items":items,"non_interaction": true});
1006
+ items = [];
1007
+ }
1008
+ if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1009
+ gtag("event","view_item_list", {
1010
+ "value": t_json_name[t_item].tvc_p,
1011
+ "items": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1012
  {
1013
+ "id": t_json_name[t_item].tvc_id,
1014
+ "google_business_vertical": "retail"
 
 
1015
  }
1016
+ ]
1017
+ });
1018
+ }
1019
+ }else{
1020
+
1021
+ t_json_length--;
1022
+ if(t_json_length==0){
1023
+ gtag("event", "view_item_list", { "event_category":"Enhanced-Ecommerce",
1024
+ "event_label":"product_impression_"+t_action, "items":items,"non_interaction": true});
1025
+ items = [];
1026
+ }
1027
+ if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1028
+ gtag("event","view_item_list", {
1029
+ "value": t_json_name[t_item].tvc_p,
1030
+ "items": [
1031
+ {
1032
+ "id": t_json_name[t_item].tvc_id,
1033
+ "google_business_vertical": "retail"
1034
+ }
1035
+ ]
1036
+ });
1037
+ }
1038
+ }
1039
+ }
1040
+ }
1041
+
1042
+ //function for comparing urls in json object
1043
+ function prod_exists_in_JSON(t_url,t_json_name,t_action){
1044
+ if(t_json_name.hasOwnProperty(t_url)){
1045
+ t_call_fired=true;
1046
+ gtag("event", "select_content", {
1047
+ "event_category":"Enhanced-Ecommerce",
1048
+ "event_label":"product_click_"+t_action,
1049
+ "content_type": "product",
1050
+ "items": [
1051
  {
1052
+ "id":t_json_name[t_url].tvc_i,
1053
+ "name": t_json_name[t_url].tvc_n,
1054
+ "category":t_json_name[t_url].tvc_c,
1055
+ "price": t_json_name[t_url].tvc_p,
1056
  }
1057
+ ],
1058
+ "non_interaction": true
1059
+ });
1060
+ }else{
1061
+ t_call_fired=false;
1062
+ }
1063
+ return t_call_fired;
1064
+ }
1065
+ function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
1066
+ t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
1067
+
1068
+ if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
1069
+ t_call_fired=true;
1070
+ // Enhanced E-commerce Add to cart clicks
1071
+ gtag("event", "add_to_cart", {
1072
+ "event_category":"Enhanced-Ecommerce",
1073
+ "event_label":"add_to_cart_click",
1074
+ "non_interaction": true,
1075
+ "items": [{
1076
+ "id" : t_prod_data_json[t_prod_url_key].tvc_i,
1077
+ "name":t_prod_data_json[t_prod_url_key].tvc_n,
1078
+ "category" : t_prod_data_json[t_prod_url_key].tvc_c,
1079
+ "price": t_prod_data_json[t_prod_url_key].tvc_p,
1080
+ "quantity" :t_qty
1081
+ }]
1082
+ });
1083
+ if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1084
+ gtag("event","add_to_cart", {
1085
+ "value": t_prod_data_json[t_prod_url_key].tvc_p,
1086
+ "items": [
1087
+ {
1088
+ "id": t_prod_data_json[t_prod_url_key].tvc_id,
1089
+ "google_business_vertical": "retail"
1090
+ }
1091
+ ]
1092
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1093
  }
1094
+
1095
+ }else{
1096
+ t_call_fired=false;
1097
+ }
1098
+ return t_call_fired;
1099
+
1100
+ }
1101
+
1102
+ ';
1103
+ }
1104
+ if($this->gm_id && $this->tracking_option == "GA4") {
1105
+ $hmpg_impressions_jQ = '
1106
+ var items = [];
1107
+ function t_products_impre_clicks(t_json_name,t_action){
1108
+ t_send_threshold=0;
1109
+ t_prod_pos=0;
1110
+ t_json_length=Object.keys(t_json_name).length;
1111
+ for(var t_item in t_json_name) {
1112
+ t_send_threshold++;
1113
+ t_prod_pos++;
1114
+ items.push({
1115
+ "item_id": t_json_name[t_item].tvc_i,
1116
+ "item_name": t_json_name[t_item].tvc_n,
1117
+ "item_category": t_json_name[t_item].tvc_c,
1118
+ "price": t_json_name[t_item].tvc_p,
1119
+ "currency": tvc_lc
1120
+ });
1121
+ if(t_json_length > ' . esc_js($impression_threshold) . ' ){
1122
+ if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
1123
+ t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
1124
+ gtag("event", "view_item_list", {
1125
+ "event_category":"Enhanced-Ecommerce",
1126
+ "event_label":"product_impression_"+t_action,
1127
+ "items":items,
1128
+ "non_interaction": true
1129
+ });
1130
+ items = [];
1131
+ }
1132
+ if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1133
+ gtag("event","view_item_list", {
1134
+ "value": t_json_name[t_item].tvc_p,
1135
+ "items": [
1136
+ {
1137
+ "id": t_json_name[t_item].tvc_id,
1138
+ "google_business_vertical": "retail"
1139
+ }
1140
+ ]
1141
+ });
1142
+ }
1143
+ }else{
1144
+ t_json_length--;
1145
+ if(t_json_length==0){
1146
+ gtag("event", "view_item_list", {
1147
+ "event_category":"Enhanced-Ecommerce",
1148
+ "event_label":"product_impression_"+t_action,
1149
+ "items":items,
1150
+ "non_interaction": true
1151
+ });
1152
+ items = [];
1153
+ }
1154
+ if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1155
+ gtag("event","view_item_list", {
1156
+ "value": t_json_name[t_item].tvc_p,
1157
+ "items": [
1158
+ {
1159
+ "id": t_json_name[t_item].tvc_id,
1160
+ "google_business_vertical": "retail"
1161
+ }
1162
+ ]
1163
+ });
1164
+ }
1165
+ }
1166
+ }
1167
+ }
1168
+
1169
+ //function for comparing urls in json object
1170
+ function prod_exists_in_JSON(t_url,t_json_name,t_action){
1171
+ if(t_json_name.hasOwnProperty(t_url)){
1172
+ t_call_fired=true;
1173
+ gtag("event", "select_item", {
1174
+ "event_category":"Enhanced-Ecommerce",
1175
+ "event_label":"product_click_"+t_action,
1176
+ "items": [
1177
+ {
1178
+ "item_id":t_json_name[t_url].tvc_i,
1179
+ "item_name": t_json_name[t_url].tvc_n,
1180
+ "item_category":t_json_name[t_url].tvc_c,
1181
+ "price": t_json_name[t_url].tvc_p,
1182
+ "currency": tvc_lc
1183
+ }
1184
+ ],
1185
+ "non_interaction": true
1186
+ });
1187
 
1188
+ }else{
1189
+ t_call_fired=false;
1190
+ }
1191
+ return t_call_fired;
1192
+ }
1193
+ function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
1194
+ t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
1195
+ if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
1196
+ t_call_fired=true;
1197
+ // Enhanced E-commerce Add to cart clicks
1198
+ gtag("event", "add_to_cart", {
1199
+ "event_category":"Enhanced-Ecommerce",
1200
+ "event_label":"add_to_cart_click",
1201
+ "non_interaction": true,
1202
+ "items": [{
1203
+ "item_id" : t_prod_data_json[t_prod_url_key].tvc_i,
1204
+ "item_name":t_prod_data_json[t_prod_url_key].tvc_n,
1205
+ "item_category" : t_prod_data_json[t_prod_url_key].tvc_c,
1206
+ "price": t_prod_data_json[t_prod_url_key].tvc_p,
1207
+ "currency": tvc_lc,
1208
+ "quantity" :t_qty
1209
+ }]
1210
+ });
1211
+
1212
+ if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
1213
+ gtag("event","add_to_cart", {
1214
+ "value": t_prod_data_json[t_prod_url_key].tvc_p,
1215
+ "items": [
1216
+ {
1217
+ "id": t_prod_data_json[t_prod_url_key].tvc_id,
1218
+ "google_business_vertical": "retail"
1219
+ }
1220
+ ]
1221
+ });
1222
+ }
1223
+ }else{
1224
+ t_call_fired=false;
1225
+ }
1226
+ return t_call_fired;
1227
+ }
1228
+ ';
1229
+ }
1230
+ if(is_home() || is_front_page()){
1231
+ $hmpg_impressions_jQ .='
1232
+ if(tvc_fp.length !== 0){
1233
+ t_products_impre_clicks(tvc_fp,"fp");
1234
+ }
1235
+ if(tvc_rcp.length !== 0){
1236
+ t_products_impre_clicks(tvc_rcp,"rp");
1237
+ }
1238
+ jQuery("a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped)").on("click",function(){
1239
+ t_url=jQuery(this).attr("href");
1240
+ //home page call for click
1241
+ t_call_fired=prod_exists_in_JSON(t_url,tvc_fp,"fp");
1242
+ if(!t_call_fired){
1243
+ prod_exists_in_JSON(t_url,tvc_rcp,"rp");
1244
+ }
1245
+ });
1246
+ //ATC click
1247
+ jQuery("a[href*=add-to-cart]").on("click",function(){
1248
+ t_url=jQuery(this).attr("href");
1249
+ t_qty=$(this).parent().find("input[name=quantity]").val();
1250
+ //default quantity 1 if quantity box is not there
1251
+ if(t_qty=="" || t_qty===undefined){
1252
+ t_qty="1";
1253
+ }
1254
+ t_call_fired=prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_fp,t_qty);
1255
+ if(!t_call_fired){
1256
+ prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_rcp,t_qty);
1257
+ }
1258
+ });
1259
+
1260
+ ';
1261
+ }else if(is_search()){
1262
+ $hmpg_impressions_jQ .='
1263
+ //search page json
1264
+ if(tvc_pgc.length !== 0){
1265
+ t_products_impre_clicks(tvc_pgc,"srch");
1266
+ }
1267
+ //search page prod click
1268
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1269
+ t_url=jQuery(this).attr("href");
1270
+ //cat page prod call for click
1271
+ prod_exists_in_JSON(t_url,tvc_pgc,"srch");
1272
+ });
1273
+
1274
+ ';
1275
+ }else if (is_product()) {
1276
+ //product page releted products
1277
+ $hmpg_impressions_jQ .='
1278
+ if(tvc_rdp.length !== 0){
1279
+ t_products_impre_clicks(tvc_rdp,"rdp");
1280
+ }
1281
+ //product click - image and product name
1282
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1283
+ t_url=jQuery(this).attr("href");
1284
+ //prod page related call for click
1285
+ prod_exists_in_JSON(t_url,tvc_rdp,"rdp");
1286
+ });
1287
+ //Prod ATC link click in related product section
1288
+ jQuery("a[href*=add-to-cart]").on("click",function(){
1289
+ t_url=jQuery(this).attr("href");
1290
+
1291
+ t_qty=$(this).parent().find("input[name=quantity]").val();
1292
+ //default quantity 1 if quantity box is not there
1293
+ if(t_qty=="" || t_qty===undefined){
1294
+ t_qty="1";
1295
+ }
1296
+ prod_ATC_link_exists(t_url,prodpage_json_ATC_link,tvc_rdp,t_qty);
1297
+ });
1298
+ ';
1299
+ }else if (is_product_category()) {
1300
+ $hmpg_impressions_jQ .='
1301
+ //category page json
1302
+ if(tvc_pgc.length !== 0){
1303
+ t_products_impre_clicks(tvc_pgc,"cp");
1304
+ }
1305
+ //Prod category ATC link click in related product section
1306
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1307
+ t_url=jQuery(this).attr("href");
1308
+ //cat page prod call for click
1309
+ prod_exists_in_JSON(t_url,tvc_pgc,"cp");
1310
+ });
1311
 
1312
+ ';
1313
+ }else if(is_shop()){
1314
+ $hmpg_impressions_jQ .='
1315
+ //shop page json
1316
+ if(tvc_pgc.length !== 0){
1317
+ t_products_impre_clicks(tvc_pgc,"sp");
1318
+ }
1319
+ //shop page prod click
1320
+ jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
1321
+ t_url=jQuery(this).attr("href");
1322
+ //cat page prod call for click
1323
+ prod_exists_in_JSON(t_url,tvc_pgc,"sp");
1324
+ });
1325
+
1326
+
1327
+ ';
1328
+ }
1329
+ //common ATC link for Category page , Shop Page and Search Page
1330
+ if(is_product_category() || is_shop() || is_search()){
1331
+ $hmpg_impressions_jQ .='
1332
+ //ATC link click
1333
+ jQuery("a[href*=add-to-cart]").on("click",function(){
1334
+ t_url=jQuery(this).attr("href");
1335
+ t_qty=$(this).parent().find("input[name=quantity]").val();
1336
+ //default quantity 1 if quantity box is not there
1337
+ if(t_qty=="" || t_qty===undefined){
1338
+ t_qty="1";
1339
+ }
1340
+ prod_ATC_link_exists(t_url,catpage_json_ATC_link,tvc_pgc,t_qty);
1341
+ });
1342
+ ';
1343
+ }
1344
+ //on home page, product page , category page
1345
+ if (is_home() || is_front_page() || is_product() || is_product_category() || is_search() || is_shop()){
1346
+ $this->wc_version_compare($hmpg_impressions_jQ);
1347
+ }
1348
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1349
 
1350
  /**
1351
  * Enhanced E-commerce tracking for remove from cart
1360
  global $woocommerce;
1361
  $cartpage_prod_array_main = array();
1362
  foreach ($woocommerce->cart->cart_contents as $key => $item) {
1363
+ //Version compare
1364
+ $prod_meta = wc_get_product($item["product_id"]);
1365
+
1366
+ if (version_compare($woocommerce->version, "3.3", "<")) {
1367
+ $cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
1368
+ } else {
1369
+ $cart_remove_link=html_entity_decode(wc_get_cart_remove_url($key));
1370
+ }
1371
+ $category = get_the_terms($item["product_id"], "product_cat");
1372
+ $categories = "";
1373
+ if ($category) {
1374
+ foreach ($category as $term) {
1375
+ $categories.=$term->name . ",";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1376
  }
1377
+ }
1378
+ //remove last comma(,) if multiple categories are there
1379
+ $categories = rtrim($categories, ",");
1380
+ $cartpage_prod_array_main[$cart_remove_link] =array(
1381
+ "tvc_id" => esc_js($prod_meta->get_id()),
1382
+ "tvc_i" => esc_js($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->get_id()),
1383
+ "tvc_n" => html_entity_decode(esc_js($prod_meta->get_title())),
1384
+ "tvc_p" => esc_js($prod_meta->get_price()),
1385
+ "tvc_c" => esc_js($categories),
1386
+ "tvc_q"=>esc_js($woocommerce->cart->cart_contents[$key]["quantity"])
1387
+ );
1388
  }
1389
 
1390
  //Cart Page item Array to Json
1440
  }
1441
  }
1442
 
1443
+ /**
1444
+ * Enhanced E-commerce tracking checkout step 1
1445
+ *
1446
+ * @access public
1447
+ * @return void
1448
+ */
1449
+ public function checkout_step_1_tracking() {
1450
+ if ($this->disable_tracking($this->ga_eeT) || !is_checkout() || is_order_received_page() ) {
1451
+ return;
1452
+ }
1453
+ //call fn to make json
1454
+ $this->get_ordered_items();
1455
+ if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
1456
+ $code= '
1457
+ var items = [];
1458
+ gtag("set", {"currency": tvc_lc});
1459
+ for(var t_item in tvc_ch){
1460
+ items.push({
1461
+ "id": tvc_ch[t_item].tvc_i,
1462
+ "name": tvc_ch[t_item].tvc_n,
1463
+ "category": tvc_ch[t_item].tvc_c,
1464
+ "attributes": tvc_ch[t_item].tvc_attr,
1465
+ "price": tvc_ch[t_item].tvc_p,
1466
+ "quantity": tvc_ch[t_item].tvc_q
1467
+ });
1468
+ }';
1469
+
1470
+ $code_step_1 = $code . 'gtag("event", "begin_checkout", {"event_category":"Enhanced-Ecommerce",
1471
+ "event_label":"checkout_step_1","items":items,"non_interaction": true });';
1472
+
1473
+ //check woocommerce version and add code
1474
+ $this->wc_version_compare($code_step_1);
1475
+ }
1476
 
1477
+ if( $this->gm_id && $this->tracking_option == "GA4") {
1478
+ $code = '
1479
+ var items = [];
1480
+ for(var t_item in tvc_ch){
1481
+ items.push({
1482
+ "item_id": tvc_ch[t_item].tvc_i,
1483
+ "item_name": tvc_ch[t_item].tvc_n,
1484
+ "item_category": tvc_ch[t_item].tvc_c,
1485
+ "item_variant": tvc_ch[t_item].tvc_attr,
1486
+ "price": tvc_ch[t_item].tvc_p,
1487
+ "quantity": tvc_ch[t_item].tvc_q
1488
+ });
1489
+ }';
1490
 
1491
+ $code_step_1 = $code . 'gtag("event", "begin_checkout", {
1492
+ "event_category":"Enhanced-Ecommerce",
1493
+ "event_label":"checkout_step_1",
1494
+ "items":items,
1495
+ "non_interaction": true
1496
+ });';
1497
 
1498
+ //check woocommerce version and add code
1499
+ $this->wc_version_compare($code_step_1);
1500
+ }
1501
+ }
1502
 
1503
  /**
1504
  * Enhanced E-commerce tracking checkout step 2
1507
  * @return void
1508
  */
1509
  public function checkout_step_2_tracking() {
1510
+ if ($this->disable_tracking($this->ga_eeT) || !is_checkout() || is_order_received_page() ) {
1511
+ return;
1512
  }
1513
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1514
  $code= '
1546
  * @access public
1547
  * @return void
1548
  */
1549
+ public function checkout_step_3_tracking(){
1550
+ if ($this->disable_tracking($this->ga_eeT) || !is_checkout() || is_order_received_page() ) {
1551
+ return;
 
1552
  }
1553
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1554
  $code= '
1594
  $code = "";
1595
  //get all items added into the cart
1596
  foreach ($woocommerce->cart->cart_contents as $item) {
1597
+ //Version Compare
1598
+ $p = wc_get_product($item["product_id"]);
1599
+
1600
+ $category = get_the_terms($item["product_id"], "product_cat");
1601
+ $categories = "";
1602
+ if ($category) {
1603
+ foreach ($category as $term) {
1604
+ $categories.=$term->name . ",";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1605
  }
1606
+ }
1607
+ //remove last comma(,) if multiple categories are there
1608
+ $categories = rtrim($categories, ",");
1609
+ $chkout_json[get_permalink($p->get_id())] = array(
1610
+ "tvc_id" => esc_js($p->get_id()),
1611
+ "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->get_id()),
1612
+ "tvc_n" => html_entity_decode(esc_js($p->get_title())),
1613
+ "tvc_p" => esc_js($p->get_price()),
1614
+ "tvc_c" => esc_js($categories),
1615
+ "tvc_q" => esc_js($item["quantity"]),
1616
+ "isfeatured"=>esc_js($p->is_featured())
1617
+ );
1618
  }
1619
  //return $code;
1620
  //make product data json on check out page
public/class-enhanced-ecommerce-google-analytics-public.php CHANGED
@@ -96,6 +96,9 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
96
  protected $TVC_Admin_Helper;
97
  protected $remarketing_snippet_id;
98
  protected $remarketing_snippets;
 
 
 
99
  /**
100
  * Enhanced_Ecommerce_Google_Analytics_Public constructor.
101
  * @param $plugin_name
@@ -103,66 +106,73 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
103
  */
104
 
105
  public function __construct($plugin_name, $version) {
106
- $this->TVC_Admin_Helper = new TVC_Admin_Helper();
107
- $this->plugin_name = sanitize_text_field($plugin_name);
108
- $this->version = sanitize_text_field($version);
109
- $this->tvc_call_hooks();
110
-
111
- $this->ga_id = sanitize_text_field($this->get_option("ga_id"));
112
- $this->ga_eeT = sanitize_text_field($this->get_option("ga_eeT"));
113
- $this->ga_ST = sanitize_text_field($this->get_option("ga_ST")); //add_gtag_snippet
114
- $this->gm_id = sanitize_text_field($this->get_option("gm_id")); //measurement_id
115
- $this->google_ads_id = sanitize_text_field($this->get_option("google_ads_id"));
116
- $this->ga_excT = sanitize_text_field($this->get_option("ga_excT")); //exception_tracking
117
- $this->exception_tracking = sanitize_text_field($this->get_option("exception_tracking")); //exception_tracking
118
- $this->ga_elaT = sanitize_text_field($this->get_option("ga_elaT")); //enhanced_link_attribution_tracking
119
- $this->google_merchant_id = sanitize_text_field($this->get_option("google_merchant_id"));
120
- $this->tracking_option = sanitize_text_field($this->get_option("tracking_option"));
121
- $this->ga_gCkout = sanitize_text_field($this->get_option("ga_gCkout") == "on" ? true : false); //guest checkout
122
- $this->ga_gUser = sanitize_text_field($this->get_option("ga_gUser") == "on" ? true : false); //guest checkout
123
- $this->ga_DF = sanitize_text_field($this->get_option("ga_DF") == "on" ? true : false);
124
- $this->ga_imTh = sanitize_text_field($this->get_option("ga_Impr") == "" ? 6 : $this->get_option("ga_Impr"));
125
- $this->ga_OPTOUT = sanitize_text_field($this->get_option("ga_OPTOUT") == "on" ? true : false); //Google Analytics Opt Out
126
- $this->ga_PrivacyPolicy = sanitize_text_field($this->get_option("ga_PrivacyPolicy") == "on" ? true : false);
127
- $this->ga_IPA = sanitize_text_field($this->get_option("ga_IPA") == "on" ? true : false); //IP Anony.
128
- $this->ads_ert = sanitize_text_field(get_option('ads_ert')); //Enable remarketing tags
129
- $this->ads_edrt = sanitize_text_field(get_option('ads_edrt')); //Enable dynamic remarketing tags
130
- $this->ads_tracking_id = sanitize_text_field(get_option('ads_tracking_id'));
131
 
132
- $remarketing = unserialize(get_option('ee_remarketing_snippets'));
133
- if(!empty($remarketing) && isset($remarketing['snippets']) && esc_attr($remarketing['snippets'])){
134
- $this->remarketing_snippets = base64_decode($remarketing['snippets']);
135
- $this->remarketing_snippet_id = isset($remarketing['id'])?esc_attr($remarketing['id']):"";
136
- }
137
 
138
- if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
139
- // Put your plugin code here
140
- add_action('woocommerce_init' , function (){
141
- $this->ga_LC = get_woocommerce_currency(); //Local Currency from Back end
142
- $this->wc_version_compare("tvc_lc=" . json_encode(esc_js($this->ga_LC)) . ";");
143
- });
144
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  }
146
  public function tvc_call_hooks(){
147
- add_action("wp_head", array($this, "enqueue_scripts"));
148
- add_action("wp_head", array($this, "ee_settings"));
149
- add_action("wp_head", array($this, "add_google_site_verification_tag"),1);
150
-
151
- add_action("wp_footer", array($this, "t_products_impre_clicks"));
152
- add_action("woocommerce_after_shop_loop_item", array($this, "bind_product_metadata"));
 
 
 
153
  add_action("woocommerce_thankyou", array($this, "ecommerce_tracking_code"));
154
- add_action("woocommerce_after_single_product", array($this, "product_detail_view"));
155
- add_action("woocommerce_after_cart",array($this, "remove_cart_tracking"));
156
- //check out step 1,2,3
157
- add_action("woocommerce_before_checkout_form", array($this, "checkout_step_1_tracking"));
158
- add_action("woocommerce_before_checkout_form", array($this, "checkout_step_2_tracking"));
159
- add_action("woocommerce_before_checkout_form", array($this, "checkout_step_3_tracking"));
160
- add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
161
- //add version details in footer
162
- add_action("wp_footer", array($this, "add_plugin_details"));
163
- //Add Dev ID
164
- add_action("wp_head", array($this, "add_dev_id"));
165
- add_action("wp_footer",array($this, "tvc_store_meta_data"));
 
 
 
 
 
166
  }
167
  public function add_google_site_verification_tag(){
168
  $TVC_Admin_Helper = new TVC_Admin_Helper();
@@ -173,15 +183,12 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
173
 
174
  }
175
  public function get_option($key){
176
- $ee_options = array();
177
- $my_option = get_option( 'ee_options' );
178
-
179
- if(!empty($my_option)){
180
- $ee_options = unserialize($my_option);
181
- }
182
- if(isset($ee_options[$key])){
183
- return $ee_options[$key];
184
- }
185
  }
186
  /**
187
  * Get store meta data for trouble shoot
@@ -283,13 +290,12 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
283
  * @return void
284
  */
285
  function wc_version_compare($codeSnippet) {
286
- global $woocommerce;
287
-
288
- if (version_compare($woocommerce->version, "2.1", ">=")) {
289
- wc_enqueue_js($codeSnippet);
290
- } else {
291
- $woocommerce->add_inline_js($codeSnippet);
292
- }
293
  }
294
  /**
295
  * Enhanced Ecommerce GA plugin Settings
@@ -397,6 +403,31 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
397
  }
398
  }
399
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
 
401
  /**
402
  * Google Analytics eCommerce tracking
@@ -406,17 +437,22 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
406
  * @return void
407
  */
408
  function ecommerce_tracking_code($order_id) {
409
-
410
  global $woocommerce;
411
- if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1){
 
 
 
 
 
 
 
412
  return;
413
  }
414
-
415
  // Doing eCommerce tracking so unhook standard tracking from the footer
416
  remove_action("wp_footer", array($this, "ee_settings"));
417
 
418
  // Get the order and output tracking code
419
- $order = new WC_Order($order_id);
420
  $orderpage_prod_Array = array();
421
  //Get Applied Coupon Codes
422
  $coupons_list = '';
@@ -472,11 +508,9 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
472
  $categories=esc_js(join(",", $out));
473
  } else {
474
  $out = array();
475
- if(version_compare($woocommerce->version, "2.7", "<")){
476
- $categories = get_the_terms($_product->ID, "product_cat");
477
- }else{
478
- $categories = get_the_terms($_product->get_id(), "product_cat");
479
- }
480
 
481
  if ($categories) {
482
  foreach ($categories as $category) {
@@ -486,61 +520,33 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
486
  $categories=esc_js(join(",", $out));
487
  }
488
  //orderpage Prod json
489
- if (isset($_product->variation_data)) {
490
- if(version_compare($woocommerce->version, "2.7", "<")){
491
- $orderpage_prod_Array[get_permalink($_product->ID)]=array(
492
- "tvc_id" => esc_js($_product->ID),
493
- "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->ID),
494
- "tvc_n" => html_entity_decode(esc_js($item["name"])),
495
- "tvc_p" => esc_js($order->get_item_total($item)),
496
- "tvc_c" => esc_js($categories),
497
- "tvc_attr" => esc_js($attributes),
498
- "tvc_q"=>esc_js($item["qty"])
499
- );
500
- }else{
501
- $orderpage_prod_Array[get_permalink($_product->get_id())]=array(
502
- "tvc_id" => esc_js($_product->get_id()),
503
- "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
504
- "tvc_n" => html_entity_decode(esc_js($item["name"])),
505
- "tvc_p" => esc_js($order->get_item_total($item)),
506
- "tvc_c" => esc_js($categories),
507
- "tvc_attr" => esc_js($attributes),
508
- "tvc_q"=>esc_js($item["qty"])
509
- );
510
- }
511
- } else {
512
- if(version_compare($woocommerce->version, "2.7", "<")){
513
- $orderpage_prod_Array[get_permalink($_product->ID)]=array(
514
- "tvc_id" => esc_js($_product->ID),
515
- "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->ID),
516
- "tvc_n" => html_entity_decode(esc_js($item["name"])),
517
- "tvc_p" => esc_js($order->get_item_total($item)),
518
- "tvc_c" => esc_js($categories),
519
- "tvc_q"=>esc_js($item["qty"])
520
- );
521
- }else{
522
- $orderpage_prod_Array[get_permalink($_product->get_id())]=array(
523
- "tvc_id" => esc_js($_product->get_id()),
524
- "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
525
- "tvc_n" => esc_js($_product->get_title()),
526
- "tvc_p" => esc_js($order->get_item_total($item)),
527
- "tvc_c" => esc_js($categories),
528
- "tvc_q"=>esc_js($item["qty"])
529
- );
530
- }
531
- }
532
-
533
  }
534
  //make json for prod meta data on order page
535
  $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
536
  }
537
-
538
- //get shipping cost based on version >2.1 get_total_shipping() < get_shipping
539
- if (version_compare($woocommerce->version, "2.1", ">=")) {
540
- $tvc_sc = $order->get_total_shipping();
541
- } else {
542
- $tvc_sc = $order->get_shipping();
543
- }
544
  //orderpage transcation data json
545
  $orderpage_trans_Array=array(
546
  "id"=> esc_js($order->get_order_number()), // Transaction ID. Required
@@ -673,11 +679,8 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
673
  return;
674
  global $product,$woocommerce;
675
 
676
- if(version_compare($woocommerce->version, "2.7", "<")){
677
- $category = get_the_terms($product->ID, "product_cat");
678
- }else{
679
- $category = get_the_terms($product->get_id(), "product_cat");
680
- }
681
  $categories = "";
682
  if ($category) {
683
  foreach ($category as $term) {
@@ -691,7 +694,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
691
  var items = [];
692
  //set local currencies
693
  gtag("set", {"currency": tvc_lc});
694
- jQuery("[class*=single_add_to_cart_button]").click(function() {
695
  // Enhanced E-commerce Add to cart clicks
696
  gtag("event", "add_to_cart", {
697
  "event_category":"Enhanced-Ecommerce",
@@ -769,16 +772,13 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
769
  */
770
  public function product_detail_view() {
771
 
772
- if ($this->disable_tracking($this->ga_eeT)) {
773
- return;
774
- }
775
-
776
- global $product,$woocommerce;
777
- if(version_compare($woocommerce->version, "2.7", "<")){
778
- $category = get_the_terms($product->ID, "product_cat");
779
- }else{
780
- $category = get_the_terms($product->get_id(), "product_cat");
781
  }
 
 
 
 
782
  $categories = "";
783
  if ($category) {
784
  foreach ($category as $term) {
@@ -787,24 +787,15 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
787
  }
788
  //remove last comma(,) if multiple categories are there
789
  $categories = rtrim($categories, ",");
790
- //product detail view json
791
- if(version_compare($woocommerce->version, "2.7", "<")){
792
- $prodpage_detail_json = array(
793
- "tvc_id" => esc_js($product->id),
794
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
795
- "tvc_n" => esc_js($product->get_title()),
796
- "tvc_c" => esc_js($categories),
797
- "tvc_p" => esc_js($product->get_price())
798
- );
799
- }else{
800
- $prodpage_detail_json = array(
801
- "tvc_id" => esc_js($product->get_id()),
802
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
803
- "tvc_n" => esc_js($product->get_title()),
804
- "tvc_c" => esc_js($categories),
805
- "tvc_p" => esc_js($product->get_price())
806
- );
807
- }
808
 
809
  if (empty($prodpage_detail_json)) {
810
  //prod page array
@@ -895,18 +886,12 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
895
  }
896
 
897
  global $product,$woocommerce;
898
- if (version_compare($woocommerce->version, "2.7", "<")) {
899
- $category = get_the_terms($product->Id, "product_cat");
900
- } else {
901
- $category = get_the_terms($product->get_id(), "product_cat");
902
- }
903
-
904
  $categories = "";
905
-
906
  if ($category) {
907
- foreach ($category as $term) {
908
- $categories.=$term->name . ",";
909
- }
910
  }
911
  //remove last comma(,) if multiple categories are there
912
  $categories = rtrim($categories, ",");
@@ -920,155 +905,82 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
920
  $homepage_json_ATC_link=array();
921
  }
922
 
923
- // ATC link Array
924
- if(version_compare($woocommerce->version, "2.7", "<")){
925
- $homepage_json_ATC_link[$product->add_to_cart_url()]=
926
- array(
927
- "ATC-link"=> esc_url_raw(get_permalink($product->id))
928
- );
929
- }else{
930
- $homepage_json_ATC_link[$product->add_to_cart_url()]=
931
- array(
932
- "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
933
- );
934
- }
935
  //check if product is featured product or not
936
  if ($product->is_featured()) {
937
- //check if product is already exists in homepage featured json
938
- if(version_compare($woocommerce->version, "2.7", "<")){
939
- if(!array_key_exists(get_permalink($product->id),$homepage_json_fp)){
940
- $homepage_json_fp[get_permalink($product->id)] = array(
941
- "tvc_id" => esc_js($product->id),
942
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
943
- "tvc_n" => esc_js($product->get_title()),
944
- "tvc_p" => esc_js($product->get_price()),
945
- "tvc_c" => esc_js($categories),
946
- "ATC-link" => esc_url_raw($product->add_to_cart_url())
947
- );
948
- //else add product in homepage recent product json
949
- }else {
950
- $homepage_json_rp[get_permalink($product->get_id())] =array(
951
- "tvc_id" => esc_js($product->get_id()),
952
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
953
- "tvc_n" => esc_js($product->get_title()),
954
- "tvc_p" => esc_js($product->get_price()),
955
- "tvc_c" => esc_js($categories)
956
- );
957
- }
958
- }else{
959
- if(!array_key_exists(get_permalink($product->get_id()),$homepage_json_fp)){
960
- $homepage_json_fp[get_permalink($product->get_id())] = array(
961
- "tvc_id" => esc_js($product->get_id()),
962
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
963
- "tvc_n" => esc_js($product->get_title()),
964
- "tvc_p" => esc_js($product->get_price()),
965
- "tvc_c" => esc_js($categories),
966
- "ATC-link"=> esc_url_raw($product->add_to_cart_url())
967
- );
968
- //else add product in homepage recent product json
969
- }else {
970
- $homepage_json_rp[get_permalink($product->get_id())] =array(
971
- "tvc_id" => esc_js($product->get_id()),
972
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
973
- "tvc_n" => esc_js($product->get_title()),
974
- "tvc_p" => esc_js($product->get_price()),
975
- "tvc_c" => esc_js($categories)
976
- );
977
- }
978
- }
979
-
980
  } else {
981
- //else prod add in homepage recent json
982
- if(version_compare($woocommerce->version, "2.7", "<")){
983
- $homepage_json_rp[get_permalink($product->id)] =array(
984
- "tvc_id" => esc_js($product->id),
985
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
986
- "tvc_n" => esc_js($product->get_title()),
987
- "tvc_p" => esc_js($product->get_price()),
988
- "tvc_c" => esc_js($categories)
989
- );
990
- }else{
991
- $homepage_json_rp[get_permalink($product->get_id())] =array(
992
- "tvc_id" => esc_js($product->get_id()),
993
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
994
- "tvc_n" => esc_js($product->get_title()),
995
- "tvc_p" => esc_js($product->get_price()),
996
- "tvc_c" => esc_js($categories)
997
- );
998
- }
999
-
1000
  }
1001
- }
1002
- //if product page then related product page array
1003
- else if(is_product()){
1004
  if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
1005
  $prodpage_json_relProd = array();
1006
  $prodpage_json_ATC_link = array();
1007
  }
1008
- // ATC link Array
1009
- if(version_compare($woocommerce->version, "2.7", "<")){
1010
- $prodpage_json_ATC_link[$product->add_to_cart_url()]=
1011
- array(
1012
- "ATC-link"=>esc_url_raw(get_permalink($product->id))
1013
- );
1014
-
1015
- $prodpage_json_relProd[get_permalink($product->id)] = array(
1016
- "tvc_id" => esc_js($product->id),
1017
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
1018
- "tvc_n" => esc_js($product->get_title()),
1019
- "tvc_p" => esc_js($product->get_price()),
1020
- "tvc_c" => esc_js($categories),
1021
- );
1022
- }else{
1023
- $prodpage_json_ATC_link[$product->add_to_cart_url()]=
1024
- array(
1025
- "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
1026
- );
1027
-
1028
- $prodpage_json_relProd[get_permalink($product->get_id())] = array(
1029
- "tvc_id" => esc_js($product->get_id()),
1030
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
1031
- "tvc_n" => esc_js($product->get_title()),
1032
- "tvc_p" => esc_js($product->get_price()),
1033
- "tvc_c" => esc_js($categories)
1034
 
1035
- );
1036
- }
1037
- }
1038
- //category page, search page and shop page json
1039
- else if (is_product_category() || is_search() || is_shop()) {
1040
  if (!is_array($catpage_json) && !is_array($catpage_json_ATC_link)){
1041
- $catpage_json=array();
1042
- $catpage_json_ATC_link=array();
1043
- }
1044
- //cat page ATC array
1045
- if(version_compare($woocommerce->version, "2.7", "<")){
1046
- $catpage_json_ATC_link[$product->add_to_cart_url()]=
1047
- array(
1048
- "ATC-link"=>esc_url_raw(get_permalink($product->id))
1049
- );
1050
-
1051
- $catpage_json[get_permalink($product->id)] =array(
1052
- "tvc_id" => esc_js($product->id),
1053
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->id),
1054
- "tvc_n" => esc_js($product->get_title()),
1055
- "tvc_p" => esc_js($product->get_price()),
1056
- "tvc_c" => esc_js($categories),
1057
- );
1058
- }else{
1059
- $catpage_json_ATC_link[$product->add_to_cart_url()]=array(
1060
- "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
1061
- );
1062
-
1063
- $catpage_json[get_permalink($product->get_id())] =array(
1064
- "tvc_id" => esc_js($product->get_id()),
1065
- "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
1066
- "tvc_n" => esc_js($product->get_title()),
1067
- "tvc_p" => esc_js($product->get_price()),
1068
- "tvc_c" => esc_js($categories)
1069
-
1070
- );
1071
  }
 
 
 
 
 
 
 
 
 
 
 
 
1072
  }
1073
  }
1074
 
@@ -1509,45 +1421,29 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1509
  global $woocommerce;
1510
  $cartpage_prod_array_main = array();
1511
  foreach ($woocommerce->cart->cart_contents as $key => $item) {
1512
- //Version compare
1513
- if (version_compare($woocommerce->version, "2.7", "<")) {
1514
- $prod_meta = get_product($item["product_id"]);
1515
- } else {
1516
- $prod_meta = wc_get_product($item["product_id"]);
1517
- }
1518
- if (version_compare($woocommerce->version, "3.3", "<")) {
1519
- $cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
1520
- } else {
1521
- $cart_remove_link=html_entity_decode(wc_get_cart_remove_url($key));
1522
- }
1523
- $category = get_the_terms($item["product_id"], "product_cat");
1524
- $categories = "";
1525
- if ($category) {
1526
- foreach ($category as $term) {
1527
- $categories.=$term->name . ",";
1528
- }
1529
- }
1530
- //remove last comma(,) if multiple categories are there
1531
- $categories = rtrim($categories, ",");
1532
- if(version_compare($woocommerce->version, "2.7", "<")){
1533
- $cartpage_prod_array_main[$cart_remove_link] =array(
1534
- "tvc_id" => esc_js($prod_meta->ID),
1535
- "tvc_i" => esc_js($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->ID),
1536
- "tvc_n" => html_entity_decode(esc_js($prod_meta->get_title())),
1537
- "tvc_p" => esc_js($prod_meta->get_price()),
1538
- "tvc_c" => esc_js($categories),
1539
- "tvc_q"=> esc_js($woocommerce->cart->cart_contents[$key]["quantity"])
1540
- );
1541
- }else{
1542
- $cartpage_prod_array_main[$cart_remove_link] =array(
1543
- "tvc_id" => esc_js($prod_meta->get_id()),
1544
- "tvc_i" => esc_js($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->get_id()),
1545
- "tvc_n" => html_entity_decode(esc_js($prod_meta->get_title())),
1546
- "tvc_p" => esc_js($prod_meta->get_price()),
1547
- "tvc_c" => esc_js($categories),
1548
- "tvc_q"=> esc_js($woocommerce->cart->cart_contents[$key]["quantity"])
1549
- );
1550
- }
1551
  }
1552
 
1553
  //Cart Page item Array to Json
@@ -1610,9 +1506,9 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1610
  * @return void
1611
  */
1612
  public function checkout_step_1_tracking() {
1613
- if ($this->disable_tracking($this->ga_eeT)) {
1614
- return;
1615
- }
1616
  //call fn to make json
1617
  $this->get_ordered_items();
1618
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
@@ -1670,9 +1566,9 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1670
  * @return void
1671
  */
1672
  public function checkout_step_2_tracking() {
1673
- if ($this->disable_tracking($this->ga_eeT)) {
1674
- return;
1675
- }
1676
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1677
  $code= '
1678
  var items = [];
@@ -1710,10 +1606,9 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1710
  * @return void
1711
  */
1712
  public function checkout_step_3_tracking() {
1713
-
1714
- if ($this->disable_tracking($this->ga_eeT)) {
1715
- return;
1716
- }
1717
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1718
  $code= '
1719
  var items = [];
@@ -1758,13 +1653,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1758
  $code = "";
1759
  //get all items added into the cart
1760
  foreach ($woocommerce->cart->cart_contents as $item) {
1761
- //Version Compare
1762
- if ( version_compare($woocommerce->version, "2.7", "<")) {
1763
- $p = get_product($item["product_id"]);
1764
- } else {
1765
- $p = wc_get_product($item["product_id"]);
1766
- }
1767
-
1768
  $category = get_the_terms($item["product_id"], "product_cat");
1769
  $categories = "";
1770
  if ($category) {
@@ -1773,28 +1662,17 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
1773
  }
1774
  }
1775
  //remove last comma(,) if multiple categories are there
1776
- $categories = rtrim($categories, ",");
1777
- if(version_compare($woocommerce->version, "2.7", "<")){
1778
- $chkout_json[get_permalink($p->ID)] = array(
1779
- "tvc_id" => esc_js($p->ID),
1780
- "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->ID),
1781
- "tvc_n" => html_entity_decode(esc_js($p->get_title())),
1782
- "tvc_p" => esc_js($p->get_price()),
1783
- "tvc_c" => esc_js($categories),
1784
- "tvc_q" => esc_js($item["quantity"]),
1785
- "isfeatured" => esc_js($p->is_featured())
1786
- );
1787
- }else{
1788
- $chkout_json[get_permalink($p->get_id())] = array(
1789
- "tvc_id" => esc_js($p->get_id()),
1790
- "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->get_id()),
1791
- "tvc_n" => html_entity_decode(esc_js($p->get_title())),
1792
- "tvc_p" => esc_js($p->get_price()),
1793
- "tvc_c" => esc_js($categories),
1794
- "tvc_q" => esc_js($item["quantity"]),
1795
- "isfeatured" => esc_js($p->is_featured())
1796
- );
1797
- }
1798
  }
1799
  //return $code;
1800
  //make product data json on check out page
96
  protected $TVC_Admin_Helper;
97
  protected $remarketing_snippet_id;
98
  protected $remarketing_snippets;
99
+ protected $tvc_conversion_tracking_type;
100
+
101
+ protected $ee_options;
102
  /**
103
  * Enhanced_Ecommerce_Google_Analytics_Public constructor.
104
  * @param $plugin_name
106
  */
107
 
108
  public function __construct($plugin_name, $version) {
109
+ $this->TVC_Admin_Helper = new TVC_Admin_Helper();
110
+ $this->plugin_name = sanitize_text_field($plugin_name);
111
+ $this->version = sanitize_text_field($version);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
+ $this->ee_options = $this->TVC_Admin_Helper->get_ee_options_settings();
114
+ $this->tvc_conversion_tracking_type = sanitize_text_field($this->get_option("tvc_conversion_tracking_type"));
 
 
 
115
 
116
+ $this->tvc_call_hooks();
117
+
118
+ $this->ga_id = sanitize_text_field($this->get_option("ga_id"));
119
+ $this->ga_eeT = sanitize_text_field($this->get_option("ga_eeT"));
120
+ $this->ga_ST = sanitize_text_field($this->get_option("ga_ST")); //add_gtag_snippet
121
+ $this->gm_id = sanitize_text_field($this->get_option("gm_id")); //measurement_id
122
+ $this->google_ads_id = sanitize_text_field($this->get_option("google_ads_id"));
123
+ $this->ga_excT = sanitize_text_field($this->get_option("ga_excT")); //exception_tracking
124
+ $this->exception_tracking = sanitize_text_field($this->get_option("exception_tracking")); //exception_tracking
125
+ $this->ga_elaT = sanitize_text_field($this->get_option("ga_elaT")); //enhanced_link_attribution_tracking
126
+ $this->google_merchant_id = sanitize_text_field($this->get_option("google_merchant_id"));
127
+ $this->tracking_option = sanitize_text_field($this->get_option("tracking_option"));
128
+ $this->ga_gCkout = sanitize_text_field($this->get_option("ga_gCkout") == "on" ? true : false); //guest checkout
129
+ $this->ga_gUser = sanitize_text_field($this->get_option("ga_gUser") == "on" ? true : false); //guest checkout
130
+ $this->ga_DF = sanitize_text_field($this->get_option("ga_DF") == "on" ? true : false);
131
+ $this->ga_imTh = sanitize_text_field($this->get_option("ga_Impr") == "" ? 6 : $this->get_option("ga_Impr"));
132
+ $this->ga_OPTOUT = sanitize_text_field($this->get_option("ga_OPTOUT") == "on" ? true : false); //Google Analytics Opt Out
133
+ $this->ga_PrivacyPolicy = sanitize_text_field($this->get_option("ga_PrivacyPolicy") == "on" ? true : false);
134
+ $this->ga_IPA = sanitize_text_field($this->get_option("ga_IPA") == "on" ? true : false); //IP Anony.
135
+ $this->ads_ert = sanitize_text_field(get_option('ads_ert')); //Enable remarketing tags
136
+ $this->ads_edrt = sanitize_text_field(get_option('ads_edrt')); //Enable dynamic remarketing tags
137
+ $this->ads_tracking_id = sanitize_text_field(get_option('ads_tracking_id'));
138
+
139
+ $remarketing = unserialize(get_option('ee_remarketing_snippets'));
140
+ if(!empty($remarketing) && isset($remarketing['snippets']) && esc_attr($remarketing['snippets'])){
141
+ $this->remarketing_snippets = base64_decode($remarketing['snippets']);
142
+ $this->remarketing_snippet_id = isset($remarketing['id'])?esc_attr($remarketing['id']):"";
143
+ }
144
+ $this->ga_LC = get_woocommerce_currency(); //Local Currency from Back end
145
+ $this->wc_version_compare("tvc_lc=" . json_encode(esc_js($this->ga_LC)) . ";");
146
+
147
  }
148
  public function tvc_call_hooks(){
149
+ add_action("wp_head", array($this, "enqueue_scripts"));
150
+ add_action("wp_head", array($this, "ee_settings"));
151
+ add_action("wp_head", array($this, "add_google_site_verification_tag"),1);
152
+
153
+ add_action("wp_footer", array($this, "t_products_impre_clicks"));
154
+ add_action("woocommerce_after_shop_loop_item", array($this, "bind_product_metadata"));
155
+ if($this->tvc_conversion_tracking_type == "on-thankyou-page"){
156
+ add_action("wp_head", array($this, "ecommerce_tracking_code"));
157
+ }else{
158
  add_action("woocommerce_thankyou", array($this, "ecommerce_tracking_code"));
159
+ }
160
+ //add_action("woocommerce_after_single_product", array($this, "product_detail_view"));
161
+ add_action("wp_head", array($this, "product_detail_view"));
162
+ add_action("woocommerce_after_cart",array($this, "remove_cart_tracking"));
163
+ //check out step 1,2,3
164
+ //add_action("woocommerce_before_checkout_form", array($this, "checkout_step_1_tracking"));
165
+ //add_action("woocommerce_before_checkout_form", array($this, "checkout_step_2_tracking"));
166
+ //add_action("woocommerce_before_checkout_form", array($this, "checkout_step_3_tracking"));
167
+ add_action("wp_head", array($this, "checkout_step_1_tracking"));
168
+ add_action("wp_head", array($this, "checkout_step_2_tracking"));
169
+ add_action("wp_head", array($this, "checkout_step_3_tracking"));
170
+ add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
171
+ //add version details in footer
172
+ add_action("wp_footer", array($this, "add_plugin_details"));
173
+ //Add Dev ID
174
+ add_action("wp_head", array($this, "add_dev_id"));
175
+ add_action("wp_footer",array($this, "tvc_store_meta_data"));
176
  }
177
  public function add_google_site_verification_tag(){
178
  $TVC_Admin_Helper = new TVC_Admin_Helper();
183
 
184
  }
185
  public function get_option($key){
186
+ if(empty($this->ee_options)){
187
+ $this->ee_options = $this->TVC_Admin_Helper->get_ee_options_settings();
188
+ }
189
+ if(isset($this->ee_options[$key])){
190
+ return $this->ee_options[$key];
191
+ }
 
 
 
192
  }
193
  /**
194
  * Get store meta data for trouble shoot
290
  * @return void
291
  */
292
  function wc_version_compare($codeSnippet) {
293
+ global $woocommerce;
294
+ if (version_compare($woocommerce->version, "2.1", ">=")) {
295
+ wc_enqueue_js($codeSnippet);
296
+ } else {
297
+ $woocommerce->add_inline_js($codeSnippet);
298
+ }
 
299
  }
300
  /**
301
  * Enhanced Ecommerce GA plugin Settings
403
  }
404
  }
405
  }
406
+ protected function tvc_get_order_with_url_order_key(){
407
+ $_get = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING );
408
+ if ( isset( $_get['key'] ) ) {
409
+ $order_key = $_get['key'];
410
+ return wc_get_order( wc_get_order_id_by_order_key( $order_key ) );
411
+ }
412
+ }
413
+ protected function tvc_get_order_from_query_vars(){
414
+ global $wp ;
415
+ $order_id = absint( $wp->query_vars['order-received'] );
416
+ if ( $order_id && 0 != $order_id && wc_get_order( $order_id ) ) {
417
+ return wc_get_order( $order_id );
418
+ }
419
+ }
420
+ protected function tvc_get_order_from_order_received_page(){
421
+ if ( $this->tvc_get_order_from_query_vars() ) {
422
+ return $this->tvc_get_order_from_query_vars();
423
+ } else {
424
+ if ( $this->tvc_get_order_with_url_order_key() ) {
425
+ return $this->tvc_get_order_with_url_order_key();
426
+ } else {
427
+ return false;
428
+ }
429
+ }
430
+ }
431
 
432
  /**
433
  * Google Analytics eCommerce tracking
437
  * @return void
438
  */
439
  function ecommerce_tracking_code($order_id) {
 
440
  global $woocommerce;
441
+ $order = "";
442
+ if($order_id == null && is_order_received_page()){
443
+ $order = $this->tvc_get_order_from_order_received_page();
444
+ $order_id = $order->get_id();
445
+ }else{
446
+ $order = new WC_Order($order_id);
447
+ }
448
+ if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1 || !is_order_received_page() ){
449
  return;
450
  }
 
451
  // Doing eCommerce tracking so unhook standard tracking from the footer
452
  remove_action("wp_footer", array($this, "ee_settings"));
453
 
454
  // Get the order and output tracking code
455
+ //$order = new WC_Order($order_id);
456
  $orderpage_prod_Array = array();
457
  //Get Applied Coupon Codes
458
  $coupons_list = '';
508
  $categories=esc_js(join(",", $out));
509
  } else {
510
  $out = array();
511
+
512
+ $categories = get_the_terms($_product->get_id(), "product_cat");
513
+
 
 
514
 
515
  if ($categories) {
516
  foreach ($categories as $category) {
520
  $categories=esc_js(join(",", $out));
521
  }
522
  //orderpage Prod json
523
+ if (isset($_product->variation_data)) {
524
+ $orderpage_prod_Array[get_permalink($_product->get_id())]=array(
525
+ "tvc_id" => esc_js($_product->get_id()),
526
+ "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
527
+ "tvc_n" => html_entity_decode(esc_js($item["name"])),
528
+ "tvc_p" => esc_js($order->get_item_total($item)),
529
+ "tvc_c" => esc_js($categories),
530
+ "tvc_attr" => esc_js($attributes),
531
+ "tvc_q"=>esc_js($item["qty"])
532
+ );
533
+ } else {
534
+ $orderpage_prod_Array[get_permalink($_product->get_id())]=array(
535
+ "tvc_id" => esc_js($_product->get_id()),
536
+ "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
537
+ "tvc_n" => esc_js($_product->get_title()),
538
+ "tvc_p" => esc_js($order->get_item_total($item)),
539
+ "tvc_c" => esc_js($categories),
540
+ "tvc_q"=>esc_js($item["qty"])
541
+ );
542
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  }
544
  //make json for prod meta data on order page
545
  $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
546
  }
547
+ //get shipping cost
548
+ $tvc_sc = $order->get_total_shipping();
549
+
 
 
 
 
550
  //orderpage transcation data json
551
  $orderpage_trans_Array=array(
552
  "id"=> esc_js($order->get_order_number()), // Transaction ID. Required
679
  return;
680
  global $product,$woocommerce;
681
 
682
+
683
+ $category = get_the_terms($product->get_id(), "product_cat");
 
 
 
684
  $categories = "";
685
  if ($category) {
686
  foreach ($category as $term) {
694
  var items = [];
695
  //set local currencies
696
  gtag("set", {"currency": tvc_lc});
697
+ jQuery("button[class*=\'btn-buy-shop\'],button[class*=\'single_add_to_cart_button\'], button[class*=\'add_to_cart\']").click(function() {
698
  // Enhanced E-commerce Add to cart clicks
699
  gtag("event", "add_to_cart", {
700
  "event_category":"Enhanced-Ecommerce",
772
  */
773
  public function product_detail_view() {
774
 
775
+ if ( $this->disable_tracking($this->ga_eeT) || !is_product() ) {
776
+ return;
 
 
 
 
 
 
 
777
  }
778
+ global $wp_query, $woocommerce ;
779
+ $product = wc_get_product();
780
+ $category = get_the_terms($product->get_id(), "product_cat");
781
+
782
  $categories = "";
783
  if ($category) {
784
  foreach ($category as $term) {
787
  }
788
  //remove last comma(,) if multiple categories are there
789
  $categories = rtrim($categories, ",");
790
+ //product detail view json
791
+ $prodpage_detail_json = array(
792
+ "tvc_id" => esc_js($product->get_id()),
793
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
794
+ "tvc_n" => esc_js($product->get_title()),
795
+ "tvc_c" => esc_js($categories),
796
+ "tvc_p" => esc_js($product->get_price())
797
+ );
798
+
 
 
 
 
 
 
 
 
 
799
 
800
  if (empty($prodpage_detail_json)) {
801
  //prod page array
886
  }
887
 
888
  global $product,$woocommerce;
889
+ $category = get_the_terms($product->get_id(), "product_cat");
 
 
 
 
 
890
  $categories = "";
 
891
  if ($category) {
892
+ foreach ($category as $term) {
893
+ $categories.=$term->name . ",";
894
+ }
895
  }
896
  //remove last comma(,) if multiple categories are there
897
  $categories = rtrim($categories, ",");
905
  $homepage_json_ATC_link=array();
906
  }
907
 
908
+ // ATC link Array
909
+ $homepage_json_ATC_link[$product->add_to_cart_url()]=
910
+ array(
911
+ "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
912
+ );
913
+
 
 
 
 
 
 
914
  //check if product is featured product or not
915
  if ($product->is_featured()) {
916
+ //check if product is already exists in homepage featured json
917
+ if(!array_key_exists(get_permalink($product->get_id()),$homepage_json_fp)){
918
+ $homepage_json_fp[get_permalink($product->get_id())] = array(
919
+ "tvc_id" => esc_js($product->get_id()),
920
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
921
+ "tvc_n" => esc_js($product->get_title()),
922
+ "tvc_p" => esc_js($product->get_price()),
923
+ "tvc_c" => esc_js($categories),
924
+ "ATC-link"=> esc_url_raw($product->add_to_cart_url())
925
+ );
926
+ //else add product in homepage recent product json
927
+ }else {
928
+ $homepage_json_rp[get_permalink($product->get_id())] =array(
929
+ "tvc_id" => esc_js($product->get_id()),
930
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
931
+ "tvc_n" => esc_js($product->get_title()),
932
+ "tvc_p" => esc_js($product->get_price()),
933
+ "tvc_c" => esc_js($categories)
934
+ );
935
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
936
  } else {
937
+ //else prod add in homepage recent json
938
+ $homepage_json_rp[get_permalink($product->get_id())] =array(
939
+ "tvc_id" => esc_js($product->get_id()),
940
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
941
+ "tvc_n" => esc_js($product->get_title()),
942
+ "tvc_p" => esc_js($product->get_price()),
943
+ "tvc_c" => esc_js($categories)
944
+ );
 
 
 
 
 
 
 
 
 
 
 
945
  }
946
+ } else if(is_product()){
947
+ //if product page then related product page array
 
948
  if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
949
  $prodpage_json_relProd = array();
950
  $prodpage_json_ATC_link = array();
951
  }
952
+ // ATC link Array
953
+ $prodpage_json_ATC_link[$product->add_to_cart_url()]=
954
+ array(
955
+ "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
956
+ );
957
+ $prodpage_json_relProd[get_permalink($product->get_id())] = array(
958
+ "tvc_id" => esc_js($product->get_id()),
959
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
960
+ "tvc_n" => esc_js($product->get_title()),
961
+ "tvc_p" => esc_js($product->get_price()),
962
+ "tvc_c" => esc_js($categories)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963
 
964
+ );
965
+
966
+ } else if (is_product_category() || is_search() || is_shop()) {
967
+ //category page, search page and shop page json
 
968
  if (!is_array($catpage_json) && !is_array($catpage_json_ATC_link)){
969
+ $catpage_json=array();
970
+ $catpage_json_ATC_link=array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971
  }
972
+ //cat page ATC array
973
+ $catpage_json_ATC_link[$product->add_to_cart_url()]=array(
974
+ "ATC-link"=> esc_url_raw(get_permalink($product->get_id()))
975
+ );
976
+ $catpage_json[get_permalink($product->get_id())] =array(
977
+ "tvc_id" => esc_js($product->get_id()),
978
+ "tvc_i" => esc_js($product->get_sku() ? $product->get_sku() : $product->get_id()),
979
+ "tvc_n" => esc_js($product->get_title()),
980
+ "tvc_p" => esc_js($product->get_price()),
981
+ "tvc_c" => esc_js($categories)
982
+ );
983
+
984
  }
985
  }
986
 
1421
  global $woocommerce;
1422
  $cartpage_prod_array_main = array();
1423
  foreach ($woocommerce->cart->cart_contents as $key => $item) {
1424
+ $prod_meta = wc_get_product($item["product_id"]);
1425
+ if (version_compare($woocommerce->version, "3.3", "<")) {
1426
+ $cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
1427
+ } else {
1428
+ $cart_remove_link=html_entity_decode(wc_get_cart_remove_url($key));
1429
+ }
1430
+ $category = get_the_terms($item["product_id"], "product_cat");
1431
+ $categories = "";
1432
+ if ($category) {
1433
+ foreach ($category as $term) {
1434
+ $categories.=$term->name . ",";
1435
+ }
1436
+ }
1437
+ //remove last comma(,) if multiple categories are there
1438
+ $categories = rtrim($categories, ",");
1439
+ $cartpage_prod_array_main[$cart_remove_link] =array(
1440
+ "tvc_id" => esc_js($prod_meta->get_id()),
1441
+ "tvc_i" => esc_js($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->get_id()),
1442
+ "tvc_n" => html_entity_decode(esc_js($prod_meta->get_title())),
1443
+ "tvc_p" => esc_js($prod_meta->get_price()),
1444
+ "tvc_c" => esc_js($categories),
1445
+ "tvc_q"=> esc_js($woocommerce->cart->cart_contents[$key]["quantity"])
1446
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1447
  }
1448
 
1449
  //Cart Page item Array to Json
1506
  * @return void
1507
  */
1508
  public function checkout_step_1_tracking() {
1509
+ if( $this->disable_tracking($this->ga_eeT) || !is_checkout() || is_order_received_page() ) {
1510
+ return;
1511
+ }
1512
  //call fn to make json
1513
  $this->get_ordered_items();
1514
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
1566
  * @return void
1567
  */
1568
  public function checkout_step_2_tracking() {
1569
+ if ($this->disable_tracking($this->ga_eeT) || !is_checkout() || is_order_received_page() ) {
1570
+ return;
1571
+ }
1572
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1573
  $code= '
1574
  var items = [];
1606
  * @return void
1607
  */
1608
  public function checkout_step_3_tracking() {
1609
+ if ( $this->disable_tracking($this->ga_eeT) || !is_checkout() || is_order_received_page() ) {
1610
+ return;
1611
+ }
 
1612
  if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
1613
  $code= '
1614
  var items = [];
1653
  $code = "";
1654
  //get all items added into the cart
1655
  foreach ($woocommerce->cart->cart_contents as $item) {
1656
+ $p = wc_get_product($item["product_id"]);
 
 
 
 
 
 
1657
  $category = get_the_terms($item["product_id"], "product_cat");
1658
  $categories = "";
1659
  if ($category) {
1662
  }
1663
  }
1664
  //remove last comma(,) if multiple categories are there
1665
+ $categories = rtrim($categories, ",");
1666
+ $chkout_json[get_permalink($p->get_id())] = array(
1667
+ "tvc_id" => esc_js($p->get_id()),
1668
+ "tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->get_id()),
1669
+ "tvc_n" => html_entity_decode(esc_js($p->get_title())),
1670
+ "tvc_p" => esc_js($p->get_price()),
1671
+ "tvc_c" => esc_js($categories),
1672
+ "tvc_q" => esc_js($item["quantity"]),
1673
+ "isfeatured" => esc_js($p->is_featured())
1674
+ );
1675
+
 
 
 
 
 
 
 
 
 
 
 
1676
  }
1677
  //return $code;
1678
  //make product data json on check out page
public/js/tvc-ee-google-analytics.js CHANGED
@@ -35,7 +35,8 @@ class TVC_Enhanced {
35
  }
36
  singleProductaddToCartEventBindings(variations_data){
37
  // alert("call first");
38
- var single_btn = document.getElementsByClassName("single_add_to_cart_button");
 
39
  if(single_btn.length > 0){
40
  single_btn[0].addEventListener("click", () => this.add_to_cart_click(variations_data, "Product Pages"));
41
  }
35
  }
36
  singleProductaddToCartEventBindings(variations_data){
37
  // alert("call first");
38
+ //var single_btn = document.getElementsByClassName("single_add_to_cart_button");
39
+ var single_btn = document.querySelectorAll("button[class*='btn-buy-shop'],button[class*='single_add_to_cart_button'], button[class*='add_to_cart']");
40
  if(single_btn.length > 0){
41
  single_btn[0].addEventListener("click", () => this.add_to_cart_click(variations_data, "Product Pages"));
42
  }
readme.txt CHANGED
@@ -6,10 +6,10 @@ Tags: Google Analytics tracking, Dynamic Remarketing, Google Shopping automation
6
  Author URI: https://conversios.io/
7
  Author: Tatvic
8
  Requires at least: 3.5.0
9
- Tested up to: 5.9
10
  Requires PHP: 5.6 or Higher
11
- Stable tag: 4.6.5
12
- Version: 4.6.5
13
  License: GPLv3
14
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
15
 
@@ -380,6 +380,11 @@ You can resolve the duplication of data by removing the manually implemented GA
380
 
381
  == Changelog ==
382
 
 
 
 
 
 
383
  = 4.6.5 - 16/02/2022 =
384
  * Fix - Fixed :- Onboarding loading issue for some users.
385
 
6
  Author URI: https://conversios.io/
7
  Author: Tatvic
8
  Requires at least: 3.5.0
9
+ Tested up to: 5.9.1
10
  Requires PHP: 5.6 or Higher
11
+ Stable tag: 4.6.6
12
+ Version: 4.6.6
13
  License: GPLv3
14
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
15
 
380
 
381
  == Changelog ==
382
 
383
+ = 4.6.6 - 03/03/2022 =
384
+ * New: In this release, we have Enhanced and optimized in Google Analytics tracking event.
385
+ * Tweak: Now, the admin user will be able to change the thank you page conversion tracking method while setting up the plugin under Google Analytics tab.
386
+ * Tweak: Plugin will no longer be supported for the woocommerce versions anything less than 2.8
387
+
388
  = 4.6.5 - 16/02/2022 =
389
  * Fix - Fixed :- Onboarding loading issue for some users.
390