If you're experiencing problems with your event tracking script not firing properly, especially on thank you or conversion pages, consider the following solutions:
1. Script Loading Order
Issue
The event tracking script may attempt to fire before the main tracking library is fully loaded and initialized. This is common on fast redirects or short-lived pages such as thank you pages.
Solution 1: Push events to a queue before initialization (Recommended)
Instead of calling the tracking function directly, use the event queue. This ensures the event is safely stored and processed once the tracking library is ready.
<script>
window.mdq = window.mdq || [];
mdq.push(["track", "Purchased", {
// Optional attributes
}]);
</script>
This approach is reliable and works even if the tracking library has not finished loading.
Solution 2: Add a delay to event firing (Not Recommended)
You may attempt to delay the event call using setTimeout:
<script>
setTimeout(() => mida.track("Purchased", {
// Optional attributes
}), 2000);
</script>
Why this is not recommended:
The tracking library may still not be loaded after the delay
The user may leave the page before the delay completes
Network conditions make timing unpredictable
Events can fire inconsistently across devices and browsers
Using delays relies on timing assumptions and should only be considered a temporary workaround.
2. Script Placement
Ensure that your main tracking library script is placed before any event tracking scripts in your HTML. This reduces the risk of events firing before initialization.
3. Console Error Checking
Always check your browser’s developer console for JavaScript errors that could prevent the tracking script from running correctly.
4. Testing and Verification
Use preview or debug modes in tag management systems to verify trigger conditions
Implement test events to confirm tracking works in a controlled environment
5. Cross-Browser Testing
Test your implementation across different browsers and devices to ensure consistent behavior.
Summary
Event tracking issues are commonly caused by scripts firing before the tracking library is ready
Queue-based tracking is the recommended and most reliable solution
Delaying event calls with
setTimeoutis not recommended due to reliability and timing issuesProper script placement and testing help prevent tracking failures
