1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-23 12:52:20 +01:00

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-03-21 17:59:38 +01:00
// 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); }
2022-03-21 17:59:38 +01:00
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,
2022-04-01 17:48:32 +02:00
value,
currency: Fablab.intl_currency
});
};
2022-03-21 17:59:38 +01:00
this.GTM = GTM;
if (typeof module !== 'undefined' && module !== null) {
module.exports = GTM;
}
}).call(this);