Skip to content

Commit

Permalink
Update link tracker documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Oct 17, 2022
1 parent 6ab1b70 commit 3d10ed0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions docs/analytics-ga4/ga4-link-tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ When one of these listeners are fired, they check if the `event.target` is an `<

Events can either have an `event_name` of `navigation`, `file_download`, or `share`. Download and preview links will use the `file_download` value, while generic external links, mailto links, and follow links will use `navigation`. Share links use `share`.

Link URLs are stripped of the `_ga` and `_gl` query parameters. These are only relevant for cross domain tracking and aren't useful for our click tracking. Link text is stripped of multiple lines and multiple spaces, as this causes issues in the analytics dashboards.

GA4 only allows event values to have a maximum character length of 100. This is a problem for tracking URLs, as many of them exceed 100 characters. Therefore, to solve this we have:
- Added a separate `link_domain` value which captures the protocol and domain of a link, such as `https://www.gov.uk`
- Created an object called `link_path_parts`, which splits the path into 100 character segments (max 5 segments, or 500 characters). For example, if your link was `https://gov.uk/supercalifragilisticexpialidocious-even-though-the-sound-of-it-is-something-quite-atrocious-if-you-say-it-loud-enough-youll-always-sound-precocious-supercalifragilisticexpialidocious-supercalifragili`, your GA4 push would contain:
```JavaScript
"link_domain": "https://www.gov.uk",
"link_path_parts": {
"1": "/supercalifragilisticexpialidocious-even-though-the-sound-of-it-is-something-quite-atrocious-if-you-",
"2": "say-it-loud-enough-youll-always-sound-precocious-supercalifragilisticexpialidocious-supercalifragili",
"3": undefined,
"4": undefined,
"5": undefined
},
```
- The link is then reconstructed in Data Studio.

## Basic use

```JavaScript
Expand Down Expand Up @@ -69,7 +86,12 @@ In the example above, on a left click of the link, the following would be pushed
"section": null,
"action": null,
"external": "true",
"link_method": "primary click"
"method": "primary click",
"link_domain": "https://assets.publishing.service.gov.uk",
"link_path_parts": {
"1": "/government/uploads/system/uploads/attachment_data/file/742746/A_quick_guide_to_govt_healthy_eating_",
"2": "update.pdf"
}
}
}
```
Expand All @@ -84,7 +106,7 @@ Share links would turn `event_name` to `share` and type to `share this page`.

Follow links would turn `event_name` to `navigation` and type to `follow us`

For `link_method`:
For `method`:

- Left clicks are a `primary click`
- Right clicks and context menu keypresses are `secondary click`
Expand Down

0 comments on commit 3d10ed0

Please sign in to comment.