Google Tag Manager
Load Databuddy through a GTM Custom HTML tag and send application events from your data layer.
TL;DR: In GTM, create a Custom HTML tag with an inline loader that appends
https://cdn.databuddy.cc/databuddy.jsand setsdata-client-id. Enable optional flags such asdata-track-attributesordata-track-errors. Page views and sessions are automatic. Choose a page or consent-granted trigger that matches your privacy configuration, then preview and publish.
Basic Setup
Step 1: Create Databuddy Tag
This loader sets the tracker attributes before loading the script and signals when it is ready:
<script>
(function () {
var el = document.createElement("script");
el.src = "https://cdn.databuddy.cc/databuddy.js";
el.async = true;
el.crossOrigin = "anonymous";
el.setAttribute("data-client-id", "{{Databuddy Client ID}}");
el.setAttribute("data-track-attributes", "true");
el.setAttribute("data-track-errors", "true");
el.onload = function () {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: 'databuddy_ready' });
};
el.onerror = function () {
console.warn('Databuddy script failed to load');
};
document.head.appendChild(el);
})();
</script>Step 2: Create Variables
Create a Constant variable for your Client ID:
Step 3: Set Trigger
Step 4: Publish
Advanced Configuration
Reuse the loader above for each configuration:
Keep the onload callback so tags waiting for databuddy_ready can fire. Use the loader once per page; automatic pageview tracking already handles SPA navigation.
Event Tracking Setup
Custom Event Tags
The loader above emits databuddy_ready after the script finishes loading. For startup events, use a Custom Event trigger named databuddy_ready. For purchase and other application events, dispatch them after readiness or buffer them in your application until then. The examples below do not queue early events. GTM tag sequencing alone does not wait for an asynchronously injected script.
Create tags for specific events:
E-commerce Purchase Tag:
Create Data Layer Variables for the values you need (e.g. Transaction ID, Purchase Revenue, Currency, Items Count), then fire this tag on your purchase event trigger:
<script>
if (window.databuddy) {
databuddy.track('purchase', {
transaction_id: '{{Transaction ID}}',
value: {{Purchase Revenue}},
currency: '{{Currency}}',
item_count: {{Items Count}}
});
}
</script>Form Submission Tag:
<script>
if (window.databuddy) {
databuddy.track('form_submit', {
form_id: '{{Form ID}}',
form_name: '{{Form Name}}',
form_location: '{{Page Path}}'
});
}
</script>Data Layer Integration
Send GTM data layer events to Databuddy:
<script>
if (window.databuddy) {
databuddy.track('{{Event}}', {
category: '{{Event Category}}',
action: '{{Event Action}}',
label: '{{Event Label}}',
value: {{Event Value}},
custom_parameter: '{{Custom Parameter}}'
});
}
</script>Triggers Configuration
The analytics script records pageviews automatically, including SPA navigation. Use the All Pages trigger only to load the script; do not add a second pageview tag.
Scroll Tracking
Databuddy's built-in tracking already covers scroll depth, so you do not need a separate GTM scroll depth tag.
Click Tracking
Track specific button clicks:
<script>
if (window.databuddy) {
databuddy.track('button_click', {
button_text: '{{Click Text}}',
button_classes: '{{Click Classes}}',
page_path: '{{Page Path}}'
});
}
</script>E-commerce Integration
Enhanced E-commerce Setup
Track the complete customer journey. Create Data Layer Variables for the product values your site pushes to the data layer, and fire each tag on the matching data layer event trigger.
Product View Tag:
<script>
if (window.databuddy) {
databuddy.track('product_view', {
product_id: '{{Product ID}}',
product_name: '{{Product Name}}',
product_category: '{{Product Category}}',
product_price: {{Product Price}},
currency: '{{Currency}}'
});
}
</script>Add to Cart Tag:
<script>
if (window.databuddy) {
databuddy.track('add_to_cart', {
product_id: '{{Product ID}}',
product_name: '{{Product Name}}',
quantity: {{Quantity}},
value: {{Item Revenue}},
currency: '{{Currency}}'
});
}
</script>Begin Checkout Tag:
<script>
if (window.databuddy) {
databuddy.track('begin_checkout', {
value: {{Cart Value}},
currency: '{{Currency}}',
item_count: {{Items Count}}
});
}
</script>User Privacy and Consent
Google's consent settings do not automatically gate Databuddy. If your deployment requires consent, configure the loader tag's additional consent checks and trigger it only after your consent manager grants analytics consent. Connect that trigger to the manager's actual consent event; its name varies by implementation.
On withdrawal, call window.databuddyOptOut() and prevent the tag from loading again. On a later grant, window.databuddyOptIn() clears that local opt-out; it does not override Do Not Track or Global Privacy Control. Test both a fresh browser session and withdrawal after collection has started.
See Google's consent overview and the Databuddy privacy guide.
Debugging and Testing
Debug Mode Setup
Enable debug mode for testing:
<script>
var isDebugMode = '{{Debug Mode}}' === 'true';
if (window.databuddy && isDebugMode) {
console.log('Databuddy Debug Mode Enabled');
databuddy.track('debug_event', {
page: '{{Page Path}}',
timestamp: new Date().toISOString()
});
}
</script>Preview Mode Testing
Variable Testing
Create test variables for debugging:
Debug Info Variable:
function() {
return {
page_path: '{{Page Path}}',
page_title: '{{Page Title}}',
user_agent: navigator.userAgent,
timestamp: new Date().toISOString()
};
}Best Practices
The loader is asynchronous and reports load failures in the browser console. A failed load does not emit databuddy_ready.
Tag Organization
Version Management
Migration from Google Analytics
Replacing GA4 with Databuddy
Data Mapping
Map GA4 events to Databuddy equivalents:
Troubleshooting
Common Issues
Tag Not Firing:
Events Not Tracking:
Performance Issues:
Debug Checklist
Related Integrations
Need help with your GTM integration? Contact us at support@databuddy.cc.
How is this guide?