You can use Cloudflare Workers to proxy your Plausible Analytics requests. Cloudflare Workers offers free service for up to 100,000 requests per day. All you need to set it up is a free Cloudflare account.
Here's the step-by-step process for creating a proxy. It takes only a few minutes and requires no tech know-how or prior experience.
Step 0: Sign up for a free Cloudflare account if you don't have an account already and add your site
In your Cloudflare account, go into the 'Workers' section. Click on 'Create a Worker' to start configuring your proxy.
Next, you'll see a page where you can edit the code for your worker:
Remove the default code that Cloudflare presents in the 'Script' section on the left side of the screen and paste the following code instead. You do not need to make any edits to this code. You do not need to make any other changes either.
Once you've added the above code to the worker, you can click on the 'Save and Deploy' button.
This is optional but you can click 'Rename' in the Workers' dashboard to give your worker a more meaningful name. Do avoid words like 'analytics', 'tracking', 'stats', etc. as they may be blocked.
Now, the Plausible script should be accessible at the following URL:
Once you have the URL for your script, you can replace your Plausible Analytics script tag in the Header (
<head>) section of your site with the proxied snippet. This is how the new snippet should look like (make sure to edit it to have the correct domain name and the correct URL to the proxied file):
Are you using our extensions such as hash-based routing, page exclusions or outbound link click tracking? Change the file name from
script.js to the script you want to use:
script.outbound-links.js. Want to use more than one extension? You can chain them like this:
script.hash.exclusions.outbound-links.js. You just need to change the script name in the snippet that you insert into your site, no need to change the code for the worker.
That's it! You're now counting your website stats using a proxy.
If you're hosting your site on the Cloudflare CDN, you can run the proxy as a subdirectory installation to avoid a third-party
request to the
workers.dev domain. This is completely optional but it can make your URLs look much cleaner and avoid third-party
First, open your site dashboard in Cloudflare and go to the 'Workers' tab. Then, click the 'Add route' button on the right hand side.
Next, enter the URL prefix where you would like to install Plausible. In this example, we'll install the proxy on the
example.com domain and we'll use
qwerty as the subdirectory name. You can choose any name for the subdirectory but it's a good idea to avoid words like 'analytics' and 'tracking'.
- Worker: Choose the worker you created in Step 1
Click on the 'Save' button. After clicking 'Save', the script should be accessible at the subdirectory URL of your site:
At this point you can change your Plausible script tag in your site header to reference the new URL. It's also important to specify the
data-api attribute to make sure data is sent through the worker as well. The new snippet in your site header should look like this:
Notice that since the script tag is installed on the same domain as the website itself, there's no need to specify the hostname in
data-api attributes. A relative path will work just fine.