Using Cloudflare Workers
Please use at least version 1.6.0
of @spindl-xyz/attribution
or @spindl-xyz/attribution-lite
for this feature.
Make sure you're logged into cloudflare. Workers are really easy to set up and allow up to 100,000 free requests per day on the free plan.
1. Create a worker
From Cloudflare dashboard, select: Workers & Pages
> Overview
> Create application
> Create Worker
. At this point, you can either keep the random worker name or choose your own. Click Deploy
once done.
2. Configure as proxy
Click Edit code
or Quick edit
once the worker is set up and paste the code. You should now be seeing a code editor for the worker. You can copy/paste code below which will forwards the traffic and data to our server on spindl.link
const API_HOST = "spindl.link"
async function handleRequest(event) {
const url = new URL(event.request.url)
const pathname = url.pathname
const search = url.search
const pathWithParams = pathname + search
return forwardRequest(event, pathWithParams)
}
async function forwardRequest(event, pathWithSearch) {
const request = new Request(event.request)
return await fetch(`https://${API_HOST}${pathWithSearch}`, request)
}
addEventListener("fetch", (event) => {
event.passThroughOnException()
event.respondWith(handleRequest(event))
})
When done, click "Save and deploy".
3. Configure Spindl SDK to use Proxy domain
Copy the xxx.workers.dev
domain that you just created! Please make sure that domain doesn't include any common words that are more likely to be blocked by ad blockers including track
, analytics
and spindl
In the sdindl sdk configure object, paste the worker url as the host
:
spindl.configure({
sdkKey: "<your SDK API key here>",
host: "https://your-worker-url.workers.dev"
});
Last updated