Skip to content

Commit b77a4e3

Browse files
authored
Merge pull request #1740 from companieshouse/origin/feature/roecct-638-matomo-pre-reg-fix
Matomo: Adding goals for the Pre-registration page of the S174 journey in CIDEV
2 parents 47087c3 + d31b1ad commit b77a4e3

File tree

5 files changed

+38
-82
lines changed

5 files changed

+38
-82
lines changed

src/frontend/analytics/piwik.relevant.period.confirm.goals.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/frontend/analytics/piwik.relevant.period.confirm.goals.spec.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% if PIWIK_RELEVANT_PERIOD_START_GOAL_ID > 0 %}
2+
{{ govukButton({
3+
text: "Continue",
4+
attributes: {
5+
"id": "submit"
6+
}
7+
}) }}
8+
{% include "includes/piwik-relevant-period-confirm-goals.html" %}
9+
{% else %}
10+
{% include "includes/continue-button.html" %}
11+
{% endif %}
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
<script type="module">
2-
import { trackRelevantPeriodGoal, isCiDevEnvironment } from "../../../../../../../../src/frontend/analytics/piwik.relevant.period.confirm.goals.ts";
1+
<script nonce={{ cspNonce | dump | safe }}>
2+
document.addEventListener("DOMContentLoaded", function () {
3+
if (!window.location.href.includes("cidev")) {
4+
return; // Don't run tracking logic unless in "cidev" environment
5+
}
6+
7+
var submitBtn = document.getElementById("submit");
38

4-
function setupRelevantPeriodTracking() {
5-
document.addEventListener("DOMContentLoaded", () => {
6-
if (!isCiDevEnvironment(window.location.hostname)) {
7-
return;
8-
}
9+
if (!submitBtn) {
10+
console.warn("Submit button not found.");
11+
return;
12+
}
913

10-
const submitButton = document.getElementById("submit");
11-
if (!submitButton) {
12-
return;
14+
submitBtn.addEventListener("click", function (event) {
15+
var selected = document.querySelector('input[name="required_information"]:checked');
16+
if (!selected) {
17+
return;
1318
}
1419

15-
submitButton.addEventListener("click", () => {
16-
const selected = document.querySelector(
17-
'input[name="required_information"]:checked'
18-
);
19-
if (!selected) {
20-
return;
21-
}
20+
event.preventDefault();
2221

23-
trackRelevantPeriodGoal(selected.value);
24-
});
25-
});
26-
}
22+
if (window._paq) {
23+
if (selected.value === "1") {
24+
_paq.push(["trackGoal", 55]);
25+
} else if (selected.value === "0") {
26+
_paq.push(["trackGoal", 118]);
27+
}
28+
}
2729

28-
setupRelevantPeriodTracking();
30+
submitBtn.click();
31+
}, { once: true });
32+
});
2933
</script>

views/update/relevant-period-required-information-confirm.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,9 @@ <h1 class="govuk-heading-xl">You'll need to tell us about the pre-registration p
8181
}
8282
]
8383
}) }}
84-
{% include "includes/continue-button.html" %}
84+
{% include "includes/piwik-pre-reg-goals-button.html" %}
8585
</form>
8686
</div>
8787
</div>
8888

89-
{% endblock %}
90-
91-
{% block scripts %}
92-
{{ super() }}
93-
{% include "includes/piwik-relevant-period-confirm-goals.html" %}
9489
{% endblock %}

0 commit comments

Comments
 (0)