Problem definition
WordPress caching and optimization plugins like WP Rocket, Autoptimize, W3 Total Cache, and LiteSpeed Cache are popular for speeding up websites. However, they can inadvertently interfere with affiliate tracking by changing how JavaScript is loaded. This can prevent Post Affiliate Pro’s tracking scripts from executing correctly, leading to missed affiliate clicks or sales.
Understanding how these plugins alter script loading is essential for maintaining accurate tracking and ensuring your affiliate program functions as intended.
How WP Rocket and other caching plugins affect Post Affiliate Pro tracking
WP Rocket and similar plugins optimize your site by delaying, combining, or minifying JavaScript files. They often add attributes such as “defer” or “async” to <script> tags, or move scripts to the footer. While these changes improve performance, they can disrupt the precise timing needed for Post Affiliate Pro tracking scripts to function, causing tracking failures.
The most common issues include:
- Tracking script not firing at all
- Tracking script firing too late (after the visitor leaves)
- Tracking script being minified or combined in a way that breaks functionality
Troubleshooting: Ensuring your tracking script is excluded from optimization
- Identify your tracking script: The tracking script’s file name in the
src attribute (e.g., a1x2j2) is unique to your installation, and the script’s ID is typically pap_x2s6df8d. To find your exact script, go to your Post Affiliate Pro merchant panel and navigate to Tools → Integration → Click tracking. Use both the script’s file name (a1x2j2) and its ID (pap_x2s6df8d) for exclusions. - Exclude from optimization:
- WP Rocket: In WP Rocket settings, go to “File Optimization” and add your tracking script’s full URL or filename (as found in the merchant panel, e.g., a1x2j2) to the “Excluded JavaScript Files” field. You can also target the script by its ID (
pap_x2s6df8d). - Custom scripts: Add the
data-nowprocket attribute to your script tag. Example:<script data-nowprocket src="https://yourpapdomain.com/scripts/a1x2j2" id="pap_x2s6df8d"></script>
- Other plugins: Look for similar “Exclude” or “Do not defer” options, and use both the script’s unique file name and ID.
- Enable asynchronous tracking: If you use the Post Affiliate Pro WordPress plugin, enable the “Use asynchronous tracking where possible” option under the plugin’s general settings.
- Test your integration: After excluding the script, use your browser’s developer tools and Post Affiliate Pro’s click tracking test feature to verify that tracking works as expected.
How to improve tracking accuracy with Post Affiliate Pro JavaScript tracking
To maximize tracking reliability:
- Always use the unique tracking script file name (e.g., a1x2j2) from your merchant panel’s Tools → Integration → Click tracking section, as the filename is unique and can change.
- Exclude your tracking script by its unique URL or ID from any caching or optimization processes.
- Consider parking a custom domain or subdomain on your Post Affiliate Pro account for tracking scripts (e.g., partners.yourdomain.com). Avoid using words like “affiliate” or “track” in the domain name, as these can be blocked by ad blockers.
- Using a custom (neutral) domain for your tracking script increases the chance that the script will load and execute, even for users with aggressive privacy or ad-blocking tools.
Best Practices for Post Affiliate Pro tracking with caching plugins
- Always exclude critical tracking scripts from JavaScript optimization (defer, combine, or minify) in your caching plugin, using both the script’s src file name and its ID.
- Use asynchronous tracking where possible to improve compatibility and site speed.
- Regularly test tracking after updating plugins or themes.
- Document any custom script changes for future site administrators.
- If possible, use server-side (S2S) tracking for maximum reliability.
General Tips: Dealing with other optimization plugins
- Autoptimize: Use the “Exclude scripts from Autoptimize” field for your tracking script (add both its src file name and ID).
- W3 Total Cache: Exclude your tracking script from minify and combine settings.
- LiteSpeed Cache: Add tracking scripts to the “JS Excludes” list.
- In all cases, consult your plugin’s documentation for the correct exclusion syntax and test thoroughly.
How do I test if my tracking is working after changes?
- Clear your site and browser cache.
- Click a referral link and ensure the tracking script loads in your browser’s network tab.
- Complete a test sale or conversion and check if it appears in the Post Affiliate Pro merchant panel.
- If tracking fails, double-check your exclusion settings and try disabling optimization features temporarily.
Why is my affiliate tracking still not working after exclusions?
- Double-check the script path or name in your exclusion settings (use both src and ID).
- Make sure there are no conflicting plugins or additional caching layers (CDN, server cache).
- Try switching to asynchronous tracking or S2S tracking for added reliability.
- Contact your web host or plugin support for advanced troubleshooting.
How to implement asynchronous tracking code manually
If you need to manually insert asynchronous tracking, use the following code template:
<script type="text/javascript">
(function() {
var papScriptHeader = document.createElement('script');
papScriptHeader.src = 'https://yourpapdomain.com/scripts/a1x2j2';
papScriptHeader.id = 'pap_x2s6df8d';
papScriptHeader.type = 'text/javascript';
papScriptHeader.onload = function() {
try {
PostAffTracker.setAccountId('default1');
PostAffTracker.track();
} catch (err) { }
}
document.body.appendChild(papScriptHeader);
})();
</script>
Replace https://yourpapdomain.com/scripts/a1x2j2 and default1 with your actual values. This ensures the script loads after your page content, improving compatibility with caching plugins.