Skip to content

Commit 94ffe21

Browse files
committed
Add documentation for GA4 tracking
- Add reference to doc in README - Add tracking doc
1 parent 131825f commit 94ffe21

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ For details on how feature flags are managed in Publisher, see the [feature flag
156156

157157
For instructions on how to add a new type of promotion to Completed Transactions, see the ["adding a promotion" documentation](docs/adding-a-promotion-to-a-completed-transaction.md).
158158

159+
### GA4 tracking
160+
161+
For details on the tracking that is applied to Publisher, see the [GA4 tracking documentation](docs/ga4-tracking.md).
162+
159163
## Further documentation
160164

161165
- [Fact Checking](docs/fact-checking.md)

docs/ga4-tracking.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# GA4 tracking
2+
3+
Tracking is added to Publisher via GA4. The full documentation is avaialable in [GA4 Publishing Implementation guide](https://docs.google.com/document/d/19RaqZttDTZXsgX4k87wAAOhsol1STM3iTPPPKNlXRl0/edit?tab=t.0#heading=h.eo3rk3rxuz4n).
4+
5+
Via this means we are tracking:
6+
- Page views
7+
- Navigation
8+
- Form interactions
9+
10+
Most of the code exists in the govuk_publishing_components gem. On publisher we are setting up various parameters on elements to make use of this. Our approach is to add these dynamically on page load via JavaScript set-up modules.
11+
12+
## Testing locally
13+
14+
Tracking can be tested locally with these steps:
15+
- ensure that the "Ga4 form tracking" feature is set to "On" via FlipFlop
16+
- ensure that "Preserve log" is set to "On" in the browser console
17+
- run `window.GOVUK.analyticsGa4.showDebug = true` in the browser console. The console will then display the tracking data for all user interactions with the form as they occur.
18+
19+
Running `window.dataLayer` in the browser console at any point will display the data that has been collected during user interactions with the page. In this work we are interested in the "event_data" events. There should be one of these for each user event with the form since the page was loaded.
20+
21+
## Automated tests
22+
23+
There are:
24+
- JavaScript Unit Tests for each set-up module:
25+
- spec/javascripts/spec/ga4-form-setup.spec.js
26+
- spec/javascripts/spec/ga4-index-section-setup.spec.js
27+
- Rails integration tests for each page that uses the set-up modules:
28+
- test/integration/ga4_tracking_test.rb

0 commit comments

Comments
 (0)