WordPress Implementation Guide
This guide provides multiple methods to implement DATA Reshape tracking on your WordPress website, from simple theme modifications to plugin-based solutions.
Prerequisites
Only implement after receiving confirmation that your custom domain and SSL certificate are active.
Required Information:
- Custom tracking subdomain (e.g.,
dre2.yourdomain.com
) - Script ID provided by DATA Reshape team
Method 1: Theme Header.php (Recommended)
This is the most reliable method that works across all WordPress configurations.
1. Access Theme Editor
- Go to Appearance > Theme Editor in WordPress admin
- Select your active theme
- Click on header.php file
2. Locate the </head>
Tag
- Find the closing
</head>
tag in the header.php file - This is usually near the top of the file
3. Add Tracking Code
Add this code before the </head>
tag:
<!-- DATA Reshape Tracking Code -->
<script>
(function(R,e,s,h,a,p,E){
R[s+a]=a;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","dre2.yourdomain.com","YOUR_LIBRARY_ID");
</script>
<?php wp_head(); ?>
</head>
4. Update File
- Click Update File
- Clear any caching plugins
Complete Header.php Example
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="https://gmpg.org/xfn/11">
<!-- DATA Reshape Tracking Code -->
<script>
(function(R,e,s,h,a,p,E){
R[s+a]=a;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","dre2.yourdomain.com","YOUR_LIBRARY_ID");
</script>
<?php wp_head(); ?>
</head>
- Replace
dre2.yourdomain.com
with your actual subdomain - Replace
YOUR_LIBRARY_ID
with your actual Library ID
Method 2: Functions.php Implementation
For developers who prefer programmatic implementation:
1. Access functions.php
- Go to Appearance > Theme Editor
- Select functions.php
2. Add This Code
Add to the end of functions.php (before the closing ?>
if it exists):
// DATA Reshape Tracking Implementation
function add_data_reshape_tracking() {
// Replace with your actual subdomain and Library ID
$subdomain = 'dre2.yourdomain.com';
$library_id = 'YOUR_LIBRARY_ID';
// Only load on frontend (not admin)
if (!is_admin()) {
?>
<script>
(function(R,e,s,h,a,p,E){
R[s+a]=a;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($library_id); ?>");
</script>
<?php
}
}
add_action('wp_head', 'add_data_reshape_tracking');
Method 3: Using Insert Headers and Footers Plugin
If you prefer not to edit theme files directly:
1. Install Plugin
- Go to Plugins > Add New
- Search for "Insert Headers and Footers"
- Install and activate the plugin
2. Add Tracking Code
- Go to Settings > Insert Headers and Footers
- In the Scripts in Header section, add:
<script>
(function(R,e,s,h,a,p,E){
R[s+a]=a;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","dre2.yourdomain.com","YOUR_LIBRARY_ID");
</script>
3. Save Settings
- Click Save button
- Clear cache if using caching plugins
Method 4: Child Theme Implementation
For theme safety during updates:
1. Create Child Theme (if not already using one)
Create these files in /wp-content/themes/your-child-theme/
:
style.css:
/*
Theme Name: Your Child Theme
Template: parent-theme-name
*/
@import url("../parent-theme/style.css");
functions.php:
<?php
// DATA Reshape Tracking for Child Theme
function add_data_reshape_tracking() {
if (!is_admin()) {
?>
<script>
(function(R,e,s,h,a,p,E){
R[s+a]=a;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","dre2.yourdomain.com","YOUR_LIBRARY_ID");
</script>
<?php
}
}
add_action('wp_head', 'add_data_reshape_tracking');
?>
Advanced WordPress Configuration
Conditional Loading by Page Type
function add_data_reshape_tracking() {
// Different Library IDs for different page types
$library_id = 'DEFAULT_LIBRARY_ID';
if (is_shop() || is_product()) {
$library_id = 'ECOMMERCE_LIBRARY_ID';
} elseif (is_home() || is_front_page()) {
$library_id = 'HOMEPAGE_LIBRARY_ID';
} elseif (is_single() && get_post_type() == 'post') {
$library_id = 'BLOG_LIBRARY_ID';
}
if (!is_admin()) {
?>
<script>
(function(R,e,s,h,a,p,E){
R[s+a]=a;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","dre2.yourdomain.com","<?php echo esc_js($library_id); ?>");
</script>
<?php
}
}
add_action('wp_head', 'add_data_reshape_tracking');
Exclude Admin and Logged-in Users
function add_data_reshape_tracking() {
// Don't load for admin users or in admin area
if (is_admin() || current_user_can('administrator')) {
return;
}
// Don't load on specific pages
if (is_page(array('privacy-policy', 'terms-of-service'))) {
return;
}
?>
<script>
(function(R,e,s,h,a,p,E){
R[s+a]=a;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","dre2.yourdomain.com","YOUR_LIBRARY_ID");
</script>
<?php
}
add_action('wp_head', 'add_data_reshape_tracking');
WordPress-Specific Considerations
Caching Plugin Compatibility
For WP Rocket:
- Go to Settings > WP Rocket
- Navigate to File Optimization
- Add your subdomain to Excluded Inline JavaScript
For W3 Total Cache:
- Go to Performance > Minify
- Add your tracking script to Never minify the following JS files
For WPEngine:
- Tracking code works automatically
- No additional configuration needed
Theme Update Protection
If you modify theme files directly, changes will be lost during theme updates. Consider:
- Using a child theme (recommended)
- Using the functions.php method
- Using a plugin-based solution
Verification for WordPress
1. Frontend Verification
Using Browser Developer Tools:
- Visit your website frontend (not admin)
- Open Developer Tools (F12)
- Check Network tab for:
https://dre2.yourdomain.com/main.js?id=YOUR_LIBRARY_ID
- Verify Console tab shows no errors
2. WordPress-Specific Checks
Page Source Verification:
- Right-click on your website and select "View Page Source"
- Search for your subdomain URL
- Confirm the script appears in the
<head>
section
Multiple Page Types: Test on different WordPress page types:
- Homepage/Front page
- Blog posts
- Pages
- Category/Archive pages
- Product pages (if WooCommerce)
Troubleshooting WordPress Issues
Script Not Loading
Check Theme Compatibility:
// Add to functions.php for debugging
function debug_data_reshape() {
if (!is_admin()) {
echo '<!-- DATA Reshape Debug: Script should load here -->';
}
}
add_action('wp_head', 'debug_data_reshape', 1);
Common WordPress Issues:
Issue | Solution |
---|---|
Script not in source | Check if wp_head() is called in header.php |
Works on some pages only | Verify implementation method loads on all page types |
Conflicts with other plugins | Test with plugins deactivated |
Caching issues | Clear all caches and test |
Plugin Conflicts
Common Conflicting Plugins:
- Security plugins blocking external scripts
- Minification plugins modifying the code
- Cookie consent plugins delaying script execution
Resolution Steps:
- Deactivate plugins one by one
- Test after each deactivation
- Configure conflicting plugins to allow your subdomain
WordPress E-commerce Integration
WooCommerce Preparation
Once global tracking is implemented, you can prepare for WooCommerce event tracking:
// Example: Prepare for WooCommerce event tracking (add after global implementation)
function prepare_woocommerce_tracking() {
// This prepares the environment for e-commerce event tracking
// Detailed WooCommerce implementation will be covered in Developer Guide
if (class_exists('WooCommerce')) {
// WooCommerce is active - ready for e-commerce events
// Implementation details in E-commerce Events section
}
}
add_action('wp_footer', 'prepare_woocommerce_tracking');
Next Steps for WordPress
Once your WordPress implementation is complete:
- Verify Installation - Test on multiple page types
- WooCommerce Events - If using WooCommerce, implement e-commerce tracking
- Contact Forms - Track form submissions from Contact Form 7, Gravity Forms, etc.
- Custom Events - Add WordPress-specific events
- Integrations - Connect to destination platforms
Implementation Complete! Your DATA Reshape tracking is now active on WordPress.
For WooCommerce stores or contact form tracking, proceed to the Developer Guide for event implementation.
Related WordPress Guides
- WooCommerce Event Tracking - Complete e-commerce implementation
- WordPress Contact Forms - Track form submissions
- WordPress Performance - Optimize tracking performance