Troubleshooting
This guide helps you diagnose and fix common issues with Moli ad tag integration. Learn how to identify problems, use debugging tools, and resolve issues quickly.
Overview
This troubleshooting guide covers:
- Common integration issues
- Debugging techniques
- Error messages and solutions
- Performance problems
- Testing and validation
Quick Diagnostic Checklist
Before diving into specific issues, run through this checklist:
- Moli script is loaded (check Network tab)
- Google Publisher Tag is loaded
- Ad slot containers exist in DOM
- Ad slot IDs match configuration
- No JavaScript errors in console
- Debug mode is enabled (if needed)
Common Issues
Ads Not Loading
Symptoms: Ad containers are empty, no ad requests in Network tab
Possible Causes:
- Moli script not loaded
- Ad slot IDs don't match configuration
- JavaScript errors preventing execution
- Ad blockers interfering
Solutions:
-
Check script loading:
-
Verify ad slot IDs:
<!-- Ensure IDs match your configuration -->
<div id="header-ad"></div>
<div id="content-ad"></div>
<div id="sidebar-ad"></div> -
Check for JavaScript errors:
// Add error handling
window.moli = window.moli || { que: [] };
window.moli.que.push(function(moliAdTag) {
try {
moliAdTag.requestAds();
} catch (error) {
console.error('Failed to request ads:', error);
}
}); -
Test without ad blockers:
- Disable ad blockers temporarily
- Test in incognito mode
- Check browser extensions
Wrong Ad Sizes
Symptoms: Ads appear in wrong sizes, layout shifts occur
Possible Causes:
- Responsive configuration issues
- CSS overriding ad container sizes
- Device detection problems
Solutions:
-
Check responsive configuration:
/* Ensure proper ad container sizing */
.ad-container {
min-height: 250px; /* Reserve space */
width: 100%;
max-width: 300px;
}
/* Mobile responsive */
@media (max-width: 768px) {
.ad-container {
min-height: 90px;
max-width: 320px;
}
} -
Verify device detection:
// Test device detection
window.moli.que.push(function(moliAdTag) {
const targeting = moliAdTag.getPageTargeting();
console.log('Device targeting:', targeting);
}); -
Check CSS conflicts:
/* Prevent CSS from overriding ad sizes */
.ad-container iframe {
width: 100% !important;
height: 100% !important;
}
Targeting Not Working
Symptoms: Ads don't reflect targeting parameters, wrong ads shown
Possible Causes:
- Targeting set after
requestAds()called - Invalid targeting keys/values
- Targeting not applied correctly
Solutions:
-
Set targeting before requesting ads:
// ✅ Correct order
window.moli.que.push(function(moliAdTag) {
moliAdTag.setTargeting('page_type', 'homepage');
moliAdTag.setTargeting('user_segment', 'premium');
moliAdTag.addLabel('mobile');
moliAdTag.requestAds(); // Call after setting targeting
});
// ❌ Wrong order
window.moli.que.push(function(moliAdTag) {
moliAdTag.requestAds(); // Too early!
moliAdTag.setTargeting('page_type', 'homepage'); // Won't work
}); -
Verify targeting values:
// Debug targeting
window.moli.que.push(function(moliAdTag) {
moliAdTag.setTargeting('page_type', getPageType());
moliAdTag.setTargeting('user_segment', getUserSegment());
// Log targeting for verification
const targeting = moliAdTag.getPageTargeting();
console.log('Current targeting:', targeting);
moliAdTag.requestAds();
}); -
Check targeting format:
// Ensure valid targeting format
moliAdTag.setTargeting('key', 'value'); // String
moliAdTag.setTargeting('array_key', ['value1', 'value2']); // Array
moliAdTag.addLabel('label'); // Single label
Single Page Application Issues
Symptoms: Ads don't refresh on route changes, duplicate ads
Possible Causes:
- SPA mode not enabled
- Route change detection not working
- Multiple ad requests triggered
Solutions:
-
Enable SPA mode:
const moliConfig = {
spa: {
enabled: true,
validateLocation: 'href' // or 'pathname'
}
}; -
Handle route changes correctly:
// React example
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
function App() {
const location = useLocation();
useEffect(() => {
window.moli.que.push(function(moliAdTag) {
moliAdTag.requestAds();
});
}, [location]); // Trigger on route change
return <Routes />;
}
- Prevent duplicate requests:
// Debounce route changes
let routeChangeTimeout;
const handleRouteChange = () => {
clearTimeout(routeChangeTimeout);
routeChangeTimeout = setTimeout(() => {
window.moli.que.push(function(moliAdTag) {
moliAdTag.requestAds();
});
}, 100);
};
Debugging Techniques
Enable Debug Mode
Enable Moli's debug console for detailed information:
// Enable debug mode programmatically
window.moli.que.push(function(moliAdTag) {
moliAdTag.openConsole();
moliAdTag.requestAds();
});
Or add to URL:
https://yoursite.com?moliDebug=true
Browser DevTools
Use browser developer tools for debugging:
-
Console tab:
- Check for JavaScript errors
- Look for Moli-related messages
- Verify targeting values
-
Network tab:
- Monitor ad requests
- Check response status codes
- Verify request parameters
-
Elements tab:
- Inspect ad containers
- Check for CSS conflicts
- Verify DOM structure
Custom Debugging
Add custom debugging code:
// Debug ad loading process
window.moli.que.push(function(moliAdTag) {
// Debug targeting
console.group('Moli Debug Info');
console.log('Ad slot IDs:', ['header-ad', 'content-ad', 'sidebar-ad']);
console.log('Page URL:', window.location.href);
console.log('User Agent:', navigator.userAgent);
// Set up event listeners for debugging
moliAdTag.addEventListener('beforeRequestAds', (event) => {
console.log('Before requesting ads:', event.runtimeConfig);
});
moliAdTag.addEventListener('afterRequestAds', (event) => {
console.log('After requesting ads:', event.state);
});
console.groupEnd();
moliAdTag.requestAds();
});
Error Messages
Common Error Messages
"Moli script not loaded"
- Check script URL is correct
- Verify script is loading in Network tab
- Check for 404 errors
"Ad slot not found"
- Verify ad slot ID exists in DOM
- Check for typos in slot IDs
- Ensure containers are created before requesting ads
"Invalid targeting key"
- Check targeting key format
- Ensure keys are strings
- Verify no special characters
"Request ads called too early"
- Ensure Moli is initialized before calling
requestAds() - Check script loading order
- Verify command queue is set up
Error Handling
Implement proper error handling:
// Comprehensive error handling
window.moli = window.moli || { que: [] };
window.moli.que.push(function(moliAdTag) {
try {
// Set up error monitoring
moliAdTag.addEventListener('afterRequestAds', (event) => {
if (event.state === 'error') {
console.error('Ad request failed:', event);
// Send error to monitoring service
errorReporting.captureException(new Error('Ad request failed'), {
tags: { component: 'moli-ad-tag' },
extra: { state: event.state }
});
}
});
// Set targeting with validation
const targeting = {
page_type: getPageType(),
user_segment: getUserSegment()
};
Object.entries(targeting).forEach(([key, value]) => {
if (value && typeof value === 'string') {
moliAdTag.setTargeting(key, value);
}
});
moliAdTag.requestAds();
} catch (error) {
console.error('Moli initialization failed:', error);
// Fallback behavior
showFallbackContent();
}
});
Performance Issues
Layout Shifts
Symptoms: Page content jumps when ads load
Solutions:
-
Reserve space for ads:
.ad-container {
min-height: 250px; /* Reserve space */
background: #f0f0f0; /* Placeholder */
} -
Use CSS containment:
.ad-container {
contain: layout style paint;
min-height: 250px;
} -
Smooth transitions:
.ad-container {
transition: height 0.3s ease;
}
Testing and Validation
Unit Testing
Test Moli integration with Jest:
// Mock Moli for testing
const mockMoliAdTag = {
requestAds: jest.fn(),
setTargeting: jest.fn(),
addLabel: jest.fn(),
getPageTargeting: jest.fn(),
addEventListener: jest.fn()
};
global.window.moli = {
que: []
};
beforeEach(() => {
global.window.moli.que = [];
jest.clearAllMocks();
});
test('should request ads with correct targeting', () => {
// Test implementation
window.moli.que.push(function(moliAdTag) {
moliAdTag.setTargeting('page_type', 'homepage');
moliAdTag.requestAds();
});
expect(mockMoliAdTag.setTargeting).toHaveBeenCalledWith('page_type', 'homepage');
expect(mockMoliAdTag.requestAds).toHaveBeenCalled();
});
Integration Testing
A basic test case is to validate that the moli.que is being processed.
const spy = sandbox.spy();
moli.moli.que.push(spy);
await new Promise(resolve => window.moli.que.push(resolve)); // requires a timeout
expect(spy).to.have.been.called;
Manual Testing
Create a testing checklist:
- Ads load on page load
- Ads refresh on route changes (SPA)
- Targeting works correctly
- Responsive ads display properly
- No console errors
- Performance is acceptable
- Layout shifts are minimal
Getting Help
Self-Service Resources
-
Check the documentation:
-
Use debugging tools:
- Enable debug mode
- Check browser console
- Monitor network requests
-
Test in isolation:
- Create minimal test case
- Test without other scripts
- Verify in different browsers
Contact Highfivve
We are always happy to help.
Best Practices
Prevention
-
Test thoroughly:
- Test in multiple browsers
- Test on different devices
- Test with different configurations
-
Monitor performance:
- Track Core Web Vitals
- Monitor ad load times
- Watch for errors
-
Use error handling:
- Implement try-catch blocks
- Add fallback behavior
- Monitor for failures
Maintenance
-
Keep updated:
- Update Moli version regularly
- Monitor for breaking changes
- Test after updates
-
Monitor analytics:
- Track ad performance
- Monitor user experience
- Watch for anomalies
-
Document changes:
- Keep integration notes
- Document customizations
- Track configuration changes