Skip to main content

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

The most reliable method that works across all WordPress configurations.

  1. Go to Appearance → Theme Editor → select header.php
  2. 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>
  1. 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:

  1. Plugins → Add New → search "Insert Headers and Footers" → install and activate
  2. 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>
  1. 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

PluginAction
WP RocketSettings → File Optimization → add subdomain to Excluded Inline JavaScript
W3 Total CachePerformance → Minify → add to "Never minify" JS list
WPEngineNo configuration needed

Verification

  1. Visit your website frontend (not admin)
  2. Right-click → View Page Source → search for your subdomain
  3. Open Developer Tools (F12) → Network tab → look for main.js?id=YOUR_SCRIPT_ID
  4. Test on multiple page types: homepage, posts, pages, categories, products (if WooCommerce)

Troubleshooting

IssueSolution
Script not in page sourceCheck if wp_head() is called in header.php
Works on some pages onlyVerify method loads on all page types
Plugin conflictsTest with security/minification plugins deactivated
Caching issuesClear all caches and test in incognito