From 325d632d2ed7b46332718d8a11173a8d190debca Mon Sep 17 00:00:00 2001 From: saladgg Date: Mon, 12 Sep 2022 11:07:31 +0300 Subject: [PATCH] chore: add google analytics for user metrics collection --- assets/static/js/project.js | 34 ++++++++++++++++++++++++++++++++ assets/templates/atoms/head.html | 15 +++----------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/assets/static/js/project.js b/assets/static/js/project.js index 12e6017..938040c 100644 --- a/assets/static/js/project.js +++ b/assets/static/js/project.js @@ -33,3 +33,37 @@ function switchDashboards(event) { // Hide the menu after selection $("#accordionSidebar.toggled #dashboards-menu").removeClass("show"); } + + +(function($) { + /* Google Analytics */ + window.dataLayer = window.dataLayer || []; + + function gtag() { + dataLayer.push(arguments); + } + gtag('js', new Date()); + gtag('config', 'G-S5JLWM36RQ'); + + // Auto-collapse open menus in responsive mode + $(".navbar-collapse a").click(function() { + $(".navbar-collapse").collapse("hide"); + }); + + // Initialize the select2 plugin + $("select").each(function() { + $(this).select2({ + allowClear: typeof $(this).data("allow-clear") !== "undefined" ? Boolean($(this).data("allow-clear")) : Boolean($(this).attr("multiple")), + closeOnSelect: !$(this).attr("multiple"), + placeholder: typeof $(this).data("placeholder") !== "undefined" ? $(this).data("placeholder") : {"id": `select2__placeholder__id__{$(this).attr('id')}`, "placeholder": `Select ${getElementLabelText(this)}`}, + theme: "bootstrap4", + width: $(this).data("width") ? $(this).data("width") : $(this).hasClass("w-100") ? "100%" : "resolve", + }); + }); + + // Initialize the date picker plugin + $(".datepicker").datepicker(); + + // Add a dashboard selection change listener + $("#dashboards-menu > div > a").click(switchDashboards); +})(jQuery); diff --git a/assets/templates/atoms/head.html b/assets/templates/atoms/head.html index 284bb03..34759f5 100644 --- a/assets/templates/atoms/head.html +++ b/assets/templates/atoms/head.html @@ -29,6 +29,7 @@ {% endblock css %} + {% block javascript %} {% compress js %} @@ -36,19 +37,9 @@ {% endcompress %} - - {% endblock javascript %} - - - - + + {% endblock javascript %}