> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sapt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get analytics data

> Get analytics data from all configured sources (Cloudflare, GA4, GSC). Returns partial data with errors if some sources fail.



## OpenAPI

````yaml https://api.sapt.ai/openapi.json get /web-analytics/{projectId}
openapi: 3.1.0
info:
  title: Sapt Platform API
  version: 1.0.0
  description: >-
    API for Sapt platform - project management, authentication, and email
    services
servers:
  - url: https://api.sapt.ai
    description: Production
  - url: http://localhost:8787
    description: Local development
security: []
tags:
  - name: Accounts
    description: >-
      The social accounts connected to a project. Start here — the `id` of an
      account is the `socialAccountId` that every posting, scheduling and
      analytics call takes.
  - name: Actions
  - name: Ads
  - name: Agents
  - name: Analytics
    description: >-
      Account- and post-level organic performance for connected Instagram and
      Facebook accounts.
  - name: Assets
  - name: Auth
  - name: CMS
  - name: CRM
  - name: Calendar
  - name: Comments
    description: >-
      Read, reply to, hide and delete comments on published Instagram and
      Facebook posts.
  - name: Content Calendar
    description: >-
      Create, schedule, update and publish organic posts, and stage the media
      they carry. Publishing a post whose status is `failed` retries it.
  - name: Contracts
  - name: Conversions
    description: >-
      Meta server-side Conversions API (CAPI): discover pixels, connect a pixel
      + CAPI token, and send deduped server-side conversions.
  - name: Dashboard Sidebar
  - name: Emails
  - name: Engagement
    description: >-
      Act as the Page or account on published posts: comment, like, unlike, and
      delete a published post.
  - name: Geo
  - name: Google Ads
  - name: Google Analytics
  - name: Google Business
  - name: Integrations
    description: >-
      Connect third-party providers (Meta, Gmail, Google Business Profile, …).
      List providers, mint OAuth connect links, and poll connection status.
  - name: Invitations
  - name: Memory
  - name: OAuth Clients
  - name: Project Roles
  - name: Project Templates
  - name: Projects
  - name: Schedules
  - name: Service Accounts
  - name: Socials
    description: >-
      Organic social: the connected accounts, the content calendar, media
      staging, publishing, comments and engagement across Instagram, Facebook,
      TikTok, YouTube and Google Business Profile.
  - name: Team
  - name: Users
  - name: Web Analytics
  - name: Workflows
