-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Zaraz Monitoring API #18168
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
Zaraz Monitoring API #18168
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
165788e
Zaraz Monitoring API
bjesus 32b7145
Update src/content/docs/zaraz/monitoring/monitoring-api.mdx
bjesus 7e8b3da
Update src/content/docs/zaraz/monitoring/monitoring-api.mdx
bjesus cc818dc
Update src/content/docs/zaraz/monitoring/monitoring-api.mdx
bjesus 2e8b7bb
Update src/content/docs/zaraz/monitoring/monitoring-api.mdx
bjesus 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
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 |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| --- | ||
| pcx_content_type: how-to | ||
| title: Monitoring API | ||
| sidebar: | ||
| order: 2 | ||
| --- | ||
|
|
||
| import { TabItem, Tabs } from "~/components"; | ||
|
|
||
| The **Zaraz Monitoring API** allows users to retrieve detailed data on Zaraz events through the **GraphQL Analytics API**. Using this API, you can monitor events, pageviews, triggers, actions, and server-side request statuses, including any errors and successes. The data available through the API mirrors what is shown on the Zaraz Monitoring page in the dashboard, but with the API, you can query it programmatically to create alerts and notifications for unexpected deviations | ||
|
|
||
| To get started, you'll need to generate an Analytics API token by following the [API token authentication guide](/analytics/graphql-api/getting-started/authentication/api-token-auth/). | ||
|
|
||
| ## Key Entities | ||
|
|
||
| The Monitoring API includes the following core entities, which each provide distinct insights: | ||
|
|
||
| - **zarazTrackAdaptiveGroups**: Contains data on Zaraz events, such as event counts and timestamps. | ||
| - **zarazActionsAdaptiveGroups**: Provides information on Zaraz Actions. | ||
| - **zarazTriggersAdaptiveGroups**: Tracks data on Zaraz Triggers. | ||
| - **zarazFetchAdaptiveGroups**: Captures server-side request data, including URLs and returning status codes for third-party requests made by Zaraz. | ||
|
|
||
| ## Example GraphQL Queries | ||
|
|
||
| You can construct any query you'd like using the above datasets, but here are some example queries you can use. | ||
|
|
||
| <Tabs syncKey="GQLExamples"><TabItem label="Events"> | ||
|
|
||
| Query for the count of Zaraz events, grouped by time. | ||
|
|
||
| ```graphql | ||
| query AllEvents( | ||
bjesus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $zoneTag: string | ||
| $limit: uint64! | ||
| $start: Date | ||
| $end: Date | ||
| $orderBy: [ZoneZarazTriggersAdaptiveGroupsOrderBy!] | ||
| ) { | ||
| viewer { | ||
| zones(filter: { zoneTag: $zoneTag }) { | ||
| data: zarazTrackAdaptiveGroups( | ||
| limit: $limit | ||
| filter: { datetimeHour_geq: $start, datetimeHour_leq: $end } | ||
| orderBy: [$orderBy] | ||
| ) { | ||
| count | ||
| dimensions { | ||
| ts: datetimeHour | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem><TabItem label="Loads"> | ||
|
|
||
| Query for the count of Zaraz loads, grouped by time. | ||
|
|
||
| ```graphql | ||
| query ZarazLoads( | ||
| $zoneTag: string | ||
| $limit: uint64! | ||
| $start: Date | ||
| $end: Date | ||
| $orderBy: [ZoneZarazTriggersAdaptiveGroupsOrderBy!] | ||
| ) { | ||
| viewer { | ||
| zones(filter: { zoneTag: $zoneTag }) { | ||
| data: zarazTriggersAdaptiveGroups( | ||
| limit: $limit | ||
| filter: { date_geq: $start, date_leq: $end, triggerName: Pageview } | ||
| orderBy: [$orderBy] | ||
| ) { | ||
| count | ||
| dimensions { | ||
| ts: date | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> <TabItem label="Triggers"> | ||
|
|
||
| Query for the total execution count of each trigger processed by Zaraz. | ||
|
|
||
| ```graphql | ||
| query ZarazTriggers( | ||
| $zoneTag: string | ||
| $limit: uint64! | ||
| $start: Date | ||
| $end: Date | ||
| $orderBy: [uint64!] | ||
| ) { | ||
| viewer { | ||
| zones(filter: { zoneTag: $zoneTag }) { | ||
| data: zarazTriggersAdaptiveGroups( | ||
| limit: $limit | ||
| filter: { date_geq: $start, date_leq: $end } | ||
| orderBy: [count_DESC] | ||
| ) { | ||
| count | ||
| dimensions { | ||
| name: triggerName | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem><TabItem label="Erroneous responses"> | ||
|
|
||
| Query for the count of 400 server-side responses, grouped by time and URL. | ||
|
|
||
| ```graphql | ||
| query SucessfulGA4Requests( | ||
bjesus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $zoneTag: string | ||
| $limit: uint64! | ||
| $start: Date | ||
| $end: Date | ||
| $orderBy: [ZoneZarazTriggersAdaptiveGroupsOrderBy!] | ||
| ) { | ||
| viewer { | ||
| zones(filter: { zoneTag: $zoneTag }) { | ||
| data: zarazFetchAdaptiveGroups( | ||
| limit: $limit | ||
| filter: { | ||
| datetimeHour_geq: $start | ||
| datetimeHour_leq: $end | ||
| url_neq: "" | ||
| OR: [{ AND: [{ status: 400 }] }] | ||
bjesus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| orderBy: [$orderBy] | ||
| ) { | ||
| count | ||
| dimensions { | ||
| ts: datetimeHour | ||
| name: url | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem></Tabs> | ||
|
|
||
| ### Variables Example | ||
|
|
||
| ```json | ||
| { | ||
| "zoneTag": "d6dfdf32c704a77ac227243a5eb5ca61", | ||
| "start": "2025-01-01T00:00:00Z", | ||
| "end": "2025-01-30T00:00:00Z", | ||
| "limit": 10000, | ||
| "orderBy": "datetimeHour_ASC" | ||
| } | ||
| ``` | ||
|
|
||
| Be sure to customize the zoneTag to match your specific zone, along with setting the desired start and end dates | ||
|
|
||
| ### Explanation of Parameters | ||
|
|
||
| - **zoneTag**: Unique identifier of your Cloudflare zone. | ||
| - **limit**: Maximum number of results to return. | ||
| - **start** and **end**: Define the date range for the query in ISO 8601 format. | ||
| - **orderBy**: Determines the sorting order, such as by ascending or descending datetime. | ||
|
|
||
| ## Example `curl` Request | ||
|
|
||
| Use this `curl` command to query the Zaraz Monitoring API for the number of events processed by Zaraz. Replace `$TOKEN` with your API token, `$ZONE_TAG` with your zone tag, and adjust the start and end dates as needed. | ||
|
|
||
| ```bash | ||
| curl -X POST https://api.cloudflare.com/client/v4/graphql \ | ||
| -H "Content-Type: application/json" \ | ||
| -H "Authorization: Bearer $TOKEN" \ | ||
| -d '{ | ||
| "query": "query AllEvents($zoneTag: String!, $limit: Int!, $start: Date, $end: Date, $orderBy: [ZoneZarazTriggersAdaptiveGroupsOrderBy!]) { viewer { zones(filter: { zoneTag: $zoneTag }) { data: zarazTrackAdaptiveGroups( limit: $limit filter: { datetimeHour_geq: $start datetimeHour_leq: $end } orderBy: [$orderBy] ) { count dimensions { ts: datetimeHour } } } } }", | ||
| "variables": { | ||
| "zoneTag": "$ZONE_TAG", | ||
| "start": "2025-01-01T00:00:00Z", | ||
| "end": "2025-01-30T00:00:00Z", | ||
| "limit": 10000, | ||
| "orderBy": "datetimeHour_ASC" | ||
| } | ||
| }' | ||
| ``` | ||
|
|
||
| ### Explanation of the `curl` Components | ||
|
|
||
| - **Authorization**: The `Authorization` header requires a Bearer token. Replace `$TOKEN` with your actual API token. | ||
| - **Content-Type**: Set `application/json` to indicate a JSON payload. | ||
| - **Data Payload**: This payload includes the GraphQL query and variable parameters, such as `zoneTag`, `start`, `end`, `limit`, and `orderBy`. | ||
|
|
||
| This `curl` example will return a JSON response containing event counts and timestamps within the specified date range. Modify the `variables` values as needed for your use case. | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| Refer to the [full GraphQL Analytics API documentation](/analytics/graphql-api/) for more details on available fields, filters, and further customization options for Zaraz Monitoring API queries. | ||
Oops, something went wrong.
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.