1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-22 11:52:21 +01:00
2022-03-29 17:21:29 +02:00

44 lines
1.1 KiB
JavaScript

// this script loads the google tag manager, used by Google Analytics V4
(function () {
const GTM = {};
window.dataLayer = window.dataLayer || [];
function gtag () { window.dataLayer.push(arguments); }
GTM.enableAnalytics = function (trackingId) {
gtag('js', new Date());
gtag('config', trackingId);
const node = document.createElement('script');
const firstScript = document.getElementsByTagName('script')[0];
node.async = true;
node.src = `//www.googletagmanager.com/gtag/js?id=${trackingId}`;
firstScript.parentNode.insertBefore(node, firstScript);
};
GTM.trackPage = function (url, title) {
gtag('event', 'page_view', {
page_location: url,
page_title: title
});
};
GTM.trackLogin = function () {
gtag('event', 'login');
};
GTM.trackPurchase = function (transactionId, value) {
gtag('event', 'purchase', {
transaction_id: transactionId,
value,
currency: Fablab.intl_currency
});
};
this.GTM = GTM;
if (typeof module !== 'undefined' && module !== null) {
module.exports = GTM;
}
}).call(this);