Analytics

Cloudflare Script Proxy

If you would like to increase the accuracy of your data and you also use Cloudflare, you can setup a proxy for the fullres script. Many script blockers and privacy shield solutions will block any and all analytics scripts served from third-party domains. Understandably, it's too much work for them to properly audit them all, and especially so if they were to do it on an ongoing basis. You can work around these blocks by serving the script file from your own domain.

Create the Script Proxy Worker

  1. Login to Cloudflare and from the Account Home dashboard, click on the Workers & Pages link in the left navigation.

  2. On the next page, click the Create Worker button.

  3. Enter a name for the Worker, e.g. "fullres-script-proxy", and click Save, then Finish, and then look for the Edit Code button on the next page and click that.

  4. Copy and paste the code below, replacing the two instances of [YOUR_CUSTOM_PATH_NAME] and [YOUR_DOMAIN] in the editor and click Deploy. You can use anything for this path name that does not conflict with your sites existing structure. For example, you could use a random string like this 7mioI3zb9A. You need to have this path name ready to copy and paste elsewhere.

addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
    const url = new URL(request.url);
    
    // Extract the path after /[YOUR_CUSTOM_PATH_NAME]/
    const path = url.pathname.replace(/^\/[YOUR_CUSTOM_PATH_NAME]\//, '');
    
    // Construct the URL for the proxied request
    const originalScriptUrl = `https://t.fullres.net/${path}`;
    
    // Create new headers by copying original request headers
    const newHeaders = new Headers(request.headers);
    
    // If there is an X-Forwarded-For header, append the original client's IP address to it
    const clientIP = request.headers.get('CF-Connecting-IP') || request.headers.get('x-forwarded-for');
    if (clientIP) {
        const existingForwardedFor = request.headers.get('x-forwarded-for');
        if (existingForwardedFor) {
            newHeaders.set('x-forwarded-for', `${existingForwardedFor}, ${clientIP}`);
        } else {
            newHeaders.set('x-forwarded-for', clientIP);
        }
    }
    
    // Create the new request with the modified headers
    const modifiedRequest = new Request(originalScriptUrl + url.search, {
        method: request.method,
        headers: newHeaders,
        body: request.body,
        redirect: 'follow'
    });
    
    // Fetch the original script
    const response = await fetch(modifiedRequest);
    const originalScript = await response.text();
    
    // Replace occurrences of t.fullres.net with [YOUR_DOMAIN].com/[YOUR_CUSTOM_PATH_NAME]/
    const modifiedScript = originalScript.replace(/t\.fullres\.net/g, '[YOUR_DOMAIN].com/[YOUR_CUSTOM_PATH_NAME]');
    
    // Return the modified script with appropriate headers
    return new Response(modifiedScript, {
        status: response.status,
        statusText: response.statusText,
        headers: {
            'Content-Type': 'application/javascript',
            'Cache-Control': 'public, max-age=43200' // 12 hours caching
        }
    });
}

Setup the route

  1. Go back to the Cloudflare Dashboard, click on Websites in the left navigation, and locate the site in your account you are implementing this on, then click it.

  2. Again from the left navigation, click on Workers Routes and then Add Route on that page.

  3. Enter [YOUR_DOMAIN].com/[YOUR_CUSTOM_PATH_NAME]/* for the Route value and select the Worker you just created above in the dropdown menu. Please note: the asterisk after [YOUR_CUSTOM_PATH_NAME] is required.

  4. Click Save.

Last step: Modify your install code from your website

  1. In your website's code, find the fullres script and change the script URL from t.fullres.net to the Route you setup above.

  2. Add a new line after fullres.src to override the site key setting: fullres.attributes.siteKeyOverride = '[YOUR_SITE_KEY]';

This is what your new fullres install script should look like:

<script>
  (function(){
    var fullres = document.createElement('script');
    fullres.async = true;
    fullres.src = 'https://[YOUR_DOMAIN].com/[YOUR_CUSTOM_PATH_NAME]/[YOUR_SITE_KEY].js?'+(new Date()-new Date()%43200000);
    fullres.attributes.siteKeyOverride = '[YOUR_SITE_KEY]';
    document.head.appendChild(fullres);
  })();
</script>

That's it! You should now be able to visit the URL of the Route on your own domain and see the fullres script load. If you run into any issues please get in touch.