From 97b851cec6e2f129a491bc146475413e314e1cec Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 11 Sep 2024 09:04:46 +0100 Subject: [PATCH] [Scorecards] Added click tracking for graphics --- scoring/static/scoring/js/main.js | 23 +++++++++++++++++++++++ scoring/templates/scoring/section.html | 14 +++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/scoring/static/scoring/js/main.js b/scoring/static/scoring/js/main.js index 4d58dbcc..92bfde1c 100644 --- a/scoring/static/scoring/js/main.js +++ b/scoring/static/scoring/js/main.js @@ -435,3 +435,26 @@ if ( typeof window.fetch !== 'undefined' ) { } }); } + +// Graphics click tracking +var trackEvent = function(eventName, params, callback){ + params = params || {}; + callback = callback || function(){}; + params['event_callback'] = callback; + setTimeout(callback, 2000); + gtag('event', eventName, params); +}; + +document.querySelectorAll('.js-social-graphic-download').forEach(function(el) { + el.addEventListener('click', function(e) { + e.preventDefault(); + var eventName = "download"; + var params = { + url: el.getAttribute('href') + }; + + trackEvent(eventName, params, function(){ + window.location.href = el.href; + }); + }); +}); diff --git a/scoring/templates/scoring/section.html b/scoring/templates/scoring/section.html index fd722575..40d0146c 100644 --- a/scoring/templates/scoring/section.html +++ b/scoring/templates/scoring/section.html @@ -133,7 +133,7 @@

Key takeaways

{% if social_graphics.zip %} - Download all (.zip) + Download all (.zip) {% endif %}
@@ -143,12 +143,12 @@

Key takeaways

{% for image in social_graphics.images %}
{% if image.src_instagram %} - + {{ image.alt }} {% endif %} {% if image.src_facebook %} - + {{ image.alt }} {% endif %} @@ -156,13 +156,13 @@

Key takeaways

Download: {% if image.src_facebook %} - + Wide {% endif %} {% if image.src_instagram %} - + Square @@ -177,8 +177,8 @@

Key takeaways

Download: - PDF - JPG + PDF + JPG
{% endif %}