Skip to content

Commit

Permalink
chore: add google analytics for user metrics collection
Browse files Browse the repository at this point in the history
  • Loading branch information
saladgg committed Sep 12, 2022
1 parent 76d4b42 commit 325d632
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
34 changes: 34 additions & 0 deletions assets/static/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 3 additions & 12 deletions assets/templates/atoms/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,17 @@
<link href="https://cdn.jsdelivr.net/npm/@ttskch/select2-bootstrap4-theme/dist/select2-bootstrap4.min.css" rel="stylesheet">
{% endblock css %}


{% block javascript %}
{% compress js %}
<script defer src="{% static 'js/vendors.min.js' %}"></script>
<script defer src="{% static 'js/sb-admin-2.min.js' %}"></script>
<script defer src="{% static 'js/project.min.js' %}"></script>
{% endcompress %}

<script src="https://kit.fontawesome.com/e1c9d8c99d.js" crossorigin="anonymous"></script>
{% endblock javascript %}


<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-S5JLWM36RQ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-S5JLWM36RQ');
</script>

<script src="https://kit.fontawesome.com/e1c9d8c99d.js" crossorigin="anonymous"></script>
{% endblock javascript %}

</head>

0 comments on commit 325d632

Please sign in to comment.