Proxy Seline through Cloudflare

As with other analytics tools — privacy-friendly or not — some ad-blocking extensions or browsers may block Seline. Either our script gets completely blocked by ad-blockers, or some of its requests get blocked. Seline allows you to bypass this by proxying our script and its requests through your own subdomain. That's possible by using Cloudflare's Workers, which allow you to run JavaScript code on Cloudflare's servers.

In this guide, we will use sln.yourdomain.com, but you can choose any subdomain you prefer.

Don't want to bother with this? You can use our managed proxy service. Read more at Ad-blocker bypass page.

Step 1. Create a Worker

From your Cloudflare dashboard, navigate to the Workers & Pages tab and create a new Worker.

Leave the worker name as is, Cloudflare might take down any Workers that have "analytics" or "tracking" in their name.

Creating new worker at Cloudflare
Creating new worker at Cloudflare

Copy the following code into the editor, replace yourdomain.com with your domain, and click Deploy when finished.

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
// script redirect
if (url.hostname === 'sln.yourdomain.com' && url.pathname === '/seline.js') {
return Response.redirect('https://cdn.seline.com/seline.js', 301)
}
// analytics requests redirect
if (url.hostname === 'sln.yourdomain.com') {
const newUrl = new URL(`https://api.seline.com${url.pathname}`)
newUrl.search = url.search
const newRequest = new Request(newUrl, {
method: request.method,
headers: request.headers,
body: request.body
})
newRequest.headers.set('Seline-IP', request.headers.get('CF-Connecting-IP'))
newRequest.headers.set('Seline-Country', request.headers.get('CF-IPCountry'))
return fetch(newRequest)
}
return fetch(request)
}
Click anywhere to copy

Step 2. Create a Worker Route

Now go to yourdomain.com domain dashboard, then to Workers Routes, and create a new route there.

Adding a new Worker Route at Cloudflare
Adding a new Worker Route at Cloudflare

Set the Route to match the domain you just configured in the Worker code. In our case, it's sln.yourdomain.com/*. Then, select the Worker you previously created, and hit Save. Don't forget the * wildcard.

Step 3. Create a DNS record

For the last bit on Cloudflare, create a DNS record with type A, name it sln, and set the content to 192.0.2.1. Make sure to leave orange Cloudflare Proxy Status as Proxied.

Adding a new DNS record at Cloudflare
Adding a new DNS record at Cloudflare

Step 4. Update Seline script

Finally, update our script with new src, and add a data-api-host attribute.

<script src="https://sln.yourdomain.com/seline.js" data-api-host="https://sln.yourdomain.com" async></script>
Click anywhere to copy

Deploy the changes and you're all set! Now all requests from our script will go through your first-party domain, and ad blockers won't block them.

Step 5. In case your website is hosted on Cloudflare Pages

For a proper country forwarding, you'll also need to turn ON the NetworkIP Geolocation setting.