Analytics
If you need a hand implementing this, let us know!
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.
Additional consideration: the Cloudflare Script Proxy technique allows you to serve the analytics tag from yourdomain.com/directoryname/scriptname.js
whereas implementing a Custom Domain allows you to serve the analytics tag from sub-domain.yourdomain.com/script.js
(or even a completely separate root domain). You don't need to implement BOTH.
Create the Script Proxy Worker
-
Login to Cloudflare and from the Account Home dashboard, click on the Workers & Pages link in the left navigation.
-
On the next page, click the Create Worker button.
-
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.
-
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 this7mioI3zb9A
. 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
}
});
}
Please be sure to replace [YOUR_CUSTOM_PATH_NAME] and [YOUR_DOMAIN].
Setup the route
-
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.
-
Again from the left navigation, click on Workers Routes and then Add Route on that page.
-
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. -
Click Save.
Last step: Modify your install code from your website
-
In your website's code, find the fullres script and change the script URL from
t.fullres.net
to the Route you setup above. -
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>
Your [YOUR_SITE_KEY] can be found on the settings page in your Fullres account. Look for the Tracking Code snippet and your unique site key can be found within this line of code: https://t.fullres.net/[YOUR_SITE_KEY].js
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.