Skip to content

Commit ef3379e

Browse files
committed
add instructions for using the api
1 parent 2de3c9d commit ef3379e

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

docs/analytics/cloud.mdx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To enable Sourcegraph Analytics:
1515

1616
## Data export
1717

18-
Sourcegraph Cloud Analytics also includes a CSV export option with key metrics like the number of searches, chats, autocomplete suggestions, completion acceptance rate (CAR %), and more. The data is split by user, day, client/editor, and programming language, perfect for automating retrieval and analyzing data in ways that make the most sense to your organization.
18+
Sourcegraph Analytics also includes a CSV export option with key metrics like the number of searches, chats, autocomplete suggestions, completion acceptance rate (CAR %), and more. The data is split by user, day, client/editor, and programming language, perfect for automating retrieval and analyzing data in ways that make the most sense to your organization.
1919

2020

2121
## Access Tokens
@@ -112,3 +112,36 @@ curl -X DELETE https://analytics.sourcegraph.com/api/service-access-tokens/$TOKE
112112
```
113113

114114
> NOTE: There is no output from the revocation request. To verify that the token has been revoked, list the tokens and verify `isExpired` is `true`.
115+
116+
## API Reference
117+
118+
Sourcegraph Analytics API is a RESTful API that allows access to Sourcegraph Analytics data. For authenticating to the API follow the [token creation](#token-creation) instructions.
119+
120+
Export your access token as en environment variable:
121+
```sh
122+
export ACCESS_TOKEN="<ACCESS_TOKEN>"
123+
```
124+
125+
### CSV Export
126+
127+
To generate a CSV export of the data for a specific instance, run the following commands:
128+
```sh
129+
export INSTANCE_URL="<INSTANCE URL>" # e.g. example.sourcegraphcloud.com
130+
131+
curl -X GET "https://analytics.sourcegraph.com/api/reports/by-user-client-date?instanceURL=$INSTANCE_URL" \
132+
-H "Authorization: Bearer $ACCESS_TOKEN"
133+
```
134+
135+
Optional granularity values can be specified. If not specified the default is `by_user_day_client_language`.
136+
- `by_user`,
137+
- `by_user_month`,
138+
- `by_user_day`,
139+
- `by_user_day_client_language`
140+
141+
```sh
142+
export INSTANCE_URL="<INSTANCE_URL>" # e.g. example.sourcegraphcloud.com
143+
export GRANULARITY="<GRANULARITY>"
144+
145+
curl -X GET "https://analytics.sourcegraph.com/api/reports/by-user-client-date?instanceURL=$INSTANCE_URL&granularity=$GRANULARITY" \
146+
-H "Authorization: Bearer $ACCESS_TOKEN"
147+
```

0 commit comments

Comments
 (0)