Changeset 3327525
- Timestamp:
- 07/14/2025 12:25:31 PM (9 months ago)
- Location:
- universal-wp-lead-tracking
- Files:
-
- 14 added
- 2 edited
-
tags/1.0.9 (added)
-
tags/1.0.9/assets (added)
-
tags/1.0.9/assets/UWPLT-Plugin-Internal-Header.jpg (added)
-
tags/1.0.9/assets/banner-1544x500.jpg (added)
-
tags/1.0.9/assets/banner-772x250.jpg (added)
-
tags/1.0.9/assets/icon-256x256.png (added)
-
tags/1.0.9/assets/screenshot-1.jpg (added)
-
tags/1.0.9/assets/screenshot-2.jpg (added)
-
tags/1.0.9/assets/screenshot-3.jpg (added)
-
tags/1.0.9/ip-lookup (added)
-
tags/1.0.9/ip-lookup/IP2LOCATION-LITE-DB1.CSV (added)
-
tags/1.0.9/ip-lookup/IP2LOCATION-LITE-DB1.IPV6.CSV (added)
-
tags/1.0.9/readme.txt (added)
-
tags/1.0.9/universal-wp-lead-tracking.php (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/universal-wp-lead-tracking.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
universal-wp-lead-tracking/trunk/readme.txt
r3324508 r3327525 6 6 License: MIT 7 7 Tested up to: 6.8 8 Stable tag: 1.0. 88 Stable tag: 1.0.9 9 9 10 10 Adds lead tracking information to e-mails coming from Contact Form 7, Gravity Forms, Ninja Forms, or Elementor PRO form submissions. … … 52 52 == Changelog == 53 53 54 = 1.0.9 - 2025-07-14 = 55 * FIX: Added code to set tracking info by JS if not set via HTTP. Required for cached pages. 56 54 57 = 1.0.8 - 2025-07-08 = 55 58 * FIX: Landing URLs could sometimes be set to /wp-json/ or /wp-admin/admin-ajax.php which is incorrect. Added a check to exclude ADMIN pages, AJAX requests, REST requests, and WP-CRON requests. -
universal-wp-lead-tracking/trunk/universal-wp-lead-tracking.php
r3324508 r3327525 3 3 Plugin Name: Universal WP Lead Tracking 4 4 Description: Adds tracking info to outgoing emails from contact forms by using the [tracking-info] shortcode. The tracking info includes the Form Page URL, Original Referrer, Landing Page, User IP, Browser. Compatible with Contact Form 7, Gravity Forms, Ninja Forms, and Elementor PRO forms! 5 Version: 1.0. 85 Version: 1.0.9 6 6 Author: Inbound Horizons 7 7 Author URI: https://www.inboundhorizons.com/ … … 43 43 44 44 45 46 45 47 // Set landing information immediately (using priority 0 to ensure it runs first) 46 add_action('init', 'UWPLT_SetLandingInfo', 0); 48 add_action('init', array($this, 'UWPLT_SetLandingInfo'), 1); 49 50 // Use JS to set tracking info if needed 51 add_action('wp_head', array($this, 'UWPLT_SetTrackingJS')); 52 //add_action('admin_head', array($this, 'UWPLT_SetTrackingJS')); // For dev purposes 53 54 add_action('wp_ajax_nopriv_UWPLT_SET_LANDING_INFO', array($this, 'AJAX_SetLandingInfo')); 55 //add_action('wp_ajax_UWPLT_SET_LANDING_INFO', array($this, 'AJAX_SetLandingInfo')); // For dev purposes 47 56 48 57 } … … 646 655 647 656 657 658 648 659 649 660 public static function GetReferringURL() { … … 666 677 667 678 668 669 679 public function AJAX_SetLandingInfo() { 680 681 $response_data = array(); 682 683 $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; 684 $nonce_verified = wp_verify_nonce($nonce, $this->NONCE_ADMIN); 685 686 if ($nonce_verified) { 687 688 // Get the data 689 $referring_url = isset($_POST['referring_url']) ? sanitize_text_field(wp_unslash($_POST['referring_url'])) : ''; 690 $current_url = isset($_POST['current_url']) ? sanitize_text_field(wp_unslash($_POST['current_url'])) : ''; 691 692 // Save the landing info 693 $session_key = $this->UWPLT_SaveLandingInfo($referring_url, $current_url); 694 695 // Pass the session key to the response data 696 $response_data['session_key'] = $session_key; 697 } 698 699 wp_send_json_success($response_data); 700 } 701 702 703 public function UWPLT_SetTrackingJS() { 704 global $UWPLT_COOKIE; 705 706 $nonce = wp_create_nonce($this->NONCE_ADMIN); 707 708 $js = ' 709 710 UWPLT_SetTrackingInfo(); 711 712 function UWPLT_SetTrackingInfo() { 713 714 // If the cookie is not set then POST the landing info 715 if (!document.cookie.includes("'.esc_js($UWPLT_COOKIE).'")) { 716 717 var data = new FormData(); 718 data.append("action", "UWPLT_SET_LANDING_INFO"); 719 data.append("nonce", "'.esc_js($nonce).'"); 720 data.append("referring_url", document.referrer); 721 data.append("current_url", window.location.href); 722 723 fetch("'.esc_js(admin_url('admin-ajax.php')).'", { 724 method: "POST", 725 body: data, 726 }); 727 } 728 } 729 730 '; 731 732 wp_register_script('uwplt-tracking', '', [], '', true); 733 wp_enqueue_script('uwplt-tracking'); 734 wp_add_inline_script('uwplt-tracking', $js); 735 736 } 737 738 public function UWPLT_SetLandingInfo() { 739 global $UWPLT_COOKIE; 740 741 742 // Exclude ADMIN pages 743 if (function_exists('is_admin') && is_admin()) { 744 return; 745 } 746 747 // Exclude AJAX requests 748 if (defined('DOING_AJAX') && DOING_AJAX) { 749 return; 750 } 751 752 // Exclude REST requests 753 if (defined('REST_REQUEST') && REST_REQUEST) { 754 return; 755 } 756 757 // Exclude WP-CRON page requests 758 // phpcs:ignore WordPress.Security.NonceVerification.Recommended 759 if (isset($_GET['doing_wp_cron']) || (defined('DOING_CRON') && DOING_CRON)) { 760 return; 761 } 762 763 764 // Get the values to save 765 $original_ref = UWPLT::GetReferringURL(); 766 $landing_page = UWPLT::GetCurrentURL(); 767 768 // Save the landing info 769 $session_key = $this->UWPLT_SaveLandingInfo($original_ref, $landing_page); 770 } 771 772 public function UWPLT_SaveLandingInfo($original_ref, $landing_page) { 773 global $UWPLT_COOKIE; 774 775 $session_key = false; 776 777 // Check if the cookie has already been set 778 if (!isset($_COOKIE[$UWPLT_COOKIE])) { 779 780 // Package the values into an array 781 $session = array( 782 'OriginalRef' => $original_ref, 783 'LandingPage' => $landing_page, 784 ); 785 786 // Save the values 787 $session_key = UWPLT_InsertSession($session); 788 789 // Set the session cookie with the DB session key 790 if (!headers_sent()) { // Only if no headers sent to avoid an error 791 if ($session_key && ($UWPLT_COOKIE != '')) { 792 $_COOKIE[$UWPLT_COOKIE] = $session_key; 793 794 setcookie($UWPLT_COOKIE, $session_key, array( 795 'expires' => time() + 21600, // 21600 = 6 hours 796 'path' => '/', 797 'secure' => true, // only over HTTPS 798 'httponly' => false, // Ensure we can access with JS 799 'samesite' => 'Lax', 800 )); 801 } 802 } 803 else { 804 //error_log("UWPLT: Unable to set cookie because headers already sent."); 805 //error_log("GetCurrentURL: ".$landing_page); 806 //error_log("GetReferringURL: ".$original_ref); 807 } 808 } 809 810 return ($session_key); 811 } 670 812 671 813 … … 829 971 830 972 831 function UWPLT_SetLandingInfo() {832 global $UWPLT_COOKIE;833 834 835 // Exclude ADMIN pages836 if (function_exists('is_admin') && is_admin()) {837 return;838 }839 840 // Exclude AJAX requests841 if (defined('DOING_AJAX') && DOING_AJAX) {842 return;843 }844 845 // Exclude REST requests846 if (defined('REST_REQUEST') && REST_REQUEST) {847 return;848 }849 850 // Exclude WP-CRON page requests851 // phpcs:ignore WordPress.Security.NonceVerification.Recommended852 if (isset($_GET['doing_wp_cron']) || (defined('DOING_CRON') && DOING_CRON)) {853 return;854 }855 856 857 858 if (!isset($_COOKIE[$UWPLT_COOKIE])) {859 860 // Get the values to save861 $original_ref = UWPLT::GetReferringURL();862 $landing_page = UWPLT::GetCurrentURL();863 864 865 // Package the values into an array866 $session = array(867 'OriginalRef' => $original_ref,868 'LandingPage' => $landing_page,869 );870 871 872 // Save the values873 $session_key = UWPLT_InsertSession($session);874 875 876 // Set the session cookie with the DB session key877 if (!headers_sent()) { // Only if no headers sent to avoid an error878 if ($session_key && ($UWPLT_COOKIE != '')) {879 $_COOKIE[$UWPLT_COOKIE] = $session_key;880 881 setcookie($UWPLT_COOKIE, $session_key, array(882 'expires' => time() + 21600, // 21600 = 6 hours883 'path' => '/',884 'secure' => true, // only over HTTPS885 'httponly' => true, // inaccessible to JavaScript886 'samesite' => 'Lax',887 ));888 }889 }890 }891 }892 893 973 add_action('init', 'UWPLT_SetShortcode'); 894 974 function UWPLT_SetShortcode() {
Note: See TracChangeset
for help on using the changeset viewer.