Changeset 2655823
- Timestamp:
- 01/11/2022 12:45:22 PM (4 years ago)
- Location:
- gtm-ecommerce-woo/trunk
- Files:
-
- 4 edited
-
gtm-ecommerce-woo.php (modified) (2 diffs)
-
lib/Service/EventInspectorService.php (modified) (1 diff)
-
lib/Service/ThemeValidatorService.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gtm-ecommerce-woo/trunk/gtm-ecommerce-woo.php
r2624990 r2655823 4 4 * Plugin URI: https://wordpress.org/plugins/gtm-ecommerce-woo 5 5 * Description: Push WooCommerce eCommerce (GA4 and UA compatible) information to GTM DataLayer. Use any GTM integration to measure your customers' activites. 6 * Version: 1.9. 36 * Version: 1.9.4 7 7 * Author: Handcraft Byte 8 8 * Author URI: https://handcraftbyte.com/ … … 13 13 * 14 14 * WC requires at least: 4.0 15 * WC tested up to: 5.8.015 * WC tested up to: 6.0.0 16 16 */ 17 17 -
gtm-ecommerce-woo/trunk/lib/Service/EventInspectorService.php
r2615627 r2655823 56 56 57 57 public function footerHtml() { 58 var_dump($this->wpSettingsUtil->getOption('event_inspector_demo_mode'));59 58 if ($this->isDisabled()) { 60 59 return; -
gtm-ecommerce-woo/trunk/lib/Service/ThemeValidatorService.php
r2618200 r2655823 35 35 return; 36 36 } 37 38 add_action( 39 'rest_api_init', 40 function () { 41 register_rest_route( 42 'gtm-ecommerce-woo/v1', 43 '/theme-validator/', 44 array( 45 'methods' => 'GET', 46 'callback' => array( $this, 'getThemeValidator' ), 47 'permission_callback' => array( $this, 'verifyRequest'), 48 ) 49 ); 50 } 51 ); 52 37 53 if (!isset($_GET['gtm-ecommerce-woo-validator']) 38 54 || md5($this->wpSettingsUtil->getOption('uuid')) !== $_GET['gtm-ecommerce-woo-validator']) { … … 49 65 } 50 66 67 public function verifyRequest($data) { 68 if (!is_string($data->get_header('X-TC-Signature')) 69 || !is_string($data->get_header('X-TC-Timestamp'))) { 70 return new \WP_Error("missing-signature", "Missing Signature"); 71 } 72 73 if ($data->get_header('X-TC-Timestamp') >= time()) { 74 return new \WP_Error("wrong-signature", "Wrong Signature"); 75 } 76 77 $response = wp_remote_get( $this->tagConciergeApiUrl . '/v2/public-key'); 78 $publicKey = wp_remote_retrieve_body( $response ); 79 80 try { 81 $verified = openssl_verify( 82 $data->get_header('X-TC-Timestamp'), 83 base64_decode($data->get_header('X-TC-Signature')), 84 $publicKey, 85 "sha512" 86 ); 87 } catch (\Exception $err) { 88 return new \WP_Error("wrong-signature", "Wrong Signature"); 89 } 90 91 if ($verified !== 1) { 92 return new \WP_Error("wrong-signature", "Wrong Signature"); 93 } 94 95 return true; 96 } 97 98 public function getThemeValidator( $data ) { 99 $query = new \WC_Order_Query( array( 100 'orderby' => 'date', 101 'order' => 'DESC', 102 'limit' => 1, 103 'type' => 'shop_order', 104 'status' => ['on-hold', 'completed'] 105 ) ); 106 $orders = $query->get_orders(); 107 if (count($orders) === 0) { 108 $thankYou = null; 109 } else { 110 $thankYou = $orders[0]->get_checkout_order_received_url(); 111 } 112 113 $query = new \WC_Product_Query( array( 114 'orderby' => 'date', 115 'order' => 'DESC', 116 'limit' => 1, 117 'status' => ['publish'] 118 ) ); 119 $products = $query->get_products(); 120 if (count($products) === 0) { 121 $productUrl = null; 122 } else { 123 $productUrl = $products[0]->get_permalink(); 124 } 125 126 $categories = get_terms( ['taxonomy' => 'product_cat'] ); 127 if (count($categories) === 0) { 128 $productCatUrl = null; 129 } else { 130 $productCatUrl = get_term_link($categories[0]); 131 } 132 133 $payload = [ 134 'platform' => 'woocommerce', 135 'uuid_hash' => md5($this->wpSettingsUtil->getOption('uuid')), 136 'uuid' => $this->wpSettingsUtil->getOption('uuid'), 137 'events' => $this->events, 138 'urls' => [ 139 'product_category' => $productCatUrl, 140 'product' => $productUrl, 141 'cart' => wc_get_cart_url(), 142 'checkout' => wc_get_checkout_url(), 143 'home' => get_home_url(), 144 'thank_you' => $thankYou, 145 'shop' => get_permalink(wc_get_page_id('shop')) 146 // 'thank_you' => $return_url = $order->get_checkout_order_received_url(); 147 // } else { 148 // $return_url = wc_get_endpoint_url( 'order-received', '', wc_get_checkout_url() ); 149 ] 150 ]; 151 return $payload; 152 } 153 51 154 public function ajaxPostValidateTheme() { 52 155 $query = new \WC_Order_Query( array( … … 54 157 'order' => 'DESC', 55 158 'limit' => 1, 159 'type' => 'shop_order', 56 160 'status' => ['on-hold', 'completed'] 57 161 ) ); -
gtm-ecommerce-woo/trunk/readme.txt
r2624990 r2655823 3 3 Tags: google tag manager, GA4, ecommerce events, Google Analytics, Facebook Pixel, shopping behavior 4 4 Requires at least: 5.1.0 5 Tested up to: 5.8. 15 Tested up to: 5.8.3 6 6 Requires PHP: 7.2 7 7 Stable tag: trunk … … 118 118 == Changelog == 119 119 120 = 1.9.4 = 121 122 * remove testing code 123 * test against latest WooCommerce and WordPress versions 124 * introduce secured endpoint for obtaining debugging info 125 120 126 = 1.9.3 = 121 127
Note: See TracChangeset
for help on using the changeset viewer.