Back to Community

Troubleshooting MonsterInsights Link Tracking Conflicts with Lightboxes and Custom Code

20 threads Sep 9, 2025 PluginMonsterinsights

Content

Many WordPress users rely on MonsterInsights to simplify Google Analytics tracking. However, a common point of confusion arises when the plugin's automated tracking features conflict with existing site functionality, such as lightbox popups (e.g., Fancybox, Magnific Popup) or custom event tracking code. This guide explains why these conflicts happen and provides the most effective solutions.

Why Do These Conflicts Occur?

MonsterInsights replaces the standard Google Analytics ga() function with its own __gaTracker() function to manage its automated tracking. This is the core reason for two primary types of conflicts:

  1. Custom Event Tracking Breaks: If you have manually added onclick event tracking using the standard ga('send', 'event'...) code, it will cease to function because the ga object is no longer defined. The console will show an error: "Uncaught ReferenceError: ga is not defined".
  2. Lightboxes and Popups Malfunction: MonsterInsights' outbound link and download tracking can interfere with scripts that power lightboxes. This often manifests as a popup opening correctly but then immediately closing or redirecting to the full-size image file. This happens because the plugin's JavaScript misidentifies a lightbox trigger as a standard outbound link or file download.

How to Resolve Custom Event Tracking Issues

If your manually implemented Google Analytics events have stopped working, the solution is to update your code to use the correct function name.

Solution 1: Update the Function Name

Replace all instances of ga('send' in your custom tracking code with __gaTracker('send'.

Old Code:
<a onclick="ga('send', 'event', 'Downloads', 'Click', 'File_Name.pdf');">Download</a>

New Code:
<a onclick="__gaTracker('send', 'event', 'Downloads', 'Click', 'File_Name.pdf');">Download</a>

This change ensures your custom events are pushed through the same tracker that MonsterInsights uses.

Solution 2: Use MonsterInsights' Custom Attribution System

As an alternative to writing manual JavaScript, the MonsterInsights team suggests using HTML attributes for event tracking. This method can be more stable across updates. You can find instructions for this method on their website.

How to Resolve Lightbox and Popup Conflicts

If your image popups (Fancybox, Magnific Popup, etc.) are broken, the conflict is likely caused by the file download tracking feature incorrectly processing the lightbox triggers.

Solution: Adjust File Download Settings

The most effective fix is to modify the file extensions that MonsterInsights tracks as downloads. Image file extensions (like .jpg, .png, .gif) are often included by default, which causes the plugin to treat a lightbox action as a file download.

  1. In your WordPress dashboard, navigate to Insights » Settings.
  2. Click on the Engagement tab.
  3. Find the setting labeled Extensions of Files to Track as Downloads.
  4. In this field, remove the image file extensions (e.g., jpg, jpeg, gif, png, bmp).
  5. Save your settings.

This tells MonsterInsights to ignore clicks on image files, allowing your lightbox script to handle them without interference. The side effect is that actual downloads of image files will no longer be tracked in Analytics, which is typically an acceptable trade-off.

Conclusion

Conflicts between MonsterInsights' automated tracking and other site elements are almost always due to the plugin's JavaScript overriding default functions or being overly aggressive in classifying clicks. By updating custom event code to use __gaTracker and fine-tuning the file download settings, you can eliminate these common issues and enjoy seamless analytics tracking alongside your site's functionality.

Related Support Threads Support