Version Description
- 13/04/2017 =
- Fixed - Compatibility with Woocommerce 3.x
- Minor Bug Fixes.
Download this release
Release Info
Developer | Tatvic |
Plugin | Enhanced Ecommerce Google Analytics Plugin for WooCommerce |
Version | 1.0.20 |
Comparing to | |
See all releases |
Code changes from version 1.0.19 to 1.0.20
includes/class-wc-enhanced-ecommerce-google-analytics-integration.php
CHANGED
@@ -5,8 +5,8 @@
|
|
5 |
*
|
6 |
* Allows tracking code to be inserted into store pages.
|
7 |
*
|
8 |
-
* @class
|
9 |
-
* @extends
|
10 |
* @author Jigar Navadiya <jigar@tatvic.com>
|
11 |
*/
|
12 |
class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
@@ -18,19 +18,22 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
18 |
* @return void
|
19 |
*/
|
20 |
//set plugin version
|
21 |
-
public $tvc_eeVer = '1.0.
|
22 |
public function __construct() {
|
23 |
|
24 |
//Set Global Variables
|
25 |
global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,
|
26 |
-
$prodpage_json_ATC_link,$catpage_json_ATC_link;
|
27 |
-
|
28 |
//define plugin ID
|
29 |
$this->id = "enhanced_ecommerce_google_analytics";
|
30 |
$this->method_title = __("Enhanced Ecommerce Google Analytics", "enhanced-e-commerce-for-woocommerce-store");
|
31 |
-
$this->method_description = __("Enhanced Ecommerce is a new feature of Universal Analytics that generates detailed statistics about the users journey from product page to thank you page on your e-store. <br/><a href='http://www.tatvic.com/blog/enhanced-ecommerce/' target='_blank'>Know more about Enhanced Ecommerce.</a><br/><br/><b>Quick Tip:</b> We recently launched an Advanced Google Analytics Plugin for WooCommerce! The plugin offers tracking of 9 Reports of Enhanced Ecommerce, User ID Tracking, 15+ Custom Dimenensions & Metrics, Content Grouping & much more. <a href='
|
32 |
-
|
33 |
|
|
|
|
|
|
|
|
|
34 |
//session for product position count //session_start removed bcoz it gives warning
|
35 |
$_SESSION['t_npcnt']=0;
|
36 |
$_SESSION['t_fpcnt']=0;
|
@@ -50,12 +53,12 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
50 |
$this->ga_gUser = $this->get_option("ga_gUser") == "yes" ? true : false; //guest checkout
|
51 |
$this->ga_eeT = $this->get_option("ga_eeT");
|
52 |
$this->ga_DF = $this->get_option("ga_DF") == "yes" ? true : false;
|
53 |
-
$this->ga_imTh = $this->get_option("ga_imTh");
|
54 |
|
55 |
|
56 |
//Save Changes action for admin settings
|
57 |
add_action("woocommerce_update_options_integration_" . $this->id, array($this, "process_admin_options"));
|
58 |
-
|
59 |
// API Call to LS with e-mail
|
60 |
// Tracking code
|
61 |
add_action("wp_head", array($this, "ee_settings"));
|
@@ -75,12 +78,12 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
75 |
// Event tracking code
|
76 |
add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
|
77 |
|
78 |
-
|
79 |
add_action("admin_footer", array($this, "admin_check_UA_enabled"));
|
80 |
|
81 |
//add version details in footer
|
82 |
add_action("wp_footer", array($this, "add_plugin_details"));
|
83 |
-
|
84 |
//Add Dev ID
|
85 |
add_action("wp_head", array($this, "add_dev_id"), 1);
|
86 |
|
@@ -182,6 +185,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
182 |
*/
|
183 |
function wc_version_compare($codeSnippet) {
|
184 |
global $woocommerce;
|
|
|
185 |
if (version_compare($woocommerce->version, "2.1", ">=")) {
|
186 |
wc_enqueue_js($codeSnippet);
|
187 |
} else {
|
@@ -250,7 +254,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
250 |
"description" => __("Enter your Google Analytics ID here. You can login into your Google Analytics account to find your ID. e.g.<code>UA-XXXXX-X</code>", "woocommerce"),
|
251 |
"type" => "text",
|
252 |
"placeholder" => "UA-XXXXX-X",
|
253 |
-
"desc_tip"
|
254 |
"default" => get_option("ga_id") // Backwards compat
|
255 |
),
|
256 |
"ga_Dname" => array(
|
@@ -258,7 +262,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
258 |
"description" => sprintf(__("Enter your domain name here (Optional)")),
|
259 |
"type" => "text",
|
260 |
"placeholder" => "",
|
261 |
-
"desc_tip"
|
262 |
"default" => get_option("ga_Dname") ? get_option("ga_Dname") : "auto"
|
263 |
),
|
264 |
"ga_ST" => array(
|
@@ -267,7 +271,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
267 |
"description" => sprintf(__("This feature adds Universal Analytics Tracking Code to your Store. You don't need to enable this if using a 3rd party analytics plugin.", "woocommerce")),
|
268 |
"type" => "checkbox",
|
269 |
"checkboxgroup" => "start",
|
270 |
-
"desc_tip"
|
271 |
"default" => get_option("ga_ST") ? get_option("ga_ST") : "no" // Backwards compat
|
272 |
),
|
273 |
"ga_DF" => array(
|
@@ -281,7 +285,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
281 |
"label" => __("Add Enhanced Ecommerce Tracking Code", "woocommerce"),
|
282 |
"type" => "checkbox",
|
283 |
"checkboxgroup" => "",
|
284 |
-
"desc_tip"
|
285 |
"description" => sprintf(__("This feature adds Enhanced Ecommerce Tracking Code to your Store", "woocommerce")),
|
286 |
"default" => get_option("ga_eeT") ? get_option("ga_eeT") : "no" // Backwards compat
|
287 |
),
|
@@ -289,7 +293,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
289 |
"label" => __("Add Code to Track the Login Step of Guest Users (Optional)", "woocommerce"),
|
290 |
"type" => "checkbox",
|
291 |
"checkboxgroup" => "",
|
292 |
-
"desc_tip"
|
293 |
"description" => sprintf(__("If you have Guest Check out enable, we recommend you to add this code", "woocommerce")),
|
294 |
"default" => get_option("ga_gUser") ? get_option("ga_gUser") : "no" // Backwards compat
|
295 |
),
|
@@ -298,15 +302,15 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
298 |
"description" => sprintf(__("This feature sets Impression threshold for category page. It sends hit after these many numbers of products impressions", "woocommerce")),
|
299 |
"type" => "number",
|
300 |
"desc_tip" => true,
|
301 |
-
|
302 |
-
|
303 |
'min' => "1",
|
304 |
),
|
305 |
"default" => get_option("ga_imTh") ? get_option("ga_imTh") : "6" // Backwards compat
|
306 |
),
|
307 |
);
|
308 |
}
|
309 |
-
|
310 |
/**
|
311 |
* Google Analytics eCommerce tracking
|
312 |
*
|
@@ -363,13 +367,13 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
363 |
}
|
364 |
|
365 |
$code = '(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
|
370 |
-
|
371 |
' . $ga_display_feature_code . '
|
372 |
-
|
373 |
' . $ga_pageview . '
|
374 |
';
|
375 |
// Order items
|
@@ -381,7 +385,12 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
381 |
$categories=esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
|
382 |
} else {
|
383 |
$out = array();
|
384 |
-
|
|
|
|
|
|
|
|
|
|
|
385 |
if ($categories) {
|
386 |
foreach ($categories as $category) {
|
387 |
$out[] = $category->name;
|
@@ -391,7 +400,8 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
391 |
}
|
392 |
|
393 |
//orderpage Prod json
|
394 |
-
|
|
|
395 |
"tvc_id" => esc_html($_product->id),
|
396 |
"tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id),
|
397 |
"tvc_n" => esc_js($item["name"]),
|
@@ -399,6 +409,17 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
399 |
"tvc_c" => $categories,
|
400 |
"tvc_q"=>esc_js($item["qty"])
|
401 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
}
|
403 |
//make json for prod meta data on order page
|
404 |
$this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
|
@@ -414,10 +435,10 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
414 |
//orderpage transcation data json
|
415 |
$orderpage_trans_Array=array(
|
416 |
"id"=> esc_js($order->get_order_number()), // Transaction ID. Required
|
417 |
-
|
418 |
-
|
419 |
"tax"=> esc_js($order->get_total_tax()), // Tax
|
420 |
-
|
421 |
"coupon"=>$coupons_list
|
422 |
);
|
423 |
//make json for trans data on order page
|
@@ -433,16 +454,16 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
433 |
"category": tvc_oc[t_item].tvc_c,
|
434 |
"price": tvc_oc[t_item].tvc_p,
|
435 |
"quantity": tvc_oc[t_item].tvc_q,
|
436 |
-
|
437 |
}
|
438 |
ga("ec:setAction","purchase", {
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
"tax": tvc_td.tax,
|
443 |
-
|
444 |
"coupon": tvc_td.coupon
|
445 |
-
|
446 |
|
447 |
ga("send", "event", "Enhanced-Ecommerce","load", "order_confirmation", {"nonInteraction": 1});
|
448 |
';
|
@@ -464,8 +485,12 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
464 |
//return if not product page
|
465 |
if (!is_single())
|
466 |
return;
|
467 |
-
global $product;
|
468 |
-
|
|
|
|
|
|
|
|
|
469 |
$categories = "";
|
470 |
if ($category) {
|
471 |
foreach ($category as $term) {
|
@@ -490,8 +515,8 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
490 |
});
|
491 |
ga("ec:setAction", "add");
|
492 |
ga("send", "event", "Enhanced-Ecommerce","click", "add_to_cart_click", {"nonInteraction": 1});
|
493 |
-
|
494 |
-
|
495 |
//check woocommerce version
|
496 |
$this->wc_version_compare($code);
|
497 |
}
|
@@ -508,8 +533,12 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
508 |
return;
|
509 |
}
|
510 |
|
511 |
-
global $product;
|
512 |
-
|
|
|
|
|
|
|
|
|
513 |
$categories = "";
|
514 |
if ($category) {
|
515 |
foreach ($category as $term) {
|
@@ -519,13 +548,24 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
519 |
//remove last comma(,) if multiple categories are there
|
520 |
$categories = rtrim($categories, ",");
|
521 |
//product detail view json
|
522 |
-
$
|
|
|
523 |
"tvc_id" => esc_html($product->id),
|
524 |
"tvc_i" => $product->get_sku() ? $product->get_sku() : $product->id,
|
525 |
"tvc_n" => $product->get_title(),
|
526 |
"tvc_c" => $categories,
|
527 |
"tvc_p" => $product->get_price()
|
528 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
529 |
if (empty($prodpage_detail_json)) { //prod page array
|
530 |
$prodpage_detail_json = array();
|
531 |
}
|
@@ -556,13 +596,20 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
556 |
*/
|
557 |
public function bind_product_metadata() {
|
558 |
|
|
|
559 |
if ($this->disable_tracking($this->ga_eeT)) {
|
560 |
return;
|
561 |
}
|
562 |
|
563 |
-
global $product;
|
564 |
-
|
|
|
|
|
|
|
|
|
|
|
565 |
$categories = "";
|
|
|
566 |
if ($category) {
|
567 |
foreach ($category as $term) {
|
568 |
$categories.=$term->name . ",";
|
@@ -579,12 +626,18 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
579 |
$homepage_json_rp = array();
|
580 |
$homepage_json_ATC_link=array();
|
581 |
}
|
|
|
582 |
// ATC link Array
|
583 |
-
$
|
|
|
|
|
|
|
|
|
584 |
//check if product is featured product or not
|
585 |
if ($product->is_featured()) {
|
586 |
-
//check if product is already exists in homepage featured json
|
587 |
-
if(
|
|
|
588 |
$homepage_json_fp[get_permalink($product->id)] = array(
|
589 |
"tvc_id" => esc_html($product->id),
|
590 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
@@ -605,9 +658,34 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
605 |
"tvc_c" => esc_html($categories)
|
606 |
);
|
607 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
608 |
} else {
|
609 |
-
//else prod add in homepage recent json
|
610 |
-
|
|
|
611 |
"tvc_id" => esc_html($product->id),
|
612 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
613 |
"tvc_n" => esc_html($product->get_title()),
|
@@ -615,6 +693,17 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
615 |
"tvc_po" => ++$_SESSION['t_npcnt'],
|
616 |
"tvc_c" => esc_html($categories)
|
617 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
618 |
}
|
619 |
}
|
620 |
//if product page then related product page array
|
@@ -622,10 +711,11 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
622 |
if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
|
623 |
$prodpage_json_relProd = array();
|
624 |
$prodpage_json_ATC_link = array();
|
625 |
-
|
626 |
-
|
|
|
627 |
$prodpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
|
628 |
-
|
629 |
$prodpage_json_relProd[get_permalink($product->id)] = array(
|
630 |
"tvc_id" => esc_html($product->id),
|
631 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
@@ -634,6 +724,20 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
634 |
"tvc_c" => esc_html($categories),
|
635 |
"tvc_po" => ++$_SESSION['t_npcnt'],
|
636 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
}
|
638 |
//category page, search page and shop page json
|
639 |
else if (is_product_category() || is_search() || is_shop()) {
|
@@ -642,9 +746,10 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
642 |
$catpage_json_ATC_link=array();
|
643 |
}
|
644 |
//cat page ATC array
|
645 |
-
$
|
646 |
-
|
647 |
-
|
|
|
648 |
"tvc_id" => esc_html($product->id),
|
649 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
650 |
"tvc_n" => esc_html($product->get_title()),
|
@@ -652,6 +757,20 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
652 |
"tvc_c" => esc_html($categories),
|
653 |
"tvc_po" => ++$_SESSION['t_npcnt'],
|
654 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
655 |
}
|
656 |
}
|
657 |
|
@@ -665,9 +784,10 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
665 |
if ($this->disable_tracking($this->ga_eeT)) {
|
666 |
return;
|
667 |
}
|
|
|
668 |
//get impression threshold
|
669 |
$impression_threshold = $this->ga_imTh;
|
670 |
-
|
671 |
//Product impression on Home Page
|
672 |
global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
|
673 |
//home page json for featured products and recent product sections
|
@@ -708,16 +828,16 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
708 |
$hmpg_impressions_jQ = '
|
709 |
ga("require", "ec", "ec.js");
|
710 |
ga("set", "&cu", tvc_lc);
|
711 |
-
|
712 |
t_send_threshold=0;
|
713 |
t_prod_pos=0;
|
714 |
|
715 |
t_json_length=Object.keys(t_json_name).length
|
716 |
|
717 |
for(var t_item in t_json_name) {
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
ga("ec:addImpression", {
|
722 |
"id": t_json_name[t_item].tvc_i,
|
723 |
"name": t_json_name[t_item].tvc_n,
|
@@ -726,8 +846,8 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
726 |
"price": t_json_name[t_item].tvc_p,
|
727 |
"position": t_json_name[t_item].tvc_po,
|
728 |
});
|
729 |
-
|
730 |
-
|
731 |
if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
|
732 |
t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
|
733 |
ga("send", "event", "Enhanced-Ecommerce","load","product_impression_"+t_action , {"nonInteraction": 1});
|
@@ -738,28 +858,28 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
738 |
if(t_json_length==0){
|
739 |
ga("send", "event", "Enhanced-Ecommerce","load", "product_impression_"+t_action, {"nonInteraction": 1});
|
740 |
}
|
741 |
-
|
742 |
}
|
743 |
-
|
744 |
|
745 |
-
|
746 |
-
|
747 |
if(t_json_name.hasOwnProperty(t_url)){
|
748 |
t_call_fired=true;
|
749 |
-
|
750 |
-
|
751 |
"name": t_json_name[t_url].tvc_n,
|
752 |
"category": t_json_name[t_url].tvc_c,
|
753 |
"price": t_json_name[t_url].tvc_p,
|
754 |
"position": t_json_name[t_url].tvc_po,
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
}else{
|
759 |
t_call_fired=false;
|
760 |
-
|
761 |
return t_call_fired;
|
762 |
-
|
763 |
function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
|
764 |
t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
|
765 |
|
@@ -777,7 +897,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
777 |
ga("send", "event", "Enhanced-Ecommerce","click", "add_to_cart_click",{"nonInteraction": 1});
|
778 |
}else{
|
779 |
t_call_fired=false;
|
780 |
-
|
781 |
return t_call_fired;
|
782 |
|
783 |
}
|
@@ -786,13 +906,13 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
786 |
if(is_home() || is_front_page()){
|
787 |
$hmpg_impressions_jQ .='
|
788 |
if(tvc_fp.length !== 0){
|
789 |
-
t_products_impre_clicks(tvc_fp,"fp","Featured Products");
|
790 |
}
|
791 |
if(tvc_rcp.length !== 0){
|
792 |
-
t_products_impre_clicks(tvc_rcp,"rp","Recent Products");
|
793 |
}
|
794 |
jQuery("a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped)").on("click",function(){
|
795 |
-
|
796 |
//home page call for click
|
797 |
t_call_fired=prod_exists_in_JSON(t_url,tvc_fp,"Featured Products","fp");
|
798 |
if(!t_call_fired){
|
@@ -801,7 +921,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
801 |
});
|
802 |
//ATC click
|
803 |
jQuery("a[href*=add-to-cart]").on("click",function(){
|
804 |
-
|
805 |
t_qty=$(this).parent().find("input[name=quantity]").val();
|
806 |
//default quantity 1 if quantity box is not there
|
807 |
if(t_qty=="" || t_qty===undefined){
|
@@ -816,24 +936,23 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
816 |
';
|
817 |
}else if(is_search()){
|
818 |
$hmpg_impressions_jQ .='
|
819 |
-
//
|
820 |
if(tvc_pgc.length !== 0){
|
821 |
t_products_impre_clicks(tvc_pgc,"srch","Search Results");
|
822 |
}
|
823 |
-
//
|
824 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
825 |
t_url=jQuery(this).attr("href");
|
826 |
//cat page prod call for click
|
827 |
prod_exists_in_JSON(t_url,catpage_json,"Search Results","srch");
|
828 |
});
|
829 |
|
830 |
-
|
831 |
-
';
|
832 |
}else if (is_product()) {
|
833 |
//product page releted products
|
834 |
$hmpg_impressions_jQ .='
|
835 |
if(tvc_rdp.length !== 0){
|
836 |
-
t_products_impre_clicks(tvc_rdp,"rdp","Related Products");
|
837 |
}
|
838 |
//product click - image and product name
|
839 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
@@ -843,7 +962,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
843 |
});
|
844 |
//Prod ATC link click in related product section
|
845 |
jQuery("a[href*=add-to-cart]").on("click",function(){
|
846 |
-
|
847 |
t_qty=$(this).parent().find("input[name=quantity]").val();
|
848 |
//default quantity 1 if quantity box is not there
|
849 |
if(t_qty=="" || t_qty===undefined){
|
@@ -856,7 +975,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
856 |
$hmpg_impressions_jQ .='
|
857 |
//category page json
|
858 |
if(tvc_pgc.length !== 0){
|
859 |
-
t_products_impre_clicks(tvc_pgc,"cp","Category Page");
|
860 |
}
|
861 |
//Prod category ATC link click in related product section
|
862 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
@@ -870,7 +989,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
870 |
$hmpg_impressions_jQ .='
|
871 |
//shop page json
|
872 |
if(tvc_pgc.length !== 0){
|
873 |
-
t_products_impre_clicks(tvc_pgc,"sp","Shop Page");
|
874 |
}
|
875 |
//shop page prod click
|
876 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
@@ -887,7 +1006,7 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
887 |
$hmpg_impressions_jQ .='
|
888 |
//ATC link click
|
889 |
jQuery("a[href*=add-to-cart]").on("click",function(){
|
890 |
-
|
891 |
t_qty=$(this).parent().find("input[name=quantity]").val();
|
892 |
//default quantity 1 if quantity box is not there
|
893 |
if(t_qty=="" || t_qty===undefined){
|
@@ -918,8 +1037,13 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
918 |
$cartpage_prod_array_main = array();
|
919 |
//echo "<pre>".print_r($woocommerce->cart->cart_contents,TRUE)."</pre>";
|
920 |
foreach ($woocommerce->cart->cart_contents as $key => $item) {
|
921 |
-
|
922 |
-
|
|
|
|
|
|
|
|
|
|
|
923 |
$cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
|
924 |
|
925 |
$category = get_the_terms($item["product_id"], "product_cat");
|
@@ -931,15 +1055,25 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
931 |
}
|
932 |
//remove last comma(,) if multiple categories are there
|
933 |
$categories = rtrim($categories, ",");
|
934 |
-
$
|
|
|
935 |
"tvc_id" => esc_html($prod_meta->id),
|
936 |
"tvc_i" => esc_html($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->id),
|
937 |
"tvc_n" => esc_html($prod_meta->get_title()),
|
938 |
"tvc_p" => esc_html($prod_meta->get_price()),
|
939 |
"tvc_c" => esc_html($categories),
|
940 |
"tvc_q"=>$woocommerce->cart->cart_contents[$key]["quantity"]
|
941 |
-
|
942 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
943 |
}
|
944 |
|
945 |
//Cart Page item Array to Json
|
@@ -982,14 +1116,14 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
982 |
ga("require", "ec", "ec.js");
|
983 |
ga("set", "&cu", tvc_lc);
|
984 |
for(var t_item in tvc_ch){
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
|
994 |
$code_step_1 = $code . 'ga("ec:setAction","checkout",{"step": 1});';
|
995 |
$code_step_1 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_1",{"nonInteraction": 1});';
|
@@ -1011,14 +1145,14 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
1011 |
$code= '
|
1012 |
|
1013 |
for(var t_item in tvc_ch){
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
|
1023 |
$code_step_2 = $code . 'ga("ec:setAction","checkout",{"step": 2});';
|
1024 |
$code_step_2 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_2",{"nonInteraction": 1});';
|
@@ -1046,14 +1180,14 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
1046 |
}
|
1047 |
$code= '
|
1048 |
for(var t_item in tvc_ch){
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
|
1058 |
//check if guest check out is enabled or not
|
1059 |
$step_2_on_proceed_to_pay = (!is_user_logged_in() && !$this->ga_gCkout ) || (!is_user_logged_in() && $this->ga_gCkout && $this->ga_gUser);
|
@@ -1084,7 +1218,12 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
1084 |
$code = "";
|
1085 |
//get all items added into the cart
|
1086 |
foreach ($woocommerce->cart->cart_contents as $item) {
|
1087 |
-
|
|
|
|
|
|
|
|
|
|
|
1088 |
|
1089 |
$category = get_the_terms($item["product_id"], "product_cat");
|
1090 |
$categories = "";
|
@@ -1095,7 +1234,8 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
1095 |
}
|
1096 |
//remove last comma(,) if multiple categories are there
|
1097 |
$categories = rtrim($categories, ",");
|
1098 |
-
|
|
|
1099 |
"tvc_id" => esc_html($p->id),
|
1100 |
"tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->id),
|
1101 |
"tvc_n" => esc_js($p->get_title()),
|
@@ -1103,7 +1243,19 @@ class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
|
1103 |
"tvc_c" => $categories,
|
1104 |
"tvc_q" => esc_js($item["quantity"]),
|
1105 |
"isfeatured"=>$p->is_featured()
|
1106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1107 |
}
|
1108 |
//return $code;
|
1109 |
//make product data json on check out page
|
5 |
*
|
6 |
* Allows tracking code to be inserted into store pages.
|
7 |
*
|
8 |
+
* @class WC_Enhanced_Ecommerce_Google_Analytics
|
9 |
+
* @extends WC_Integration
|
10 |
* @author Jigar Navadiya <jigar@tatvic.com>
|
11 |
*/
|
12 |
class WC_Enhanced_Ecommerce_Google_Analytics extends WC_Integration {
|
18 |
* @return void
|
19 |
*/
|
20 |
//set plugin version
|
21 |
+
public $tvc_eeVer = '1.0.20';
|
22 |
public function __construct() {
|
23 |
|
24 |
//Set Global Variables
|
25 |
global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,
|
26 |
+
$prodpage_json_ATC_link,$catpage_json_ATC_link,$woocommerce;
|
27 |
+
if (version_compare($woocommerce->version, "2.1", ">="))
|
28 |
//define plugin ID
|
29 |
$this->id = "enhanced_ecommerce_google_analytics";
|
30 |
$this->method_title = __("Enhanced Ecommerce Google Analytics", "enhanced-e-commerce-for-woocommerce-store");
|
31 |
+
$this->method_description = __("Enhanced Ecommerce is a new feature of Universal Analytics that generates detailed statistics about the users journey from product page to thank you page on your e-store. <br/><a href='http://www.tatvic.com/blog/enhanced-ecommerce/' target='_blank'>Know more about Enhanced Ecommerce.</a><br/><br/><b>Quick Tip:</b> We recently launched an Advanced Google Analytics Plugin for WooCommerce! The plugin offers tracking of 9 Reports of Enhanced Ecommerce, User ID Tracking, 15+ Custom Dimenensions & Metrics, Content Grouping & much more. <a href='https://codecanyon.net/item/actionable-google-analytics-for-woocommerce/9899552' target='_blank'>Learn More</a>", "woocommerce");
|
|
|
32 |
|
33 |
+
if(!isset($_SESSION) )
|
34 |
+
{
|
35 |
+
session_start();
|
36 |
+
}
|
37 |
//session for product position count //session_start removed bcoz it gives warning
|
38 |
$_SESSION['t_npcnt']=0;
|
39 |
$_SESSION['t_fpcnt']=0;
|
53 |
$this->ga_gUser = $this->get_option("ga_gUser") == "yes" ? true : false; //guest checkout
|
54 |
$this->ga_eeT = $this->get_option("ga_eeT");
|
55 |
$this->ga_DF = $this->get_option("ga_DF") == "yes" ? true : false;
|
56 |
+
$this->ga_imTh = $this->get_option("ga_imTh") == "" ? 6 : $this->get_option("ga_imTh");
|
57 |
|
58 |
|
59 |
//Save Changes action for admin settings
|
60 |
add_action("woocommerce_update_options_integration_" . $this->id, array($this, "process_admin_options"));
|
61 |
+
|
62 |
// API Call to LS with e-mail
|
63 |
// Tracking code
|
64 |
add_action("wp_head", array($this, "ee_settings"));
|
78 |
// Event tracking code
|
79 |
add_action("woocommerce_after_add_to_cart_button", array($this, "add_to_cart"));
|
80 |
|
81 |
+
//Enable display feature code checkbox
|
82 |
add_action("admin_footer", array($this, "admin_check_UA_enabled"));
|
83 |
|
84 |
//add version details in footer
|
85 |
add_action("wp_footer", array($this, "add_plugin_details"));
|
86 |
+
|
87 |
//Add Dev ID
|
88 |
add_action("wp_head", array($this, "add_dev_id"), 1);
|
89 |
|
185 |
*/
|
186 |
function wc_version_compare($codeSnippet) {
|
187 |
global $woocommerce;
|
188 |
+
|
189 |
if (version_compare($woocommerce->version, "2.1", ">=")) {
|
190 |
wc_enqueue_js($codeSnippet);
|
191 |
} else {
|
254 |
"description" => __("Enter your Google Analytics ID here. You can login into your Google Analytics account to find your ID. e.g.<code>UA-XXXXX-X</code>", "woocommerce"),
|
255 |
"type" => "text",
|
256 |
"placeholder" => "UA-XXXXX-X",
|
257 |
+
"desc_tip" => true,
|
258 |
"default" => get_option("ga_id") // Backwards compat
|
259 |
),
|
260 |
"ga_Dname" => array(
|
262 |
"description" => sprintf(__("Enter your domain name here (Optional)")),
|
263 |
"type" => "text",
|
264 |
"placeholder" => "",
|
265 |
+
"desc_tip" => true,
|
266 |
"default" => get_option("ga_Dname") ? get_option("ga_Dname") : "auto"
|
267 |
),
|
268 |
"ga_ST" => array(
|
271 |
"description" => sprintf(__("This feature adds Universal Analytics Tracking Code to your Store. You don't need to enable this if using a 3rd party analytics plugin.", "woocommerce")),
|
272 |
"type" => "checkbox",
|
273 |
"checkboxgroup" => "start",
|
274 |
+
"desc_tip" => true,
|
275 |
"default" => get_option("ga_ST") ? get_option("ga_ST") : "no" // Backwards compat
|
276 |
),
|
277 |
"ga_DF" => array(
|
285 |
"label" => __("Add Enhanced Ecommerce Tracking Code", "woocommerce"),
|
286 |
"type" => "checkbox",
|
287 |
"checkboxgroup" => "",
|
288 |
+
"desc_tip" => true,
|
289 |
"description" => sprintf(__("This feature adds Enhanced Ecommerce Tracking Code to your Store", "woocommerce")),
|
290 |
"default" => get_option("ga_eeT") ? get_option("ga_eeT") : "no" // Backwards compat
|
291 |
),
|
293 |
"label" => __("Add Code to Track the Login Step of Guest Users (Optional)", "woocommerce"),
|
294 |
"type" => "checkbox",
|
295 |
"checkboxgroup" => "",
|
296 |
+
"desc_tip" => true,
|
297 |
"description" => sprintf(__("If you have Guest Check out enable, we recommend you to add this code", "woocommerce")),
|
298 |
"default" => get_option("ga_gUser") ? get_option("ga_gUser") : "no" // Backwards compat
|
299 |
),
|
302 |
"description" => sprintf(__("This feature sets Impression threshold for category page. It sends hit after these many numbers of products impressions", "woocommerce")),
|
303 |
"type" => "number",
|
304 |
"desc_tip" => true,
|
305 |
+
"css"=>"width:112px !important;",
|
306 |
+
'custom_attributes' => array(
|
307 |
'min' => "1",
|
308 |
),
|
309 |
"default" => get_option("ga_imTh") ? get_option("ga_imTh") : "6" // Backwards compat
|
310 |
),
|
311 |
);
|
312 |
}
|
313 |
+
|
314 |
/**
|
315 |
* Google Analytics eCommerce tracking
|
316 |
*
|
367 |
}
|
368 |
|
369 |
$code = '(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
|
370 |
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
371 |
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
372 |
+
})(window,document,"script","//www.google-analytics.com/analytics.js","ga");
|
373 |
|
374 |
+
ga("create", "' . esc_js($tracking_id) . '", "' . $set_domain_name . '");
|
375 |
' . $ga_display_feature_code . '
|
376 |
+
ga("require", "ec", "ec.js");
|
377 |
' . $ga_pageview . '
|
378 |
';
|
379 |
// Order items
|
385 |
$categories=esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
|
386 |
} else {
|
387 |
$out = array();
|
388 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
389 |
+
$categories = get_the_terms($_product->id, "product_cat");
|
390 |
+
}else{
|
391 |
+
$categories = get_the_terms($_product->get_id(), "product_cat");
|
392 |
+
}
|
393 |
+
|
394 |
if ($categories) {
|
395 |
foreach ($categories as $category) {
|
396 |
$out[] = $category->name;
|
400 |
}
|
401 |
|
402 |
//orderpage Prod json
|
403 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
404 |
+
$orderpage_prod_Array[get_permalink($_product->id)]=array(
|
405 |
"tvc_id" => esc_html($_product->id),
|
406 |
"tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id),
|
407 |
"tvc_n" => esc_js($item["name"]),
|
409 |
"tvc_c" => $categories,
|
410 |
"tvc_q"=>esc_js($item["qty"])
|
411 |
);
|
412 |
+
}else{
|
413 |
+
$orderpage_prod_Array[get_permalink($_product->get_id())]=array(
|
414 |
+
"tvc_id" => esc_html($_product->get_id()),
|
415 |
+
"tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
|
416 |
+
"tvc_n" => esc_js($item["name"]),
|
417 |
+
"tvc_p" => esc_js($order->get_item_total($item)),
|
418 |
+
"tvc_c" => $categories,
|
419 |
+
"tvc_q"=>esc_js($item["qty"])
|
420 |
+
);
|
421 |
+
}
|
422 |
+
|
423 |
}
|
424 |
//make json for prod meta data on order page
|
425 |
$this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
|
435 |
//orderpage transcation data json
|
436 |
$orderpage_trans_Array=array(
|
437 |
"id"=> esc_js($order->get_order_number()), // Transaction ID. Required
|
438 |
+
"affiliation"=> esc_js(get_bloginfo('name')), // Affiliation or store name
|
439 |
+
"revenue"=>esc_js($order->get_total()), // Grand Total
|
440 |
"tax"=> esc_js($order->get_total_tax()), // Tax
|
441 |
+
"shipping"=> esc_js($tvc_sc), // Shipping
|
442 |
"coupon"=>$coupons_list
|
443 |
);
|
444 |
//make json for trans data on order page
|
454 |
"category": tvc_oc[t_item].tvc_c,
|
455 |
"price": tvc_oc[t_item].tvc_p,
|
456 |
"quantity": tvc_oc[t_item].tvc_q,
|
457 |
+
});
|
458 |
}
|
459 |
ga("ec:setAction","purchase", {
|
460 |
+
"id": tvc_td.id,
|
461 |
+
"affiliation": tvc_td.affiliation,
|
462 |
+
"revenue": tvc_td.revenue,
|
463 |
"tax": tvc_td.tax,
|
464 |
+
"shipping": tvc_td.shipping,
|
465 |
"coupon": tvc_td.coupon
|
466 |
+
});
|
467 |
|
468 |
ga("send", "event", "Enhanced-Ecommerce","load", "order_confirmation", {"nonInteraction": 1});
|
469 |
';
|
485 |
//return if not product page
|
486 |
if (!is_single())
|
487 |
return;
|
488 |
+
global $product,$woocommerce;
|
489 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
490 |
+
$category = get_the_terms($product->ID, "product_cat");
|
491 |
+
}else{
|
492 |
+
$category = get_the_terms($product->get_id(), "product_cat");
|
493 |
+
}
|
494 |
$categories = "";
|
495 |
if ($category) {
|
496 |
foreach ($category as $term) {
|
515 |
});
|
516 |
ga("ec:setAction", "add");
|
517 |
ga("send", "event", "Enhanced-Ecommerce","click", "add_to_cart_click", {"nonInteraction": 1});
|
518 |
+
});
|
519 |
+
';
|
520 |
//check woocommerce version
|
521 |
$this->wc_version_compare($code);
|
522 |
}
|
533 |
return;
|
534 |
}
|
535 |
|
536 |
+
global $product,$woocommerce;
|
537 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
538 |
+
$category = get_the_terms($product->ID, "product_cat");
|
539 |
+
}else{
|
540 |
+
$category = get_the_terms($product->get_id(), "product_cat");
|
541 |
+
}
|
542 |
$categories = "";
|
543 |
if ($category) {
|
544 |
foreach ($category as $term) {
|
548 |
//remove last comma(,) if multiple categories are there
|
549 |
$categories = rtrim($categories, ",");
|
550 |
//product detail view json
|
551 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
552 |
+
$prodpage_detail_json = array(
|
553 |
"tvc_id" => esc_html($product->id),
|
554 |
"tvc_i" => $product->get_sku() ? $product->get_sku() : $product->id,
|
555 |
"tvc_n" => $product->get_title(),
|
556 |
"tvc_c" => $categories,
|
557 |
"tvc_p" => $product->get_price()
|
558 |
);
|
559 |
+
}else{
|
560 |
+
$prodpage_detail_json = array(
|
561 |
+
"tvc_id" => esc_html($product->get_id()),
|
562 |
+
"tvc_i" => $product->get_sku() ? $product->get_sku() : $product->get_id(),
|
563 |
+
"tvc_n" => $product->get_title(),
|
564 |
+
"tvc_c" => $categories,
|
565 |
+
"tvc_p" => $product->get_price()
|
566 |
+
);
|
567 |
+
}
|
568 |
+
|
569 |
if (empty($prodpage_detail_json)) { //prod page array
|
570 |
$prodpage_detail_json = array();
|
571 |
}
|
596 |
*/
|
597 |
public function bind_product_metadata() {
|
598 |
|
599 |
+
|
600 |
if ($this->disable_tracking($this->ga_eeT)) {
|
601 |
return;
|
602 |
}
|
603 |
|
604 |
+
global $product,$woocommerce;
|
605 |
+
if (version_compare($woocommerce->version, "2.4", "<=")) {
|
606 |
+
$category = get_the_terms($product->Id, "product_cat");
|
607 |
+
} else {
|
608 |
+
$category = get_the_terms($product->get_id(), "product_cat");
|
609 |
+
}
|
610 |
+
|
611 |
$categories = "";
|
612 |
+
|
613 |
if ($category) {
|
614 |
foreach ($category as $term) {
|
615 |
$categories.=$term->name . ",";
|
626 |
$homepage_json_rp = array();
|
627 |
$homepage_json_ATC_link=array();
|
628 |
}
|
629 |
+
|
630 |
// ATC link Array
|
631 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
632 |
+
$homepage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
|
633 |
+
}else{
|
634 |
+
$homepage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->get_id()));
|
635 |
+
}
|
636 |
//check if product is featured product or not
|
637 |
if ($product->is_featured()) {
|
638 |
+
//check if product is already exists in homepage featured json
|
639 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
640 |
+
if(!array_key_exists(get_permalink($product->id),$homepage_json_fp)){
|
641 |
$homepage_json_fp[get_permalink($product->id)] = array(
|
642 |
"tvc_id" => esc_html($product->id),
|
643 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
658 |
"tvc_c" => esc_html($categories)
|
659 |
);
|
660 |
}
|
661 |
+
}else{
|
662 |
+
if(!array_key_exists(get_permalink($product->get_id()),$homepage_json_fp)){
|
663 |
+
$homepage_json_fp[get_permalink($product->get_id())] = array(
|
664 |
+
"tvc_id" => esc_html($product->get_id()),
|
665 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
666 |
+
"tvc_n" => esc_html($product->get_title()),
|
667 |
+
"tvc_n" => esc_html($product->get_price()),
|
668 |
+
"tvc_c" => esc_html($categories),
|
669 |
+
"tvc_po" => ++$_SESSION['t_fpcnt'],
|
670 |
+
"ATC-link"=>$product->add_to_cart_url()
|
671 |
+
);
|
672 |
+
//else add product in homepage recent product json
|
673 |
+
}else {
|
674 |
+
$homepage_json_rp[get_permalink($product->get_id())] =array(
|
675 |
+
"tvc_id" => esc_html($product->get_id()),
|
676 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
677 |
+
"tvc_n" => esc_html($product->get_title()),
|
678 |
+
"tvc_p" => esc_html($product->get_price()),
|
679 |
+
"tvc_po" => ++$_SESSION['t_npcnt'],
|
680 |
+
"tvc_c" => esc_html($categories)
|
681 |
+
);
|
682 |
+
}
|
683 |
+
}
|
684 |
+
|
685 |
} else {
|
686 |
+
//else prod add in homepage recent json
|
687 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
688 |
+
$homepage_json_rp[get_permalink($product->id)] =array(
|
689 |
"tvc_id" => esc_html($product->id),
|
690 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
691 |
"tvc_n" => esc_html($product->get_title()),
|
693 |
"tvc_po" => ++$_SESSION['t_npcnt'],
|
694 |
"tvc_c" => esc_html($categories)
|
695 |
);
|
696 |
+
}else{
|
697 |
+
$homepage_json_rp[get_permalink($product->get_id())] =array(
|
698 |
+
"tvc_id" => esc_html($product->get_id()),
|
699 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
700 |
+
"tvc_n" => esc_html($product->get_title()),
|
701 |
+
"tvc_p" => esc_html($product->get_price()),
|
702 |
+
"tvc_po" => ++$_SESSION['t_npcnt'],
|
703 |
+
"tvc_c" => esc_html($categories)
|
704 |
+
);
|
705 |
+
}
|
706 |
+
|
707 |
}
|
708 |
}
|
709 |
//if product page then related product page array
|
711 |
if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
|
712 |
$prodpage_json_relProd = array();
|
713 |
$prodpage_json_ATC_link = array();
|
714 |
+
}
|
715 |
+
// ATC link Array
|
716 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
717 |
$prodpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
|
718 |
+
|
719 |
$prodpage_json_relProd[get_permalink($product->id)] = array(
|
720 |
"tvc_id" => esc_html($product->id),
|
721 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
724 |
"tvc_c" => esc_html($categories),
|
725 |
"tvc_po" => ++$_SESSION['t_npcnt'],
|
726 |
);
|
727 |
+
}else{
|
728 |
+
$prodpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->get_id()));
|
729 |
+
|
730 |
+
$prodpage_json_relProd[get_permalink($product->get_id())] = array(
|
731 |
+
"tvc_id" => esc_html($product->get_id()),
|
732 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
733 |
+
"tvc_n" => esc_html($product->get_title()),
|
734 |
+
"tvc_p" => esc_html($product->get_price()),
|
735 |
+
"tvc_po" => ++$_SESSION['t_npcnt'],
|
736 |
+
"tvc_c" => esc_html($categories)
|
737 |
+
|
738 |
+
);
|
739 |
+
}
|
740 |
+
|
741 |
}
|
742 |
//category page, search page and shop page json
|
743 |
else if (is_product_category() || is_search() || is_shop()) {
|
746 |
$catpage_json_ATC_link=array();
|
747 |
}
|
748 |
//cat page ATC array
|
749 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
750 |
+
$catpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
|
751 |
+
|
752 |
+
$catpage_json[get_permalink($product->id)] =array(
|
753 |
"tvc_id" => esc_html($product->id),
|
754 |
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
755 |
"tvc_n" => esc_html($product->get_title()),
|
757 |
"tvc_c" => esc_html($categories),
|
758 |
"tvc_po" => ++$_SESSION['t_npcnt'],
|
759 |
);
|
760 |
+
}else{
|
761 |
+
$catpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->get_id()));
|
762 |
+
|
763 |
+
$catpage_json[get_permalink($product->get_id())] =array(
|
764 |
+
"tvc_id" => esc_html($product->get_id()),
|
765 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
766 |
+
"tvc_n" => esc_html($product->get_title()),
|
767 |
+
"tvc_p" => esc_html($product->get_price()),
|
768 |
+
"tvc_po" => ++$_SESSION['t_npcnt'],
|
769 |
+
"tvc_c" => esc_html($categories)
|
770 |
+
|
771 |
+
);
|
772 |
+
}
|
773 |
+
|
774 |
}
|
775 |
}
|
776 |
|
784 |
if ($this->disable_tracking($this->ga_eeT)) {
|
785 |
return;
|
786 |
}
|
787 |
+
|
788 |
//get impression threshold
|
789 |
$impression_threshold = $this->ga_imTh;
|
790 |
+
|
791 |
//Product impression on Home Page
|
792 |
global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
|
793 |
//home page json for featured products and recent product sections
|
828 |
$hmpg_impressions_jQ = '
|
829 |
ga("require", "ec", "ec.js");
|
830 |
ga("set", "&cu", tvc_lc);
|
831 |
+
function t_products_impre_clicks(t_json_name,t_action,t_list){
|
832 |
t_send_threshold=0;
|
833 |
t_prod_pos=0;
|
834 |
|
835 |
t_json_length=Object.keys(t_json_name).length
|
836 |
|
837 |
for(var t_item in t_json_name) {
|
838 |
+
t_send_threshold++;
|
839 |
+
t_prod_pos++;
|
840 |
+
|
841 |
ga("ec:addImpression", {
|
842 |
"id": t_json_name[t_item].tvc_i,
|
843 |
"name": t_json_name[t_item].tvc_n,
|
846 |
"price": t_json_name[t_item].tvc_p,
|
847 |
"position": t_json_name[t_item].tvc_po,
|
848 |
});
|
849 |
+
|
850 |
+
if(t_json_length > ' . esc_js($impression_threshold) .' ){
|
851 |
if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
|
852 |
t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
|
853 |
ga("send", "event", "Enhanced-Ecommerce","load","product_impression_"+t_action , {"nonInteraction": 1});
|
858 |
if(t_json_length==0){
|
859 |
ga("send", "event", "Enhanced-Ecommerce","load", "product_impression_"+t_action, {"nonInteraction": 1});
|
860 |
}
|
861 |
+
}
|
862 |
}
|
863 |
+
}
|
864 |
|
865 |
+
//function for comparing urls in json object
|
866 |
+
function prod_exists_in_JSON(t_url,t_json_name,t_list,t_action){
|
867 |
if(t_json_name.hasOwnProperty(t_url)){
|
868 |
t_call_fired=true;
|
869 |
+
ga("ec:addProduct", {
|
870 |
+
"id": t_json_name[t_url].tvc_i,
|
871 |
"name": t_json_name[t_url].tvc_n,
|
872 |
"category": t_json_name[t_url].tvc_c,
|
873 |
"price": t_json_name[t_url].tvc_p,
|
874 |
"position": t_json_name[t_url].tvc_po,
|
875 |
+
});
|
876 |
+
ga("ec:setAction", "click", {"list": t_list});
|
877 |
+
ga("send", "event", "Enhanced-Ecommerce","click", "product_click_"+t_action, {"nonInteraction": 1});
|
878 |
}else{
|
879 |
t_call_fired=false;
|
880 |
+
}
|
881 |
return t_call_fired;
|
882 |
+
}
|
883 |
function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
|
884 |
t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
|
885 |
|
897 |
ga("send", "event", "Enhanced-Ecommerce","click", "add_to_cart_click",{"nonInteraction": 1});
|
898 |
}else{
|
899 |
t_call_fired=false;
|
900 |
+
}
|
901 |
return t_call_fired;
|
902 |
|
903 |
}
|
906 |
if(is_home() || is_front_page()){
|
907 |
$hmpg_impressions_jQ .='
|
908 |
if(tvc_fp.length !== 0){
|
909 |
+
t_products_impre_clicks(tvc_fp,"fp","Featured Products");
|
910 |
}
|
911 |
if(tvc_rcp.length !== 0){
|
912 |
+
t_products_impre_clicks(tvc_rcp,"rp","Recent Products");
|
913 |
}
|
914 |
jQuery("a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped)").on("click",function(){
|
915 |
+
t_url=jQuery(this).attr("href");
|
916 |
//home page call for click
|
917 |
t_call_fired=prod_exists_in_JSON(t_url,tvc_fp,"Featured Products","fp");
|
918 |
if(!t_call_fired){
|
921 |
});
|
922 |
//ATC click
|
923 |
jQuery("a[href*=add-to-cart]").on("click",function(){
|
924 |
+
t_url=jQuery(this).attr("href");
|
925 |
t_qty=$(this).parent().find("input[name=quantity]").val();
|
926 |
//default quantity 1 if quantity box is not there
|
927 |
if(t_qty=="" || t_qty===undefined){
|
936 |
';
|
937 |
}else if(is_search()){
|
938 |
$hmpg_impressions_jQ .='
|
939 |
+
//search page json
|
940 |
if(tvc_pgc.length !== 0){
|
941 |
t_products_impre_clicks(tvc_pgc,"srch","Search Results");
|
942 |
}
|
943 |
+
//search page prod click
|
944 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
945 |
t_url=jQuery(this).attr("href");
|
946 |
//cat page prod call for click
|
947 |
prod_exists_in_JSON(t_url,catpage_json,"Search Results","srch");
|
948 |
});
|
949 |
|
950 |
+
';
|
|
|
951 |
}else if (is_product()) {
|
952 |
//product page releted products
|
953 |
$hmpg_impressions_jQ .='
|
954 |
if(tvc_rdp.length !== 0){
|
955 |
+
t_products_impre_clicks(tvc_rdp,"rdp","Related Products");
|
956 |
}
|
957 |
//product click - image and product name
|
958 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
962 |
});
|
963 |
//Prod ATC link click in related product section
|
964 |
jQuery("a[href*=add-to-cart]").on("click",function(){
|
965 |
+
t_url=jQuery(this).attr("href");
|
966 |
t_qty=$(this).parent().find("input[name=quantity]").val();
|
967 |
//default quantity 1 if quantity box is not there
|
968 |
if(t_qty=="" || t_qty===undefined){
|
975 |
$hmpg_impressions_jQ .='
|
976 |
//category page json
|
977 |
if(tvc_pgc.length !== 0){
|
978 |
+
t_products_impre_clicks(tvc_pgc,"cp","Category Page");
|
979 |
}
|
980 |
//Prod category ATC link click in related product section
|
981 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
989 |
$hmpg_impressions_jQ .='
|
990 |
//shop page json
|
991 |
if(tvc_pgc.length !== 0){
|
992 |
+
t_products_impre_clicks(tvc_pgc,"sp","Shop Page");
|
993 |
}
|
994 |
//shop page prod click
|
995 |
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
1006 |
$hmpg_impressions_jQ .='
|
1007 |
//ATC link click
|
1008 |
jQuery("a[href*=add-to-cart]").on("click",function(){
|
1009 |
+
t_url=jQuery(this).attr("href");
|
1010 |
t_qty=$(this).parent().find("input[name=quantity]").val();
|
1011 |
//default quantity 1 if quantity box is not there
|
1012 |
if(t_qty=="" || t_qty===undefined){
|
1037 |
$cartpage_prod_array_main = array();
|
1038 |
//echo "<pre>".print_r($woocommerce->cart->cart_contents,TRUE)."</pre>";
|
1039 |
foreach ($woocommerce->cart->cart_contents as $key => $item) {
|
1040 |
+
//Version compare
|
1041 |
+
if (version_compare($woocommerce->version, "2.1", ">=") && version_compare($woocommerce->version, "2.7", "<=") ) {
|
1042 |
+
$prod_meta = get_product($item["product_id"]);
|
1043 |
+
} else {
|
1044 |
+
$prod_meta = wc_get_product($item["product_id"]);
|
1045 |
+
}
|
1046 |
+
|
1047 |
$cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
|
1048 |
|
1049 |
$category = get_the_terms($item["product_id"], "product_cat");
|
1055 |
}
|
1056 |
//remove last comma(,) if multiple categories are there
|
1057 |
$categories = rtrim($categories, ",");
|
1058 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
1059 |
+
$cartpage_prod_array_main[$cart_remove_link] =array(
|
1060 |
"tvc_id" => esc_html($prod_meta->id),
|
1061 |
"tvc_i" => esc_html($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->id),
|
1062 |
"tvc_n" => esc_html($prod_meta->get_title()),
|
1063 |
"tvc_p" => esc_html($prod_meta->get_price()),
|
1064 |
"tvc_c" => esc_html($categories),
|
1065 |
"tvc_q"=>$woocommerce->cart->cart_contents[$key]["quantity"]
|
1066 |
+
);
|
1067 |
+
}else{
|
1068 |
+
$cartpage_prod_array_main[$cart_remove_link] =array(
|
1069 |
+
"tvc_id" => esc_html($prod_meta->get_id()),
|
1070 |
+
"tvc_i" => esc_html($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->get_id()),
|
1071 |
+
"tvc_n" => esc_html($prod_meta->get_title()),
|
1072 |
+
"tvc_p" => esc_html($prod_meta->get_price()),
|
1073 |
+
"tvc_c" => esc_html($categories),
|
1074 |
+
"tvc_q"=>$woocommerce->cart->cart_contents[$key]["quantity"]
|
1075 |
+
);
|
1076 |
+
}
|
1077 |
}
|
1078 |
|
1079 |
//Cart Page item Array to Json
|
1116 |
ga("require", "ec", "ec.js");
|
1117 |
ga("set", "&cu", tvc_lc);
|
1118 |
for(var t_item in tvc_ch){
|
1119 |
+
ga("ec:addProduct", {
|
1120 |
+
"id": tvc_ch[t_item].tvc_i,
|
1121 |
+
"name": tvc_ch[t_item].tvc_n,
|
1122 |
+
"category": tvc_ch[t_item].tvc_c,
|
1123 |
+
"price": tvc_ch[t_item].tvc_p,
|
1124 |
+
"quantity": tvc_ch[t_item].tvc_q
|
1125 |
+
});
|
1126 |
+
}';
|
1127 |
|
1128 |
$code_step_1 = $code . 'ga("ec:setAction","checkout",{"step": 1});';
|
1129 |
$code_step_1 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_1",{"nonInteraction": 1});';
|
1145 |
$code= '
|
1146 |
|
1147 |
for(var t_item in tvc_ch){
|
1148 |
+
ga("ec:addProduct", {
|
1149 |
+
"id": tvc_ch[t_item].tvc_i,
|
1150 |
+
"name": tvc_ch[t_item].tvc_n,
|
1151 |
+
"category": tvc_ch[t_item].tvc_c,
|
1152 |
+
"price": tvc_ch[t_item].tvc_p,
|
1153 |
+
"quantity": tvc_ch[t_item].tvc_q
|
1154 |
+
});
|
1155 |
+
}';
|
1156 |
|
1157 |
$code_step_2 = $code . 'ga("ec:setAction","checkout",{"step": 2});';
|
1158 |
$code_step_2 .= 'ga("send", "event", "Enhanced-Ecommerce","load","checkout_step_2",{"nonInteraction": 1});';
|
1180 |
}
|
1181 |
$code= '
|
1182 |
for(var t_item in tvc_ch){
|
1183 |
+
ga("ec:addProduct", {
|
1184 |
+
"id": tvc_ch[t_item].tvc_i,
|
1185 |
+
"name": tvc_ch[t_item].tvc_n,
|
1186 |
+
"category": tvc_ch[t_item].tvc_c,
|
1187 |
+
"price": tvc_ch[t_item].tvc_p,
|
1188 |
+
"quantity": tvc_ch[t_item].tvc_q
|
1189 |
+
});
|
1190 |
+
}';
|
1191 |
|
1192 |
//check if guest check out is enabled or not
|
1193 |
$step_2_on_proceed_to_pay = (!is_user_logged_in() && !$this->ga_gCkout ) || (!is_user_logged_in() && $this->ga_gCkout && $this->ga_gUser);
|
1218 |
$code = "";
|
1219 |
//get all items added into the cart
|
1220 |
foreach ($woocommerce->cart->cart_contents as $item) {
|
1221 |
+
//Version Compare
|
1222 |
+
if (version_compare($woocommerce->version, "2.1", ">=") && version_compare($woocommerce->version, "2.7", "<=") ) {
|
1223 |
+
$p = get_product($item["product_id"]);
|
1224 |
+
} else {
|
1225 |
+
$p = wc_get_product($item["product_id"]);
|
1226 |
+
}
|
1227 |
|
1228 |
$category = get_the_terms($item["product_id"], "product_cat");
|
1229 |
$categories = "";
|
1234 |
}
|
1235 |
//remove last comma(,) if multiple categories are there
|
1236 |
$categories = rtrim($categories, ",");
|
1237 |
+
if(version_compare($woocommerce->version, "2.4", "<=")){
|
1238 |
+
$chkout_json[get_permalink($p->id)] = array(
|
1239 |
"tvc_id" => esc_html($p->id),
|
1240 |
"tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->id),
|
1241 |
"tvc_n" => esc_js($p->get_title()),
|
1243 |
"tvc_c" => $categories,
|
1244 |
"tvc_q" => esc_js($item["quantity"]),
|
1245 |
"isfeatured"=>$p->is_featured()
|
1246 |
+
);
|
1247 |
+
}else{
|
1248 |
+
$chkout_json[get_permalink($p->get_id())] = array(
|
1249 |
+
"tvc_id" => esc_html($p->get_id()),
|
1250 |
+
"tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->get_id()),
|
1251 |
+
"tvc_n" => esc_js($p->get_title()),
|
1252 |
+
"tvc_p" => esc_js($p->get_price()),
|
1253 |
+
"tvc_c" => $categories,
|
1254 |
+
"tvc_q" => esc_js($item["quantity"]),
|
1255 |
+
"isfeatured"=>$p->is_featured()
|
1256 |
+
);
|
1257 |
+
}
|
1258 |
+
|
1259 |
}
|
1260 |
//return $code;
|
1261 |
//make product data json on check out page
|
readme.txt
CHANGED
@@ -6,9 +6,9 @@ Tags: Google Analytics, Universal Analytics, Enhanced E-commerce, E-commerce, e-
|
|
6 |
Author URI: http://www.tatvic.com/
|
7 |
Author: Tatvic
|
8 |
Requires at least: 3.6
|
9 |
-
Tested up to: 4.7
|
10 |
-
Stable tag: 1.0.
|
11 |
-
Version: 1.0.
|
12 |
License: GPLv3
|
13 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
14 |
|
@@ -52,6 +52,13 @@ Provides integration between Enhanced Ecommerce feature of Google Analytics and
|
|
52 |
= Need an Advanced Google Analytics Plugin? =
|
53 |
We have recently launched an Advanced Google Analytics Plugin for WooCommerce which includes tracking of 9 Reports of Enhanced Ecommerce, User ID Tracking, Product Refund, I.P. Anonymization, 15+ Custom Dimenensions & Metrics, Form Field Tracking, Content Grouping & much more. <a href="http://bit.ly/1yFqA04" target="_blank">Learn More</a>
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
== Installation ==
|
56 |
1. Download the plugin file to your computer and unzip it
|
57 |
2. Using an FTP program, or your hosting control panel, upload the unzipped plugin folder to your WordPress installation’s wp-content/plugins/ directory
|
@@ -206,3 +213,7 @@ Important Note: When you update the plugin, please save your settings again.
|
|
206 |
= 1.0.19 - 21/12/2016 =
|
207 |
* Fixed - Compatibility with Wordpress 4.7 & Woocommerce 2.6.x
|
208 |
* Minor Bug Fixes.
|
|
|
|
|
|
|
|
6 |
Author URI: http://www.tatvic.com/
|
7 |
Author: Tatvic
|
8 |
Requires at least: 3.6
|
9 |
+
Tested up to: 4.7.x
|
10 |
+
Stable tag: 1.0.20
|
11 |
+
Version: 1.0.20
|
12 |
License: GPLv3
|
13 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
14 |
|
52 |
= Need an Advanced Google Analytics Plugin? =
|
53 |
We have recently launched an Advanced Google Analytics Plugin for WooCommerce which includes tracking of 9 Reports of Enhanced Ecommerce, User ID Tracking, Product Refund, I.P. Anonymization, 15+ Custom Dimenensions & Metrics, Form Field Tracking, Content Grouping & much more. <a href="http://bit.ly/1yFqA04" target="_blank">Learn More</a>
|
54 |
|
55 |
+
== Note : ==
|
56 |
+
= Our plugin does not support the below features out of the box =
|
57 |
+
* Highly Customized store
|
58 |
+
* Not fully compatible with Child/Custom Themes.
|
59 |
+
* Variable Product
|
60 |
+
* Store with the Subscription product for Orders.
|
61 |
+
|
62 |
== Installation ==
|
63 |
1. Download the plugin file to your computer and unzip it
|
64 |
2. Using an FTP program, or your hosting control panel, upload the unzipped plugin folder to your WordPress installation’s wp-content/plugins/ directory
|
213 |
= 1.0.19 - 21/12/2016 =
|
214 |
* Fixed - Compatibility with Wordpress 4.7 & Woocommerce 2.6.x
|
215 |
* Minor Bug Fixes.
|
216 |
+
|
217 |
+
= 1.0.20 - 13/04/2017 =
|
218 |
+
* Fixed - Compatibility with Woocommerce 3.x
|
219 |
+
* Minor Bug Fixes.
|
woocommerce-enhanced-ecommerce-google-analytics-integration.php
CHANGED
@@ -21,7 +21,7 @@
|
|
21 |
Description: Allows Enhanced E-commerce Google Analytics tracking code to be inserted into WooCommerce store pages.
|
22 |
Author: Tatvic
|
23 |
Author URI: http://www.tatvic.com
|
24 |
-
Version: 1.0.
|
25 |
*/
|
26 |
if (!defined('ABSPATH')) {
|
27 |
exit; // Exit if accessed directly
|
21 |
Description: Allows Enhanced E-commerce Google Analytics tracking code to be inserted into WooCommerce store pages.
|
22 |
Author: Tatvic
|
23 |
Author URI: http://www.tatvic.com
|
24 |
+
Version: 1.0.20
|
25 |
*/
|
26 |
if (!defined('ABSPATH')) {
|
27 |
exit; // Exit if accessed directly
|