Skip to content

Commit

Permalink
Merge pull request #1690 from companieshouse/ROECCT-289-MATOMO-FIX-PR…
Browse files Browse the repository at this point in the history
…OBLEMS-CSP

ROECCT-289: Fix Matomo problems caused by Content Security Policy
  • Loading branch information
jnicholson-ch authored Feb 12, 2025
2 parents 8549bc6 + 0708257 commit e767084
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
27 changes: 27 additions & 0 deletions views/includes/piwik-goal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script nonce={{ cspNonce | dump | safe }}>
function trackGoal(elementId, goalId) {
document
.getElementById(elementId)
.addEventListener("click", () => {
_paq.push(["trackGoal", goalId]);
});
}

function addGoalEventListeners() {
{% if (journey == "remove") %}
trackGoal("submit", {{PIWIK_REMOVE_START_GOAL_ID}} );
{% elif (update.owned_land_relevant_period == 1) %}
trackGoal("submit", {{PIWIK_RELEVANT_PERIOD_START_GOAL_ID}} );
{% else %}
trackGoal("submit", {{PIWIK_UPDATE_START_GOAL_ID}} );
{% endif %}
}

if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", function (e) {
addGoalEventListeners()
});
} else {
addGoalEventListeners()
}
</script>
6 changes: 3 additions & 3 deletions views/includes/relevant-period-start-goal-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{{ govukButton({
text: "Continue",
attributes: {
"id": "submit",
"onclick": "_paq.push(['trackGoal', '" + PIWIK_RELEVANT_PERIOD_START_GOAL_ID + "'])"
"id": "submit"
}
}) }}
{% include "includes/piwik-goal.html" %}
{% else %}
{% include "includes/continue-button.html" %}
{% endif %}
{% endif %}
6 changes: 3 additions & 3 deletions views/includes/remove-start-goal-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{{ govukButton({
text: "Continue",
attributes: {
"id": "submit",
"onclick": "_paq.push(['trackGoal', '" + PIWIK_REMOVE_START_GOAL_ID + "'])"
"id": "submit"
}
}) }}
{% include "includes/piwik-goal.html" %}
{% else %}
{% include "includes/continue-button.html" %}
{% endif %}
{% endif %}
6 changes: 3 additions & 3 deletions views/includes/update-start-goal-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{{ govukButton({
text: "Continue",
attributes: {
"id": "submit",
"onclick": "_paq.push(['trackGoal', '" + PIWIK_UPDATE_START_GOAL_ID + "'])"
"id": "submit"
}
}) }}
{% include "includes/piwik-goal.html" %}
{% else %}
{% include "includes/continue-button.html" %}
{% endif %}
{% endif %}

0 comments on commit e767084

Please sign in to comment.