Skip to content

Commit

Permalink
setup updated to follow gtag implementation (#3069)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessioventuriniAND authored Mar 5, 2024
1 parent 6f779ea commit 679e07b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/js/analytics.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import domready from './domready';

export let trackEvent = () => {
console.log('Google analytics not connected'); // eslint-disable-line no-console
};
setTimeout(() => {
if (window.google_tag_manager !== 'undefined') {
console.log('GA active');
export let trackEvent = () => {};

if (window.google_tag_manager !== undefined) {
console.log('GA active');
trackEvent = (type, data) => {
window.dataLayer = window.dataLayer || [];
trackEvent = (data) => {
console.log('Data sent to Data Layer');
window.dataLayer.push({ data });
};
}
}, 300);
function gtag() {
dataLayer.push(arguments);
}
gtag('event', type, { ...data });
console.log('Data sent to Data Layer');
};
} else {
console.log('Google analytics not connected');
}

export const trackElement = (el, type) => {
return trackEvent({
event_type: type,
return trackEvent(type, {
event_category: el.getAttribute('data-ga-category') || '',
event_action: el.getAttribute('data-ga-action') || '',
event_label: el.getAttribute('data-ga-label') || '',
Expand Down

0 comments on commit 679e07b

Please sign in to comment.