Changeset 3081708
- Timestamp:
- 05/06/2024 07:05:13 AM (2 years ago)
- Location:
- ecomdy-pixel
- Files:
-
- 5 edited
-
tags/1.0.1/pixel-tiktok.php (modified) (14 diffs)
-
tags/1.0.1/uninstall.php (modified) (1 diff)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/pixel-tiktok.php (modified) (14 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ecomdy-pixel/tags/1.0.1/pixel-tiktok.php
r3081640 r3081708 23 23 pixel_name VARCHAR(255) NOT NULL, 24 24 pixel_id VARCHAR(255) NOT NULL, 25 real_id VARCHAR(255) NOT NULL, 25 26 pixel_events VARCHAR(255) NOT NULL, 26 27 pixel_status BOOLEAN NOT NULL, … … 40 41 foreach ($pixels as $pixel) { 41 42 $pixel_id = esc_js($pixel['pixel_id']); 43 $real_id = esc_js($pixel['real_id']); 44 $pixel_status = esc_js($pixel['pixel_status']); 42 45 if (strlen($pixel_id) == 24) { 43 46 if (ctecd_check_timeout($pixel['id'])) { 44 47 $result = ctecd_get_official_pixel_async($pixel_id)['result']; 45 if ($result["status"] == "OK" ) {48 if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") { 46 49 $pixel_id = $result["pixelCode"]; 47 50 ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id); 51 ctecd_update_tiktok_pixel_timeout($pixel['id']); 48 52 } else { 53 ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id,false); 49 54 ctecd_update_tiktok_pixel_timeout($pixel['id']); 50 55 } 51 56 } 52 57 } 53 if (strlen($ pixel_id) != 24) {58 if (strlen($real_id) != 24) { 54 59 ?> 55 <script> 56 ! function(w, d, t) { 57 w.TiktokAnalyticsObject = t; 58 var ttq = w[t] = w[t] || []; 59 ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"], ttq.setAndDefer = function(t, e) { 60 t[e] = function() { 61 t.push([e].concat(Array.prototype.slice.call(arguments, 0))) 62 } 63 }; 64 for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]); 65 ttq.instance = function(t) { 66 for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]); 67 return e 68 }, ttq.load = function(e, n) { 69 var i = "https://analytics.tiktok.com/i18n/pixel/events.js"; 70 ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq._o = ttq._o || {}, ttq._o[e] = n || {}; 71 n = document.createElement("script"); 72 n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t; 73 e = document.getElementsByTagName("script")[0]; 74 e.parentNode.insertBefore(n, e) 75 }; 76 ttq.load('<?php echo esc_js($pixel_id); ?>'); 77 }(window, document, 'ttq'); 78 </script> 79 <?php 60 <script> 61 ! function(w, d, t) { 62 w.TiktokAnalyticsObject = t; 63 var ttq = w[t] = w[t] || []; 64 ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", 65 "enableCookie", "disableCookie" 66 ], ttq.setAndDefer = function(t, e) { 67 t[e] = function() { 68 t.push([e].concat(Array.prototype.slice.call(arguments, 0))) 69 } 70 }; 71 for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]); 72 ttq.instance = function(t) { 73 for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]); 74 return e 75 }, ttq.load = function(e, n) { 76 var i = "https://analytics.tiktok.com/i18n/pixel/events.js"; 77 ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq 78 ._o = ttq._o || {}, ttq._o[e] = n || {}; 79 n = document.createElement("script"); 80 n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t; 81 e = document.getElementsByTagName("script")[0]; 82 e.parentNode.insertBefore(n, e) 83 }; 84 ttq.load('<?php echo esc_js($real_id); ?>'); 85 }(window, document, 'ttq'); 86 </script> 87 <?php 80 88 } 81 89 } … … 106 114 $table_name, 107 115 array( 108 ' pixel_id' => $new_pixel_id,116 'real_id' => $new_pixel_id, 109 117 'pixel_status' => $new_pixel_status, 110 118 ), … … 141 149 $ten_minutes_ago = date('Y-m-d H:i:s', strtotime('-10 minutes', strtotime($current_time))); 142 150 151 // Properly escape the table name to prevent SQL injection (though specific for table names, manual input is generally safe) 152 $table_name_escaped = esc_sql($table_name); 153 143 154 // Check if the last update was more than 10 minutes ago 144 $last_updated = $wpdb->get_var($wpdb->prepare("SELECT updated FROM %s WHERE id = %d", $table_name, $id)); 155 // Directly using the table name in the query since placeholders cannot be used for table names 156 $query = "SELECT updated FROM `{$table_name_escaped}` WHERE id = %d"; 157 $last_updated = $wpdb->get_var($wpdb->prepare($query, $id)); 145 158 146 159 return strtotime($last_updated) < strtotime($ten_minutes_ago); … … 155 168 $currency = get_woocommerce_currency(); 156 169 ?> 170 <script> 171 document.addEventListener('DOMContentLoaded', function() { 172 ttq.track('ViewContent', { 173 content_id: '<?php echo esc_js($product_id); ?>', 174 content_type: 'product', 175 value: '<?php echo esc_js($product_price); ?>', 176 currency: '<?php echo esc_js($currency); ?>' 177 }); 178 }); 179 </script> 180 <?php 181 } 182 } 183 add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20); 184 185 add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6); 186 187 function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data) 188 { 189 $product = wc_get_product($product_id); 190 if (!$product) { 191 return; 192 } 193 ?> 157 194 <script> 158 195 document.addEventListener('DOMContentLoaded', function() { 159 ttq.track('ViewContent', { 160 content_id: '<?php echo esc_js($product_id); ?>', 161 content_type: 'product', 162 value: '<?php echo esc_js($product_price); ?>', 163 currency: '<?php echo esc_js($currency); ?>' 164 }); 196 var event_data = { 197 'price': <?php echo esc_js((float) $product->get_price()); ?>, 198 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>', 199 'content_name': '<?php echo esc_js($product->get_name()); ?>', 200 'quantity': <?php echo esc_js((int) $request_quantity); ?>, 201 'content_type': 'product', 202 'content_id': '<?php echo esc_js($product_id); ?>', 203 'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>, 204 }; 205 if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) { 206 ttq.track('AddToCart', event_data); 207 } 165 208 }); 166 209 </script> 167 210 <?php 168 }169 }170 add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20);171 172 add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6);173 174 function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data)175 {176 $product = wc_get_product($product_id);177 if (!$product) {178 return;179 }180 ?>181 <script>182 document.addEventListener('DOMContentLoaded', function() {183 var event_data = {184 'price': <?php echo esc_js((float) $product->get_price()); ?>,185 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',186 'content_name': '<?php echo esc_js($product->get_name()); ?>',187 'quantity': <?php echo esc_js((int) $request_quantity); ?>,188 'content_type': 'product',189 'content_id': '<?php echo esc_js($product_id); ?>',190 'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>,191 };192 if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) {193 ttq.track('AddToCart', event_data);194 }195 });196 </script>197 <?php198 211 } 199 212 … … 206 219 function ctecd_wp_kama_woocommerce_cart_needs_shipping_filter($needs_shipping) 207 220 { 208 209 221 if (!is_checkout() || did_action('wp_footer')) { 210 222 remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter'); 211 223 return; 212 224 } 225 213 226 // Removed Script on Every Ajax Request on Checkout Page By M Usman Rashid 214 227 if(wp_doing_ajax() ){ … … 216 229 return; 217 230 } 218 231 219 232 remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter'); 220 221 233 222 234 $cart_contents = WC()->cart->get_cart(); 223 235 $js_event_data = []; … … 247 259 248 260 ?> 249 <script>250 document.addEventListener('DOMContentLoaded', function() {251 var event_data = {261 <script> 262 document.addEventListener('DOMContentLoaded', function() { 263 var event_data = { 252 264 'contents': <?php echo wp_json_encode($js_event_data); ?>, 253 265 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>', 254 266 'value': <?php echo esc_js($value); ?>, 255 };256 257 // Check if ttq is defined before tracking258 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {267 }; 268 269 // Check if ttq is defined before tracking 270 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) { 259 271 ttq.track('InitiateCheckout', event_data); 260 }261 });262 </script>272 } 273 }); 274 </script> 263 275 <?php 264 276 return; … … 296 308 297 309 ?> 298 <script>299 document.addEventListener('DOMContentLoaded', function() {300 var event_data = {310 <script> 311 document.addEventListener('DOMContentLoaded', function() { 312 var event_data = { 301 313 'contents': <?php echo wp_json_encode($js_event_data); ?>, 302 314 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>', 303 315 'value': <?php echo esc_js($value); ?>, 304 };305 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {316 }; 317 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) { 306 318 ttq.track('Purchase', event_data); 307 }308 });309 </script>319 } 320 }); 321 </script> 310 322 <?php 311 323 } … … 331 343 $pixel_name = sanitize_text_field($_POST['pixel_name']); 332 344 $pixel_id = sanitize_text_field($_POST['pixel_id']); 345 $real_id = sanitize_text_field($_POST['pixel_id']); 333 346 $event = sanitize_text_field($_POST['event']); 334 347 $status = (strlen($pixel_id) == 24) ? 0 : 1; … … 336 349 if (strlen($pixel_id) == 24) { 337 350 $result = ctecd_get_official_pixel_async($pixel_id)['result']; 338 if ($result["status"] == "OK" ) {339 $ pixel_id = $result["pixelCode"];351 if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") { 352 $real_id = $result["pixelCode"]; 340 353 $status = 1; 341 354 } … … 343 356 // Validate and save data to the database or perform any other necessary actions 344 357 if ($pixel_name && $pixel_id && $event) { 345 ctecd_save_pixel($pixel_name, $pixel_id, $event, $status);358 ctecd_save_pixel($pixel_name, $pixel_id,$real_id, $event, $status); 346 359 } 347 360 } … … 382 395 ); 383 396 } 384 function ctecd_save_pixel($pixel_name, $pixel_id, $ event, $status)397 function ctecd_save_pixel($pixel_name, $pixel_id, $real_id, $event, $status) 385 398 { 386 399 global $wpdb; … … 392 405 'pixel_name' => $pixel_name, 393 406 'pixel_id' => $pixel_id, 394 'pixel_events' => $event, // Corrected array key 407 'real_id' => $real_id, 408 'pixel_events' => $event, 395 409 'pixel_status' => $status, 396 410 ), 397 array('%s', '%s', '%s', '% d') // Adjusted data types411 array('%s', '%s', '%s', '%s', '%d') // Adjusted data types 398 412 ); 399 413 } -
ecomdy-pixel/tags/1.0.1/uninstall.php
r3081640 r3081708 9 9 $pixel_table = $wpdb->prefix . 'tiktok_pixel'; 10 10 11 // Drop the table 12 $wpdb->query( $wpdb->prepare( "DROP TABLE IF EXISTS %s", $pixel_table ) ); 11 // Properly escape the table name to prevent SQL injection 12 $pixel_table_escaped = esc_sql( $pixel_table ); 13 14 // Drop the table using the properly escaped table name directly in the query 15 $wpdb->query( "DROP TABLE IF EXISTS `{$pixel_table_escaped}`" ); -
ecomdy-pixel/trunk/README.txt
r3081645 r3081708 64 64 65 65 == Changelog == 66 67 66 = 1.0.1 = 68 67 * Fix conflict issues with elementor plugin. 69 68 * Update on/off function from Ecomdy platform 70 71 69 = 1.0.0 = 72 70 * Initial release. … … 77 75 * Fix conflict issues with elementor plugin. 78 76 * Update on/off function from Ecomdy platform 79 80 77 = 1.0.0 = 81 78 Initial release of Ecomdy Pixel. -
ecomdy-pixel/trunk/pixel-tiktok.php
r3081645 r3081708 23 23 pixel_name VARCHAR(255) NOT NULL, 24 24 pixel_id VARCHAR(255) NOT NULL, 25 real_id VARCHAR(255) NOT NULL, 25 26 pixel_events VARCHAR(255) NOT NULL, 26 27 pixel_status BOOLEAN NOT NULL, … … 40 41 foreach ($pixels as $pixel) { 41 42 $pixel_id = esc_js($pixel['pixel_id']); 43 $real_id = esc_js($pixel['real_id']); 44 $pixel_status = esc_js($pixel['pixel_status']); 42 45 if (strlen($pixel_id) == 24) { 43 46 if (ctecd_check_timeout($pixel['id'])) { 44 47 $result = ctecd_get_official_pixel_async($pixel_id)['result']; 45 if ($result["status"] == "OK" ) {48 if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") { 46 49 $pixel_id = $result["pixelCode"]; 47 50 ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id); 51 ctecd_update_tiktok_pixel_timeout($pixel['id']); 48 52 } else { 53 ctecd_update_tiktok_pixel_id($pixel['id'], $pixel_id,false); 49 54 ctecd_update_tiktok_pixel_timeout($pixel['id']); 50 55 } 51 56 } 52 57 } 53 if (strlen($ pixel_id) != 24) {58 if (strlen($real_id) != 24) { 54 59 ?> 55 <script> 56 ! function(w, d, t) { 57 w.TiktokAnalyticsObject = t; 58 var ttq = w[t] = w[t] || []; 59 ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"], ttq.setAndDefer = function(t, e) { 60 t[e] = function() { 61 t.push([e].concat(Array.prototype.slice.call(arguments, 0))) 62 } 63 }; 64 for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]); 65 ttq.instance = function(t) { 66 for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]); 67 return e 68 }, ttq.load = function(e, n) { 69 var i = "https://analytics.tiktok.com/i18n/pixel/events.js"; 70 ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq._o = ttq._o || {}, ttq._o[e] = n || {}; 71 n = document.createElement("script"); 72 n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t; 73 e = document.getElementsByTagName("script")[0]; 74 e.parentNode.insertBefore(n, e) 75 }; 76 ttq.load('<?php echo esc_js($pixel_id); ?>'); 77 }(window, document, 'ttq'); 78 </script> 79 <?php 60 <script> 61 ! function(w, d, t) { 62 w.TiktokAnalyticsObject = t; 63 var ttq = w[t] = w[t] || []; 64 ttq.methods = ["track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", 65 "enableCookie", "disableCookie" 66 ], ttq.setAndDefer = function(t, e) { 67 t[e] = function() { 68 t.push([e].concat(Array.prototype.slice.call(arguments, 0))) 69 } 70 }; 71 for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]); 72 ttq.instance = function(t) { 73 for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]); 74 return e 75 }, ttq.load = function(e, n) { 76 var i = "https://analytics.tiktok.com/i18n/pixel/events.js"; 77 ttq._i = ttq._i || {}, ttq._i[e] = [], ttq._i[e]._u = i, ttq._t = ttq._t || {}, ttq._t[e] = +new Date, ttq 78 ._o = ttq._o || {}, ttq._o[e] = n || {}; 79 n = document.createElement("script"); 80 n.type = "text/javascript", n.async = !0, n.src = i + "?sdkid=" + e + "&lib=" + t; 81 e = document.getElementsByTagName("script")[0]; 82 e.parentNode.insertBefore(n, e) 83 }; 84 ttq.load('<?php echo esc_js($real_id); ?>'); 85 }(window, document, 'ttq'); 86 </script> 87 <?php 80 88 } 81 89 } … … 106 114 $table_name, 107 115 array( 108 ' pixel_id' => $new_pixel_id,116 'real_id' => $new_pixel_id, 109 117 'pixel_status' => $new_pixel_status, 110 118 ), … … 141 149 $ten_minutes_ago = date('Y-m-d H:i:s', strtotime('-10 minutes', strtotime($current_time))); 142 150 151 // Properly escape the table name to prevent SQL injection (though specific for table names, manual input is generally safe) 152 $table_name_escaped = esc_sql($table_name); 153 143 154 // Check if the last update was more than 10 minutes ago 144 $last_updated = $wpdb->get_var($wpdb->prepare("SELECT updated FROM %s WHERE id = %d", $table_name, $id)); 155 // Directly using the table name in the query since placeholders cannot be used for table names 156 $query = "SELECT updated FROM `{$table_name_escaped}` WHERE id = %d"; 157 $last_updated = $wpdb->get_var($wpdb->prepare($query, $id)); 145 158 146 159 return strtotime($last_updated) < strtotime($ten_minutes_ago); … … 155 168 $currency = get_woocommerce_currency(); 156 169 ?> 170 <script> 171 document.addEventListener('DOMContentLoaded', function() { 172 ttq.track('ViewContent', { 173 content_id: '<?php echo esc_js($product_id); ?>', 174 content_type: 'product', 175 value: '<?php echo esc_js($product_price); ?>', 176 currency: '<?php echo esc_js($currency); ?>' 177 }); 178 }); 179 </script> 180 <?php 181 } 182 } 183 add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20); 184 185 add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6); 186 187 function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data) 188 { 189 $product = wc_get_product($product_id); 190 if (!$product) { 191 return; 192 } 193 ?> 157 194 <script> 158 195 document.addEventListener('DOMContentLoaded', function() { 159 ttq.track('ViewContent', { 160 content_id: '<?php echo esc_js($product_id); ?>', 161 content_type: 'product', 162 value: '<?php echo esc_js($product_price); ?>', 163 currency: '<?php echo esc_js($currency); ?>' 164 }); 196 var event_data = { 197 'price': <?php echo esc_js((float) $product->get_price()); ?>, 198 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>', 199 'content_name': '<?php echo esc_js($product->get_name()); ?>', 200 'quantity': <?php echo esc_js((int) $request_quantity); ?>, 201 'content_type': 'product', 202 'content_id': '<?php echo esc_js($product_id); ?>', 203 'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>, 204 }; 205 if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) { 206 ttq.track('AddToCart', event_data); 207 } 165 208 }); 166 209 </script> 167 210 <?php 168 }169 }170 add_action('wp_footer', 'ctecd_add_tiktok_viewcontent_event', 20);171 172 add_action('woocommerce_add_to_cart', 'ctecd_wp_kama_woocommerce_add_to_cart_action', 10, 6);173 174 function ctecd_wp_kama_woocommerce_add_to_cart_action($cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data)175 {176 $product = wc_get_product($product_id);177 if (!$product) {178 return;179 }180 ?>181 <script>182 document.addEventListener('DOMContentLoaded', function() {183 var event_data = {184 'price': <?php echo esc_js((float) $product->get_price()); ?>,185 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>',186 'content_name': '<?php echo esc_js($product->get_name()); ?>',187 'quantity': <?php echo esc_js((int) $request_quantity); ?>,188 'content_type': 'product',189 'content_id': '<?php echo esc_js($product_id); ?>',190 'value': <?php echo esc_js((float) $product->get_price() * (float) $request_quantity); ?>,191 };192 if (typeof ttq !== 'undefined' && event_data.price && event_data.quantity) {193 ttq.track('AddToCart', event_data);194 }195 });196 </script>197 <?php198 211 } 199 212 … … 206 219 function ctecd_wp_kama_woocommerce_cart_needs_shipping_filter($needs_shipping) 207 220 { 208 209 221 if (!is_checkout() || did_action('wp_footer')) { 210 222 remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter'); 211 223 return; 212 224 } 225 213 226 // Removed Script on Every Ajax Request on Checkout Page By M Usman Rashid 214 227 if(wp_doing_ajax() ){ … … 216 229 return; 217 230 } 218 231 219 232 remove_filter('woocommerce_cart_needs_shipping', 'ctecd_wp_kama_woocommerce_cart_needs_shipping_filter'); 220 221 233 222 234 $cart_contents = WC()->cart->get_cart(); 223 235 $js_event_data = []; … … 247 259 248 260 ?> 249 <script>250 document.addEventListener('DOMContentLoaded', function() {251 var event_data = {261 <script> 262 document.addEventListener('DOMContentLoaded', function() { 263 var event_data = { 252 264 'contents': <?php echo wp_json_encode($js_event_data); ?>, 253 265 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>', 254 266 'value': <?php echo esc_js($value); ?>, 255 };256 257 // Check if ttq is defined before tracking258 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {267 }; 268 269 // Check if ttq is defined before tracking 270 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) { 259 271 ttq.track('InitiateCheckout', event_data); 260 }261 });262 </script>272 } 273 }); 274 </script> 263 275 <?php 264 276 return; … … 296 308 297 309 ?> 298 <script>299 document.addEventListener('DOMContentLoaded', function() {300 var event_data = {310 <script> 311 document.addEventListener('DOMContentLoaded', function() { 312 var event_data = { 301 313 'contents': <?php echo wp_json_encode($js_event_data); ?>, 302 314 'currency': '<?php echo esc_js(get_woocommerce_currency()); ?>', 303 315 'value': <?php echo esc_js($value); ?>, 304 };305 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) {316 }; 317 if (typeof ttq !== 'undefined' && event_data.contents.length > 0) { 306 318 ttq.track('Purchase', event_data); 307 }308 });309 </script>319 } 320 }); 321 </script> 310 322 <?php 311 323 } … … 331 343 $pixel_name = sanitize_text_field($_POST['pixel_name']); 332 344 $pixel_id = sanitize_text_field($_POST['pixel_id']); 345 $real_id = sanitize_text_field($_POST['pixel_id']); 333 346 $event = sanitize_text_field($_POST['event']); 334 347 $status = (strlen($pixel_id) == 24) ? 0 : 1; … … 336 349 if (strlen($pixel_id) == 24) { 337 350 $result = ctecd_get_official_pixel_async($pixel_id)['result']; 338 if ($result["status"] == "OK" ) {339 $ pixel_id = $result["pixelCode"];351 if ($result["status"] == "OK" && $result["pixelStatus"]=="RUNNING") { 352 $real_id = $result["pixelCode"]; 340 353 $status = 1; 341 354 } … … 343 356 // Validate and save data to the database or perform any other necessary actions 344 357 if ($pixel_name && $pixel_id && $event) { 345 ctecd_save_pixel($pixel_name, $pixel_id, $event, $status);358 ctecd_save_pixel($pixel_name, $pixel_id,$real_id, $event, $status); 346 359 } 347 360 } … … 382 395 ); 383 396 } 384 function ctecd_save_pixel($pixel_name, $pixel_id, $ event, $status)397 function ctecd_save_pixel($pixel_name, $pixel_id, $real_id, $event, $status) 385 398 { 386 399 global $wpdb; … … 392 405 'pixel_name' => $pixel_name, 393 406 'pixel_id' => $pixel_id, 394 'pixel_events' => $event, // Corrected array key 407 'real_id' => $real_id, 408 'pixel_events' => $event, 395 409 'pixel_status' => $status, 396 410 ), 397 array('%s', '%s', '%s', '% d') // Adjusted data types411 array('%s', '%s', '%s', '%s', '%d') // Adjusted data types 398 412 ); 399 413 } -
ecomdy-pixel/trunk/uninstall.php
r3038226 r3081708 9 9 $pixel_table = $wpdb->prefix . 'tiktok_pixel'; 10 10 11 // Drop the table 12 $wpdb->query( $wpdb->prepare( "DROP TABLE IF EXISTS %s", $pixel_table ) ); 11 // Properly escape the table name to prevent SQL injection 12 $pixel_table_escaped = esc_sql( $pixel_table ); 13 14 // Drop the table using the properly escaped table name directly in the query 15 $wpdb->query( "DROP TABLE IF EXISTS `{$pixel_table_escaped}`" );
Note: See TracChangeset
for help on using the changeset viewer.