Articles on: Client Side
This article is also available in:

DataLayer Script Installation - AdPage Data Assistant Tag

Overview

This article explains how to add a DataLayer script to your website to collect various data points. This script is essential for the proper functioning of AdPage's Data Assistant Tag and ensures that user data is automatically collected and made available for your marketing tools.



When do you need this script?

This DataLayer script is only needed for websites/webshops where the AdPage plugin or app is NOT installed.


AdPage plugin/app available for:

  • Shopify: AdPage App via Shopify App Store
  • WooCommerce: AdPage Plugin for WordPress/WooCommerce
  • WordPress: AdPage Plugin via WordPress Plugin Directory
  • Magento: AdPage Extension for Magento
  • Lightspeed: AdPage App via Lightspeed App Store

Use this DataLayer script when:

  • You have a custom website (not built on the above platforms)
  • You haven't installed the AdPage plugin/app yet
  • You're using a platform that doesn't have AdPage integration yet
  • You want manual control over data collection

Note: If you are using the AdPage plugin/app, this script is NOT needed. The plugin/app automatically handles proper data collection.



What does this script do?

The DataLayer script automatically collects:

  • Device information: Browser, operating system, screen resolution
  • Marketing data: UTM parameters, referrers, campaign information
  • User behavior: Session information and interactions

This data is then made available via the dataLayer for use by Google Tag Manager, AdPage tags, and other tracking tools.




Perfect for AdPage MCP Integration

This DataLayer script is perfectly suited for AdPage MCP (Model Context Protocol) integration. After the script loads, all dataLayer events that occur after the trytagging_user_data event are automatically stored and monitored.

MCP Benefits:

  • Automatic event monitoring: All dataLayer pushes are captured
  • Complete user journey: From first visit to conversion
  • Real-time data analysis: Events are immediately available for analysis
  • Custom event tracking: Your own events are also included

Important: For optimal MCP functionality, the Data Assistant Tag must be configured correctly. Follow the instructions at: Setting up the AdPage Data Assistant Monitoring Tag




Installation

Step 1: Replace the domain name

IMPORTANT: For the script to work correctly, you must replace yourdomain.com with your own domain name.

Example:



Step 2: Add the script to your website

Add the following script to the <head> section of your website, before other tracking scripts like Google Tag Manager:

html

<script>
(function() {
// Function to load external script with defer
function loadScript(url) {
return new Promise(function(resolve, reject) {
var script = document.createElement('script');
script.defer = true;
script.src = url;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}

// Function to check if taggingHelpers is available
function checkTaggingHelpers(timeout) {
timeout = timeout || 10000;
var startTime = Date.now();
return new Promise(function(resolve, reject) {
function check() {
// Check if helpers exist and have required methods
if (window.taggingHelpers &&
typeof window.taggingHelpers.getMarketingObject === 'function' &&
typeof window.taggingHelpers.getDeviceInfo === 'function') {
resolve();
} else if (Date.now() - startTime > timeout) {
reject(new Error('Timeout waiting for taggingHelpers'));
} else {
setTimeout(check, 50);
}
}
check();
});
}

// Function to collect data from taggingHelpers
function collectData() {
try {
return {
event: 'trytagging_user_data',
device: window.taggingHelpers.getDeviceInfo() || {},
marketing: window.taggingHelpers.getMarketingObject() || {}
};
} catch (error) {
console.error('Error collecting tagging data:', error);
return null;
}
}

// Function to push to dataLayer
function pushToDataLayer(data) {
if (!data) return;

window.dataLayer = window.dataLayer || [];
window.dataLayer.push(data);
}

// Main execution
function init() {
loadScript('https://tagging.yourdomain.com/user-data-minified.js')
.then(function() {
return checkTaggingHelpers();
})
.then(function() {
var data = collectData();
pushToDataLayer(data);
})
.catch(function(error) {
console.error('Error in tagging initialization:', error);
});
}

// Start initialization when DOM is ready
if (document.readyState !== 'loading') {
init();
} else {
document.addEventListener('DOMContentLoaded', init);
}
})();
</script>



Step 3: Verification

After installation, you can check if the script is working correctly:

  1. Browser Console: Open developer tools (F12) and check for any errors
  2. DataLayer Check: Type dataLayer in the console to see if data is being added
  3. Network Tab: Verify that the user-data-minified.js script loads successfully



Implementation per platform

WordPress

  • Add the script via Appearance → Theme Editor → header.php
  • Or use a plugin like "Insert Headers and Footers"

Shopify

  • Go to Online Store → Themes → Actions → Edit Code
  • Open Layout → theme.liquid
  • Place the script in the <head> section

Magento

  • Add via Content → Design → Configuration
  • Or edit the template file head.phtml

Custom HTML

  • Place directly in the <head> section of your HTML files




Troubleshooting

Script doesn't load

No data in dataLayer

  • Check browser console for error messages
  • Ensure the script is placed before other tracking scripts

Data Assistant Tag not working

  • Check if the DataLayer script is loaded correctly
  • Verify that the trytagging_user_data event is being sent

Updated on: 31/07/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!