Does AffiliateWP work with caching?

Does caching affect AffiliateWP’s referral tracking? While caching is essential for fast-loading websites, it can sometimes interfere with tracking if not configured correctly. AffiliateWP is designed to work with most caching solutions, often requiring no changes. However, if visits or referrals aren’t tracking properly, a few adjustments may be needed.

This guide provides plugin-specific steps to ensure accurate tracking while maintaining site performance.

How Caching Impacts Tracking

AffiliateWP uses cookies to track visits, referrals, and campaigns. If caching systems improperly handle these cookies, tracking issues can occur. The three main cookies AffiliateWP uses are:

  • affwp_ref – Stores the affiliate ID.
  • affwp_ref_visit_id – Tracks the visit ID.
  • affwp_campaign – Records campaign names for tracking specific marketing efforts.

For sites hosted on Pantheon, Cloudflare, or similar platforms, AffiliateWP automatically adjusts cookie names to comply with platform policies. For example, on Pantheon, cookies are prefixed with wp_, resulting in wp_affwp_ref, wp_affwp_ref_visit_id, and wp_affwp_campaign. Excluding these cookies from caching ensures accurate affiliate tracking.

You should also exclude specific AffiliateWP-related URLs, such as the Affiliate Area, registration, and login pages, as well as the AffiliateWP tracking script (/wp-content/plugins/affiliate-wp/assets/js/tracking.min.js).

Plugin-Specific Caching Adjustments

WP Rocket

To ensure proper tracking with WP Rocket:

  • Navigate to Dashboard » Settings » WP Rocket » Advanced Rules.
  • In the Never cache URLs field, add slugs for the Affiliate Area, registration, and login pages.
  • Add each of the three cookies (affwp_ref, affwp_ref_visit_id, and affwp_campaign) in the Never cache cookies field, one per line.
  • Save the changes and purge all caches.

Additionally, WP Rocket allows disabling caching per page in the sidebar settings for pages experiencing specific issues.

NitroPack

To adjust caching in NitroPack:

  • Log into the NitroPack dashboard and open the Settings tab.
  • Enable the Excluded URLs option and add the URLs for the Affiliate Area, registration, and login pages.
  • Scroll down to Excluded Cookies, enable it, and add the cookies affwp_ref, affwp_ref_visit_id, and affwp_campaign.
  • Save the changes and click the Purge Cache button in the main dashboard.

WP Fastest Cache

For WP Fastest Cache users:

  • Open the Dashboard » WP Fastest Cache » Exclude tab.
  • Use the Add New Rule button to exclude AffiliateWP-related pages.
  • Similarly, exclude the cookies affwp_ref, affwp_ref_visit_id, and affwp_campaign by adding them as separate rules.
  • Save the changes and purge all caches.

Breeze

To configure Breeze:

  • Go to Dashboard » Settings » Breeze » Advanced Options.
  • Add AffiliateWP-related URLs to the Never cache these URLs field.
  • Breeze doesn’t support cookie exclusions natively. If needed, contact Breeze’s support team or, for Cloudways users, adjust cookie exclusions in the Varnish settings. Refer to Cloudways Varnish Cookie Exclusion Guide.
  • Save the changes and ensure the Auto Purge Varnish option is enabled.

LiteSpeed Cache

In LiteSpeed Cache:

  • Navigate to Dashboard » LiteSpeed Cache » Cache » Excludes.
  • Add AffiliateWP-related page slugs to the Do Not Cache URIs field.
  • Enter the cookies affwp_ref, affwp_ref_visit_id, and affwp_campaign in the Do Not Cache Cookies field.
  • Save the settings and purge all caches.

W3 Total Cache

For W3 Total Cache:

  • Open Dashboard » Performance » Page Cache.
  • Add AffiliateWP-related page slugs to the Never cache the following pages field.
  • Enter the cookies affwp_ref, affwp_ref_visit_id, and affwp_campaign in the Rejected cookies field.
  • Save your settings and purge all caches.

Cloudflare

If you’re using Cloudflare without an enterprise plan, AffiliateWP can generate platform-compatible cookie names (wp_affwp_ref, etc.). To fully implement cookie bypass on Cloudflare, you’ll need to add custom code to your theme’s functions.php file or a code snippet plugin.

To enable Cloudflare-compatible cookie names, use:

add_filter( 'affwp_tracking_cookie_compat_mode', '__return_true' );

For WooCommerce integration, include:

add_filter( 'affwp_get_referring_affiliate_id', function( $affiliate_id, $reference, $context ) {
   if ( 'woocommerce' === $context ) {
      $affiliate_id = affiliate_wp()->tracking->get_affiliate_id();
   }
   return $affiliate_id;
}, 10, 3 );

For non-WooCommerce integrations, use this instead:

add_filter( 'affwp_get_referring_affiliate_id', function( $affiliate_id, $reference, $context ) {
   $affiliate_id = affiliate_wp()->tracking->get_affiliate_id();
   return $affiliate_id;
}, 10, 3 );

Testing and Troubleshooting

After excluding cookies and URLs, purge all caches and test the system by clicking a referral link and completing a test purchase. If tracking still isn’t functioning as expected, check for additional caching layers (e.g., server-level caching) and disable script optimizations that affect the AffiliateWP tracking script.

Frequently Asked Questions

What cookies should I exclude from caching?

Exclude affwp_ref, affwp_ref_visit_id, and affwp_campaign. On platforms like Pantheon or Cloudflare, use the prefixed versions (e.g., wp_affwp_ref).

Does Cloudflare support AffiliateWP tracking?

Yes, but you may need to enable cookie bypass using custom code and ensure exclusions are applied for AffiliateWP’s cookies and tracking script.

Do I need to configure exclusions in both a caching plugin and a CDN?

Yes, if you’re using a caching plugin and a CDN like Cloudflare, apply the exclusions in both systems to avoid conflicts.


That’s it! AffiliateWP works seamlessly with caching when properly configured. By excluding essential cookies, URLs, and scripts, you can maintain optimal site performance while ensuring accurate affiliate tracking.