Global Code Setup
The DATA Reshape tracking script is a lightweight JavaScript snippet that enables server-side tracking across all pages of your website. It collects event data, manages user sessions, and forwards information to your configured destinations.
The script operates under your own domain (first-party), avoiding ad blockers and third-party cookie restrictions.
Prerequisites
Only implement after receiving confirmation from the DATA Reshape team that your custom domain and SSL certificate are active.
You will need:
- Custom tracking subdomain (e.g.
dre2.yourdomain.com) - Script ID provided by the DATA Reshape team
Implementation
Add this code to your website's <head> section on all pages:
<script>
(function(R,e,s,h,a,p,E){
var b=R.Reshape=R.Reshape||{};
b.setCookie=function(n,v,t,d){try{e.cookie=n+'='+v+';max-age='+t+';domain='+d+';path=/;SameSite=None;Secure';}catch(e){}};
b.id=a;b.cdn=h;b.sts=new Date().getTime();
E=e.getElementsByTagName(s)[0];p=e.createElement(s);p.async=true;p.src="https://"+h+"/main.js?id="+a;E.parentNode.insertBefore(p,E);
})(window,document,"script","YOUR_SUBDOMAIN","YOUR_SCRIPT_ID");
</script>
Replace YOUR_SUBDOMAIN with your custom subdomain and YOUR_SCRIPT_ID with your Script ID.
HTML Template Example
Here's how it should look in a complete HTML document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Website</title>
<!-- DATA Reshape Tracking Code -->
<script>
(function(R,e,s,h,a,p,E){
var b=R.Reshape=R.Reshape||{};
b.setCookie=function(n,v,t,d){try{e.cookie=n+'='+v+';max-age='+t+';domain='+d+';path=/;SameSite=None;Secure';}catch(e){}};
b.id=a;b.cdn=h;b.sts=new Date().getTime();
E=e.getElementsByTagName(s)[0];p=e.createElement(s);p.async=true;p.src="https://"+h+"/main.js?id="+a;E.parentNode.insertBefore(p,E);
})(window,document,"script","YOUR_SUBDOMAIN","YOUR_SCRIPT_ID");
</script>
</head>
<body>
<!-- Your website content -->
</body>
</html>
Platform-Specific Guides
| Platform | Guide |
|---|---|
| WordPress | WordPress Setup |
| Shopify | Shopify Setup |
Multiple Script IDs
A single website can use different Script IDs based on subdomain or pathname — useful for multi-store setups (e.g. Magento), multi-market configurations, or the PLUS plan with separate tracking configs.
<script>
var getScriptConfig = function() {
var path = window.location.pathname;
var hostname = window.location.hostname;
if (hostname.indexOf('store-b.') > -1) return { subdomain: 'dre2.store-b.com', id: 'STOREB_ID' };
if (path.indexOf('/shop/') === 0) return { subdomain: 'dre2.yourdomain.com', id: 'SHOP_SCRIPT_ID' };
return { subdomain: 'dre2.yourdomain.com', id: 'MAIN_SCRIPT_ID' };
};
var config = getScriptConfig();
(function(R,e,s,h,a,p,E){
var b=R.Reshape=R.Reshape||{};
b.setCookie=function(n,v,t,d){try{e.cookie=n+'='+v+';max-age='+t+';domain='+d+';path=/;SameSite=None;Secure';}catch(e){}};
b.id=a;b.cdn=h;b.sts=new Date().getTime();
E=e.getElementsByTagName(s)[0];p=e.createElement(s);p.async=true;p.src="https://"+h+"/main.js?id="+a;E.parentNode.insertBefore(p,E);
})(window,document,"script",config.subdomain,config.id);
</script>
Content Security Policy (CSP)
If your website uses Content Security Policy, add these directives:
Content-Security-Policy: script-src 'self' 'unsafe-inline' https://YOUR_SUBDOMAIN; connect-src 'self' https://YOUR_SUBDOMAIN;
Verification
- Open your website in a browser
- Open Developer Tools (F12) → Network tab
- Look for a request to
https://YOUR_SUBDOMAIN/main.js?id=YOUR_SCRIPT_ID - Check the Console tab for any errors
Troubleshooting
| Symptom | Cause | Solution |
|---|---|---|
| No request in Network tab | DNS not configured | Verify subdomain DNS records |
ERR_NAME_NOT_RESOLVED | DNS issue | Check DNS, allow 24-48h for propagation |
Mixed Content error | HTTP instead of HTTPS | Ensure subdomain has valid SSL certificate |
CORS policy error | SSL or server config | Contact DATA Reshape team |
Next Steps
Once the script loads correctly:
- Implement events — see Events documentation
- Add user data — include User object for better attribution
- Configure destinations — connect your analytics and advertising platforms