From 9ce39d34da8c0cba1258f84ec6824b40dc12cdf6 Mon Sep 17 00:00:00 2001 From: laszlokajtar <126791628+laszlokajtar@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:40:19 +0200 Subject: [PATCH] GROWENG-3818 changing legacy google analytics event to datalayer push (#13954) --- static/js/src/dynamic-forms.js | 48 ++++++++++++--------------- static/js/src/kernel-form.js | 60 ++++++++++++++-------------------- 2 files changed, 45 insertions(+), 63 deletions(-) diff --git a/static/js/src/dynamic-forms.js b/static/js/src/dynamic-forms.js index 9ff51994c6e..f229524b03e 100644 --- a/static/js/src/dynamic-forms.js +++ b/static/js/src/dynamic-forms.js @@ -83,13 +83,11 @@ import { prepareInputFields } from "./prepare-form-inputs.js"; // Open the contact us modal function open() { updateHash(triggeringHash); - ga( - "send", - "event", - "interactive-forms", - "open", - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "open", + path: window.location.pathname, + }); } // Removes the triggering hash @@ -243,13 +241,11 @@ import { prepareInputFields } from "./prepare-form-inputs.js"; if (button.classList.contains("pagination__link--previous")) { index = index - 1; setState(index); - ga( - "send", - "event", - "interactive-forms", - "goto:" + index, - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "goto:" + index, + path: window.location.pathname, + }); } else { var valid = true; @@ -262,13 +258,11 @@ import { prepareInputFields } from "./prepare-form-inputs.js"; if (valid) { index = index + 1; setState(index); - ga( - "send", - "event", - "interactive-forms", - "goto:" + index, - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "goto:" + index, + path: window.location.pathname, + }); } } }); @@ -346,13 +340,11 @@ import { prepareInputFields } from "./prepare-form-inputs.js"; formContainer.removeChild(contactModal); modalTrigger.focus(); updateHash(""); - ga( - "send", - "event", - "interactive-forms", - "close", - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "close", + path: window.location.pathname, + }); } // Update the content of the modal based on the current index diff --git a/static/js/src/kernel-form.js b/static/js/src/kernel-form.js index 1a81301243a..d9096cc30b8 100644 --- a/static/js/src/kernel-form.js +++ b/static/js/src/kernel-form.js @@ -78,13 +78,11 @@ // Open the contact us modal function open() { updateHash(triggeringHash); - ga( - "send", - "event", - "interactive-forms", - "open", - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "open", + path: window.location.pathname, + }); } // Removes the triggering hash @@ -195,13 +193,11 @@ if (submitButton) { submitButton.addEventListener("click", function () { - ga( - "send", - "event", - "interactive-forms", - "submitted", - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "submitted", + path: window.location.pathname, + }); }); } @@ -236,13 +232,11 @@ if (button.classList.contains("pagination__link--previous")) { index = index - 1; setState(index); - ga( - "send", - "event", - "interactive-forms", - "goto:" + index, - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "goto:" + index, + path: window.location.pathname, + }); } else { var valid = true; @@ -255,13 +249,11 @@ if (valid) { index = index + 1; setState(index); - ga( - "send", - "event", - "interactive-forms", - "goto:" + index, - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "goto:" + index, + path: window.location.pathname, + }); } } }); @@ -337,13 +329,11 @@ formContainer.classList.add("u-hide"); formContainer.removeChild(contactModal); updateHash(""); - ga( - "send", - "event", - "interactive-forms", - "close", - window.location.pathname - ); + dataLayer.push({ + event: "interactive-forms", + action: "close", + path: window.location.pathname, + }); } // Update the content of the modal based on the current index