Does AffiliateWP work with caching?

Yes it does! One of our number one frustrations with previous systems was the lack of support for aggressive caching. You often had to make a compromise: either have good caching and a fast site with no referral tracking, or successful referral tracking with little to no caching and a slow site.

In many cases, AffiliateWP will work with your caching plugin with no specific configuration changes needed. If you do encounter issues where visits or referrals aren’t tracking correctly, though, or your affiliates are having trouble logging in, it may be necessary to make a few changes to your caching settings.

Recommended caching settings to troubleshoot tracking or login issues

The first step we recommend is excluding AffiliateWP’s cookies from caching. If the cookies are being cached, this could result in (1) visits and referrals not tracking at all, (2) visits and/or referrals being credited to the wrong affiliate, or (3) affiliates unable to log in or logged into the wrong account.

For most web hosts, AffiliateWP creates three cookies that should be excluded from caching:

  • affwp_ref
  • affwp_ref_visit_id
  • affwp_campaign

For Pantheon, AffiliateWP creates the same three cookies as above but with names compatible with Pantheon’s cookie policy:

  • wp_affwp_ref
  • wp_affwp_ref_visit_id
  • wp_affwp_campaign

For Cloudflare sites that do not have the Cloudflare plans (Business and Enterprise) that allow exclusions to be set, we have made similar changes as Pantheon to create the same three cookies with names compatible with Cloudflare’s recommendations as seen here – Cloudflare Docs – Automatic Platform Optimizatio

  • wp_affwp_ref
  • wp_affwp_ref_visit_id
  • wp_affwp_campaign

To implement the CloudFlare cookie bypass completely, this requires a few entries in your active theme’s functions.php file (USE CAUTION!) or a code snippet plugin of your choice is recommended.

The first entry turns on the Cloudflare-specific cookie names:

add_filter( 'affwp_tracking_cookie_compat_mode', '__return_true' );

The second entry assures the affiliate_id is transported successfully through the WooCommerce order transaction:

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 );

If you are not integrating with WooCommerce, use this snippet in place of the above:

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 );

Next, we recommend excluding any AffiliateWP-related URLs from caching, and also script loading. This could include the following:

The process to exclude the above cookies and URLs varies depending on which caching plugin you use. Below are the locations for those settings in several popular caching plugins.


WP Rocket

To exclude cookies and URLs in WP Rocket, navigate to Dashboard » Settings » WP Rocket » Advanced Rules.

  1. In the “Never cache URLs” field at the top, add the slugs for your pages.
  2. Add each of the three cookies, one per line, on the next field labeled “Never cache cookies.”
  3. Save your settings.
  4. Purge all caches.

Need help with your WP Rocket settings? You can contact their support team here.

NitroPack

To exclude cookies and URLs in NitroPack, log into your NitroPack dashboard and follow these steps:

  1. Click on the Settings tab.
  2. Scroll down to Excluded URLs and click the toggle to enable (if not already enabled).
  3. Enter the URL of your affiliate area page.
  4. Scroll down a bit more to Excluded Cookies and click the toggle to enable (if not already enabled).
  5. Click the Add Cookie button and enter the following:
    1. Cookie name: affwp_ref / Cookie value: (leave blank)
    2. Cookie name: affwp_ref_visit_id / Cookie value: (leave blank)
    3. Cookie name: affwp_campaign / Cookie value: (leave blank)
  6. Scroll back to the top and click the Save Settings button.
  7. Go back to the main dashboard screen and click the Purge Cache button.

Need help with your NitroPack settings? You can contact their support team here.

WP Fastest Cache

To exclude cookies and URLs in WP Fastest Cache, navigate to Dashboard » WP Fastest Cache » Exclude tab

  1. Click the “Add New Rule” button next to Exclude Pages to add the slugs for your pages.
  2. Click the “Add New Rule” button next to Exclude Cookies to add each of the three cookies.
  3. Save your settings.
  4. Purge all caches.

Need help with your WP Fastest Cache settings? You can contact their support team here for the free plugin or here for the premium version.

Breeze

To exclude cookies and URLs in Breeze, navigate to Dashboard » Settings » Breeze » Advanced Options tab.

  1. In the “Never cache these URLs” field at the top, add the URLs for your pages.
  2. Breeze does not have cookie-specific settings built into the plugin, so we recommend contacting their support team for assistance if needed.
  3. If you are using Varnish on a Cloudways server alongside the Breeze plugin, it’s possible to exclude the cookies and URLs directly within your Varnish settings. Please refer to this article from Cloudways for instructions on excluding URLs. Refer to this one for instructions on excluding cookies.
  4. Save your settings.
  5. Purge all caches. If you use Varnish, please check in Dashboard » Settings » Breeze » Varnish to ensure the “Auto Purge Varnish” option is enabled.

Need help with your Breeze settings? If you are a Cloudways user, please log into your Cloudways account to use live chat or open a ticket; if you use a different web host, you can seek support here.

LiteSpeed Cache

To exclude cookies and URLs in LiteSpeed Cache, navigate to Dashboard » LiteSpeed Cache » Cache » Excludes tab.

  1. In the “Do Not Cache URIs” field, add the slugs for your pages.
  2. In the “Do Not Cache Cookies” field, add each of the three cookies, one per line.
  3. Save your settings.
  4. Purge all caches.

Need help with your LiteSpeed Cache settings? If you use the premium plugin, you can open a support request here, or you can go here if you use the free version.

W3 Total Cache

To exclude cookies and URLs in W3 Total Cache, navigate to Dashboard » Performance » Page Cache.

  1. In the “Never cache the following pages” field, add the slugs for your pages.
  2. Scroll down to the “Rejected cookies” field and add each of the three cookies, one per line.
  3. Save your settings.
  4. Purge all caches.

Need help with your W3 Total Cache settings? You can contact their support team here for the free plugin or here for the premium version.

Once the cookie and URL exclusions are in place, please purge all caches and follow the
steps to test a visit and referral. Still not working? Let us know and we’ll be glad to help!