Changeset 3342104
- Timestamp:
- 08/09/2025 06:56:29 PM (8 months ago)
- Location:
- utm-tracker-for-contact-form-7
- Files:
-
- 5 added
- 6 edited
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (modified) (previous)
-
assets/screenshot-3.png (modified) (previous)
-
tags/1.4 (added)
-
tags/1.4/js (added)
-
tags/1.4/js/utm-tracker.js (added)
-
tags/1.4/readme.txt (added)
-
tags/1.4/utm-tracker-for-contact-form-7.php (added)
-
trunk/js/utm-tracker.js (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/utm-tracker-for-contact-form-7.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
utm-tracker-for-contact-form-7/trunk/js/utm-tracker.js
r3334582 r3342104 1 document.addEventListener("DOMContentLoaded", function() {2 'use strict';1 (function() { 2 var keys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_id', 'utm_term', 'utm_content']; 3 3 4 function setCookie(name, value, days) { 5 try { 6 const d = new Date(); 7 d.setTime(d.getTime() + (days * 86400000)); // days to milliseconds 8 document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + d.toUTCString() + ";path=/;SameSite=Lax"; 9 } catch (e) { 10 console.warn("UTM cookie set failed:", name, e); 4 // Store UTM to sessionStorage 5 if (window.location.search) { 6 var params = new URLSearchParams(window.location.search); 7 keys.forEach(function(key) { 8 if (params.has(key)) { 9 sessionStorage.setItem(key, params.get(key)); 10 } 11 }); 11 12 } 12 }13 13 14 const params = new URLSearchParams(window.location.search); 15 const keys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']; 16 17 keys.forEach((key) => { 18 const val = params.get(key); 19 if (val) setCookie(key, val, 30); 20 }); 21 }); 14 // Restore UTM if cookies missing 15 keys.forEach(function(key) { 16 if (!document.cookie.includes(key + '=')) { 17 var val = sessionStorage.getItem(key); 18 if (val) { 19 var expires = new Date(); 20 expires.setTime(expires.getTime() + 30 * 24 * 60 * 60 * 1000); 21 document.cookie = key + '=' + encodeURIComponent(val) + ';path=/;expires=' + expires.toUTCString(); 22 } 23 } 24 }); 25 })(); -
utm-tracker-for-contact-form-7/trunk/readme.txt
r3334582 r3342104 1 1 === UTM Tracker for Contact Form 7 === 2 2 Contributors: AdnanBuksh 3 Donate link: https://adnanwebworks.com /4 Tags: utm, utm tracking, contact form 7, marketing, analytics, campaign, leadtracking3 Donate link: https://adnanwebworks.com?utm_source=wordpress&utm_medium=utm-tracker-cf7 4 Tags: contact form 7, utm tracking, lead tracking, marketing analytics, campaign tracking 5 5 Requires Plugins: contact-form-7 6 Requires at least: 5. 06 Requires at least: 5.6 7 7 Tested up to: 6.8 8 Stable tag: 1. 38 Stable tag: 1.4 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Automatically track and store UTM parameters from URLs in Contact Form 7 submissions. Lightweight, cache-safe, and fully automatic.12 Capture and track UTM parameters in Contact Form 7 submissions. Works with cached pages, supports HTML emails, and is marketer-friendly. 13 13 14 14 == Description == 15 **UTM Tracker for Contact Form 7** is a lightweight plugin that automatically captures UTM parameters from the URL and appends them to Contact Form 7 email notifications.15 **UTM Tracker for Contact Form 7** helps you track the source of every lead by automatically capturing UTM parameters from URLs and attaching them to form submissions. 16 16 17 Perfect for marketers, freelancers, and businesses who want to track marketing campaigns, ad performance, and lead sources—all without writing any code. 17 Perfect for: 18 - Marketers who want to see which ads generate leads 19 - Agencies proving ROI to clients 20 - Business owners avoiding wasted ad spend 18 21 19 This plugin works out of the box, supports all standard UTM parameters (`utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content`), and is compatible with cached pages via cookie storage. 22 If you run **Google Ads**, **Meta Ads**, or other paid/organic campaigns with **UTM parameters** in your URLs, this plugin automatically: 23 1. Detects UTM parameters when a visitor arrives. 24 2. Stores them in cookies (up to 30 days). 25 3. Appends them to your Contact Form 7 submission — works with plain text & HTML emails. 20 26 21 === ✅ Features === 22 * Automatically injects UTM parameters into selected CF7 forms 23 * Stores UTM values in cookies (persist for up to 30 days) 24 * Works perfectly with cached pages and most caching plugins 25 * Appends UTM data to the CF7 email body 26 * Skips empty UTM fields (no clutter) 27 * Fully plug-and-play — no configuration needed 28 * Clean and minimal codebase 27 **Works with popular caching plugins** (e.g., WP Rocket, LiteSpeed, W3 Total Cache) and optimized for high-performance sites. 28 29 === Key Features === 30 - Tracks all standard UTM parameters + `utm_id` (Campaign ID) 31 - Works even if users browse multiple pages before submitting 32 - Stores UTM values for 30 days in cookies 33 - Compatible with HTML & plain text CF7 emails 34 - Backward compatible with WP 5.6.15 & CF7 5.1.9 35 - Zero coding needed — activate and go 36 - Fully compatible with cached pages 37 38 --- 39 40 ### How It Works 41 1. Visitor lands on a page with UTM parameters: 42 `https://yoursite.com/?utm_source=google&utm_medium=cpc&utm_campaign=spring_sale&utm_id=12345` 43 2. Plugin saves the UTM values in cookies. 44 3. When they submit a CF7 form, the UTM data is included in the email. 45 4. You instantly see which campaign generated the lead. 46 47 --- 29 48 30 49 == Installation == 31 1. Upload the plugin folder to `/wp-content/plugins/` or install via the WordPress Plugins directory. 32 2. Activate the plugin from the **Plugins** menu in WordPress. 33 3. Go to **Settings → UTM Tracker for Contact Form 7** and select which forms should track UTM data. 50 1. Upload to `/wp-content/plugins/` or install via Plugins → Add New. 51 2. Activate the plugin. 52 3. Go to **Settings → UTM Tracker for Contact Form 7** and enable tracking for your desired forms. 53 4. Test by submitting a form with UTM parameters in the URL. 54 55 --- 34 56 35 57 == Frequently Asked Questions == 36 58 37 = Does it work with cached pages? = 38 Yes! UTM values are stored in cookies on the first visit and injected into the form later. This makes it compatible with most caching setups. 59 = What is UTM tracking and why is it important? = 60 UTM tracking identifies where your website visitors and leads come from. By adding UTM parameters such as `utm_source` or `utm_campaign` to your links, you can measure campaign performance in detail. 61 Example: You can see if a lead came from Google Ads, Facebook, or an email newsletter. This plugin automatically captures that data in Contact Form 7 submissions — no manual work required. 39 62 40 = Does it track all UTM parameters? = 41 Yes. It supports `utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, and `utm_content` by default. 63 = How do I set up UTM tracking with Contact Form 7? = 64 1. Install and activate Contact Form 7 (required). 65 2. Install and activate **UTM Tracker for Contact Form 7**. 66 3. Open **Settings → UTM Tracker for Contact Form 7** and select the forms that should track UTM data. 67 4. Visit a URL with UTM parameters, for example: 68 `https://example.com/?utm_source=google&utm_medium=cpc&utm_campaign=summer_sale&utm_id=12345` 69 5. Submit the form — the UTM values will appear in your email notification. 42 70 43 = Will this slow down my site? = 44 Not at all. It’s optimized for performance and uses native WordPress & JavaScript APIs only when needed. 71 Need a detailed guide? Visit the **[UTM Tracker Setup Tutorial](https://adnanwebworks.com/blog/utm-tracker-for-contact-form-7-free-plugin-to-track-lead-sources/?utm_source=plugin&utm_medium=faq-link)**. 45 72 46 = Can I use this with multiple forms? = 47 Yes. You can choose which Contact Form 7 forms should track UTM data from the plugin settings. 73 = Does it work with cached or static pages? = 74 Yes. The plugin stores campaign values in cookies when a visitor first arrives, so even with popular caching plugins (e.g., WP Rocket, LiteSpeed, W3 Total Cache), the data is preserved until the form is submitted. 75 76 = Which UTM parameters does this plugin capture? = 77 The plugin supports all common UTM parameters and the newer Campaign ID (`utm_id`): 78 - `utm_source` – Traffic source (e.g., google, facebook, newsletter) 79 - `utm_medium` – Marketing medium (e.g., cpc, email, display) 80 - `utm_campaign` – Campaign name (e.g., summer_sale, product_launch) 81 - `utm_term` – Paid keyword 82 - `utm_content` – Ad variation or content label 83 - `utm_id` – Campaign ID for platforms like Google Ads 84 85 = How long is UTM data stored? = 86 By default, campaign values are stored for **30 days**. This helps track leads who convert later. The duration can be changed with a simple code snippet — see the **[Developer Documentation](https://adnanwebworks.com/utm-tracker-cf7-developer-docs?utm_source=plugin&utm_medium=faq-link)**. 87 88 = Can this plugin help prove marketing ROI? = 89 Yes. Businesses and agencies can see exactly which campaigns, ads, or sources generate form submissions. This makes it easier to allocate ad spend to the highest-performing channels. 90 91 = Is it GDPR compliant? = 92 Yes. The plugin stores only non-personal UTM values in cookies. No personal data is collected or transmitted. However, update your privacy policy to mention UTM cookie usage. 93 94 = Will it slow down my website? = 95 No. The plugin is lightweight, uses minimal JavaScript, and does not add heavy assets. It’s fully compatible with high-performance hosting and caching setups. 96 97 If you need extra functionality beyond UTM tracking — like custom reporting, integrations, or automation — I offer [custom plugin development](https://adnanwebworks.com/custom-plugin-development?utm_source=plugin&utm_medium=faq-link) for WordPress. 98 99 --- 48 100 49 101 == Screenshots == … … 52 104 3. Browser address bar with UTM parameters before form submission. 53 105 106 --- 107 54 108 == Changelog == 55 109 110 = 1.4 = 111 * Added `utm_id` (Campaign ID) support 112 * HTML email compatibility 113 * Improved sanitization & performance 114 * Verified WP 5.6.15 + CF7 5.1.9 support 115 56 116 = 1.3 = 57 * Added JS hydration to auto-fill UTM values intoCF7 forms58 * Fixed mail formatting for better readability59 * Added fallback logic if UTM values are missing117 * Added JS hydration for CF7 forms 118 * Fixed email formatting 119 * Added fallback logic for missing values 60 120 61 121 = 1.2 = 62 * Added admin UI to select which forms should track UTM63 * Improved settings UX and save logic122 * Added form selection UI in settings 123 * Improved settings UX 64 124 65 125 = 1.1 = 66 * Initial public release 126 * First public release 127 128 --- 67 129 68 130 == Upgrade Notice == 69 = 1. 3=70 Recommended update. This version improves JS hydration and compatibility with more themes and caching solutions.131 = 1.4 = 132 Supports `utm_id` and HTML emails. Upgrade recommended for accurate tracking. -
utm-tracker-for-contact-form-7/trunk/utm-tracker-for-contact-form-7.php
r3334582 r3342104 2 2 /** 3 3 * Plugin Name: UTM Tracker for Contact Form 7 4 * Description: Fully automatic UTM tracker for CF7 with no manual work. Cache-safe, plug-and-play.5 * Version: 1. 34 * Description: Automatically capture and store UTM parameters in Contact Form 7 submissions — works with cached pages, supports HTML emails, and tracks campaign sources with no manual setup. 5 * Version: 1.4 6 6 * Author: Adnan Buksh 7 * Author URI: https://adnanwebworks.com /7 * Author URI: https://adnanwebworks.com?utm_source=wordpress&utm_medium=utm+tracker+for+contact+form+7 8 8 * Text Domain: utm-tracker-for-contact-form-7 9 9 * Requires Plugins: contact-form-7 10 10 * License: GPLv2 or later 11 11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 12 * Requires at least: 5. 012 * Requires at least: 5.6 13 13 * Tested up to: 6.8 14 14 * Requires PHP: 7.2 15 15 */ 16 16 17 if (!defined('ABSPATH')) exit; 17 add_action( 'init', function () { 18 if ( is_admin() ) { 19 return; 20 } 21 22 $utm_keys = [ 'utm_source', 'utm_medium', 'utm_campaign', 'utm_id', 'utm_term', 'utm_content' ]; 23 24 foreach ( $utm_keys as $key ) { 25 // Get the value from the query string safely 26 $value = filter_input( INPUT_GET, $key, FILTER_SANITIZE_STRING ); 27 28 if ( $value && ! isset( $_COOKIE[ $key ] ) ) { 29 $sanitized_value = sanitize_text_field( wp_unslash( $value ) ); 30 31 setcookie( 32 $key, 33 $sanitized_value, 34 time() + 30 * DAY_IN_SECONDS, 35 COOKIEPATH ? COOKIEPATH : '/', 36 COOKIE_DOMAIN 37 ); 38 } 39 } 40 }, 1 ); 41 42 18 43 19 44 class UTM_Tracker_CF7 { … … 23 48 add_action('admin_menu', array($this, 'add_admin_menu')); 24 49 add_action('admin_init', array($this, 'register_settings')); 25 26 50 add_action('wpcf7_init', array($this, 'add_utm_form_tags')); 27 51 add_action('wpcf7_before_send_mail', array($this, 'set_utm_mail_tags'), 10, 3); 28 52 add_filter('wpcf7_posted_data', array($this, 'save_utm_data')); 29 30 53 add_filter('wpcf7_form_elements', array($this, 'inject_hidden_fields'), 20, 2); 31 54 add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); … … 96 119 plugins_url('js/utm-tracker.js', __FILE__), 97 120 array(), 98 '1. 3',121 '1.4', 99 122 true 100 123 ); … … 102 125 103 126 public function add_utm_form_tags() { 104 $keys = array('source', 'medium', 'campaign', ' term', 'content');127 $keys = array('source', 'medium', 'campaign', 'id', 'term', 'content'); 105 128 foreach ($keys as $key) { 106 129 wpcf7_add_form_tag('utm_' . $key, '__return_empty_string', array('name-attr' => true)); … … 114 137 115 138 $fields = "\n"; 116 foreach (array('source', 'medium', 'campaign', ' term', 'content') as $key) {117 $fields .= '<input type="hidden" name="utm_' . esc_attr($key) . '" class="utm utm_' . esc_attr($key) . '" value="" />' ;139 foreach (array('source', 'medium', 'campaign', 'id', 'term', 'content') as $key) { 140 $fields .= '<input type="hidden" name="utm_' . esc_attr($key) . '" class="utm utm_' . esc_attr($key) . '" value="" />' . "\n"; 118 141 } 119 120 $fields .= "\n<script>121 document.addEventListener('DOMContentLoaded', function() {122 ['source','medium','campaign','term','content'].forEach(function(k){123 var val = decodeURIComponent((document.cookie.match('(^|;) ?utm_' + k + '=([^;]*)(;|$)')||[])[2]||'');124 if (val) document.querySelectorAll('.utm_' + k).forEach(function(f){ f.value = val; });125 });126 });127 </script>\n";128 142 129 143 return $content . $fields; … … 131 145 132 146 public function save_utm_data($posted_data) { 133 foreach (array('utm_source', 'utm_medium', 'utm_campaign', 'utm_ term', 'utm_content') as $key) {147 foreach (array('utm_source', 'utm_medium', 'utm_campaign', 'utm_id', 'utm_term', 'utm_content') as $key) { 134 148 if (isset($_COOKIE[$key])) { 135 149 $posted_data[$key] = sanitize_text_field(wp_unslash($_COOKIE[$key])); … … 151 165 'utm_medium' => 'UTM Medium', 152 166 'utm_campaign' => 'UTM Campaign', 167 'utm_id' => 'UTM ID', 153 168 'utm_term' => 'UTM Term', 154 169 'utm_content' => 'UTM Content', … … 164 179 if (!empty($lines)) { 165 180 $properties = $contact_form->get_properties(); 166 $properties['mail']['body'] .= "\n\n--- UTM DATA ---\n" . implode("\n", $lines); 181 $is_html = !empty($properties['mail']['use_html']) && $properties['mail']['use_html']; 182 183 $separator = $is_html ? '<br>' : "\n"; 184 $utm_block = ($is_html ? '<br><strong>--- UTM DATA ---</strong><br>' : "\n\n--- UTM DATA ---\n") . implode($separator, $lines); 185 186 $properties['mail']['body'] .= $utm_block; 167 187 $contact_form->set_properties($properties); 168 188 }
Note: See TracChangeset
for help on using the changeset viewer.