@@ -50,41 +50,105 @@ is configured to write to the same database and run with the `--write-to-databas
50
50
51
51
# Using the API
52
52
53
+ Full API docs can be found here: https://open.gsa.gov/api/dap/
54
+
55
+ ## Environments
56
+
57
+ The base URLs for the 3 API envrionments:
58
+ - development: https://api.gsa.gov/analytics/dap/develop/
59
+ - staging: https://api.gsa.gov/analytics/dap/staging/
60
+ - production: https://api.gsa.gov/analytics/dap/
61
+
62
+ ## Overview
63
+
53
64
The Analytics API exposes 3 API endpoints:
54
- include version in the request, ie ` /v2/ `
55
65
56
- - ` /reports/: report_name/data `
57
- - ` /agencies/: agency_name/reports/:reportName /data `
58
- - ` /domain/: domain/reports/:reportName /data `
66
+ - ` /v{api_version}/ reports/{ report_name} /data `
67
+ - ` /v{api_version}/ agencies/{ agency_name} /reports/{report_name} /data `
68
+ - ` /v{api_version}/ domain/{ domain} /reports/{report_name} /data `
59
69
60
- Each endpoint renders a JSON array with the most recent 1000 records the
70
+ Each endpoint renders a JSON array with the most recent 1000 records that the
61
71
Analytics Reporter has generated for the given agency and report. If no records
62
72
are found, an empty array is returned.
63
73
64
74
Records are sorted according to the associated date.
65
75
66
- ##### Limit
76
+ ### Limit query parameter
67
77
68
78
If a different number of records is desired, the ` limit ` query parameter can be
69
79
set to specify the desired number of records.
70
80
71
81
```
72
- /reports/realtime/data?limit=500
82
+ /v2/ reports/realtime/data?limit=500
73
83
```
74
84
75
85
The maximum number of records that can be rendered for any given request is
76
86
10,000.
77
87
78
- ##### Page
88
+ ### Page query parameter
79
89
80
90
If the desired record does not appear for the current request, the ` page ` query
81
91
parameter can be used to get the next series of data points. Since the data is
82
92
ordered by date, this parameter effectively allows older data to be queried.
83
93
84
94
```
85
- /reports/realtime/data?page=2
95
+ /v2/ reports/realtime/data?page=2
86
96
```
87
97
98
+ ## Migrating from API V1 to API V2
99
+
100
+ ### Background
101
+
102
+ Analytics API V1 returns data from Google Analytics V3, also known as Universal
103
+ Analytics (UA).
104
+
105
+ Google is retiring UA and is encouraging users to move to their new
106
+ version Google Analytics V4 (GA4) in 2024.
107
+
108
+ Analytics API V2 returns data from GA4.
109
+
110
+ ### Migration details
111
+
112
+ #### Requests
113
+
114
+ The Analytics API endpoints are the same between V1 and V2, the only difference
115
+ for API requests is the API version string.
116
+
117
+ #### Responses
118
+
119
+ Response data is slightly different in Analytics API V2. This change is due to
120
+ the data provided by Google Analytics. Some data fields were retired in GA4, and
121
+ some other useful data fields were added. The changes follow:
122
+
123
+ ##### Deprecated fields
124
+
125
+ - browser_version
126
+ - has_social_referral
127
+ - exits
128
+ - exit_page
129
+
130
+ ##### New fields
131
+
132
+ ###### bounce_rate
133
+
134
+ The percentage of sessions that were not engaged. GA4 defines engaged as a
135
+ session that lasts longer than 10 seconds or has multiple pageviews.
136
+
137
+ ###### file_name
138
+
139
+ The page path of a downloaded file.
140
+
141
+ ###### language_code
142
+
143
+ The ISO639 language setting of the user's device. e.g. 'en-us'
144
+
145
+ ###### session_default_channel_group
146
+
147
+ An enum which describes the session. Possible values:
148
+
149
+ 'Direct', 'Organic Search', 'Paid Social', 'Organic Social', 'Email',
150
+ 'Affiliates', 'Referral', 'Paid Search', 'Video', and 'Display'
151
+
88
152
# Running the Tests
89
153
90
154
The Analytics API application is backed by a test suite that uses
0 commit comments