Back to Community

Resolving the 'ga is not defined' JavaScript Conflict on Login Pages

Content

One of the most common and disruptive issues reported by users of the ExactMetrics plugin (formerly GADWP) is a JavaScript conflict that occurs on the WordPress login page. This problem often manifests as a "ga is not defined" error in the browser console and can prevent other critical functions, like two-factor authentication from Wordfence, from working correctly.

What Causes the "ga is not defined" Error?

The root cause is a setting within the ExactMetrics plugin. When the "Track form submit actions" option is enabled on the "Events Tracking" tab, the plugin injects a JavaScript click handler to track form submissions. This script runs on all pages, including wp-login.php.

The Google Analytics tracking code (analytics.js), which defines the ga() function, is intentionally not loaded on the login page for privacy and performance reasons. Therefore, when the plugin's event tracking script tries to call the non-existent ga() function, it throws a ReferenceError and halts the execution of any subsequent JavaScript on the page.

How to Identify the Problem

If you are experiencing login issues, especially with 2FA, follow these steps to confirm this is the cause:

  1. Open your browser's developer tools (F12).
  2. Navigate to the Console tab.
  3. Go to your WordPress login page.
  4. If you see an error like Uncaught ReferenceError: ga is not defined, this guide applies to you.

How to Fix It

The most effective and immediate solution is to adjust the plugin's settings.

  1. Log into your WordPress admin dashboard.
  2. Navigate to ExactMetrics -> Settings.
  3. Click on the "Engagement" tab.
  4. Locate the "Events Tracking" section.
  5. Find the setting for "Track form submit actions" and disable it.
  6. Save your changes.

This prevents the plugin from attempting to track events on the login page, eliminating the JavaScript error and resolving the conflict with other scripts.

For Developers: A Code-Based Workaround

If you must keep form tracking enabled, a more technical solution involves adding a custom filter to your theme's functions.php file. This code will prevent the ExactMetrics events tracking script from loading on the login page entirely.

/**
 * Dequeue ExactMetrics events tracking on the login page
 */
function my_dequeue_exactmetrics_login_script() {
    if ( isset( $_SERVER['SCRIPT_NAME'] ) && strpos( $_SERVER['SCRIPT_NAME'], 'wp-login.php' ) !== false ) {
        wp_dequeue_script( 'exactmetrics-frontend-script' ); // The script handle may vary.
    }
}
add_action( 'wp_print_scripts', 'my_dequeue_exactmetrics_login_script' );

Note: Use this code with caution and always test on a staging site first. The exact script handle may change between plugin versions.

Conclusion

This conflict is a classic example of how a powerful feature in one plugin can inadvertently affect another. The ExactMetrics team has been made aware of this interaction in the past. For most users, simply disabling the "Track form submit actions" option provides a quick and complete resolution, allowing for a smooth login experience without sacrificing the core analytics functionality of the plugin.

Related Support Threads Support