Plugin Directory

Changeset 3342104


Ignore:
Timestamp:
08/09/2025 06:56:29 PM (8 months ago)
Author:
adnanbuksh
Message:

Release version 1.4 - Added utm_id support, fixed HTML email formatting, and preserved UTM after redirects.

Location:
utm-tracker-for-contact-form-7
Files:
5 added
6 edited

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'];
    33
    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        });
    1112    }
    12   }
    1313
    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  
    11=== UTM Tracker for Contact Form 7 ===
    22Contributors: AdnanBuksh
    3 Donate link: https://adnanwebworks.com/
    4 Tags: utm, utm tracking, contact form 7, marketing, analytics, campaign, lead tracking
     3Donate link: https://adnanwebworks.com?utm_source=wordpress&utm_medium=utm-tracker-cf7
     4Tags: contact form 7, utm tracking, lead tracking, marketing analytics, campaign tracking
    55Requires Plugins: contact-form-7
    6 Requires at least: 5.0
     6Requires at least: 5.6
    77Tested up to: 6.8
    8 Stable tag: 1.3
     8Stable tag: 1.4
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1111
    12 Automatically track and store UTM parameters from URLs in Contact Form 7 submissions. Lightweight, cache-safe, and fully automatic.
     12Capture and track UTM parameters in Contact Form 7 submissions. Works with cached pages, supports HTML emails, and is marketer-friendly.
    1313
    1414== 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.
    1616
    17 Perfect for marketers, freelancers, and businesses who want to track marketing campaigns, ad performance, and lead sources—all without writing any code.
     17Perfect for:
     18- Marketers who want to see which ads generate leads
     19- Agencies proving ROI to clients
     20- Business owners avoiding wasted ad spend
    1821
    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.
     22If you run **Google Ads**, **Meta Ads**, or other paid/organic campaigns with **UTM parameters** in your URLs, this plugin automatically:
     231. Detects UTM parameters when a visitor arrives.
     242. Stores them in cookies (up to 30 days).
     253. Appends them to your Contact Form 7 submission — works with plain text & HTML emails.
    2026
    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
     411. 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`
     432. Plugin saves the UTM values in cookies.
     443. When they submit a CF7 form, the UTM data is included in the email.
     454. You instantly see which campaign generated the lead.
     46
     47---
    2948
    3049== 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.
     501. Upload to `/wp-content/plugins/` or install via Plugins → Add New.
     512. Activate the plugin.
     523. Go to **Settings → UTM Tracker for Contact Form 7** and enable tracking for your desired forms.
     534. Test by submitting a form with UTM parameters in the URL.
     54
     55---
    3456
    3557== Frequently Asked Questions ==
    3658
    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? =
     60UTM 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. 
     61Example: 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.
    3962
    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? =
     641. Install and activate Contact Form 7 (required). 
     652. Install and activate **UTM Tracker for Contact Form 7**. 
     663. Open **Settings → UTM Tracker for Contact Form 7** and select the forms that should track UTM data. 
     674. 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` 
     695. Submit the form — the UTM values will appear in your email notification. 
    4270
    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.
     71Need 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)**.
    4572
    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? =
     74Yes. 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? =
     77The 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? =
     86By 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? =
     89Yes. 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? =
     92Yes. 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? =
     95No. 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
     97If 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---
    48100
    49101== Screenshots ==
     
    521043. Browser address bar with UTM parameters before form submission.
    53105
     106---
     107
    54108== Changelog ==
    55109
     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
    56116= 1.3 =
    57 * Added JS hydration to auto-fill UTM values into CF7 forms
    58 * Fixed mail formatting for better readability
    59 * Added fallback logic if UTM values are missing
     117* Added JS hydration for CF7 forms
     118* Fixed email formatting
     119* Added fallback logic for missing values
    60120
    61121= 1.2 =
    62 * Added admin UI to select which forms should track UTM
    63 * Improved settings UX and save logic
     122* Added form selection UI in settings
     123* Improved settings UX
    64124
    65125= 1.1 =
    66 * Initial public release
     126* First public release
     127
     128---
    67129
    68130== Upgrade Notice ==
    69 = 1.3 =
    70 Recommended update. This version improves JS hydration and compatibility with more themes and caching solutions.
     131= 1.4 =
     132Supports `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  
    22/**
    33 * 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.3
     4 * 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
    66 * 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
    88 * Text Domain: utm-tracker-for-contact-form-7
    99 * Requires Plugins: contact-form-7
    1010 * License: GPLv2 or later
    1111 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    12  * Requires at least: 5.0
     12 * Requires at least: 5.6
    1313 * Tested up to: 6.8
    1414 * Requires PHP: 7.2
    1515 */
    1616
    17 if (!defined('ABSPATH')) exit;
     17add_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
    1843
    1944class UTM_Tracker_CF7 {
     
    2348        add_action('admin_menu', array($this, 'add_admin_menu'));
    2449        add_action('admin_init', array($this, 'register_settings'));
    25 
    2650        add_action('wpcf7_init', array($this, 'add_utm_form_tags'));
    2751        add_action('wpcf7_before_send_mail', array($this, 'set_utm_mail_tags'), 10, 3);
    2852        add_filter('wpcf7_posted_data', array($this, 'save_utm_data'));
    29 
    3053        add_filter('wpcf7_form_elements', array($this, 'inject_hidden_fields'), 20, 2);
    3154        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
     
    96119            plugins_url('js/utm-tracker.js', __FILE__),
    97120            array(),
    98             '1.3',
     121            '1.4',
    99122            true
    100123        );
     
    102125
    103126    public function add_utm_form_tags() {
    104         $keys = array('source', 'medium', 'campaign', 'term', 'content');
     127        $keys = array('source', 'medium', 'campaign', 'id', 'term', 'content');
    105128        foreach ($keys as $key) {
    106129            wpcf7_add_form_tag('utm_' . $key, '__return_empty_string', array('name-attr' => true));
     
    114137
    115138        $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";
    118141        }
    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";
    128142
    129143        return $content . $fields;
     
    131145
    132146    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) {
    134148            if (isset($_COOKIE[$key])) {
    135149                $posted_data[$key] = sanitize_text_field(wp_unslash($_COOKIE[$key]));
     
    151165            'utm_medium'   => 'UTM Medium',
    152166            'utm_campaign' => 'UTM Campaign',
     167            'utm_id'       => 'UTM ID',
    153168            'utm_term'     => 'UTM Term',
    154169            'utm_content'  => 'UTM Content',
     
    164179        if (!empty($lines)) {
    165180            $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;
    167187            $contact_form->set_properties($properties);
    168188        }
Note: See TracChangeset for help on using the changeset viewer.