-
Couldn't load subscription status.
- Fork 76
Add Analytics access token docs #1160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4affb63
Add Analytics access token docs
jac acfdaf3
feedback
jac 21c33ed
session cookie screenshot
jac 702ed30
Update docs/analytics/cloud.mdx
jac bbb84f7
Update docs/analytics/cloud.mdx
jac 43a93cc
Update docs/analytics/cloud.mdx
jac 0ffcbc8
Update docs/analytics/cloud.mdx
jac 2de3c9d
remove $
jac ef3379e
add instructions for using the api
jac caa2acc
tweak
jac c5ab5ab
Update docs/analytics/cloud.mdx
jac c8ecda5
Apply suggestions from code review
jac 0e477e0
Add improvemets and callouts
MaedahBatool c81f64b
consistent indentation
jac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -11,8 +11,137 @@ To enable Sourcegraph Analytics: | |
| - Create an account on [Sourcegraph Accounts](https://accounts.sourcegraph.com/), or find the email address associated with your existing account. | ||
| - Contact your Sourcegraph Technical Advisor or point of contact (or email us at [email protected] if you don't know your contact), provide them with the email address you used to register above and ask for access to Sourcegraph Analytics. | ||
| - They will validate your account and link it to your Sourcegraph Enterprise instance's usage metrics. | ||
| - Sign in to [Sourcegraph Analytics](https://cody-analytics.sourcegraph.com). | ||
| - Sign in to [Sourcegraph Analytics](https://analytics.sourcegraph.com). | ||
|
|
||
| ## Data export | ||
|
|
||
| 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. | ||
| 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. | ||
|
|
||
|
|
||
| ## Access Tokens | ||
|
|
||
| For Sourcegraph Analytics, you can generate an access token for programmatic access. Tokens are long lived with an optional expiry and have the same permissions to access instance data as the user who created them. | ||
|
|
||
| ### Token management APIs | ||
|
|
||
| Token management is currently only available via the Sourcegraph Analytics API. | ||
| Authentication for token management APIs is done via the `cas` session cookie. | ||
|
|
||
| - Sign in to [Sourcegraph Analytics](https://analytics.sourcegraph.com). | ||
| - Retrieve your session cookie, `cas`, from your browser's developer tools. | ||
jac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|  | ||
| - Export the cookie as an environment variable to use in the following commands: | ||
| ```sh | ||
| export CAS_COOKIE="<CAS_COOKIE_VALUE>" | ||
| ``` | ||
|
|
||
| #### Token creation | ||
|
|
||
| Create the token by running the following command: | ||
|
|
||
| ```sh | ||
| curl -X POST https://analytics.sourcegraph.com/api/service-access-tokens \ | ||
| -H "Content-Type: application/json" \ | ||
| -H "Cookie: cas=$CAS_COOKIE" \ | ||
| -d '{}' | ||
|
|
||
| # Optionally include displayName, expiresAt, or both in the request body. | ||
| # If expiresAt is not provided, the token will never expire and must be revoked manually. | ||
| # -d '{"displayName": "My Analytics Token", "expiresAt": "2025-12-31T23:59:59Z"}' | ||
| ``` | ||
|
|
||
| The response will include the token ID, secret, creation date, and, if provided, display name and expiration date. For example: | ||
|
|
||
| ```json | ||
| { | ||
| "id": "4cf96e80-d5f3-4af0-a28d-3c70ba97abb4", | ||
| "displayName": "My Analytics Token", | ||
| "secret": "sams_at_abcdefghijk", | ||
| "createdAt": "2025-05-28T12:00:00Z", | ||
| "expiresAt": "2025-12-31T23:59:59Z" | ||
| } | ||
| ``` | ||
|
|
||
| #### Token listing | ||
|
|
||
| List the tokens by running the following command: | ||
| ```sh | ||
| curl -X GET https://analytics.sourcegraph.com/api/service-access-tokens \ | ||
| -H "Cookie: cas=$CAS_COOKIE" | ||
| ``` | ||
| Each token in the response will include the token ID, creation date, a boolean indicating if the token is expired, and if provided: display name and expiration date. For example: | ||
| ```json | ||
| { | ||
| "tokens": [ | ||
| { | ||
| "id": "5a140b00-3a79-497d-bcfb-c1d2e3d8c747", | ||
| "displayName": "My Analytics Token", | ||
| "createdAt": "2025-05-27T12:00:00Z", | ||
| "expiresAt": "2025-05-27T13:00:00Z", | ||
| "isExpired": true | ||
| }, | ||
| { | ||
| "id": "eaf8a6f1-1302-43f6-a9ad-f9862d75e959", | ||
| "createdAt": "2025-05-28T12:30:00Z", | ||
| "expiresAt": "2025-05-28T13:30:00Z", | ||
| "isExpired": true | ||
| }, | ||
| { | ||
| "id": "d7df6636-99d0-4266-9f32-a2fb7ccbfcd5", | ||
| "displayName": "My Analytics Token 2", | ||
| "createdAt": "2025-05-28T15:00:00Z", | ||
| "isExpired": false | ||
| }, | ||
| { | ||
| "id": "8ea63000-a164-44ca-8834-bb71e9b788fb", | ||
| "createdAt": "2025-05-28T15:30:00Z", | ||
| "isExpired": false | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| #### Token revocation | ||
|
|
||
| Revoke a token by running the following commands: | ||
| ```sh | ||
| export TOKEN_ID="<TOKEN_ID>" | ||
|
|
||
| curl -X DELETE https://analytics.sourcegraph.com/api/service-access-tokens/$TOKEN_ID \ | ||
| -H "Cookie: cas=$CAS_COOKIE" | ||
| ``` | ||
|
|
||
| > 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`. | ||
|
|
||
| ## API Reference | ||
jac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
|
||
| Export your access token as en environment variable: | ||
| ```sh | ||
| export ACCESS_TOKEN="<ACCESS_TOKEN>" | ||
| ``` | ||
|
|
||
| ### CSV Export | ||
jac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To generate a CSV export of the data for a specific instance, run the following commands: | ||
| ```sh | ||
| export INSTANCE_URL="<INSTANCE URL>" # e.g. example.sourcegraphcloud.com | ||
|
|
||
| curl -X GET "https://analytics.sourcegraph.com/api/reports/by-user-client-date?instanceURL=$INSTANCE_URL" \ | ||
| -H "Authorization: Bearer $ACCESS_TOKEN" | ||
| ``` | ||
|
|
||
| Optional granularity values can be specified. If not specified the default is `by_user_day_client_language`. | ||
| - `by_user`, | ||
| - `by_user_month`, | ||
| - `by_user_day`, | ||
| - `by_user_day_client_language` | ||
|
|
||
| ```sh | ||
| export INSTANCE_URL="<INSTANCE_URL>" # e.g. example.sourcegraphcloud.com | ||
| export GRANULARITY="<GRANULARITY>" | ||
|
|
||
| curl -X GET "https://analytics.sourcegraph.com/api/reports/by-user-client-date?instanceURL=$INSTANCE_URL&granularity=$GRANULARITY" \ | ||
| -H "Authorization: Bearer $ACCESS_TOKEN" | ||
| ``` | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -35881,7 +35881,7 @@ Enterprise customers can use Sourcegraph Analytics to get a clear view of usage, | |
|
|
||
| ## Sourcegraph Cloud Analytics | ||
|
|
||
| [Sourcegraph Cloud](/cloud) customers can use our managed [cloud analytics service](https://cody-analytics.sourcegraph.com) for Cody and Code Search usage data. | ||
| [Sourcegraph Cloud](/cloud) customers can use our managed [cloud analytics service](https://analytics.sourcegraph.com) for Cody and Code Search usage data. | ||
| Self-hosted customers can also use this service, but they must | ||
|
|
||
| Upgrade to a supported version of Sourcegraph (5.9+) | ||
|
|
@@ -36005,7 +36005,7 @@ To enable Sourcegraph Analytics: | |
| - Create an account on [Sourcegraph Accounts](https://accounts.sourcegraph.com/), or find the email address associated with your existing account. | ||
| - Contact your Sourcegraph Technical Advisor or point of contact (or email us at [email protected] if you don't know your contact), provide them with the email address you used to register above and ask for access to Sourcegraph Analytics. | ||
| - They will validate your account and link it to your Sourcegraph Enterprise instance's usage metrics. | ||
| - Sign in to [Sourcegraph Analytics](https://cody-analytics.sourcegraph.com). | ||
| - Sign in to [Sourcegraph Analytics](https://analytics.sourcegraph.com). | ||
|
|
||
| ## Data export | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.