-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3963 from alphagov/docs-updates
Clean up the GA4 docs
- Loading branch information
Showing
18 changed files
with
106 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Using our GA4 tracking in your application | ||
|
||
If you are a developer on GOV.UK looking to integrate the tracking code into one of our Rails applications there are several steps needed. | ||
|
||
The code in this gem is set up to track and structure data in a very specific way. If you wish to use a different [data schema](schemas.md) or track different things it may be easier to implement GA4 in a different way. Ask in the `#govuk-ga4` slack channel for advice. | ||
|
||
## Installation | ||
|
||
Ensure the gem is [installed in your application](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/install-and-use.md). | ||
|
||
Include the gem dependencies in your main JavaScript file: `//= require govuk_publishing_components/dependencies`. | ||
|
||
Add this meta tag to your main page template: `<meta name="govuk:components_gem_version" content="<%= GovukPublishingComponents::VERSION %>" />` (the gem version number is read from here for versioning purposes in the analytics data). | ||
|
||
Configure the GTM variables for your site as described in 'Passing extra options' in the [load analytics documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/load-analytics.md), and include the `load-analytics.js` script in your code. | ||
|
||
If your application does not require cookie consent from your users, you will need to 'force' cookie consent to occur, as the analytics code depends upon it. | ||
|
||
```JavaScript | ||
window.GOVUK.approveAllCookieTypes() | ||
window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 }) | ||
``` | ||
|
||
If your application already has a cookie banner and it is not the one from this gem, you will need to switch to ours. | ||
|
||
## Testing | ||
|
||
Once the code is configured correctly, data will start to be pushed to the dataLayer. Read the 'Testing and debugging' section of the [developer guide](developer-guide.md) to see how to check it is working correctly. | ||
|
||
Page views and some link tracking should happen automatically. Some components also track automatically. If you wish to add new tracking, start with the 'Creating tracking' section of the developer guide. | ||
|
||
## Configuring GTM/GA4 | ||
|
||
Even if all of the above has worked correctly some configuration will still need to be done at the GTM/GA4 level to actually collect and store the analytics data. Talk to a performance analyst or ask in `#govuk-ga4` for more information. |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Trackers | ||
|
||
For tracking different kinds of data on GOV.UK we have built several different trackers. Each type of tracking is handled by a separate script, but some code is shared between them as they often do similar things. | ||
|
||
Most of the trackers work by adding a `data-module` attribute to an element along with additional data attributes to provide specific tracking information. Some components have this already built into their code by default. These components should also include a `disable_ga4` option as a failsafe. | ||
|
||
## Auto tracker | ||
|
||
The [auto tracker](trackers/ga4-auto-tracker.md) is used to cause an event to occur as soon as a page has finished loading (but after a page view). This is used to track significant moments in journeys, such as the successful completion of a smart answer, or an error. | ||
|
||
## Copy tracker | ||
|
||
The [copy tracker](trackers/ga4-copy-tracker.md) fires an event when text is copied from a page. | ||
|
||
## Ecommerce tracker | ||
|
||
The [ecommerce tracker](trackers/ga4-ecommerce-tracker.md) is used to track things like search results within a finder. | ||
|
||
## Event tracker | ||
|
||
The [event tracker](trackers/ga4-event-tracker.md) handles tracking on buttons or other interactive elements, such as tabs and details elements. | ||
|
||
## Focus loss tracker | ||
|
||
The [focus loss tracker](trackers/ga4-focus-loss-tracker.md) is designed to capture data about an element when it loses focus. | ||
|
||
## Form tracker | ||
|
||
The [form tracker](trackers/ga4-form-tracker.md) is designed to capture data about a form when it has been submitted. | ||
|
||
## Link tracker | ||
|
||
There are several types of link tracking. To distinguish them and simplify the code, we define them as follows. | ||
|
||
- the [link tracker](trackers/ga4-link-tracker.md) handles link clicks with data attributes added to specific links, or to parent elements of groups of links | ||
- the [specialist link tracker](trackers/ga4-specialist-link-tracker.md) automatically tracks clicks on 'special' links, such as external links, download links and mailto links | ||
|
||
## Print intent tracker | ||
|
||
The [print intent tracker](trackers/ga4-print-intent-tracker.md) tracks if the page has been requested to be printed. | ||
|
||
## Scroll tracker | ||
|
||
The [scroll tracker](trackers/ga4-scroll-tracker.md) tracks how much of a page has been viewed. | ||
|
||
## Smart answer results tracker | ||
|
||
The [smart answer results tracker](trackers/ga4-smart-answer-results-tracker.md) has been built specifically to track the Cost of Living smart answer. | ||
|
||
## Video tracker | ||
|
||
The [video tracker](trackers/ga4-video-tracker.md) tracks video views. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.