Skip to content

Add GA4 conversion tracking for subscription form - #93

Merged
katsar0v merged 8 commits into
mainfrom
copilot/add-ga4-conversion-tracking
Feb 12, 2026
Merged

Add GA4 conversion tracking for subscription form#93
katsar0v merged 8 commits into
mainfrom
copilot/add-ga4-conversion-tracking

Conversation

Copilot AI commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Marketing teams cannot track newsletter signups as conversions because the AJAX subscription handler doesn't emit analytics events.

Changes

Settings

  • Added enable_ga4_tracking checkbox in admin settings (Subscription Form section)
  • Defaults to disabled; stored as 0/1 integer following plugin conventions

Frontend

  • Pass setting to JavaScript via wp_localize_script
  • Fire gtag('event', 'generate_lead', {...}) on successful subscription when enabled
  • Strict boolean check (=== true) and existence verification for gtag
  • Try-catch wrapper prevents errors if GA4/GTM fails

Example

// In public-script.js AJAX success handler
if (mskd_public.enable_ga4_tracking === true && typeof gtag !== 'undefined') {
    try {
        gtag('event', 'generate_lead', {
            'event_category': 'newsletter',
            'event_label': 'subscription_form'
        });
    } catch (error) {
        console.warn('MSKD: Failed to send GA4 event', error);
    }
}

Tests & Translations

  • Added unit tests for setting defaults and state changes
  • Updated Bulgarian and German translations

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/d95a9d895352c30f47604ad1b825ab8fa9d1a373
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/vEACbP /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0ca86845ce43291e8f5692c7356fccf3bcf02bf4
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/vEACbP /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/845eb62303d2ca9b289ef216356568ccc075ffd1
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/244d7b04fc4bc2117c15f5abe23eb933b5f02bbf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/7c8d18b4d90dac9e86b0869a608fa09158e168fa
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/antecedent/patchwork/zipball/8b6b235f405af175259c8f56aea5fc23ab9f03ce
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/composer/installers/zipball/12fb2dfe5e16183de69e784a7b84046c43d97e8e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/vEACbP /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/vEACbP /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/hamcrest/hamcrest-php/zipball/f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/mockery/mockery/zipball/1f4efdd7d3beafe9807b08156dfcb176d18f1699
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/nikic/PHP-Parser/zipball/3a454ca033b9e06b63282ce19562e892747449bb
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/aqPzP7 /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Add GA4 Conversion Tracking Option for Subscription Form</issue_title>
<issue_description># Add GA4 Conversion Tracking Option for Subscription Form

Description

Currently, the subscription form does not fire any Google Analytics 4 (GA4) or Google Tag Manager (GTM) events upon successful subscription.

Problem

Marketing teams cannot track successful newsletter signups as conversions in GA4 because the AJAX handler (public/js/public-script.js) only updates the UI text without emitting a data layer event.

Proposed Solution

Add a new setting in the plugin settings page (under the "Styling" or a new "Tracking" section):

  • Enable GA4 Conversion Tracking

Implementation Details

  1. Add a checkbox to the settings page in admin/partials/settings.php.
  2. Pass this setting to the frontend via wp_localize_script in public/class-public.php.
  3. In public/js/public-script.js, check if this setting is enabled.
  4. If enabled, fire a gtag event on successful subscription:
    if (mskd_public.enable_tracking) {
        gtag('event', 'generate_lead', {
            'event_category': 'newsletter',
            'event_label': 'subscription_form'
        });
    }</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 6, 2026 12:19
Co-authored-by: katsar0v <7236157+katsar0v@users.noreply.github.com>
Co-authored-by: katsar0v <7236157+katsar0v@users.noreply.github.com>
Co-authored-by: katsar0v <7236157+katsar0v@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GA4 conversion tracking option for subscription form Add GA4 conversion tracking for subscription form Jan 6, 2026
Copilot AI requested a review from katsar0v January 6, 2026 12:25
- Document new GA4 conversion tracking feature
- Added entry to [Unreleased] section
- Includes details about the new setting and tracking functionality
Resolved conflicts:
- CHANGELOG.md: Merged GA4 Conversion Tracking and Mass Delete Subscribers features
- languages/mail-system-by-katsarov-design-bg_BG.po: Merged translation strings
- languages/mail-system-by-katsarov-design.pot: Merged translation strings
- languages/mail-system-by-katsarov-design-bg_BG.mo: Regenerated from .po file
- languages/mail-system-by-katsarov-design-de_DE.mo: Regenerated from .po file
- plans/: Removed directory (not part of merge scope)

All 191 tests passed successfully.
@katsar0v
katsar0v marked this pull request as ready for review February 12, 2026 08:29
@katsar0v
katsar0v merged commit da45fea into main Feb 12, 2026
7 checks passed
@katsar0v
katsar0v deleted the copilot/add-ga4-conversion-tracking branch February 12, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add GA4 Conversion Tracking Option for Subscription Form

2 participants