WordPress Implementation Guide
Multiple methods to implement DATA Reshape tracking on WordPress. Choose the one that fits your setup.
Prerequisites
Required Before Implementation
Only implement after receiving confirmation 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
Method 1: Theme header.php (Recommended)
The most reliable method that works across all WordPress configurations.
- Go to Appearance → Theme Editor → select header.php
- Add this code before the
</head>tag:
<!-- 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>
<?php wp_head(); ?>
</head>
- Click Update File and clear any caching plugins
Theme Updates
Changes to theme files are lost during theme updates. Use a child theme or the functions.php method for persistence.
Method 2: functions.php
Programmatic implementation via WordPress hooks. Add to the end of Appearance → Theme Editor → functions.php:
function add_data_reshape_tracking() {
$subdomain = 'YOUR_SUBDOMAIN';
$script_id = 'YOUR_SCRIPT_ID';
if (!is_admin()) {
?>
<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","<?php echo esc_js($subdomain); ?>","<?php echo esc_js($script_id); ?>");
</script>
<?php
}
}
add_action('wp_head', 'add_data_reshape_tracking');
Method 3: Insert Headers and Footers Plugin
If you prefer not to edit theme files:
- Plugins → Add New → search "Insert Headers and Footers" → install and activate
- Settings → Insert Headers and Footers → paste in Scripts in Header:
<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>
- Click Save and clear cache
Method 4: Child Theme
For persistence during theme updates. Create /wp-content/themes/your-child-theme/functions.php:
<?php
function add_data_reshape_tracking() {
if (!is_admin()) {
?>
<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>
<?php
}
}
add_action('wp_head', 'add_data_reshape_tracking');
Caching Plugins
| Plugin | Action |
|---|---|
| WP Rocket | Settings → File Optimization → add subdomain to Excluded Inline JavaScript |
| W3 Total Cache | Performance → Minify → add to "Never minify" JS list |
| WPEngine | No configuration needed |
Verification
- Visit your website frontend (not admin)
- Right-click → View Page Source → search for your subdomain
- Open Developer Tools (F12) → Network tab → look for
main.js?id=YOUR_SCRIPT_ID - Test on multiple page types: homepage, posts, pages, categories, products (if WooCommerce)
Troubleshooting
| Issue | Solution |
|---|---|
| Script not in page source | Check if wp_head() is called in header.php |
| Works on some pages only | Verify method loads on all page types |
| Plugin conflicts | Test with security/minification plugins deactivated |
| Caching issues | Clear all caches and test in incognito |