Skip to content

Commit f62268d

Browse files
authored
Merge pull request #1735 from companieshouse/origin/feature/roecct-638-matomo-adding-goals-for-the-pre-registration-page-of-the-s174-journey-in-cidev
Matomo: Adding goals for the Pre-registration page of the S174 journey in CIDEV
2 parents 4a7fcca + 1d2ce06 commit f62268d

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function isCiDevEnvironment(hostname: string): boolean {
2+
return hostname.includes("cidev");
3+
}
4+
5+
export type MatomoPaq = {
6+
push: (args: [string, number]) => void;
7+
};
8+
9+
export function trackRelevantPeriodGoal(
10+
value: string,
11+
paq: MatomoPaq | undefined = (window as any).paq
12+
): void {
13+
14+
if (value === "1") {
15+
paq.push(["trackGoal", 55]); // User selected YES
16+
} else if (value === "0") {
17+
paq.push(["trackGoal", 118]); // User selected NO
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
isCiDevEnvironment,
3+
trackRelevantPeriodGoal,
4+
MatomoPaq,
5+
} from "../../../src/frontend/analytics/piwik.relevant.period.confirm.goals";
6+
7+
describe("isCiDevEnvironment", () => {
8+
it("returns true when hostname includes 'cidev'", () => {
9+
expect(isCiDevEnvironment("dev.cidev.internal")).toBe(true);
10+
});
11+
12+
it("returns false when hostname does not include 'cidev'", () => {
13+
expect(isCiDevEnvironment("example.gov.uk")).toBe(false);
14+
});
15+
});
16+
17+
describe("trackRelevantPeriodGoal", () => {
18+
let mockPaq: MatomoPaq;
19+
20+
beforeEach(() => {
21+
mockPaq = { push: jest.fn() };
22+
});
23+
24+
it("tracks goal 55 for value '1'", () => {
25+
trackRelevantPeriodGoal("1", mockPaq);
26+
expect(mockPaq.push).toHaveBeenCalledWith(["trackGoal", 55]);
27+
});
28+
29+
it("tracks goal 118 for value '0'", () => {
30+
trackRelevantPeriodGoal("0", mockPaq);
31+
expect(mockPaq.push).toHaveBeenCalledWith(["trackGoal", 118]);
32+
});
33+
});
34+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script type="module">
2+
import { trackRelevantPeriodGoal, isCiDevEnvironment } from "../../../../../../../../src/frontend/analytics/piwik.relevant.period.confirm.goals.ts";
3+
4+
function setupRelevantPeriodTracking() {
5+
document.addEventListener("DOMContentLoaded", () => {
6+
if (!isCiDevEnvironment(window.location.hostname)) {
7+
return;
8+
}
9+
10+
const submitButton = document.getElementById("submit");
11+
if (!submitButton) {
12+
return;
13+
}
14+
15+
submitButton.addEventListener("click", () => {
16+
const selected = document.querySelector(
17+
'input[name="relevant-period-required-information"]:checked'
18+
);
19+
if (!selected) {
20+
return;
21+
}
22+
23+
trackRelevantPeriodGoal(selected.value);
24+
});
25+
});
26+
}
27+
28+
setupRelevantPeriodTracking();
29+
</script>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,9 @@ <h1 class="govuk-heading-xl">You'll need to tell us about the pre-registration p
8686
</div>
8787
</div>
8888

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

0 commit comments

Comments
 (0)