paths:
  /web-analytics/{projectId}:
    get:
      tags:
        - Web Analytics
      summary: Get analytics data
      description: >-
        Get analytics data from all configured sources (Cloudflare, GA4, GSC).
        Returns partial data with errors if some sources fail.
      operationId: getWebAnalytics
      parameters:
        - schema:
            type: string
            format: uuid
            example: 123e4567-e89b-12d3-a456-426614174000
          required: true
          name: projectId
          in: path
        - schema:
            type: string
            pattern: ^\d{4}-\d{2}-\d{2}$
            description: Start date in YYYY-MM-DD format
            example: '2024-01-01'
          required: true
          description: Start date in YYYY-MM-DD format
          name: startDate
          in: query
        - schema:
            type: string
            pattern: ^\d{4}-\d{2}-\d{2}$
            description: End date in YYYY-MM-DD format
            example: '2024-01-31'
          required: true
          description: End date in YYYY-MM-DD format
          name: endDate
          in: query
      responses:
        '200':
          description: Analytics data
          content:
            application/json:
              schema:
                type: object
                properties:
                  projectId:
                    type: string
                  dateRange:
                    type: object
                    properties:
                      startDate:
                        type: string
                      endDate:
                        type: string
                    required:
                      - startDate
                      - endDate
                  ga4:
                    type:
                      - object
                      - 'null'
                    properties:
                      source:
                        type: string
                        enum:
                          - ga4
                      totalPageviews:
                        type: integer
                      totalVisitors:
                        type: integer
                      totalVisits:
                        type: integer
                      bounceRate:
                        type: number
                      avgSessionDuration:
                        type: number
                      dailyMetrics:
                        type: array
                        items:
                          type: object
                          properties:
                            date:
                              type: string
                            pageviews:
                              type: integer
                            visitors:
                              type: integer
                            visits:
                              type: integer
                            bounceRate:
                              type: number
                            avgSessionDuration:
                              type: number
                          required:
                            - date
                            - pageviews
                            - visitors
                            - visits
                      topPages:
                        type: array
                        items:
                          type: object
                          properties:
                            path:
                              type: string
                            pageviews:
                              type: integer
                            visitors:
                              type: integer
                          required:
                            - path
                            - pageviews
                            - visitors
                      topReferrers:
                        type: array
                        items:
                          type: object
                          properties:
                            referrer:
                              type: string
                            visits:
                              type: integer
                          required:
                            - referrer
                            - visits
                      topCountries:
                        type: array
                        items:
                          type: object
                          properties:
                            country:
                              type: string
                            countryName:
                              type: string
                            visitors:
                              type: integer
                          required:
                            - country
                            - visitors
                      trafficSources:
                        type: array
                        items:
                          type: object
                          properties:
                            source:
                              type: string
                            medium:
                              type: string
                            sessions:
                              type: integer
                            users:
                              type: integer
                            bounceRate:
                              type: number
                          required:
                            - source
                            - medium
                            - sessions
                            - users
                      landingPages:
                        type: array
                        items:
                          type: object
                          properties:
                            path:
                              type: string
                            sessions:
                              type: integer
                            users:
                              type: integer
                            bounceRate:
                              type: number
                            avgSessionDuration:
                              type: number
                          required:
                            - path
                            - sessions
                            - users
                      outboundLinks:
                        type: array
                        items:
                          type: object
                          properties:
                            url:
                              type: string
                            domain:
                              type: string
                            clicks:
                              type: integer
                          required:
                            - url
                            - domain
                            - clicks
                      devices:
                        type: array
                        items:
                          type: object
                          properties:
                            device:
                              type: string
                              enum:
                                - desktop
                                - mobile
                                - tablet
                            sessions:
                              type: integer
                            users:
                              type: integer
                            bounceRate:
                              type: number
                          required:
                            - device
                            - sessions
                            - users
                      browsers:
                        type: array
                        items:
                          type: object
                          properties:
                            browser:
                              type: string
                            users:
                              type: integer
                          required:
                            - browser
                            - users
                      operatingSystems:
                        type: array
                        items:
                          type: object
                          properties:
                            os:
                              type: string
                            users:
                              type: integer
                          required:
                            - os
                            - users
                      usStates:
                        type: array
                        items:
                          type: object
                          properties:
                            region:
                              type: string
                            regionCode:
                              type: string
                            visitors:
                              type: integer
                          required:
                            - region
                            - visitors
                      fetchedAt:
                        type: string
                        format: date-time
                    required:
                      - source
                      - totalPageviews
                      - totalVisitors
                      - totalVisits
                      - dailyMetrics
                      - fetchedAt
                  gsc:
                    type:
                      - object
                      - 'null'
                    properties:
                      totalClicks:
                        type: integer
                      totalImpressions:
                        type: integer
                      averageCtr:
                        type: number
                      averagePosition:
                        type: number
                      dailyMetrics:
                        type: array
                        items:
                          type: object
                          properties:
                            date:
                              type: string
                            clicks:
                              type: integer
                            impressions:
                              type: integer
                            ctr:
                              type: number
                            position:
                              type: number
                          required:
                            - date
                            - clicks
                            - impressions
                            - ctr
                            - position
                      topQueries:
                        type: array
                        items:
                          type: object
                          properties:
                            query:
                              type: string
                            clicks:
                              type: integer
                            impressions:
                              type: integer
                            ctr:
                              type: number
                            position:
                              type: number
                          required:
                            - query
                            - clicks
                            - impressions
                            - ctr
                            - position
                      topPages:
                        type: array
                        items:
                          type: object
                          properties:
                            page:
                              type: string
                            clicks:
                              type: integer
                            impressions:
                              type: integer
                            ctr:
                              type: number
                            position:
                              type: number
                          required:
                            - page
                            - clicks
                            - impressions
                            - ctr
                            - position
                      fetchedAt:
                        type: string
                        format: date-time
                    required:
                      - totalClicks
                      - totalImpressions
                      - averageCtr
                      - averagePosition
                      - dailyMetrics
                      - topQueries
                      - topPages
                      - fetchedAt
                  errors:
                    type: array
                    items:
                      type: object
                      properties:
                        source:
                          type: string
                          enum:
                            - ga4
                            - gsc
                        message:
                          type: string
                        code:
                          type: string
                      required:
                        - source
                        - message
                  fetchedAt:
                    type: string
                    format: date-time
                required:
                  - projectId
                  - dateRange
                  - ga4
                  - gsc
                  - fetchedAt
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT token obtained from /api/auth/token endpoint. Token is verified
        using JWKS and must include a valid user identifier.

````