Skip to content

Commit

Permalink
change in initialization and condition access of dataLayer
Browse files Browse the repository at this point in the history
Removed the global initialization of dataLayer and added conditional checks for dataLayer.

Ref - #506
  • Loading branch information
shraddha committed Sep 9, 2024
1 parent eed09fd commit f925328
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions assets/js/event-handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"use-strict";

// Ensure dataLayer is defined Globally before using it
window.dataLayer = window.dataLayer || [];

const Toast = Swal.mixin({
toast: true,
position: 'center',
Expand All @@ -19,12 +16,14 @@ document.getElementById('bug-report').addEventListener('vl-bug-report', (e) => {
if (e.detail.status === 200 || e.detail.status === 201) {
const learningUnit = document.head.querySelector('meta[name="learning-unit"]').content;
const task = document.head.querySelector('meta[name="task-name"]').content;
dataLayer.push({
event: "vl-bug-report",
"bug-type": e.detail.issues,
"learning-unit": learningUnit ? learningUnit : "",
"task-name": task ? task : ""
})
if (window.dataLayer) {
window.dataLayer.push({
event: "vl-bug-report",
"bug-type": e.detail.issues,
"learning-unit": learningUnit ? learningUnit : "",
"task-name": task ? task : ""
})
}
Toast.fire({
icon: 'success',
iconColor: "white",
Expand All @@ -47,13 +46,15 @@ document.getElementById('bug-report').addEventListener('vl-bug-report', (e) => {
function handleRatingSubmit(e) {
const learningUnit = document.head.querySelector('meta[name="learning-unit"]').content;
const task = document.head.querySelector('meta[name="task-name"]').content;
dataLayer.push({
event: "vl-rating-submit",
"rating": e.detail.rating,
"rating-value": e.detail.rating,
"learning-unit": learningUnit ? learningUnit : "",
"task-name": task ? task : ""
});
if (window.dataLayer) {
window.dataLayer.push({
event: "vl-rating-submit",
"rating": e.detail.rating,
"rating-value": e.detail.rating,
"learning-unit": learningUnit ? learningUnit : "",
"task-name": task ? task : ""
});
}
Toast.fire({
icon: 'success',
iconColor: "white",
Expand Down

0 comments on commit f925328

Please sign in to comment.