Skip to content

Commit c4c6eb2

Browse files
authored
Merge pull request #4841 from segmentio/client-hints
Add a.js client hints documentation
2 parents acd50fa + bcde60d commit c4c6eb2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/connections/sources/catalog/libraries/website/javascript/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ For example:
559559
analytics.load('writekey', { disableAutoISOConversion: true })
560560
```
561561

562+
#### Client hints
563+
Some `userAgent` strings are frozen and contain less information. If you would like to request more information when it's available, you can pass an array of strings with fields you would like to request to the `highEntropyValuesClientHints` option. The example array below contains all possible values.
564+
565+
For example:
566+
567+
```js
568+
analytics.load('writekey', { highEntropyValuesClientHints: ['architecture', 'bitness', 'model', 'platformVersion', 'uaFullVersion', 'fullVersionList', 'wow64'] })
569+
```
562570

563571
## Retries
564572

src/connections/spec/common.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,25 @@ Here's an example of these common fields in raw JSON:
7575
},
7676
"groupId": "12345",
7777
"timezone": "Europe/Amsterdam",
78-
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"
78+
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
79+
"userAgentData": {
80+
"brands": [
81+
{
82+
"brand": "Google Chrome",
83+
"version": "113"
84+
},
85+
{
86+
"brand": "Chromium",
87+
"version": "113"
88+
},
89+
{
90+
"brand": "Not-A.Brand",
91+
"version": "24"
92+
}
93+
],
94+
"mobile": false,
95+
"platform": "macOS"
96+
}
7997
},
8098
"integrations": {
8199
"All": true,
@@ -134,6 +152,7 @@ Context is a dictionary of extra information that provides useful context about
134152
| `groupId` | String | Group / Account ID. <br><br> This is useful in B2B use cases where you need to attribute your non-group calls to a company or account. It is relied on by several Customer Success and CRM tools. |
135153
| `traits` | Object | Dictionary of `traits` of the current user. <br><br> This is useful in cases where you need to `track` an event, but also associate information from a previous `identify` call. You should fill this object the same way you would fill traits in an [identify call](/docs/connections/spec/identify/#traits). |
136154
| `userAgent` | String | User agent of the device making the request. |
155+
| `userAgentData` | Object | The user agent data of the device making the request. This always contains `brands`, `mobile`, `platform`, and may contain `bitness`, `model`, `platformVersion`,`uaFullVersion`, `fullVersionList`, `wow64`, if [requested](/docs/connections/sources/catalog/libraries/website/javascript/#client-hints) and available. <br><br> This populates if the [Client Hints API](https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API){:target="_blank"} is available on the browser. <br><br> This may contain more information than is available in the `userAgent` in some cases. |
137156
| `channel` | String | where the request originated from: server, browser or mobile |
138157

139158

@@ -180,6 +199,7 @@ Other libraries only collect `context.library`, any other context variables must
180199
| screen.width | |||
181200
| traits | |||
182201
| userAgent || ||
202+
| userAgentData* || | |
183203
| timezone | |||
184204

185205
- IP Address isn't collected by Segment's libraries, but is instead filled in by Segment's servers when it receives a message for **client side events only**.
@@ -188,6 +208,8 @@ Other libraries only collect `context.library`, any other context variables must
188208
189209
- The Android library collects `screen.density` with [this method](/docs/connections/spec/common/#context-fields-automatically-collected).
190210

211+
- userAgentData is only collected if the [Client Hints API](https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API){:target="_blank"} is available on the browser.
212+
191213
To pass the context variables which are not automatically collected by Segment's libraries, you must manually include them in the event payload. The following code shows how to pass `groupId` as the context field of Analytics.js's `.track()` event:
192214

193215
```js

0 commit comments

Comments
 (0)