Google Tag Manager
Load Databuddy from one Custom HTML tag, then send your data layer events to it.
Add the Databuddy tag
Add a Client ID variable
In Variables → User-Defined Variables, choose New → Constant. Name it Databuddy Client ID and paste the Client ID from your website's Settings → General in Databuddy.
Add a Custom HTML tag
Choose Add a new tag → Custom HTML, name it Databuddy - Analytics Script, and paste:
<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>Set the trigger
Choose All Pages, or your consent manager's granted trigger if you need consent first. Under Advanced Settings → Tag firing options, choose Once per page.
Preview and publish
Choose Preview, visit your website and check the tag fires. Then Submit and Publish.
Pageviews, single-page app navigation and scroll depth are tracked automatically, so you don't need GA4-style page_view or scroll tags.
Send a data layer event
Create Data Layer Variables for the values, then fire a Custom HTML tag on the matching event:
<script>
if (window.databuddy) {
databuddy.track("purchase", {
transaction_id: "{{Transaction ID}}",
value: {{Purchase Revenue}},
currency: "{{Currency}}",
item_count: {{Items Count}}
});
}
</script>Quote text variables and leave number variables bare. The same pattern sends add_to_cart, begin_checkout or a form submit.
Track a click
Use a Click - All Elements trigger, for example where Click Classes contains track-button:
<script>
if (window.databuddy) {
databuddy.track("button_click", {
button_text: "{{Click Text}}",
page_path: "{{Page Path}}"
});
}
</script>Use a Client ID per hostname
Make Databuddy Client ID a Lookup Table keyed by Page Hostname, with each hostname's Client ID, including staging. Add a trigger condition so the tag fires only on mapped hostnames, never with an empty Client ID.
Wait for consent
Google's consent settings don't gate Databuddy on their own. Fire the tag from your consent manager's granted event, and set its additional consent checks.
Related
How is this guide?