apps/web/guides/gtm-client-sdk.md
This guide will walk you through the process of integrating Dub with Google Tag Manager (GTM).
First, navigate to your Google Tag Manager account and create a new tag:
In the Custom HTML section, you’ll need to add the Dub client-side script. Copy and paste the following code into the HTML field:
<!-- prettier-ignore --><script>
(function (c, n) {
c[n] =
c[n] ||
function () {
(c[n].q = c[n].q || []).push(arguments);
};
var methods = ["trackClick", "trackLead", "trackSale"];
for (var i = 0; i < methods.length; i++) {
(function (method) {
c[n][method] = function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
c[n].apply(null, args);
};
})(methods[i]);
}
var s = document.createElement("script");
s.defer = 1;
s.src = "https://www.dubcdn.com/analytics/script.js";
document.head.appendChild(s);
})(window, "dubAnalytics");
</script>
To ensure the analytics script loads on all pages: